Isis 3 Programmer Reference
ImagePointTreeModel.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "IsisDebug.h"
10 
11 #include "ImagePointTreeModel.h"
12 
13 #include <iostream>
14 
15 #include <QFuture>
16 #include <QFutureWatcher>
17 #include <QList>
18 #include <QModelIndex>
19 #include <QString>
20 #include <QtConcurrentMap>
21 
22 #include "ControlMeasure.h"
23 #include "ControlNet.h"
24 #include "ControlPoint.h"
25 
26 #include "TreeView.h"
27 #include "TreeViewContent.h"
28 #include "PointLeafItem.h"
29 #include "RootItem.h"
30 #include "ImageParentItem.h"
31 
32 #include <QTime>
33 
34 
35 using std::cerr;
36 
37 
38 namespace Isis {
39  ImagePointTreeModel::ImagePointTreeModel(ControlNet *controlNet,
40  TreeView *v, QObject *parent) :
41  AbstractTreeModel(controlNet, v, parent) {
42  rebuildItems();
43  }
44 
45 
46  ImagePointTreeModel::~ImagePointTreeModel() {
47  }
48 
49 
50  ImagePointTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
51  AbstractTreeModel *tm, ControlNet *net, QThread *tt) {
52  m_treeModel = tm;
53  m_controlNet = net;
54  m_targetThread = tt;
55  m_avgCharWidth = QFontMetrics(
56  m_treeModel->getView()->getContentFont()).averageCharWidth();
57  }
58 
59 
60  ImagePointTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
61  const CreateRootItemFunctor &other) {
62  m_treeModel = other.m_treeModel;
63  m_controlNet = other.m_controlNet;
64  m_targetThread = other.m_targetThread;
65  m_avgCharWidth = other.m_avgCharWidth;
66  }
67 
68 
69  ImagePointTreeModel::CreateRootItemFunctor::~CreateRootItemFunctor() {
70  m_targetThread = NULL;
71  m_controlNet = NULL;
72  m_treeModel = NULL;
73  }
74 
75 
76  ImageParentItem *ImagePointTreeModel::CreateRootItemFunctor::operator()(
77  QString imageSerial) const {
78  ImageParentItem *imageItem = NULL;
79 
80  // TODO connect parent item destroy to image removed from network
81 
82  imageItem = new ImageParentItem(imageSerial, m_controlNet, m_avgCharWidth);
83  imageItem->setSelectable(false);
84  imageItem->moveToThread(m_targetThread);
85  QList< ControlMeasure * > measures = m_controlNet->GetMeasuresInCube(imageSerial);
86  for (int j = 0; j < measures.size(); j++) {
87  ASSERT(measures[j]);
88  ControlPoint *point = measures[j]->Parent();
89 
90  ASSERT(point);
91  PointLeafItem *pointItem = new PointLeafItem(
92  point, m_avgCharWidth, imageItem);
93  pointItem->setSelectable(false);
94  pointItem->moveToThread(m_targetThread);
95 
96  imageItem->addChild(pointItem);
97  }
98 
99  return imageItem;
100  }
101 
102 
103  void ImagePointTreeModel::CreateRootItemFunctor::addToRootItem(
104  QAtomicPointer< RootItem > & root, ImageParentItem *const &item) {
105 
106  // Allocate a new root item if our root is NULL
107  if (root.testAndSetOrdered(NULL, new RootItem)) {
108  root.loadAcquire()->moveToThread(item->thread());
109  }
110 
111  if (item)
112  root.loadAcquire()->addChild(item);
113  }
114 
115 
116  ImagePointTreeModel::CreateRootItemFunctor &
117  ImagePointTreeModel::CreateRootItemFunctor::operator=(
118  const CreateRootItemFunctor &other) {
119  if (this != &other) {
120  m_treeModel = other.m_treeModel;
121  m_avgCharWidth = other.m_avgCharWidth;
122  }
123 
124  return *this;
125  }
126 
127 
128  void ImagePointTreeModel::rebuildItems() {
129  // cerr << "ImagePointTreeModel::rebuildItems\n";
130  if (!isFrozen()) {
131  emit cancelSort();
132  setRebuilding(true);
133  emit filterCountsChanged(-1, getTopLevelItemCount());
134  QFuture< QAtomicPointer< RootItem > > futureRoot;
135  if (getRebuildWatcher()->isStarted()) {
136  futureRoot = getRebuildWatcher()->future();
137  futureRoot.cancel();
138  // futureRoot.waitForFinished();
139  // if (futureRoot.result())
140  // delete futureRoot.result();
141  }
142 
143  futureRoot = QtConcurrent::mappedReduced(
144  getControlNetwork()->GetCubeSerials(),
145  CreateRootItemFunctor(this, getControlNetwork(), QThread::currentThread()),
146  &CreateRootItemFunctor::addToRootItem,
147  QtConcurrent::OrderedReduce | QtConcurrent::SequentialReduce);
148 
149  getRebuildWatcher()->setFuture(futureRoot);
150  }
151  else {
152  queueRebuild();
153  }
154  // cerr << "/ImagePointTreeModel::rebuildItems\n";
155  }
156 }
Isis::AbstractTreeModel::filterCountsChanged
void filterCountsChanged(int visibleTopLevelItemCount, int topLevelItemCount)
This signal is emitted after filtering to provide the number of visible top-level items remaining aft...
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
QThread
QAtomicPointer
This is free and unencumbered software released into the public domain.
Definition: ConcurrentControlNetReader.h:20
QObject
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16