9#include "PointMeasureTreeModel.h" 
   14#include <QFutureWatcher> 
   17#include <QtConcurrentMap> 
   19#include "ControlNet.h" 
   20#include "ControlPoint.h" 
   23#include "TreeViewContent.h" 
   24#include "PointParentItem.h" 
   25#include "MeasureLeafItem.h" 
   33  PointMeasureTreeModel::PointMeasureTreeModel(ControlNet *controlNet,
 
   35    AbstractTreeModel(controlNet, v, parent) {
 
   40  PointMeasureTreeModel::~PointMeasureTreeModel() {
 
   44  PointMeasureTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
 
   45    AbstractTreeModel *tm, 
QThread *tt) {
 
   48    m_avgCharWidth = QFontMetrics(
 
   49        m_treeModel->getView()->getContentFont()).averageCharWidth();
 
   53  PointMeasureTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
 
   54    const CreateRootItemFunctor &other) {
 
   55    m_treeModel = other.m_treeModel;
 
   56    m_targetThread = other.m_targetThread;
 
   57    m_avgCharWidth = other.m_avgCharWidth;
 
   60  PointMeasureTreeModel::CreateRootItemFunctor::~CreateRootItemFunctor() {
 
   65  PointParentItem *PointMeasureTreeModel::CreateRootItemFunctor::operator()(
 
   66    ControlPoint *
const &point)
 const {
 
   67    PointParentItem *pointItem = 
new PointParentItem(point, m_avgCharWidth);
 
   68    pointItem->moveToThread(m_targetThread);
 
   70    for (
int j = 0; j < point->GetNumMeasures(); j++) {
 
   71      const ControlMeasure *measure = point->GetMeasure(j);
 
   73      MeasureLeafItem *measureItem = 
new MeasureLeafItem(
 
   74        const_cast< ControlMeasure * 
>(measure), m_avgCharWidth, pointItem);
 
   75      measureItem->moveToThread(m_targetThread);
 
   77      pointItem->addChild(measureItem);
 
   84  void PointMeasureTreeModel::CreateRootItemFunctor::addToRootItem(
 
   85    QAtomicPointer< RootItem > & root, PointParentItem *
const &item) {
 
   88    if (root.testAndSetOrdered(NULL, 
new RootItem)) {
 
   89      root.loadAcquire()->moveToThread(item->thread());
 
   93      root.loadAcquire()->addChild(item);
 
   97  PointMeasureTreeModel::CreateRootItemFunctor &
 
   98  PointMeasureTreeModel::CreateRootItemFunctor::operator=(
 
   99    const CreateRootItemFunctor &other) {
 
  100    if (
this != &other) {
 
  101      m_treeModel = other.m_treeModel;
 
  102      m_avgCharWidth = other.m_avgCharWidth;
 
  108  void PointMeasureTreeModel::rebuildItems() {
 
  112      emit filterCountsChanged(-1, getTopLevelItemCount());
 
  113      QFuture< QAtomicPointer< RootItem > > futureRoot;
 
  114      if (getRebuildWatcher()->isStarted()) {
 
  115        futureRoot = getRebuildWatcher()->future();
 
  119      futureRoot = QtConcurrent::mappedReduced(
 
  120          getControlNetwork()->GetPoints(),
 
  121          CreateRootItemFunctor(
this, QThread::currentThread()),
 
  122          &CreateRootItemFunctor::addToRootItem,
 
  123          QtConcurrent::OrderedReduce | QtConcurrent::SequentialReduce);
 
  125      getRebuildWatcher()->setFuture(futureRoot);
 
This is free and unencumbered software released into the public domain.