11 #include "PointTableDelegate.h"
17 #include <QMessageBox>
21 #include "ControlMeasure.h"
22 #include "ControlPoint.h"
23 #include "IException.h"
25 #include "AbstractPointItem.h"
26 #include "AbstractTreeItem.h"
27 #include "PointTableModel.h"
28 #include "TableColumn.h"
31 PointTableDelegate::PointTableDelegate() {
35 PointTableDelegate::~PointTableDelegate() {
39 QWidget *PointTableDelegate::getWidget(TableColumn
const *col)
const {
40 AbstractPointItem::Column column =
41 AbstractPointItem::getColumn(col->getTitle());
45 case AbstractPointItem::PointType:
46 case AbstractPointItem::EditLock:
47 case AbstractPointItem::Ignored:
48 case AbstractPointItem::Reference:
49 case AbstractPointItem::APrioriSPSource:
50 case AbstractPointItem::APrioriRadiusSource: {
54 case AbstractPointItem::PointType:
55 for (
int i = 0; i < ControlPoint::PointTypeCount; i++) {
60 case AbstractPointItem::EditLock:
61 combo->insertItem(0,
"Yes");
62 combo->insertItem(1,
"No");
64 case AbstractPointItem::Ignored:
65 combo->insertItem(0,
"Yes");
66 combo->insertItem(1,
"No");
68 case AbstractPointItem::Reference:
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");
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");
97 return new QLineEdit();
100 QString msg =
"Could not create delegate widget for column ["
101 + col->getTitle() +
"]";
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);
112 QString data = row->getFormattedData(columnTitle);
113 ASSERT(row->getPointerType() == AbstractTreeItem::Point);
114 ControlPoint *point = (ControlPoint *)row->getPointer();
117 case AbstractPointItem::Reference: {
120 for (
int i = 0; i < point->GetNumMeasures(); i++)
121 combo->insertItem(i, point->GetMeasure(i)->GetCubeSerialNumber());
122 combo->setCurrentIndex(point->IndexOfRefMeasure());
126 case AbstractPointItem::PointType:
127 case AbstractPointItem::EditLock:
128 case AbstractPointItem::Ignored:
129 case AbstractPointItem::APrioriSPSource:
130 case AbstractPointItem::APrioriRadiusSource: {
134 case AbstractPointItem::PointType:
135 combo->setCurrentIndex(
136 (
int) point->StringToPointType(data));
138 case AbstractPointItem::EditLock:
139 combo->setCurrentIndex(point->IsEditLocked() ? 0 : 1);
141 case AbstractPointItem::Ignored:
142 combo->setCurrentIndex(point->IsIgnored() ? 0 : 1);
144 case AbstractPointItem::APrioriSPSource:
145 combo->setCurrentIndex(
146 (
int) point->StringToSurfacePointSource(data));
148 case AbstractPointItem::APrioriRadiusSource:
149 combo->setCurrentIndex(
150 (
int) point->StringToRadiusSource(data));
158 QLineEdit *lineEdit =
static_cast< QLineEdit *
>(widget);
159 lineEdit->setText(data);
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);
172 QString data = row->getFormattedData(columnTitle);
173 ASSERT(row->getPointerType() == AbstractTreeItem::Point);
174 ControlPoint *point = (ControlPoint *)row->getPointer();
177 case AbstractPointItem::Reference: {
180 for (
int i = 0; i < point->GetNumMeasures(); i++)
181 combo->insertItem(i, point->GetMeasure(i)->GetCubeSerialNumber());
183 combo->setCurrentIndex(point->IndexOfRefMeasure());
185 for (
int i = combo->count() - 1; i >= 0; --i)
186 if (combo->itemText(i).toLower().startsWith(newData.toLower()))
187 combo->setCurrentIndex(i);
191 case AbstractPointItem::PointType:
192 case AbstractPointItem::EditLock:
193 case AbstractPointItem::Ignored:
194 case AbstractPointItem::APrioriSPSource:
195 case AbstractPointItem::APrioriRadiusSource: {
199 case AbstractPointItem::PointType:
200 combo->setCurrentIndex(
201 (
int) point->StringToPointType(data));
203 case AbstractPointItem::EditLock:
204 combo->setCurrentIndex(point->IsEditLocked() ? 0 : 1);
206 case AbstractPointItem::Ignored:
207 combo->setCurrentIndex(point->IsIgnored() ? 0 : 1);
209 case AbstractPointItem::APrioriSPSource:
210 combo->setCurrentIndex(
211 (
int) point->StringToSurfacePointSource(data));
213 case AbstractPointItem::APrioriRadiusSource:
214 combo->setCurrentIndex(
215 (
int) point->StringToRadiusSource(data));
221 for (
int i = combo->count() - 1; i >= 0; --i)
222 if (combo->itemText(i).toLower().startsWith(newData.toLower()))
223 combo->setCurrentIndex(i);
227 QLineEdit *lineEdit =
static_cast< QLineEdit *
>(widget);
228 lineEdit->setText(newData);
234 void PointTableDelegate::saveData(
QWidget *widget,
235 AbstractTreeItem *row,
const TableColumn *col)
const {
236 AbstractPointItem::Column column =
237 AbstractPointItem::getColumn(col->getTitle());
242 case AbstractPointItem::PointType:
243 case AbstractPointItem::EditLock:
244 case AbstractPointItem::Ignored:
245 case AbstractPointItem::Reference:
246 case AbstractPointItem::APrioriSPSource:
247 case AbstractPointItem::APrioriRadiusSource: {
249 newData = combo->currentText();
253 QLineEdit *lineEdit =
static_cast< QLineEdit *
>(widget);
254 newData = lineEdit->text();
258 QString warningText = PointTableModel::getPointWarningMessage(
261 bool changeData =
true;
263 if (!warningText.isEmpty()) {
264 QMessageBox::StandardButton status = QMessageBox::warning(
265 NULL,
"Change cell?", warningText, QMessageBox::Yes |
268 changeData = (status == QMessageBox::Yes);
272 row->setData(col->getTitle(), newData);