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