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

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 ISIS Support Center
File Modified: 07/12/2023 23:20:07