USGS

Isis 3.0 Object Programmers' Reference

Home

QnetCubeNameFilter.cpp
1 #include "QnetCubeNameFilter.h"
2 
3 #include <QGridLayout>
4 #include <QLabel>
5 #include <QLineEdit>
6 #include <QMessageBox>
7 #include <QRegExp>
8 
9 #include "QnetNavTool.h"
10 #include "ControlNet.h"
11 #include "SerialNumberList.h"
12 
13 using namespace std;
14 
15 namespace Isis {
27  QnetCubeNameFilter::QnetCubeNameFilter(QnetNavTool *navTool, QWidget *parent) :
28  QnetFilter(navTool, parent) {
29  p_cubeNameEdit = NULL;
30  // Create the components for the filter window
31  QLabel *label = new QLabel("Filter by cube name (Regular Expressions");
32  p_cubeNameEdit = new QLineEdit;
33 
34  // Create the layout and add the components to it
35  QVBoxLayout *vertLayout = new QVBoxLayout;
36  vertLayout->addWidget(label);
37  vertLayout->addWidget(p_cubeNameEdit);
38  vertLayout->addStretch();
39  setLayout(vertLayout);
40  }
41 
54  // Make sure we have a list of images to filter
55  if (serialNumberList() == NULL) {
56  QMessageBox::information((QWidget *)parent(),
57  "Error", "No cubes to filter");
58  return;
59  }
60 
61  // Make sure the user has entered a regular expression for filtering
62  QRegExp rx(p_cubeNameEdit->text());
63  rx.setPatternSyntax(QRegExp::Wildcard);
64  if (rx.isEmpty()) {
65  QMessageBox::information((QWidget *)parent(),
66  "Error", "Enter search string");
67  return;
68  }
69 
70 
71  // Loop through each image in the filtered list
72  // Loop in reverse order since removal list of elements affects index number
73  for (int i = filteredImages().size() - 1; i >= 0; i--) {
74  QString tempFileName = serialNumberList()->fileName(filteredImages()[i]);
75  // this name contains the string, keep it in the filtered list
76  if (rx.indexIn(QString(tempFileName)) != -1) {
77  continue;
78  }
79  // if there is no match, remove image from filtered list
80  else
81  filteredImages().removeAt(i);
82 
83  }
84  // Tell the navtool a list has been filtered and it needs to update
85  emit filteredListModified();
86  return;
87 
88  }
89 }