USGS

Isis 3.0 Object Programmers' Reference

Home

QnetNewMeasureDialog.cpp
1 #include "QnetNewMeasureDialog.h"
2 
3 #include <algorithm>
4 #include <string>
5 
6 #include <QtGui>
7 
8 #include "ControlPoint.h"
9 #include "IString.h"
10 #include "QnetTool.h"
11 #include "SerialNumberList.h"
12 
13 namespace Isis {
24  QWidget *parent) : QDialog(parent) {
25  m_fileList = NULL;
26  m_okButton = NULL;
27  m_qnetTool = qnetTool;
28 
29  QLabel *listLabel = new QLabel("Select Files:");
30 
31  m_fileList = new QListWidget;
32  m_fileList->setSelectionMode(QAbstractItemView::ExtendedSelection);
33 
34  // Create OK & Cancel buttons
35  m_okButton = new QPushButton("OK");
36  //m_okButton->setEnabled(false);
37  QPushButton *cancelButton = new QPushButton("Cancel");
38  QHBoxLayout *buttonLayout = new QHBoxLayout;
39  buttonLayout->addWidget(m_okButton);
40  buttonLayout->addWidget(cancelButton);
41 
42  connect(m_okButton, SIGNAL(clicked()), this, SLOT(accept()));
43  connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
44 
45  QVBoxLayout *vLayout = new QVBoxLayout;
46  vLayout->addWidget(listLabel);
47  vLayout->addWidget(m_fileList);
48  vLayout->addLayout(buttonLayout);
49 
50  setLayout(vLayout);
51  setWindowTitle("Add Measures to ControlPoint");
52 
53  }
54 
55 
64  QStringList pointFiles) {
65  int bottomMostSelectedItemIndex = 0;
66 
67  // Add all entries in the SerialNumberList
68  SerialNumberList *snList = m_qnetTool->serialNumberList();
69  for (int i = 0; i < snList->size(); i++) {
70  QString curSerialNum = snList->serialNumber(i);
71 
72  // Don't add if already in this point
73  if (point.HasSerialNumber(curSerialNum))
74  continue;
75 
76  // build new item...
77  QString label(snList->fileName(i));
78  QListWidgetItem *item = new QListWidgetItem(label);
79 
80  // if this entry of the SerialNumberList is also in the pointFiles then
81  // mark it as selected and insert after the last selected item (toward
82  // the top, otherwise add it to the end
83  if (pointFiles.contains(label)) {
84  m_fileList->insertItem(bottomMostSelectedItemIndex++, item);
85  item->setSelected(true);
86  }
87  else {
88  m_fileList->addItem(item);
89  }
90  }
91  }
92 
93 
94  QStringList QnetNewMeasureDialog::selectedFiles() const {
95  QStringList result;
96 
97  foreach (QListWidgetItem *fileItem, m_fileList->selectedItems()) {
98  result.append(fileItem->text());
99  }
100 
101  return result;
102  }
103 
104 
105  void QnetNewMeasureDialog::enableOkButton(const QString &text) {
106  m_okButton->setEnabled(!text.isEmpty());
107  }
108 }