9#include "ImageImageTreeModel.h"
14#include <QFutureWatcher>
17#include <QtConcurrentMap>
19#include "ControlMeasure.h"
20#include "ControlNet.h"
23#include "TreeViewContent.h"
24#include "PointLeafItem.h"
26#include "ImageLeafItem.h"
27#include "ImageParentItem.h"
36 ImageImageTreeModel::ImageImageTreeModel(ControlNet *cNet, TreeView *v,
37 QObject *parent) : AbstractTreeModel(cNet, v, parent) {
42 ImageImageTreeModel::~ImageImageTreeModel() {
46 ImageImageTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
47 AbstractTreeModel *tm, ControlNet *net,
QThread *tt) {
51 m_avgCharWidth = QFontMetrics(
52 m_treeModel->getView()->getContentFont()).averageCharWidth();
56 ImageImageTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
57 const CreateRootItemFunctor &other) {
58 m_treeModel = other.m_treeModel;
59 m_controlNet = other.m_controlNet;
60 m_targetThread = other.m_targetThread;
61 m_avgCharWidth = other.m_avgCharWidth;
65 ImageImageTreeModel::CreateRootItemFunctor::~CreateRootItemFunctor() {
68 m_targetThread = NULL;
72 ImageParentItem *ImageImageTreeModel::CreateRootItemFunctor::operator()(
73 const QString imageSerial)
const {
75 ImageParentItem *parentItem =
76 new ImageParentItem(imageSerial, m_controlNet, m_avgCharWidth);
77 parentItem->setSelectable(
false);
78 parentItem->moveToThread(m_targetThread);
80 QList< QString > connectedImages = m_controlNet->getAdjacentImages(imageSerial);
82 for (
int j = 0; j < connectedImages.size(); j++) {
83 ImageLeafItem *childItem =
84 new ImageLeafItem(connectedImages[j], m_controlNet, m_avgCharWidth, parentItem);
85 childItem->setSelectable(
false);
86 childItem->moveToThread(m_targetThread);
88 parentItem->addChild(childItem);
95 void ImageImageTreeModel::CreateRootItemFunctor::addToRootItem(
96 QAtomicPointer< RootItem > & root, ImageParentItem *
const &item) {
99 if (root.testAndSetOrdered(NULL,
new RootItem)) {
100 root.loadAcquire()->moveToThread(item->thread());
104 root.loadAcquire()->addChild(item);
108 ImageImageTreeModel::CreateRootItemFunctor &
109 ImageImageTreeModel::CreateRootItemFunctor::operator=(
110 const CreateRootItemFunctor &other) {
111 if (
this != &other) {
112 m_treeModel = other.m_treeModel;
113 m_avgCharWidth = other.m_avgCharWidth;
120 void ImageImageTreeModel::rebuildItems() {
125 emit filterCountsChanged(-1, getTopLevelItemCount());
126 QFuture< QAtomicPointer< RootItem > > futureRoot;
128 if (getRebuildWatcher()->isStarted()) {
129 futureRoot = getRebuildWatcher()->future();
136 futureRoot = QtConcurrent::mappedReduced(
137 getControlNetwork()->GetCubeSerials(),
138 CreateRootItemFunctor(
this, getControlNetwork(), QThread::currentThread()),
139 &CreateRootItemFunctor::addToRootItem,
140 QtConcurrent::OrderedReduce | QtConcurrent::SequentialReduce);
142 getRebuildWatcher()->setFuture(futureRoot);
This is free and unencumbered software released into the public domain.