Isis 3 Programmer Reference
PointTableDelegate.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "IsisDebug.h"
10 
11 #include "PointTableDelegate.h"
12 
13 #include <iostream>
14 
15 #include <QComboBox>
16 #include <QLineEdit>
17 #include <QMessageBox>
18 #include <QString>
19 #include <QWidget>
20 
21 #include "ControlMeasure.h"
22 #include "ControlPoint.h"
23 #include "IException.h"
24 
25 #include "AbstractPointItem.h"
26 #include "AbstractTreeItem.h"
27 #include "PointTableModel.h"
28 #include "TableColumn.h"
29 
30 namespace Isis {
31  PointTableDelegate::PointTableDelegate() {
32  }
33 
34 
35  PointTableDelegate::~PointTableDelegate() {
36  }
37 
38 
39  QWidget *PointTableDelegate::getWidget(TableColumn const *col) const {
40  AbstractPointItem::Column column =
41  AbstractPointItem::getColumn(col->getTitle());
42 
43  switch (column) {
44  // handle combo box cases
45  case AbstractPointItem::PointType:
46  case AbstractPointItem::EditLock:
47  case AbstractPointItem::Ignored:
48  case AbstractPointItem::Reference:
49  case AbstractPointItem::APrioriSPSource:
50  case AbstractPointItem::APrioriRadiusSource: {
51  QComboBox *combo = new QComboBox;
52 
53  switch (column) {
54  case AbstractPointItem::PointType:
55  for (int i = 0; i < ControlPoint::PointTypeCount; i++) {
56  combo->insertItem(i, ControlPoint::PointTypeToString(
58  }
59  break;
60  case AbstractPointItem::EditLock:
61  combo->insertItem(0, "Yes");
62  combo->insertItem(1, "No");
63  break;
64  case AbstractPointItem::Ignored:
65  combo->insertItem(0, "Yes");
66  combo->insertItem(1, "No");
67  break;
68  case AbstractPointItem::Reference:
69  // Reference depends on possibilities, not static, so will be
70  // populated later in readData(...).
71  break;
72  case AbstractPointItem::APrioriSPSource:
73  combo->insertItem(0, "None");
74  combo->insertItem(1, "User");
75  combo->insertItem(2, "AverageOfMeasures");
76  combo->insertItem(3, "Reference");
77  combo->insertItem(4, "Basemap");
78  combo->insertItem(5, "BundleSolution");
79  break;
80  case AbstractPointItem::APrioriRadiusSource:
81  combo->insertItem(0, "None");
82  combo->insertItem(1, "User");
83  combo->insertItem(2, "AverageOfMeasures");
84  combo->insertItem(3, "Ellipsoid");
85  combo->insertItem(4, "DEM");
86  combo->insertItem(5, "BundleSolution");
87  break;
88  default:
89  break;
90  }
91 
92  return combo;
93  }
94 
95  // handle line edit cases
96  default:
97  return new QLineEdit();
98  }
99 
100  QString msg = "Could not create delegate widget for column ["
101  + col->getTitle() + "]";
102  throw IException(IException::Programmer, msg, _FILEINFO_);
103  }
104 
105 
106  void PointTableDelegate::readData(QWidget *widget,
107  AbstractTreeItem *row, TableColumn const *col) const {
108  QString columnTitle = col->getTitle();
109  AbstractPointItem::Column column =
110  AbstractPointItem::getColumn(columnTitle);
111 
112  QString data = row->getFormattedData(columnTitle);
113  ASSERT(row->getPointerType() == AbstractTreeItem::Point);
114  ControlPoint *point = (ControlPoint *)row->getPointer();
115 
116  switch (column) {
117  case AbstractPointItem::Reference: {
118  QComboBox *combo = static_cast< QComboBox * >(widget);
119 
120  for (int i = 0; i < point->GetNumMeasures(); i++)
121  combo->insertItem(i, point->GetMeasure(i)->GetCubeSerialNumber());
122  combo->setCurrentIndex(point->IndexOfRefMeasure());
123  }
124  break;
125 
126  case AbstractPointItem::PointType:
127  case AbstractPointItem::EditLock:
128  case AbstractPointItem::Ignored:
129  case AbstractPointItem::APrioriSPSource:
130  case AbstractPointItem::APrioriRadiusSource: {
131  QComboBox *combo = static_cast< QComboBox * >(widget);
132 
133  switch (column) {
134  case AbstractPointItem::PointType:
135  combo->setCurrentIndex(
136  (int) point->StringToPointType(data));
137  break;
138  case AbstractPointItem::EditLock:
139  combo->setCurrentIndex(point->IsEditLocked() ? 0 : 1);
140  break;
141  case AbstractPointItem::Ignored:
142  combo->setCurrentIndex(point->IsIgnored() ? 0 : 1);
143  break;
144  case AbstractPointItem::APrioriSPSource:
145  combo->setCurrentIndex(
146  (int) point->StringToSurfacePointSource(data));
147  break;
148  case AbstractPointItem::APrioriRadiusSource:
149  combo->setCurrentIndex(
150  (int) point->StringToRadiusSource(data));
151  break;
152  default:
153  break;
154  }
155  }
156  break;
157  default: {
158  QLineEdit *lineEdit = static_cast< QLineEdit * >(widget);
159  lineEdit->setText(data);
160  }
161  }
162  }
163 
164 
165  void PointTableDelegate::readData(QWidget *widget,
166  AbstractTreeItem *row, TableColumn const *col,
167  QString newData) const {
168  QString columnTitle = col->getTitle();
169  AbstractPointItem::Column column =
170  AbstractPointItem::getColumn(columnTitle);
171 
172  QString data = row->getFormattedData(columnTitle);
173  ASSERT(row->getPointerType() == AbstractTreeItem::Point);
174  ControlPoint *point = (ControlPoint *)row->getPointer();
175 
176  switch (column) {
177  case AbstractPointItem::Reference: {
178  QComboBox *combo = static_cast< QComboBox * >(widget);
179 
180  for (int i = 0; i < point->GetNumMeasures(); i++)
181  combo->insertItem(i, point->GetMeasure(i)->GetCubeSerialNumber());
182 
183  combo->setCurrentIndex(point->IndexOfRefMeasure());
184 
185  for (int i = combo->count() - 1; i >= 0; --i)
186  if (combo->itemText(i).toLower().startsWith(newData.toLower()))
187  combo->setCurrentIndex(i);
188  }
189  break;
190 
191  case AbstractPointItem::PointType:
192  case AbstractPointItem::EditLock:
193  case AbstractPointItem::Ignored:
194  case AbstractPointItem::APrioriSPSource:
195  case AbstractPointItem::APrioriRadiusSource: {
196  QComboBox *combo = static_cast< QComboBox * >(widget);
197 
198  switch (column) {
199  case AbstractPointItem::PointType:
200  combo->setCurrentIndex(
201  (int) point->StringToPointType(data));
202  break;
203  case AbstractPointItem::EditLock:
204  combo->setCurrentIndex(point->IsEditLocked() ? 0 : 1);
205  break;
206  case AbstractPointItem::Ignored:
207  combo->setCurrentIndex(point->IsIgnored() ? 0 : 1);
208  break;
209  case AbstractPointItem::APrioriSPSource:
210  combo->setCurrentIndex(
211  (int) point->StringToSurfacePointSource(data));
212  break;
213  case AbstractPointItem::APrioriRadiusSource:
214  combo->setCurrentIndex(
215  (int) point->StringToRadiusSource(data));
216  break;
217  default:
218  break;
219  }
220 
221  for (int i = combo->count() - 1; i >= 0; --i)
222  if (combo->itemText(i).toLower().startsWith(newData.toLower()))
223  combo->setCurrentIndex(i);
224  }
225  break;
226  default: {
227  QLineEdit *lineEdit = static_cast< QLineEdit * >(widget);
228  lineEdit->setText(newData);
229  }
230  }
231  }
232 
233 
234  void PointTableDelegate::saveData(QWidget *widget,
235  AbstractTreeItem *row, const TableColumn *col) const {
236  AbstractPointItem::Column column =
237  AbstractPointItem::getColumn(col->getTitle());
238 
239  QString newData;
240 
241  switch (column) {
242  case AbstractPointItem::PointType:
243  case AbstractPointItem::EditLock:
244  case AbstractPointItem::Ignored:
245  case AbstractPointItem::Reference:
246  case AbstractPointItem::APrioriSPSource:
247  case AbstractPointItem::APrioriRadiusSource: {
248  QComboBox *combo = static_cast< QComboBox * >(widget);
249  newData = combo->currentText();
250  break;
251  }
252  default: {
253  QLineEdit *lineEdit = static_cast< QLineEdit * >(widget);
254  newData = lineEdit->text();
255  }
256  }
257 
258  QString warningText = PointTableModel::getPointWarningMessage(
259  row, col, newData);
260 
261  bool changeData = true;
262 
263  if (!warningText.isEmpty()) {
264  QMessageBox::StandardButton status = QMessageBox::warning(
265  NULL, "Change cell?", warningText, QMessageBox::Yes |
266  QMessageBox::No);
267 
268  changeData = (status == QMessageBox::Yes);
269  }
270 
271  if (changeData)
272  row->setData(col->getTitle(), newData);
273  }
274 }
QWidget
Isis::ControlPoint::PointTypeToString
static QString PointTypeToString(PointType type)
Obtain a string representation of a given PointType.
Definition: ControlPoint.cpp:1333
Isis::ControlPoint::PointType
PointType
These are the valid 'types' of point.
Definition: ControlPoint.h:364
QComboBox
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16