11 #include "ImageImageTreeModel.h"
16 #include <QFutureWatcher>
19 #include <QtConcurrentMap>
21 #include "ControlMeasure.h"
22 #include "ControlNet.h"
25 #include "TreeViewContent.h"
26 #include "PointLeafItem.h"
28 #include "ImageLeafItem.h"
29 #include "ImageParentItem.h"
38 ImageImageTreeModel::ImageImageTreeModel(ControlNet *cNet, TreeView *v,
39 QObject *parent) : AbstractTreeModel(cNet, v, parent) {
44 ImageImageTreeModel::~ImageImageTreeModel() {
48 ImageImageTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
49 AbstractTreeModel *tm, ControlNet *net,
QThread *tt) {
53 m_avgCharWidth = QFontMetrics(
54 m_treeModel->getView()->getContentFont()).averageCharWidth();
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;
67 ImageImageTreeModel::CreateRootItemFunctor::~CreateRootItemFunctor() {
70 m_targetThread = NULL;
74 ImageParentItem *ImageImageTreeModel::CreateRootItemFunctor::operator()(
75 const QString imageSerial)
const {
77 ImageParentItem *parentItem =
78 new ImageParentItem(imageSerial, m_controlNet, m_avgCharWidth);
79 parentItem->setSelectable(
false);
80 parentItem->moveToThread(m_targetThread);
82 QList< QString > connectedImages = m_controlNet->getAdjacentImages(imageSerial);
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);
90 parentItem->addChild(childItem);
97 void ImageImageTreeModel::CreateRootItemFunctor::addToRootItem(
101 if (root.testAndSetOrdered(NULL,
new RootItem)) {
102 root.loadAcquire()->moveToThread(item->thread());
106 root.loadAcquire()->addChild(item);
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;
122 void ImageImageTreeModel::rebuildItems() {
128 QFuture< QAtomicPointer< RootItem > > futureRoot;
130 if (getRebuildWatcher()->isStarted()) {
131 futureRoot = getRebuildWatcher()->future();
138 futureRoot = QtConcurrent::mappedReduced(
139 getControlNetwork()->GetCubeSerials(),
140 CreateRootItemFunctor(
this, getControlNetwork(), QThread::currentThread()),
141 &CreateRootItemFunctor::addToRootItem,
142 QtConcurrent::OrderedReduce | QtConcurrent::SequentialReduce);
144 getRebuildWatcher()->setFuture(futureRoot);