9#include "ImagePointTreeModel.h"
14#include <QFutureWatcher>
18#include <QtConcurrentMap>
20#include "ControlMeasure.h"
21#include "ControlNet.h"
22#include "ControlPoint.h"
25#include "TreeViewContent.h"
26#include "PointLeafItem.h"
28#include "ImageParentItem.h"
37 ImagePointTreeModel::ImagePointTreeModel(
ControlNet *controlNet,
44 ImagePointTreeModel::~ImagePointTreeModel() {
48 ImagePointTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
49 AbstractTreeModel *tm, ControlNet *net,
QThread *tt) {
53 m_avgCharWidth = QFontMetrics(
54 m_treeModel->getView()->getContentFont()).averageCharWidth();
58 ImagePointTreeModel::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;
67 ImagePointTreeModel::CreateRootItemFunctor::~CreateRootItemFunctor() {
68 m_targetThread = NULL;
74 ImageParentItem *ImagePointTreeModel::CreateRootItemFunctor::operator()(
75 QString imageSerial)
const {
76 ImageParentItem *imageItem = NULL;
80 imageItem =
new ImageParentItem(imageSerial, m_controlNet, m_avgCharWidth);
81 imageItem->setSelectable(
false);
82 imageItem->moveToThread(m_targetThread);
84 for (
int j = 0; j < measures.size(); j++) {
85 ControlPoint *point = measures[j]->Parent();
87 PointLeafItem *pointItem =
new PointLeafItem(
88 point, m_avgCharWidth, imageItem);
89 pointItem->setSelectable(
false);
90 pointItem->moveToThread(m_targetThread);
92 imageItem->addChild(pointItem);
99 void ImagePointTreeModel::CreateRootItemFunctor::addToRootItem(
103 if (root.testAndSetOrdered(NULL,
new RootItem)) {
104 root.loadAcquire()->moveToThread(item->thread());
108 root.loadAcquire()->addChild(item);
112 ImagePointTreeModel::CreateRootItemFunctor &
113 ImagePointTreeModel::CreateRootItemFunctor::operator=(
114 const CreateRootItemFunctor &other) {
115 if (
this != &other) {
116 m_treeModel = other.m_treeModel;
117 m_avgCharWidth = other.m_avgCharWidth;
124 void ImagePointTreeModel::rebuildItems() {
129 emit filterCountsChanged(-1, getTopLevelItemCount());
130 QFuture< QAtomicPointer< RootItem > > futureRoot;
131 if (getRebuildWatcher()->isStarted()) {
132 futureRoot = getRebuildWatcher()->future();
139 futureRoot = QtConcurrent::mappedReduced(
140 getControlNetwork()->GetCubeSerials(),
141 CreateRootItemFunctor(
this, getControlNetwork(), QThread::currentThread()),
142 &CreateRootItemFunctor::addToRootItem,
143 QtConcurrent::OrderedReduce | QtConcurrent::SequentialReduce);
145 getRebuildWatcher()->setFuture(futureRoot);
Base class for tree models.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.