X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_ObjectsBrowser.cpp;h=acdd5e5fb4806d2b37b0190e62d802d55a60c197;hb=45fcac308a927f173b4cf7a5c705776be26c687f;hp=81e5b9d4cb344c9509625a8641f527beb08c2f12;hpb=0b64e548d2b27f6c0bfd5a52e20c1f157caa7464;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 81e5b9d4c..acdd5e5fb 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -2,10 +2,12 @@ #include "XGUI_ObjectsBrowser.h" #include "XGUI_Tools.h" +#include "XGUI_DataModel.h" #include #include #include +#include #include #include @@ -18,7 +20,7 @@ #include #include #include - +#include /// Width of second column (minimum acceptable = 27) #define SECOND_COL_WIDTH 30 @@ -66,6 +68,11 @@ XGUI_DataTree::XGUI_DataTree(QWidget* theParent) setSelectionMode(QAbstractItemView::ExtendedSelection); setItemDelegateForColumn(0, new XGUI_TreeViewItemDelegate(this)); + +#ifndef ModuleDataModel + connect(this, SIGNAL(doubleClicked(const QModelIndex&)), + SLOT(onDoubleClick(const QModelIndex&))); +#endif } XGUI_DataTree::~XGUI_DataTree() @@ -86,13 +93,19 @@ void XGUI_DataTree::commitData(QWidget* theEditor) { QLineEdit* aEditor = dynamic_cast(theEditor); if (aEditor) { - QString aRes = aEditor->text(); + QString aName = aEditor->text(); QModelIndexList aIndexList = selectionModel()->selectedIndexes(); ModuleBase_IDocumentDataModel* aModel = dataModel(); ObjectPtr aObj = aModel->object(aIndexList.first()); SessionPtr aMgr = ModelAPI_Session::get(); aMgr->startOperation("Rename"); - aObj->data()->setName(qPrintable(aRes)); + + if (!XGUI_Tools::canRename(this, aObj, aName)) { + aMgr->abortOperation(); + return; + } + + aObj->data()->setName(qPrintable(aName)); aMgr->finishOperation(); } } @@ -113,6 +126,50 @@ void XGUI_DataTree::resizeEvent(QResizeEvent* theEvent) } } +void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex) +{ + if (theIndex.column() != 1) + return; + ModuleBase_IDocumentDataModel* aModel = dataModel(); + if (aModel->flags(theIndex) == 0) + return; + ObjectPtr aObj = aModel->object(theIndex); + + SessionPtr aMgr = ModelAPI_Session::get(); + DocumentPtr aDoc = aMgr->activeDocument(); + + QModelIndex aOldIndex = aModel->lastHistoryIndex(); + + std::string aOpName = tr("History change").toStdString(); + if (aObj.get()) { + if (aObj->document() != aDoc) + return; + aMgr->startOperation(aOpName); + aDoc->setCurrentFeature(std::dynamic_pointer_cast(aObj), true); + aMgr->finishOperation(); + } else { + // Ignore clicks on folders outside current document + if ((theIndex.internalId() == -1) && (aDoc != aMgr->moduleDocument())) + // Clicked folder under root but active document is another + return; + if ((theIndex.internalId() != -1) && (aDoc.get() != theIndex.internalPointer())) + // Cliced not on active document folder + return; + + aMgr->startOperation(aOpName); + aDoc->setCurrentFeature(FeaturePtr(), true); + aMgr->finishOperation(); + } + QModelIndex aNewIndex = aModel->lastHistoryIndex(); + QModelIndex aParent = theIndex.parent(); + int aStartRow = std::min(aOldIndex.row(), aNewIndex.row()); + int aEndRow = std::max(aOldIndex.row(), aNewIndex.row()); + for (int i = aStartRow; i <= aEndRow; i++) { + update(aModel->index(i, 0, aParent)); + } + update(aOldIndex); + update(aNewIndex); +} //******************************************************************** //******************************************************************** @@ -266,6 +323,12 @@ void XGUI_ObjectsBrowser::onEditItem() if (aSelectedData.size() > 0) { ObjectPtr aFeature = aSelectedData.first(); if (aFeature) { // Selection happens in TreeView + QObjectPtrList aList; + aList.append(aFeature); + // check whether the object can be deleted. There should not be parts which are not loaded + if (!XGUI_Tools::canRemoveOrRename((QWidget*)parent(), aList)) + return; + // Find index which corresponds the feature QModelIndex aIndex; foreach(QModelIndex aIdx, selectedIndexes()) { @@ -321,7 +384,11 @@ void XGUI_ObjectsBrowser::clearContent() void XGUI_ObjectsBrowser::setDataModel(ModuleBase_IDocumentDataModel* theModel) { +#ifdef ModuleDataModel myDocModel = theModel; +#else + myDocModel = new XGUI_DataModel(this); +#endif myTreeView->setModel(myDocModel); QItemSelectionModel* aSelMod = myTreeView->selectionModel(); connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), @@ -338,7 +405,11 @@ QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) { QObjectPtrList aList; QModelIndexList aIndexes = selectedIndexes(); +#ifdef ModuleDataModel ModuleBase_IDocumentDataModel* aModel = dataModel(); +#else + XGUI_DataModel* aModel = dataModel(); +#endif QModelIndexList::const_iterator aIt; for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) { if ((*aIt).column() == 0) {