USGS

Isis 3.0 Application Source Code Reference

Home

QnetCubeNameFilter.cpp

Go to the documentation of this file.
00001 #include <QGridLayout>
00002 #include <QMessageBox>
00003 #include <QRegExp>
00004 #include "QnetCubeNameFilter.h"
00005 #include "QnetNavTool.h"
00006 #include "ControlNet.h"
00007 #include "SerialNumberList.h"
00008 
00009 #include "qnet.h"
00010 
00011 using namespace Isis::Qnet;
00012 using namespace std;
00013 
00014 namespace Isis {
00015   /**
00016    * Contructor for the Cube Image filter.  It creates the Cube Name filter window
00017    * found in the navtool
00018    *
00019    * @param parent The parent widget for the
00020    *               cube points filter
00021    * @internal
00022    *   @history 2010-06-03 Jeannie Walldren - Initialized pointers
00023    *                          to null
00024    *
00025    */
00026   QnetCubeNameFilter::QnetCubeNameFilter(QWidget *parent) : QnetFilter(parent) {
00027     p_cubeNameEdit = NULL;
00028     // Create the components for the filter window
00029     QLabel *label = new QLabel("Filter by cube name (Regular Expressions");
00030     p_cubeNameEdit = new QLineEdit();
00031 
00032     // Create the layout and add the components to it
00033     QVBoxLayout *vertLayout = new QVBoxLayout();
00034     vertLayout->addWidget(label);
00035     vertLayout->addWidget(p_cubeNameEdit);
00036     vertLayout->addStretch();
00037     this->setLayout(vertLayout);
00038   }
00039 
00040   /**
00041    * Filters a list of images looking for cube names using the regular expression
00042    * entered.  The filtered list will appear in the navtools cube list display.
00043    * @internal
00044    *   @history 2009-01-08 Jeannie Walldren - Modified to create
00045    *                          new filtered list from images in the
00046    *                          existing filtered list. Previously,
00047    *                          a new filtered list was created from
00048    *                          the entire serial number list each
00049    *                          time.
00050    */
00051   void QnetCubeNameFilter::filter() {
00052     // Make sure we have a list of images to filter
00053     if (g_serialNumberList == NULL) {
00054       QMessageBox::information((QWidget *)parent(),
00055           "Error", "No cubes to filter");
00056       return;
00057     }
00058 
00059     // Make sure the user has entered a regular expression for filtering
00060     QRegExp rx(p_cubeNameEdit->text());
00061     rx.setPatternSyntax(QRegExp::Wildcard);
00062     if (rx.isEmpty()) {
00063       QMessageBox::information((QWidget *)parent(),
00064           "Error", "Enter search string");
00065       return;
00066     }
00067 
00068 
00069     // Loop through each image in the filtered list
00070     // Loop in reverse order since removal list of elements affects index number
00071     for (int i = g_filteredImages.size() - 1; i >= 0; i--) {
00072       string tempFilename = g_serialNumberList->Filename(g_filteredImages[i]);
00073       // this name contains the string, keep it in the filtered list
00074       if (rx.indexIn(QString(tempFilename.c_str())) != -1) {
00075         continue;
00076       }
00077       // if there is no match, remove image from filtered list
00078       else
00079         g_filteredImages.removeAt(i);
00080 
00081     }
00082     // Tell the navtool a list has been filtered and it needs to update
00083     emit filteredListModified();
00084     return;
00085 
00086   }
00087 }