3 #include "ImageImageTreeModel.h" 8 #include <QFutureWatcher> 11 #include <QtConcurrentMap> 17 #include "TreeViewContent.h" 18 #include "PointLeafItem.h" 20 #include "ImageLeafItem.h" 21 #include "ImageParentItem.h" 30 ImageImageTreeModel::ImageImageTreeModel(ControlNet *cNet, TreeView *v,
31 QObject *parent) : AbstractTreeModel(cNet, v, parent) {
36 ImageImageTreeModel::~ImageImageTreeModel() {
40 ImageImageTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
41 AbstractTreeModel *tm, ControlNet *net,
QThread *tt) {
45 m_avgCharWidth = QFontMetrics(
46 m_treeModel->getView()->getContentFont()).averageCharWidth();
50 ImageImageTreeModel::CreateRootItemFunctor::CreateRootItemFunctor(
51 const CreateRootItemFunctor &other) {
52 m_treeModel = other.m_treeModel;
53 m_controlNet = other.m_controlNet;
54 m_targetThread = other.m_targetThread;
55 m_avgCharWidth = other.m_avgCharWidth;
59 ImageImageTreeModel::CreateRootItemFunctor::~CreateRootItemFunctor() {
62 m_targetThread = NULL;
66 ImageParentItem *ImageImageTreeModel::CreateRootItemFunctor::operator()(
67 const QString imageSerial)
const {
69 ImageParentItem *parentItem =
70 new ImageParentItem(imageSerial, m_controlNet, m_avgCharWidth);
71 parentItem->setSelectable(
false);
72 parentItem->moveToThread(m_targetThread);
74 QList< QString > connectedImages = m_controlNet->getAdjacentImages(imageSerial);
76 for (
int j = 0; j < connectedImages.size(); j++) {
77 ImageLeafItem *childItem =
78 new ImageLeafItem(connectedImages[j], m_controlNet, m_avgCharWidth, parentItem);
79 childItem->setSelectable(
false);
80 childItem->moveToThread(m_targetThread);
82 parentItem->addChild(childItem);
89 void ImageImageTreeModel::CreateRootItemFunctor::addToRootItem(
93 if (root.testAndSetOrdered(NULL,
new RootItem)) {
94 root.loadAcquire()->moveToThread(item->thread());
98 root.loadAcquire()->addChild(item);
102 ImageImageTreeModel::CreateRootItemFunctor &
103 ImageImageTreeModel::CreateRootItemFunctor::operator=(
104 const CreateRootItemFunctor &other) {
105 if (
this != &other) {
106 m_treeModel = other.m_treeModel;
107 m_avgCharWidth = other.m_avgCharWidth;
114 void ImageImageTreeModel::rebuildItems() {
120 QFuture< QAtomicPointer< RootItem > > futureRoot;
122 if (getRebuildWatcher()->isStarted()) {
123 futureRoot = getRebuildWatcher()->future();
130 futureRoot = QtConcurrent::mappedReduced(
131 getControlNetwork()->GetCubeSerials(),
132 CreateRootItemFunctor(
this, getControlNetwork(), QThread::currentThread()),
133 &CreateRootItemFunctor::addToRootItem,
134 QtConcurrent::OrderedReduce | QtConcurrent::SequentialReduce);
136 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...
Namespace for ISIS/Bullet specific routines.