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