3 #include "PointMeasureTreeModel.h"
8 #include <QFutureWatcher>
11 #include <QtConcurrentMap>
17 #include "TreeViewContent.h"
18 #include "PointParentItem.h"
19 #include "MeasureLeafItem.h"
28 PointMeasureTreeModel::PointMeasureTreeModel(ControlNet *controlNet,
30 AbstractTreeModel(controlNet, v, parent) {
35 PointMeasureTreeModel::~PointMeasureTreeModel() {
39 PointMeasureTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
40 AbstractTreeModel *tm,
QThread *tt) {
43 m_avgCharWidth = QFontMetrics(
44 m_treeModel->getView()->getContentFont()).averageCharWidth();
48 PointMeasureTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
49 const CreateRootItemFunctor &other) {
50 m_treeModel = other.m_treeModel;
51 m_targetThread = other.m_targetThread;
52 m_avgCharWidth = other.m_avgCharWidth;
55 PointMeasureTreeModel::CreateRootItemFunctor::~CreateRootItemFunctor() {
60 PointParentItem *PointMeasureTreeModel::CreateRootItemFunctor::operator()(
61 ControlPoint *
const &point)
const {
62 PointParentItem *pointItem =
new PointParentItem(point, m_avgCharWidth);
63 pointItem->moveToThread(m_targetThread);
65 for (
int j = 0; j < point->GetNumMeasures(); j++) {
66 const ControlMeasure *measure = point->GetMeasure(j);
69 MeasureLeafItem *measureItem =
new MeasureLeafItem(
70 const_cast< ControlMeasure * >(measure), m_avgCharWidth, pointItem);
71 measureItem->moveToThread(m_targetThread);
73 pointItem->addChild(measureItem);
80 void PointMeasureTreeModel::CreateRootItemFunctor::addToRootItem(
84 if (root.testAndSetOrdered(NULL,
new RootItem)) {
85 root.loadAcquire()->moveToThread(item->thread());
89 root.loadAcquire()->addChild(item);
93 PointMeasureTreeModel::CreateRootItemFunctor &
94 PointMeasureTreeModel::CreateRootItemFunctor::operator=(
95 const CreateRootItemFunctor &other) {
97 m_treeModel = other.m_treeModel;
98 m_avgCharWidth = other.m_avgCharWidth;
104 void PointMeasureTreeModel::rebuildItems() {
109 QFuture< QAtomicPointer< RootItem > > futureRoot;
110 if (getRebuildWatcher()->isStarted()) {
111 futureRoot = getRebuildWatcher()->future();
115 ASSERT(getControlNetwork());
116 futureRoot = QtConcurrent::mappedReduced(
117 getControlNetwork()->GetPoints(),
118 CreateRootItemFunctor(
this, QThread::currentThread()),
119 &CreateRootItemFunctor::addToRootItem,
120 QtConcurrent::OrderedReduce | QtConcurrent::SequentialReduce);
122 getRebuildWatcher()->setFuture(futureRoot);
void filterCountsChanged(int visibleTopLevelItemCount, int topLevelItemCount)
This signal is emitted after filtering to provide the number of visible top-level items remaining aft...