} 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;
}
}
//***************************************************
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);
}
emit selectionChanged();
}
-QObjectPtrList XGUI_ObjectsBrowser::selectedObjects() const
+QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) const
{
QObjectPtrList aList;
QModelIndexList aIndexes = selectedIndexes();
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;
}
//! 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