Isis 3 Programmer Reference
MeasureTableDelegate.cpp
1 #include "IsisDebug.h"
2 
3 #include "MeasureTableDelegate.h"
4 
5 #include <iostream>
6 
7 #include <QComboBox>
8 #include <QLineEdit>
9 #include <QMessageBox>
10 #include <QString>
11 #include <QVariant>
12 #include <QWidget>
13 
14 #include "ControlMeasure.h"
15 #include "ControlMeasure.h"
16 #include "IException.h"
17 #include "IString.h"
18 
19 #include "AbstractMeasureItem.h"
20 #include "AbstractTreeItem.h"
21 #include "MeasureTableModel.h"
22 #include "TableColumn.h"
23 
24 namespace Isis {
25  MeasureTableDelegate::MeasureTableDelegate() {
26  }
27 
28 
29  MeasureTableDelegate::~MeasureTableDelegate() {
30  }
31 
32 
33  QWidget *MeasureTableDelegate::getWidget(TableColumn const *col)
34  const {
35  AbstractMeasureItem::Column column =
36  AbstractMeasureItem::getColumn(col->getTitle());
37 
38  switch (column) {
39  case AbstractMeasureItem::Ignored:
40  case AbstractMeasureItem::EditLock: {
41  QComboBox *combo = new QComboBox;
42 
43  combo->insertItem(0, "Yes");
44  combo->insertItem(1, "No");
45  return combo;
46  }
47  case AbstractMeasureItem::Type: {
48  QComboBox *combo = new QComboBox;
49 
50  combo->insertItem(0, "Candidate");
51  combo->insertItem(1, "Manual");
52  combo->insertItem(2, "RegisteredPixel");
53  combo->insertItem(3, "RegisteredSubPixel");
54  return combo;
55  }
56  default: {
57  QLineEdit *lineEdit = new QLineEdit;
58  return lineEdit;
59  }
60  }
61 
62  IString msg = "Could not create delegate widget for column ["
63  + col->getTitle() + "]";
64  throw IException(IException::Programmer, msg, _FILEINFO_);
65  }
66 
67 
68  void MeasureTableDelegate::readData(QWidget *widget,
69  AbstractTreeItem *row, TableColumn const *col) const {
70  AbstractMeasureItem::Column column =
71  AbstractMeasureItem::getColumn(col->getTitle());
72 
73  QString data = row->getFormattedData(col->getTitle());
74  ASSERT(row->getPointerType() == AbstractTreeItem::Measure);
75  ControlMeasure *measure = (ControlMeasure *)row->getPointer();
76 
77  switch (column) {
78  case AbstractMeasureItem::EditLock: {
79  QComboBox *combo = static_cast< QComboBox * >(widget);
80  if (measure->IsEditLocked())
81  combo->setCurrentIndex(0);
82  else
83  combo->setCurrentIndex(1);
84  break;
85  }
86  case AbstractMeasureItem::Ignored: {
87  QComboBox *combo = static_cast< QComboBox * >(widget);
88  if (measure->IsIgnored())
89  combo->setCurrentIndex(0);
90  else
91  combo->setCurrentIndex(1);
92  break;
93  }
94  case AbstractMeasureItem::Type: {
95  QComboBox *combo = static_cast< QComboBox * >(widget);
96  combo->setCurrentIndex((int) measure->StringToMeasureType(data));
97  break;
98  }
99  default: {
100  QLineEdit *lineEdit = static_cast< QLineEdit * >(widget);
101  lineEdit->setText(data);
102  }
103  }
104  }
105 
106 
107  void MeasureTableDelegate::readData(QWidget *widget,
108  AbstractTreeItem *row, TableColumn const *col,
109  QString newData) const {
110  AbstractMeasureItem::Column column =
111  AbstractMeasureItem::getColumn(col->getTitle());
112 
113  QString data = row->getFormattedData(col->getTitle());
114  ASSERT(row->getPointerType() == AbstractTreeItem::Measure);
115  ControlMeasure *measure = (ControlMeasure *) row->getPointer();
116 
117  switch (column) {
118  case AbstractMeasureItem::EditLock: {
119  QComboBox *combo = static_cast< QComboBox * >(widget);
120 
121  if (measure->IsEditLocked())
122  combo->setCurrentIndex(0);
123  else
124  combo->setCurrentIndex(1);
125 
126  if (QString("yes").startsWith(newData.toLower()))
127  combo->setCurrentIndex(0);
128  else if (QString("no").startsWith(newData.toLower()))
129  combo->setCurrentIndex(1);
130  }
131  break;
132 
133  case AbstractMeasureItem::Ignored: {
134  QComboBox *combo = static_cast< QComboBox * >(widget);
135 
136  if (measure->IsIgnored())
137  combo->setCurrentIndex(0);
138  else
139  combo->setCurrentIndex(1);
140 
141  if (QString("yes").startsWith(newData.toLower()))
142  combo->setCurrentIndex(0);
143  if (QString("no").startsWith(newData.toLower()))
144  combo->setCurrentIndex(1);
145  }
146  break;
147 
148  case AbstractMeasureItem::Type: {
149  QComboBox *combo = static_cast< QComboBox * >(widget);
150 
151  combo->setCurrentIndex((int) measure->StringToMeasureType(data));
152 
153  for (int i = combo->count() - 1; i >= 0; --i)
154  if (combo->itemText(i).toLower().startsWith(newData.toLower()))
155  combo->setCurrentIndex(i);
156  }
157  break;
158 
159  default: {
160  QLineEdit *lineEdit = static_cast< QLineEdit * >(widget);
161  lineEdit->setText(newData);
162  }
163  }
164  }
165 
166 
167  void MeasureTableDelegate::saveData(QWidget *widget,
168  AbstractTreeItem *row, TableColumn const *col) const {
169  AbstractMeasureItem::Column column =
170  AbstractMeasureItem::getColumn(col->getTitle());
171  QString newData;
172 
173  switch (column) {
174  case AbstractMeasureItem::EditLock:
175  case AbstractMeasureItem::Ignored:
176  case AbstractMeasureItem::Type: {
177  QComboBox *combo = static_cast< QComboBox * >(widget);
178  newData = combo->currentText();
179  break;
180  }
181  default: {
182  QLineEdit *lineEdit = static_cast< QLineEdit * >(widget);
183  newData = lineEdit->text();
184  }
185  }
186 
187  QString warningText = MeasureTableModel::getMeasureWarningMessage(
188  row, col, newData);
189 
190  bool changeData = true;
191 
192  if (!warningText.isEmpty()) {
193  QMessageBox::StandardButton status = QMessageBox::warning(
194  NULL, "Change cell?", warningText, QMessageBox::Yes |
195  QMessageBox::No);
196 
197  changeData = (status == QMessageBox::Yes);
198  }
199 
200  if (changeData)
201  row->setData(col->getTitle(), newData);
202  }
203 }
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31