From: vsv Date: Mon, 25 May 2015 09:20:51 +0000 (+0300) Subject: Issue #556: Make computation of flags more correct for root model X-Git-Tag: V_1.2.0~99 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c83f12f16a84be5881402a01e4c1345dd454be10;p=modules%2Fshaper.git Issue #556: Make computation of flags more correct for root model --- diff --git a/src/PartSet/PartSet_DocumentDataModel.cpp b/src/PartSet/PartSet_DocumentDataModel.cpp index 50bae54ac..c4f245821 100644 --- a/src/PartSet/PartSet_DocumentDataModel.cpp +++ b/src/PartSet/PartSet_DocumentDataModel.cpp @@ -644,7 +644,12 @@ Qt::ItemFlags PartSet_DocumentDataModel::flags(const QModelIndex& theIndex) cons } else { QModelIndex* aIndex = toSourceModelIndex(theIndex); const QAbstractItemModel* aModel = aIndex->model(); - return aModel->flags(*aIndex); + Qt::ItemFlags aFlags = aModel->flags(*aIndex); + if (aModel == myModel) { + if (myModel->object(*aIndex)) + aFlags |= Qt::ItemIsEditable; + } + return aFlags; } } diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 25e2db0f5..e8b0a1fed 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -229,8 +229,13 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave) //*************************************************** void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) { - QObjectPtrList aSelectedData = selectedObjects(); - bool toEnable = aSelectedData.size() == 1; + QModelIndexList aIndexes; + QObjectPtrList aSelectedData = selectedObjects(&aIndexes); + bool toEnable = false; + if (aSelectedData.size() == 1) { + Qt::ItemFlags aFlags = dataModel()->flags(aIndexes.first()); + toEnable = ((aFlags & Qt::ItemIsEditable) != 0); + } foreach(QAction* aCmd, actions()) { aCmd->setEnabled(toEnable); } @@ -324,7 +329,7 @@ void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected, emit selectionChanged(); } -QObjectPtrList XGUI_ObjectsBrowser::selectedObjects() const +QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) const { QObjectPtrList aList; QModelIndexList aIndexes = selectedIndexes(); @@ -333,8 +338,11 @@ QObjectPtrList XGUI_ObjectsBrowser::selectedObjects() const for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) { if ((*aIt).column() == 0) { ObjectPtr aObject = aModel->object(*aIt); - if (aObject) + if (aObject) { aList.append(aObject); + if (theIndexes) + theIndexes->append(*aIt); + } } } return aList; diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index e5965b0dd..530a86a51 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -73,7 +73,8 @@ Q_OBJECT } //! Returns list of currently selected objects - QObjectPtrList selectedObjects() const; + //! \param theIndexes - output list of corresponded indexes (can be NULL) + QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const; /// Set selected list of objects /// \param theObjects list of objects to select