11 #include "ImagePointTreeModel.h"
16 #include <QFutureWatcher>
18 #include <QModelIndex>
20 #include <QtConcurrentMap>
22 #include "ControlMeasure.h"
23 #include "ControlNet.h"
24 #include "ControlPoint.h"
27 #include "TreeViewContent.h"
28 #include "PointLeafItem.h"
30 #include "ImageParentItem.h"
39 ImagePointTreeModel::ImagePointTreeModel(ControlNet *controlNet,
41 AbstractTreeModel(controlNet, v, parent) {
46 ImagePointTreeModel::~ImagePointTreeModel() {
50 ImagePointTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
51 AbstractTreeModel *tm, ControlNet *net,
QThread *tt) {
55 m_avgCharWidth = QFontMetrics(
56 m_treeModel->getView()->getContentFont()).averageCharWidth();
60 ImagePointTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
61 const CreateRootItemFunctor &other) {
62 m_treeModel = other.m_treeModel;
63 m_controlNet = other.m_controlNet;
64 m_targetThread = other.m_targetThread;
65 m_avgCharWidth = other.m_avgCharWidth;
69 ImagePointTreeModel::CreateRootItemFunctor::~CreateRootItemFunctor() {
70 m_targetThread = NULL;
76 ImageParentItem *ImagePointTreeModel::CreateRootItemFunctor::operator()(
77 QString imageSerial)
const {
78 ImageParentItem *imageItem = NULL;
82 imageItem =
new ImageParentItem(imageSerial, m_controlNet, m_avgCharWidth);
83 imageItem->setSelectable(
false);
84 imageItem->moveToThread(m_targetThread);
86 for (
int j = 0; j < measures.size(); j++) {
88 ControlPoint *point = measures[j]->Parent();
91 PointLeafItem *pointItem =
new PointLeafItem(
92 point, m_avgCharWidth, imageItem);
93 pointItem->setSelectable(
false);
94 pointItem->moveToThread(m_targetThread);
96 imageItem->addChild(pointItem);
103 void ImagePointTreeModel::CreateRootItemFunctor::addToRootItem(
107 if (root.testAndSetOrdered(NULL,
new RootItem)) {
108 root.loadAcquire()->moveToThread(item->thread());
112 root.loadAcquire()->addChild(item);
116 ImagePointTreeModel::CreateRootItemFunctor &
117 ImagePointTreeModel::CreateRootItemFunctor::operator=(
118 const CreateRootItemFunctor &other) {
119 if (
this != &other) {
120 m_treeModel = other.m_treeModel;
121 m_avgCharWidth = other.m_avgCharWidth;
128 void ImagePointTreeModel::rebuildItems() {
134 QFuture< QAtomicPointer< RootItem > > futureRoot;
135 if (getRebuildWatcher()->isStarted()) {
136 futureRoot = getRebuildWatcher()->future();
143 futureRoot = QtConcurrent::mappedReduced(
144 getControlNetwork()->GetCubeSerials(),
145 CreateRootItemFunctor(
this, getControlNetwork(), QThread::currentThread()),
146 &CreateRootItemFunctor::addToRootItem,
147 QtConcurrent::OrderedReduce | QtConcurrent::SequentialReduce);
149 getRebuildWatcher()->setFuture(futureRoot);