USGS

Isis 3.0 Object Programmers' Reference

Home

CnetEditorWidget.cpp
1 #include "IsisDebug.h"
2 
3 #include "CnetEditorWidget.h"
4 
5 #include <QAction>
6 #include <QApplication>
7 #include <QBoxLayout>
8 #include <QByteArray>
9 #include <QCloseEvent>
10 #include <QDebug>
11 #include <QGroupBox>
12 #include <QHBoxLayout>
13 #include <QHeaderView>
14 #include <QItemSelection>
15 #include <QMenu>
16 #include <QMessageBox>
17 #include <QModelIndex>
18 #include <QScrollArea>
19 #include <QScrollBar>
20 #include <QSettings>
21 #include <QSplitter>
22 #include <QString>
23 #include <QStringList>
24 #include <QTime>
25 #include <QTimer>
26 #include <QToolBar>
27 #include <QVBoxLayout>
28 #include <QWhatsThis>
29 
30 #include "ControlMeasure.h"
31 #include "ControlNet.h"
32 #include "ControlPoint.h"
33 #include "IException.h"
34 
35 #include "AbstractMeasureItem.h"
36 #include "AbstractPointItem.h"
37 #include "AbstractTreeItem.h"
38 #include "CnetDisplayProperties.h"
39 #include "CnetEditorSortConfigDialog.h"
40 #include "FileName.h"
41 #include "MeasureTableModel.h"
42 #include "PointTableModel.h"
43 #include "TableView.h"
44 #include "TableViewHeader.h"
45 #include "TreeView.h"
46 #include "ImageImageTreeModel.h"
47 #include "FilterWidget.h"
48 #include "PointMeasureTreeModel.h"
49 #include "ImagePointTreeModel.h"
50 
51 
52 namespace Isis {
53  using namespace CnetViz;
54 
55 //**************************************************************
56 //**************************************************************
57 //**************************************************************
58 
59  const QString CnetEditorWidget::VERSION = "0.1";
60 
61 //**************************************************************
62 //**************************************************************
63 //**************************************************************
64 
65 
66  CnetEditorWidget::CnetEditorWidget(ControlNet *cNet,
67  QString pathForSettings) {
68  nullify();
69 
70  m_workingVersion = new QString;
71  m_menuActions = new QMap< QAction *, QList< QString > >;
72  m_toolBarActions = new QMap< QString, QList< QAction * > >;
73 
74  m_updatingSelection = false;
75 
76  m_controlNet = cNet;
77  connect(CnetDisplayProperties::getInstance(), SIGNAL(compositionFinished()),
78  this, SLOT(rebuildModels()));
79 
80  m_settingsPath = new QString(pathForSettings);
81 
82  QBoxLayout *mainLayout = createMainLayout();
83  setLayout(mainLayout);
84 
85  createActions();
86 
87  readSettings();
88 
89  upgradeVersion();
90 
91  installEventFilter(this);
92  }
93 
94 
95  CnetEditorWidget::~CnetEditorWidget() {
96  writeSettings();
97 
98  delete m_workingVersion;
99  m_workingVersion = NULL;
100 
101  delete m_settingsPath;
102  m_settingsPath = NULL;
103 
104  delete m_pointTreeView;
105  m_pointTreeView = NULL;
106 
107  delete m_imageTreeView;
108  m_imageTreeView = NULL;
109 
110  delete m_connectionTreeView;
111  m_connectionTreeView = NULL;
112 
113  delete m_pointTableView;
114  m_pointTableView = NULL;
115 
116  delete m_measureTableView;
117  m_measureTableView = NULL;
118 
119  delete m_pointFilterWidget;
120  m_pointFilterWidget = NULL;
121 
122  delete m_serialFilterWidget;
123  m_serialFilterWidget = NULL;
124 
125  delete m_connectionFilterWidget;
126  m_connectionFilterWidget = NULL;
127 
128  delete m_menuActions;
129  m_menuActions = NULL;
130 
131  delete m_toolBarActions;
132  m_toolBarActions = NULL;
133 
134  m_pointTableBox = NULL;
135  m_measureTableBox = NULL;
136  m_mainSplitter = NULL;
137 
138  // TODO: null all member widgets!
139 
140  delete m_pointModel;
141  m_pointModel = NULL;
142 
143  delete m_imageModel;
144  m_imageModel = NULL;
145 
146  delete m_connectionModel;
147  m_connectionModel = NULL;
148  }
149 
150 
151  void CnetEditorWidget::nullify() {
152  m_pointTreeView = NULL;
153  m_imageTreeView = NULL;
154  m_connectionTreeView = NULL;
155 
156  m_pointModel = NULL;
157  m_imageModel = NULL;
158  m_connectionModel = NULL;
159 
160  m_pointTableModel = NULL;
161  m_measureTableModel = NULL;
162 
163  m_pointTableBox = NULL;
164  m_measureTableBox = NULL;
165 
166  m_pointTableView = NULL;
167  m_measureTableView = NULL;
168 
169  m_mainSplitter = NULL;
170 
171  m_menuActions = NULL;
172  m_toolBarActions = NULL;
173 
174  m_filterArea = NULL;
175 
176  m_pointFilterWidget = NULL;
177  m_serialFilterWidget = NULL;
178  m_connectionFilterWidget = NULL;
179 
180  m_controlNet = NULL;
181  m_settingsPath = NULL;
182  m_workingVersion = NULL;
183  }
184 
185 
186  void CnetEditorWidget::rebuildModels(QList<AbstractTreeItem *> itemsToDelete) {
187  m_pointModel->stopWorking();
188  m_imageModel->stopWorking();
189  m_connectionModel->stopWorking();
190 
191  bool ignoreAll = false;
192  foreach (AbstractTreeItem * item, itemsToDelete) {
193  try {
194  item->deleteSource();
195  }
196  catch (IException &e) {
197  QString message = e.what();
198 
199  if (!ignoreAll) {
200  if (item == itemsToDelete.last()) {
201  QMessageBox::warning(
202  this, "Failed to delete row", message, QMessageBox::Ok);
203  }
204  else {
205  message += "\n\nOkay to continue?";
206 
207  QMessageBox::StandardButton status = QMessageBox::warning(
208  this, "Failed to delete row", message, QMessageBox::Yes |
209  QMessageBox::YesToAll | QMessageBox::No);
210 
211  if (status == QMessageBox::YesToAll)
212  ignoreAll = true;
213  else if (status == QMessageBox::No)
214  break;
215  }
216  }
217  }
218  }
219 
220  m_pointModel->rebuildItems();
221  m_imageModel->rebuildItems();
222  m_connectionModel->rebuildItems();
223  }
224 
225 
226  QBoxLayout *CnetEditorWidget::createMainLayout() {
227  createPointTreeView();
228  createSerialTreeView();
229  createConnectionTreeView();
230 
231  connect(m_pointTreeView, SIGNAL(activated()),
232  m_imageTreeView, SLOT(deactivate()));
233  connect(m_pointTreeView, SIGNAL(activated()),
234  m_connectionTreeView, SLOT(deactivate()));
235 
236  connect(m_imageTreeView, SIGNAL(activated()),
237  m_pointTreeView, SLOT(deactivate()));
238  connect(m_imageTreeView, SIGNAL(activated()),
239  m_connectionTreeView, SLOT(deactivate()));
240 
241  connect(m_connectionTreeView, SIGNAL(activated()),
242  m_pointTreeView, SLOT(deactivate()));
243  connect(m_connectionTreeView, SIGNAL(activated()),
244  m_imageTreeView, SLOT(deactivate()));
245 
246  createFilterArea();
247 
248  createPointTableView();
249  m_pointTableBox = new QGroupBox(tr("Control Point Table"));
250  QHBoxLayout *pointTableLayout = new QHBoxLayout;
251  pointTableLayout->addWidget(m_pointTableView);
252  m_pointTableBox->setLayout(pointTableLayout);
253 
254  createMeasureTableView();
255  m_measureTableBox = new QGroupBox(tr("Control Measure Table"));
256  QHBoxLayout *measureTableLayout = new QHBoxLayout;
257  measureTableLayout->addWidget(m_measureTableView);
258  m_measureTableBox->setLayout(measureTableLayout);
259 
260  m_mainSplitter = new QSplitter(Qt::Vertical);
261  m_mainSplitter->addWidget(m_pointTableBox);
262  m_mainSplitter->addWidget(m_measureTableBox);
263 
264  QBoxLayout *mainLayout = new QHBoxLayout;
265  mainLayout->addWidget(m_mainSplitter);
266 
267  return mainLayout;
268  }
269 
270 
271  void CnetEditorWidget::createActions() {
272  ASSERT(m_menuActions);
273 
274  QAction *freezeTablesAct = new QAction(QIcon(FileName("$base/icons/ice.png").expanded()),
275  tr("&Freeze Tables"), this);
276  freezeTablesAct->setCheckable(true);
277  freezeTablesAct->setToolTip(tr("Freeze tables (filters will not take "
278  "effect until unfrozen)"));
279  freezeTablesAct->setStatusTip(tr("Freeze tables (filters will not take "
280  "effect until unfrozen)"));
281  freezeTablesAct->setWhatsThis(tr("<html>When frozen, the contents of the "
282  "tables will be locked. Current filters will not be applied to the "
283  "tables until they are unfrozen.</html>"));
284  connect(freezeTablesAct, SIGNAL(toggled(bool)),
285  this, SLOT(setTablesFrozen(bool)));
286  QList< QString > freezeTablesLocation;
287  freezeTablesLocation.append(tr("&Tables"));
288  m_menuActions->insert(freezeTablesAct, freezeTablesLocation);
289 
290  QAction *configureSortAct = new QAction(QIcon(FileName("$base/icons/sort.png").expanded()),
291  tr("&Sorting Options..."), this);
292  QString configureSortToolTipText = tr("Configure table sorting options");
293  configureSortAct->setToolTip(configureSortToolTipText);
294  configureSortAct->setStatusTip(configureSortToolTipText);
295  configureSortAct->setWhatsThis(tr("<html>Click here to configure options "
296  "related to the sorting of table columns.</html>"));
297  connect(configureSortAct, SIGNAL(triggered()),
298  this, SLOT(configSorting()));
299  QList< QString > configureSortLocation;
300  configureSortLocation.append(tr("&Tables"));
301  m_menuActions->insert(configureSortAct, configureSortLocation);
302 
303  QAction *whatsThisAct = QWhatsThis::createAction(this);
304  QList< QString > whatsThisLocation;
305  whatsThisLocation.append(tr("&Help"));
306  m_menuActions->insert(whatsThisAct, whatsThisLocation);
307 
308  QList< QAction * > tbActionList;
309  tbActionList.append(freezeTablesAct);
310  tbActionList.append(configureSortAct);
311  m_toolBarActions->insert("settingsToolBar", tbActionList);
312  }
313 
314 
315  void CnetEditorWidget::createPointTreeView() {
316  m_pointTreeView = new TreeView();
317  m_pointTreeView->setTitle("Point View");
318  m_pointModel = new PointMeasureTreeModel(m_controlNet, m_pointTreeView, qApp);
319  m_pointTreeView->setModel(m_pointModel);
320  }
321 
322 
323  void CnetEditorWidget::createSerialTreeView() {
324  m_imageTreeView = new TreeView();
325  m_imageTreeView->setTitle("Cube View");
326  m_imageModel = new ImagePointTreeModel(m_controlNet, m_imageTreeView, qApp);
327  m_imageTreeView->setModel(m_imageModel);
328  }
329 
330 
331  void CnetEditorWidget::createConnectionTreeView() {
332  m_connectionTreeView = new TreeView();
333  m_connectionTreeView->setTitle("Cube Connection View");
334  m_connectionModel = new ImageImageTreeModel(m_controlNet, m_connectionTreeView, qApp);
335  m_connectionTreeView->setModel(m_connectionModel);
336  }
337 
338 
339  void CnetEditorWidget::createFilterArea() {
340  ASSERT(m_pointModel);
341  ASSERT(m_imageModel);
342  ASSERT(m_connectionModel);
343 
344  FilterWidget *pointFilter = new FilterWidget("Points and Measures");
345  if (m_pointModel) {
346  m_pointModel->setFilter(pointFilter);
347  }
348 
349  QHBoxLayout *pointFilterLayout = new QHBoxLayout;
350  pointFilterLayout->addWidget(pointFilter);
351  QWidget *pointArea = new QWidget;
352  pointArea->setLayout(pointFilterLayout);
353  QScrollArea *pointFilterScrollArea = new QScrollArea;
354  pointFilterScrollArea->setWidget(pointArea);
355  pointFilterScrollArea->setWidgetResizable(true);
356  m_pointFilterWidget = pointFilterScrollArea;
357 
358  FilterWidget *serialFilter = new FilterWidget("Images and Points");
359  if (m_imageModel) {
360  m_imageModel->setFilter(serialFilter);
361  }
362 
363  QHBoxLayout *serialFilterLayout = new QHBoxLayout;
364  serialFilterLayout->addWidget(serialFilter);
365  QWidget *serialArea = new QWidget;
366  serialArea->setLayout(serialFilterLayout);
367  QScrollArea *serialFilterScrollArea = new QScrollArea;
368  serialFilterScrollArea->setWidget(serialArea);
369  serialFilterScrollArea->setWidgetResizable(true);
370  m_serialFilterWidget = serialFilterScrollArea;
371 
372  FilterWidget *connectionFilter = new FilterWidget("Connections");
373  if (m_connectionModel) {
374  m_connectionModel->setFilter(connectionFilter);
375  }
376 
377  QHBoxLayout *connectionFilterLayout = new QHBoxLayout;
378  connectionFilterLayout->addWidget(connectionFilter);
379  QWidget *connectionArea = new QWidget;
380  connectionArea->setLayout(connectionFilterLayout);
381  QScrollArea *connectionFilterScrollArea = new QScrollArea;
382  connectionFilterScrollArea->setWidget(connectionArea);
383  connectionFilterScrollArea->setWidgetResizable(true);
384  m_connectionFilterWidget = connectionFilterScrollArea;
385  }
386 
387 
388  void CnetEditorWidget::createPointTableView() {
389  m_pointTableModel = new PointTableModel(m_pointModel);
390  m_pointTableView = new TableView(m_pointTableModel, *m_settingsPath,
391  "m_pointTableView");
392  m_pointTableView->setWhatsThis("<html>Each row in the table is a control "
393  "point. Each column in the table is an attribute of a control "
394  "point.<br/><br/>Cells that are gray are not editable.</html>");
395  connect(m_pointTableView, SIGNAL(modelDataChanged()),
396  this, SIGNAL(cnetModified()));
397 
398  connect(m_pointTreeView, SIGNAL(selectionChanged()),
399  m_pointTableView, SLOT(handleModelSelectionChanged()));
400  connect(m_pointTableView, SIGNAL(selectionChanged()),
401  m_pointTreeView, SLOT(handleModelSelectionChanged()));
402 
403  connect(m_pointTableView,
404  SIGNAL(rebuildModels(QList< CnetViz::AbstractTreeItem * >)),
405  this,
406  SLOT(rebuildModels(QList< CnetViz::AbstractTreeItem * >)));
407 
408  connect(m_pointTableView, SIGNAL(filterCountsChanged(int, int)),
409  this, SLOT(handlePointTableFilterCountsChanged(int, int)));
410 
411  for (int i = 0; i < AbstractPointItem::COLS; i++) {
412  QAction *act = new QAction(
413  AbstractPointItem::getColumnName((AbstractPointItem::Column) i), this);
414  act->setCheckable(true);
415  connect(act, SIGNAL(toggled(bool)), this, SLOT(pointColToggled()));
416  m_pointTableView->getHorizontalHeader()->addAction(act);
417  }
418 
419  m_pointTableView->getHorizontalHeader()->setContextMenuPolicy(
420  Qt::ActionsContextMenu);
421  }
422 
423 
424  void CnetEditorWidget::createMeasureTableView() {
425  m_measureTableModel = new MeasureTableModel(m_pointModel);
426  m_measureTableView = new TableView(m_measureTableModel, *m_settingsPath,
427  "m_measureTableView");
428  m_measureTableView->setWhatsThis("<html>Each row in the table is a control "
429  "measure. Each column in the table is an attribute of a control "
430  "measure.<br/><br/>Rows with bold text are reference measures. "
431  "Cells that are gray are not editable.</html>");
432  ASSERT(m_pointTableView);
433  connect(m_pointTableView,
434  SIGNAL(tableSelectionChanged(QList< AbstractTreeItem * >)),
435  m_measureTableModel,
436  SLOT(handleTreeSelectionChanged(QList<AbstractTreeItem *>)));
437 
438  connect(m_measureTableView,
439  SIGNAL(tableSelectionChanged(QList< AbstractTreeItem * >)),
440  m_pointTableModel,
441  SLOT(handleTreeSelectionChanged(QList< AbstractTreeItem * >)));
442 
443 
444  connect(m_measureTableView, SIGNAL(modelDataChanged()),
445  this, SIGNAL(cnetModified()));
446  connect(m_pointTreeView, SIGNAL(selectionChanged()),
447  m_measureTableView, SLOT(handleModelSelectionChanged()));
448  connect(m_measureTableView, SIGNAL(selectionChanged()),
449  m_pointTreeView, SLOT(handleModelSelectionChanged()));
450  connect(m_measureTableView,
451  SIGNAL(rebuildModels(QList< CnetViz::AbstractTreeItem * >)),
452  this,
453  SLOT(rebuildModels(QList< CnetViz::AbstractTreeItem * >)));
454 
455  connect(m_measureTableView, SIGNAL(filterCountsChanged(int, int)),
456  this, SLOT(handleMeasureTableFilterCountsChanged(int, int)));
457 
458  for (int i = 0; i < AbstractMeasureItem::COLS; i++) {
459  QAction *act = new QAction(AbstractMeasureItem::getColumnName(
460  (AbstractMeasureItem::Column) i), this);
461  act->setCheckable(true);
462  connect(act, SIGNAL(toggled(bool)), this, SLOT(measureColToggled()));
463  m_measureTableView->getHorizontalHeader()->addAction(act);
464  }
465 
466  m_measureTableView->getHorizontalHeader()->setContextMenuPolicy(
467  Qt::ActionsContextMenu);
468  }
469 
470 
471  void CnetEditorWidget::rebuildModels() {
472  rebuildModels(QList< AbstractTreeItem * >());
473  }
474 
475 
476  void CnetEditorWidget::pointColToggled() {
477  QList< QAction * > actions =
478  m_pointTableView->getHorizontalHeader()->actions();
479 
480  for (int i = 0; i < actions.size(); i++) {
481  m_pointTableView->setColumnVisible(actions[i]->text(),
482  actions[i]->isChecked());
483  }
484  }
485 
486 
487  void CnetEditorWidget::measureColToggled() {
488  QList< QAction * > actions =
489  m_measureTableView->getHorizontalHeader()->actions();
490  for (int i = 0; i < actions.size(); i++)
491  m_measureTableView->setColumnVisible(actions[i]->text(),
492  actions[i]->isChecked());
493  }
494 
495  void CnetEditorWidget::handlePointTableFilterCountsChanged(
496  int visibleRows, int totalRows) {
497  handleTableFilterCountsChanged(visibleRows, totalRows, m_pointTableBox,
498  "Control Point Table");
499  }
500 
501 
502  void CnetEditorWidget::handleMeasureTableFilterCountsChanged(
503  int visibleRows, int totalRows) {
504  handleTableFilterCountsChanged(visibleRows, totalRows, m_measureTableBox,
505  "Control Measure Table");
506  }
507 
508 
509  void CnetEditorWidget::handleTableFilterCountsChanged(
510  int visibleRows, int totalRows, QGroupBox *box, QString initialText) {
511  if (box) {
512  QString newTitle = initialText + " (";
513  if (visibleRows > -1)
514  newTitle += QString::number(visibleRows);
515  else
516  newTitle += "???";
517 
518  newTitle += " / " + QString::number(totalRows) + ")";
519 
520  box->setTitle(newTitle);
521  }
522  }
523 
524 
525  void CnetEditorWidget::upgradeVersion() {
526  if (*m_workingVersion == "") {
527  *m_workingVersion = "0.1";
528  }
529 
530  if (*m_workingVersion != VERSION)
531  upgradeVersion();
532  }
533 
534 
535  void CnetEditorWidget::readSettings() {
536  ASSERT(m_workingVersion);
537  ASSERT(m_settingsPath);
538  ASSERT(m_measureTableView);
539 
540  QSettings settings(*m_settingsPath, QSettings::NativeFormat);
541  *m_workingVersion = settings.value("version", "").toString();
542 
543  m_mainSplitter->restoreState(settings.value("mainSplitter").toByteArray());
544 
545  QString key;
546 
547  QList< QAction * > actions =
548  m_measureTableView->getHorizontalHeader()->actions();
549  for (int i = 0; i < actions.size(); i++) {
550  key = m_measureTableView->objectName() + " " +
551  AbstractMeasureItem::getColumnName((AbstractMeasureItem::Column) i);
552  key.replace(" ", "_");
553  actions[i]->setChecked(settings.value(key, true).toBool());
554  }
555 
556  actions = m_pointTableView->getHorizontalHeader()->actions();
557  for (int i = 0; i < actions.size(); i++) {
558  key = m_pointTableView->objectName() + " " +
559  AbstractPointItem::getColumnName((AbstractPointItem::Column) i);
560  key.replace(" ", "_");
561  actions[i]->setChecked(settings.value(key, true).toBool());
562  }
563 
564  // Restore sorting configuration settings.
565  setMeasureTableSortingEnabled(
566  settings.value("measureTableSortingEnabled", true).toBool());
567  setMeasureTableSortLimit(
568  settings.value("measureTableSortLimit", 500000).toInt());
569  setPointTableSortingEnabled(
570  settings.value("pointTableSortingEnabled", true).toBool());
571  setPointTableSortLimit(
572  settings.value("pointTableSortLimit", 100000).toInt());
573  }
574 
575 
576  void CnetEditorWidget::writeSettings() {
577  ASSERT(m_mainSplitter);
578  ASSERT(m_settingsPath);
579  ASSERT(m_measureTableView);
580 
581  QSettings settings(*m_settingsPath, QSettings::NativeFormat);
582  settings.setValue("version", VERSION);
583  settings.setValue("mainSplitter", m_mainSplitter->saveState());
584 
585  QString key;
586 
587  QList< QAction * > actions =
588  m_measureTableView->getHorizontalHeader()->actions();
589  for (int i = 0; i < actions.size(); i++) {
590  key = m_measureTableView->objectName() + " " +
591  AbstractMeasureItem::getColumnName((AbstractMeasureItem::Column) i);
592  key.replace(" ", "_");
593  settings.setValue(key, actions[i]->isChecked());
594  }
595 
596  actions = m_pointTableView->getHorizontalHeader()->actions();
597  for (int i = 0; i < actions.size(); i++) {
598  key = m_pointTableView->objectName() + " " +
599  AbstractPointItem::getColumnName((AbstractPointItem::Column) i);
600  key.replace(" ", "_");
601  settings.setValue(key, actions[i]->isChecked());
602  }
603 
604  // Write sorting configuration settings.
605  settings.setValue("measureTableSortingEnabled",
606  measureTableSortingEnabled());
607  settings.setValue("measureTableSortLimit",
608  measureTableSortLimit());
609  settings.setValue("pointTableSortingEnabled",
610  pointTableSortingEnabled());
611  settings.setValue("pointTableSortLimit",
612  pointTableSortLimit());
613  }
614 
615  QWidget *CnetEditorWidget::pointTreeView() {
616  return m_pointTreeView;
617  }
618 
619 
620  QWidget *CnetEditorWidget::serialTreeView() {
621  return m_imageTreeView;
622  }
623 
624 
625  QWidget *CnetEditorWidget::connectionTreeView() {
626  return m_connectionTreeView;
627  }
628 
629 
630  QWidget *CnetEditorWidget::pointFilterWidget() {
631  return m_pointFilterWidget;
632  }
633 
634 
635  QWidget *CnetEditorWidget::serialFilterWidget() {
636  return m_serialFilterWidget;
637  }
638 
639 
640  QWidget *CnetEditorWidget::connectionFilterWidget() {
641  return m_connectionFilterWidget;
642  }
643 
644 
645  CnetViz::AbstractTableModel *CnetEditorWidget::measureTableModel() {
646  return m_measureTableModel;
647  }
648 
649 
650  CnetViz::AbstractTableModel *CnetEditorWidget::pointTableModel() {
651  return m_pointTableModel;
652  }
653 
654 
655  QMap< QAction *, QList< QString > > CnetEditorWidget::menuActions() {
656  ASSERT(m_menuActions);
657  return *m_menuActions;
658  }
659 
660 
661  QMap< QString, QList< QAction * > > CnetEditorWidget::toolBarActions() {
662  ASSERT(m_toolBarActions);
663  return *m_toolBarActions;
664  }
665 
666 
667  ControlNet *CnetEditorWidget::filteredNetwork() const {
668  ControlNet *filteredCnet = new ControlNet(*m_controlNet);
669 
670  QList<AbstractTreeItem *> networkItems = m_pointModel->getItems(0, -1,
671  AbstractTreeModel::MeasureItems | AbstractTreeModel::PointItems, true);
672 
673  // Iterate through our copy of the cnet, deleting anything that doesn't
674  // exactly match our networkItems.
675  for (int pointIndex = filteredCnet->GetNumPoints() - 1;
676  pointIndex >= 0;
677  pointIndex--) {
678  if (networkItems.isEmpty()) {
679  ControlPoint *cp = filteredCnet->GetPoint(pointIndex);
680  cp->SetEditLock(false);
681 
682  for (int measureIndex = 0;
683  measureIndex < cp->GetNumMeasures();
684  measureIndex++) {
685  cp->GetMeasure(measureIndex)->SetEditLock(false);
686  }
687 
688  filteredCnet->DeletePoint(cp);
689  }
690  else if (networkItems.last()->getPointerType() ==
691  AbstractTreeItem::Point) {
692  ControlPoint *networkItemsCp =
693  (ControlPoint *)networkItems.last()->getPointer();
694  ControlPoint *cp = filteredCnet->GetPoint(pointIndex);
695  if (cp->GetId() != networkItemsCp->GetId()) {
696  cp->SetEditLock(false);
697 
698  for (int measureIndex = 0;
699  measureIndex < cp->GetNumMeasures();
700  measureIndex++) {
701  cp->GetMeasure(measureIndex)->SetEditLock(false);
702  }
703 
704  filteredCnet->DeletePoint(cp);
705  }
706  else {
707  networkItems.removeLast();
708  }
709  }
710  else if (networkItems.last()->getPointerType() ==
711  AbstractTreeItem::Measure) {
712  ControlPoint *cp = filteredCnet->GetPoint(pointIndex);
713  ControlMeasure *networkItemsCm =
714  (ControlMeasure *)networkItems.last()->getPointer();
715 
716  if (cp->GetId() != networkItemsCm->Parent()->GetId()) {
717  cp->SetEditLock(false);
718 
719  for (int measureIndex = 0;
720  measureIndex < cp->GetNumMeasures();
721  measureIndex++) {
722  cp->GetMeasure(measureIndex)->SetEditLock(false);
723  }
724 
725  filteredCnet->DeletePoint(cp);
726  }
727  else {
728  // Our CP stays, figure out which CMs stay.
729  for (int measureIndex = cp->GetNumMeasures() - 1;
730  networkItemsCm && measureIndex >= 0;
731  measureIndex--) {
732  ControlMeasure *cm = cp->GetMeasure(measureIndex);
733  if (cm->GetCubeSerialNumber() !=
734  networkItemsCm->GetCubeSerialNumber()) {
735  cm->SetEditLock(false);
736  cp->Delete(cm);
737  }
738  else {
739  networkItems.removeLast();
740  networkItemsCm = NULL;
741 
742  if (networkItems.last()->getPointerType() ==
743  AbstractTreeItem::Measure) {
744  networkItemsCm =
745  (ControlMeasure *)networkItems.last()->getPointer();
746  }
747  }
748  }
749 
750  // We still need to verify the copied CP at this index... although
751  // nothing should go wrong, we know things do go wrong so do
752  // the verify instead of just tossing the last networkItems item.
753  pointIndex++;
754  }
755  }
756  }
757 
758  return filteredCnet;
759  }
760 
761 
762  bool CnetEditorWidget::measureTableSortingEnabled() const {
763  return m_measureTableModel->sortingIsEnabled();
764  }
765 
766 
767  int CnetEditorWidget::measureTableSortLimit() const {
768  return m_measureTableModel->sortLimit();
769  }
770 
771 
772  bool CnetEditorWidget::pointTableSortingEnabled() const {
773  return m_pointTableModel->sortingIsEnabled();
774  }
775 
776 
777  int CnetEditorWidget::pointTableSortLimit() const {
778  return m_pointTableModel->sortLimit();
779  }
780 
781 
782  void CnetEditorWidget::setMeasureTableSortingEnabled(bool enabled) {
783  m_measureTableModel->setSortingEnabled(enabled);
784  }
785 
786 
787  void CnetEditorWidget::setMeasureTableSortLimit(int limit) {
788  m_measureTableModel->setSortLimit(limit);
789  }
790 
791 
792  void CnetEditorWidget::setPointTableSortingEnabled(bool enabled) {
793  m_pointTableModel->setSortingEnabled(enabled);
794  }
795 
796 
797  void CnetEditorWidget::setPointTableSortLimit(int limit) {
798  m_pointTableModel->setSortLimit(limit);
799  }
800 
801 
802  void CnetEditorWidget::configSorting() {
803  CnetEditorSortConfigDialog *dialog = new CnetEditorSortConfigDialog(this);
804  dialog->setAttribute(Qt::WA_DeleteOnClose);
805  dialog->show();
806  }
807 
808 
809  void CnetEditorWidget::setTablesFrozen(bool freezeTables) {
810  if (freezeTables) {
811  m_connectionModel->setFrozen(true);
812  m_imageModel->setFrozen(true);
813  m_pointModel->setFrozen(true);
814  }
815  else {
816  m_pointModel->setFrozen(false);
817  m_imageModel->setFrozen(false);
818  m_connectionModel->setFrozen(false);
819  }
820  }
821 }
822