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

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:17:01