Isis 3.0 Programmer Reference
Home
PointMeasureTreeModel.cpp
1 #include "IsisDebug.h"
2 
3 #include "PointMeasureTreeModel.h"
4 
5 #include <iostream>
6 
7 #include <QFuture>
8 #include <QFutureWatcher>
9 #include <QMutex>
10 #include <QString>
11 #include <QtConcurrentMap>
12 
13 #include "ControlNet.h"
14 #include "ControlPoint.h"
15 
16 #include "TreeView.h"
17 #include "TreeViewContent.h"
18 #include "PointParentItem.h"
19 #include "MeasureLeafItem.h"
20 #include "RootItem.h"
21 
22 #include <QTime>
23 #include <QVariant>
24 
25 
26 namespace Isis {
27  namespace CnetViz {
28  PointMeasureTreeModel::PointMeasureTreeModel(ControlNet *controlNet,
29  TreeView *v, QObject *parent) :
30  AbstractTreeModel(controlNet, v, parent) {
31  rebuildItems();
32  }
33 
34 
35  PointMeasureTreeModel::~PointMeasureTreeModel() {
36  }
37 
38 
39  PointMeasureTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
40  AbstractTreeModel *tm, QThread *tt) {
41  m_treeModel = tm;
42  m_targetThread = tt;
43  m_avgCharWidth = QFontMetrics(
44  m_treeModel->getView()->getContentFont()).averageCharWidth();
45  }
46 
47 
48  PointMeasureTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
49  const CreateRootItemFunctor &other) {
50  m_treeModel = other.m_treeModel;
51  m_targetThread = other.m_targetThread;
52  m_avgCharWidth = other.m_avgCharWidth;
53  }
54 
55  PointMeasureTreeModel::CreateRootItemFunctor::~CreateRootItemFunctor() {
56  m_treeModel = NULL;
57  }
58 
59 
60  PointParentItem *PointMeasureTreeModel::CreateRootItemFunctor::operator()(
61  ControlPoint *const &point) const {
62  PointParentItem *pointItem = new PointParentItem(point, m_avgCharWidth);
63  pointItem->moveToThread(m_targetThread);
64 
65  for (int j = 0; j < point->GetNumMeasures(); j++) {
66  const ControlMeasure *measure = point->GetMeasure(j);
67  ASSERT(measure);
68 
69  MeasureLeafItem *measureItem = new MeasureLeafItem(
70  const_cast< ControlMeasure * >(measure), m_avgCharWidth, pointItem);
71  measureItem->moveToThread(m_targetThread);
72 
73  pointItem->addChild(measureItem);
74  }
75 
76  return pointItem;
77  }
78 
79 
80  void PointMeasureTreeModel::CreateRootItemFunctor::addToRootItem(
81  QAtomicPointer< RootItem > & root, PointParentItem *const &item) {
82 
83  // Allocate a new root item if our root is NULL
84  if (root.testAndSetOrdered(NULL, new RootItem)) {
85  root.loadAcquire()->moveToThread(item->thread());
86  }
87 
88  if (item)
89  root.loadAcquire()->addChild(item);
90  }
91 
92 
93  PointMeasureTreeModel::CreateRootItemFunctor &
94  PointMeasureTreeModel::CreateRootItemFunctor::operator=(
95  const CreateRootItemFunctor &other) {
96  if (this != &other) {
97  m_treeModel = other.m_treeModel;
98  m_avgCharWidth = other.m_avgCharWidth;
99  }
100 
101  return *this;
102  }
103 
104  void PointMeasureTreeModel::rebuildItems() {
105  if (!isFrozen()) {
106  emit cancelSort();
107  setRebuilding(true);
108  emit filterCountsChanged(-1, getTopLevelItemCount());
109  QFuture< QAtomicPointer< RootItem > > futureRoot;
110  if (getRebuildWatcher()->isStarted()) {
111  futureRoot = getRebuildWatcher()->future();
112  futureRoot.cancel();
113  }
114 
115  ASSERT(getControlNetwork());
116  futureRoot = QtConcurrent::mappedReduced(
117  getControlNetwork()->GetPoints(),
118  CreateRootItemFunctor(this, QThread::currentThread()),
119  &CreateRootItemFunctor::addToRootItem,
120  QtConcurrent::OrderedReduce | QtConcurrent::SequentialReduce);
121 
122  getRebuildWatcher()->setFuture(futureRoot);
123  }
124  else {
125  queueRebuild();
126  }
127  }
128  }
129 }
130 
void filterCountsChanged(int visibleTopLevelItemCount, int topLevelItemCount)
This signal is emitted after filtering to provide the number of visible top-level items remaining aft...