diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp index 9da7d44f3d..e5e09d23fa 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp @@ -965,3 +965,40 @@ RimCase* RimUiTreeModelPdm::caseFromItemIndex(const QModelIndex& itemIndex) return rimCase; } +//-------------------------------------------------------------------------------------------------- +/// Set toggle state for list of model indices. +/// +/// NOTE: Set toggle state directly on object, does not use setValueFromUi() +/// The caller must make sure the relevant dependencies are updated +//-------------------------------------------------------------------------------------------------- +void RimUiTreeModelPdm::setObjectToggleStateForSelection(QModelIndexList selectedIndexes, int state) +{ + bool toggleOn = (state == Qt::Checked); + + foreach (QModelIndex index, selectedIndexes) + { + if (!index.isValid()) + { + continue; + } + + caf::PdmUiTreeItem* treeItem = UiTreeModelPdm::getTreeItemFromIndex(index); + assert(treeItem); + + caf::PdmObject* obj = treeItem->dataObject(); + assert(obj); + + if (obj && obj->objectToggleField()) + { + caf::PdmField* field = dynamic_cast* >(obj->objectToggleField()); + if (field) + { + // Does not use setValueFromUi(), so the caller must make sure dependencies are updated + field->v() = toggleOn; + + emitDataChanged(index); + } + } + } +} + diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h index 4e015cb30d..cb16cc93eb 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h +++ b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h @@ -80,6 +80,7 @@ public: virtual QStringList mimeTypes() const; RimIdenticalGridCaseGroup* gridCaseGroupFromItemIndex(const QModelIndex& itemIndex); + void setObjectToggleStateForSelection(QModelIndexList selectedIndexes, int state); private slots: void slotRefreshScriptTree(QString path); @@ -87,7 +88,6 @@ private slots: private: void clearClipboard(); RimCase* caseFromItemIndex(const QModelIndex& itemIndex); - private: QFileSystemWatcher* m_scriptChangeDetector; }; diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp index 5749972ef3..edf8da282c 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp @@ -1177,9 +1177,20 @@ bool RimUiTreeView::checkAndHandleToggleOfMultipleSelection() state = Qt::Checked; } - foreach (QModelIndex mi, selectedIndexes) + RimUiTreeModelPdm* myModel = dynamic_cast(model()); + myModel->setObjectToggleStateForSelection(selectedIndexes, state); + + caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(curr); + + RimWell* well = dynamic_cast(uiItem->dataObject().p()); + if (well) { - model()->setData(mi, state, Qt::CheckStateRole); + RimReservoirView* reservoirView = NULL; + well->firstAncestorOfType(reservoirView); + if (reservoirView) + { + reservoirView->createDisplayModelAndRedraw(); + } } return true;