X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_ObjectsBrowser.cpp;h=c43ca86fa984f2763438d973f0266923fb7f1d79;hb=13d3f0d8b46a06931cbe8620b8563049eff4a9f6;hp=417a95ec69da8682c58794dbf86abf09130ed11f;hpb=eb0cd64411cc25e50efff3f695fca2ccf8be7a85;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 417a95ec6..c43ca86fa 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -2,6 +2,7 @@ #include "XGUI_ObjectsBrowser.h" #include "XGUI_Tools.h" +#include "XGUI_DataModel.h" #include #include @@ -67,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() @@ -94,7 +100,7 @@ void XGUI_DataTree::commitData(QWidget* theEditor) SessionPtr aMgr = ModelAPI_Session::get(); aMgr->startOperation("Rename"); - if (!canRename(aObj, aName)) { + if (!XGUI_Tools::canRename(this, aObj, aName)) { aMgr->abortOperation(); return; } @@ -104,21 +110,6 @@ void XGUI_DataTree::commitData(QWidget* theEditor) } } -bool XGUI_DataTree::canRename(const ObjectPtr& theObject, const QString& theName) -{ - double aValue; - ResultParameterPtr aParam; - - bool isVariableFound = ModelAPI_Tools::findVariable(theObject->document(), qPrintable(theName), aValue, aParam); - - if (isVariableFound) - QMessageBox::information(this, tr("Rename parameter"), - QString(tr("Selected parameter can not be renamed to: %1. \ -There is a parameter with the same name. Its value is: %2.")).arg(qPrintable(theName)).arg(aValue)); - - return !isVariableFound; -} - void XGUI_DataTree::clear() { ModuleBase_IDocumentDataModel* aModel = dataModel(); @@ -135,6 +126,48 @@ void XGUI_DataTree::resizeEvent(QResizeEvent* theEvent) } } +void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex) +{ + if (theIndex.column() != 1) + return; + SessionPtr aMgr = ModelAPI_Session::get(); + // When operation is opened then we can not change history + if (aMgr->isOperation()) + return; + ModuleBase_IDocumentDataModel* aModel = dataModel(); + if (aModel->flags(theIndex) == 0) + return; + ObjectPtr aObj = aModel->object(theIndex); + + DocumentPtr aDoc = aMgr->activeDocument(); + + 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 aSize = aModel->rowCount(aParent); + for (int i = 0; i < aSize; i++) { + update(aModel->index(i, 0, aParent)); + } +} //******************************************************************** //******************************************************************** @@ -186,16 +219,18 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) aLabelWgt->setFrameShape(myTreeView->frameShape()); aLabelWgt->setFrameShadow(myTreeView->frameShadow()); +#ifndef ModuleDataModel + myDocModel = new XGUI_DataModel(this); + myTreeView->setModel(myDocModel); + QItemSelectionModel* aSelMod = myTreeView->selectionModel(); + connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), + this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&))); +#endif + connect(myActiveDocLbl, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onLabelContextMenuRequested(const QPoint&))); connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this, SLOT(onContextMenuRequested(QContextMenuEvent*))); - - // Create internal actions - QAction* aAction = new QAction(QIcon(":pictures/rename_edit.png"), tr("Rename"), this); - aAction->setData("RENAME_CMD"); - connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onEditItem())); - addAction(aAction); } //*************************************************** @@ -347,14 +382,17 @@ void XGUI_ObjectsBrowser::clearContent() myTreeView->clear(); } +#ifdef ModuleDataModel void XGUI_ObjectsBrowser::setDataModel(ModuleBase_IDocumentDataModel* theModel) { myDocModel = theModel; + //myDocModel = new XGUI_DataModel(this); myTreeView->setModel(myDocModel); QItemSelectionModel* aSelMod = myTreeView->selectionModel(); connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&))); } +#endif void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected) @@ -366,7 +404,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) {