X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_ObjectsBrowser.cpp;h=2ff582bb7c70b08fa7024558839f717aa2a8eca3;hb=3a5be0c5d1edb60a71f9daab6dd834ffa45eb550;hp=125e1aaf4bc17cd6d52adda9f90296f88e671bb0;hpb=057e426145a26c02a1c5d6e1c220f92a17d8e53d;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 125e1aaf4..2ff582bb7 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -1,12 +1,16 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + #include "XGUI_ObjectsBrowser.h" #include "XGUI_DocumentDataModel.h" #include "XGUI_Tools.h" #include -#include +#include #include #include +#include + #include #include #include @@ -15,16 +19,16 @@ #include #include - - XGUI_DataTree::XGUI_DataTree(QWidget* theParent) - : QTreeView(theParent) + : QTreeView(theParent) { setHeaderHidden(true); setModel(new XGUI_DocumentDataModel(this)); setEditTriggers(QAbstractItemView::NoEditTriggers); + setSelectionBehavior(QAbstractItemView::SelectRows); + setSelectionMode(QAbstractItemView::ExtendedSelection); - connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), + connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&))); } @@ -32,23 +36,22 @@ XGUI_DataTree::~XGUI_DataTree() { } -XGUI_DocumentDataModel* XGUI_DataTree::dataModel() const -{ - return static_cast(model()); +XGUI_DocumentDataModel* XGUI_DataTree::dataModel() const +{ + return static_cast(model()); } - -void XGUI_DataTree::onSelectionChanged(const QItemSelection& theSelected, - const QItemSelection& theDeselected) +void XGUI_DataTree::onSelectionChanged(const QItemSelection& theSelected, + const QItemSelection& theDeselected) { mySelectedData.clear(); QModelIndexList aIndexes = selectionModel()->selectedIndexes(); XGUI_DocumentDataModel* aModel = dataModel(); QModelIndexList::const_iterator aIt; for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) { - FeaturePtr aFeature = aModel->feature(*aIt); - if (aFeature) - mySelectedData.append(aFeature); + ObjectPtr aObject = aModel->object(*aIt); + if (aObject) + mySelectedData.append(aObject); } emit selectionChanged(); } @@ -58,18 +61,12 @@ void XGUI_DataTree::mouseDoubleClickEvent(QMouseEvent* theEvent) if (theEvent->button() == Qt::LeftButton) { QModelIndex aIndex = currentIndex(); XGUI_DocumentDataModel* aModel = dataModel(); - - if ((aModel->activePartIndex() != aIndex) && aModel->activePartIndex().isValid()) { - setExpanded(aModel->activePartIndex(), false); - } - bool isChanged = aModel->activatedIndex(aIndex); - QTreeView::mouseDoubleClickEvent(theEvent); - if (isChanged) { - if (aModel->activePartIndex().isValid()) - setExpanded(aIndex, true); - emit activePartChanged(aModel->activePart()); + ObjectPtr aObject = aModel->object(aIndex); + ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); + if (aPart) { + aPart->activate(); } - } else + } else QTreeView::mouseDoubleClickEvent(theEvent); } @@ -83,25 +80,30 @@ void XGUI_DataTree::commitData(QWidget* theEditor) QLineEdit* aEditor = dynamic_cast(theEditor); if (aEditor) { QString aRes = aEditor->text(); - FeaturePtr aFeature = mySelectedData.first(); - PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); - aMgr->rootDocument()->startOperation(); - if (!XGUI_Tools::isModelObject(aFeature)) - aFeature->data()->setName(qPrintable(aRes)); - else - boost::dynamic_pointer_cast(aFeature)->setName(qPrintable(aRes)); - aMgr->rootDocument()->finishOperation(); + ObjectPtr aFeature = mySelectedData.first(); + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->startOperation("Rename"); + aFeature->data()->setName(qPrintable(aRes)); + aMgr->finishOperation(); } } +void XGUI_DataTree::clear() +{ + mySelectedData.clear(); + XGUI_DocumentDataModel* aModel = dataModel(); + aModel->clear(); + reset(); +} + //******************************************************************** //******************************************************************** //******************************************************************** XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) - : QWidget(theParent) + : QWidget(theParent) { QVBoxLayout* aLayout = new QVBoxLayout(this); - aLayout->setContentsMargins(0, 0, 0, 0); + ModuleBase_Tools::zeroMargins(aLayout); aLayout->setSpacing(0); QFrame* aLabelWgt = new QFrame(this); @@ -112,7 +114,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) aLayout->addWidget(aLabelWgt); QHBoxLayout* aLabelLay = new QHBoxLayout(aLabelWgt); - aLabelLay->setContentsMargins(0, 0, 0, 0); + ModuleBase_Tools::zeroMargins(aLabelLay); aLabelLay->setSpacing(0); QLabel* aLbl = new QLabel(aLabelWgt); @@ -123,8 +125,8 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) aLabelLay->addWidget(aLbl); - PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); - DocumentPtr aDoc = aMgr->rootDocument(); + SessionPtr aMgr = ModelAPI_Session::get(); + DocumentPtr aDoc = aMgr->moduleDocument(); // TODO: Find a name of the root document myActiveDocLbl = new QLineEdit(tr("Part set"), aLabelWgt); @@ -136,7 +138,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) myActiveDocLbl->installEventFilter(this); aLabelLay->addWidget(myActiveDocLbl); - aLabelLay->setStretch(1,1); + aLabelLay->setStretch(1, 1); myTreeView = new XGUI_DataTree(this); aLayout->addWidget(myTreeView); @@ -146,16 +148,18 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) aLabelWgt->setFrameShape(myTreeView->frameShape()); aLabelWgt->setFrameShadow(myTreeView->frameShadow()); - connect(myTreeView, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); - connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr))); - connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr))); + connect(myTreeView, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + connect(myTreeView, SIGNAL(activePartChanged(ObjectPtr)), this, + SLOT(onActivePartChanged(ObjectPtr))); + connect(myTreeView, SIGNAL(activePartChanged(ObjectPtr)), this, + SIGNAL(activePartChanged(ObjectPtr))); - connect(myActiveDocLbl, SIGNAL(customContextMenuRequested(const QPoint&)), - this, SLOT(onLabelContextMenuRequested(const QPoint&))); - connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), - this, SLOT(onContextMenuRequested(QContextMenuEvent*))); - - onActivePartChanged(FeaturePtr()); + connect(myActiveDocLbl, SIGNAL(customContextMenuRequested(const QPoint&)), this, + SLOT(onLabelContextMenuRequested(const QPoint&))); + connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this, + SLOT(onContextMenuRequested(QContextMenuEvent*))); + + onActivePartChanged(ObjectPtr()); // Create internal actions QAction* aAction = new QAction(QIcon(":pictures/rename_edit.png"), tr("Rename"), this); @@ -170,12 +174,12 @@ XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser() } //*************************************************** -void XGUI_ObjectsBrowser::onActivePartChanged(FeaturePtr thePart) +void XGUI_ObjectsBrowser::onActivePartChanged(ObjectPtr thePart) { QPalette aPalet = myActiveDocLbl->palette(); if (thePart) { aPalet.setColor(QPalette::Text, Qt::black); - } else { + } else { aPalet.setColor(QPalette::Text, QColor(0, 72, 140)); } myActiveDocLbl->setPalette(aPalet); @@ -191,8 +195,8 @@ bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent) myTreeView->setExpanded(myDocModel->activePartIndex(), false); } myDocModel->deactivatePart(); - onActivePartChanged(FeaturePtr()); - emit activePartChanged(FeaturePtr()); + onActivePartChanged(ObjectPtr()); + emit activePartChanged(ObjectPtr()); } } else { // End of editing by mouse click @@ -205,13 +209,14 @@ bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent) } else if (theEvent->type() == QEvent::KeyRelease) { QKeyEvent* aEvent = (QKeyEvent*) theEvent; switch (aEvent->key()) { - case Qt::Key_Return: // Accept current input - closeDocNameEditing(true); - break; - case Qt::Key_Escape: // Cancel the input - closeDocNameEditing(false); - break; - } + case Qt::Key_Return: + case Qt::Key_Enter: // Accept current input + closeDocNameEditing(true); + break; + case Qt::Key_Escape: // Cancel the input + closeDocNameEditing(false); + break; + } } } } @@ -227,15 +232,15 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave) myActiveDocLbl->setReadOnly(true); if (toSave) { // TODO: Save the name of root document - PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); - DocumentPtr aDoc = aMgr->rootDocument(); + SessionPtr aMgr = ModelAPI_Session::get(); + DocumentPtr aDoc = aMgr->moduleDocument(); } else { myActiveDocLbl->setText(myActiveDocLbl->property("OldText").toString()); } } //*************************************************** -void XGUI_ObjectsBrowser::activatePart(const FeaturePtr& thePart) +void XGUI_ObjectsBrowser::activatePart(const ResultPartPtr& thePart) { if (thePart) { QModelIndex aIndex = myDocModel->partIndex(thePart); @@ -248,9 +253,9 @@ void XGUI_ObjectsBrowser::activatePart(const FeaturePtr& thePart) if (myDocModel->activePartIndex().isValid()) { myTreeView->setExpanded(aIndex.parent(), true); myTreeView->setExpanded(aIndex, true); - onActivePartChanged(myDocModel->feature(aIndex)); + onActivePartChanged(myDocModel->object(aIndex)); } else { - onActivePartChanged(FeaturePtr()); + onActivePartChanged(ObjectPtr()); } } } else { @@ -258,17 +263,18 @@ void XGUI_ObjectsBrowser::activatePart(const FeaturePtr& thePart) if (aIndex.isValid()) { myDocModel->activatedIndex(aIndex); myTreeView->setExpanded(aIndex, false); - onActivePartChanged(FeaturePtr()); + onActivePartChanged(ObjectPtr()); } } } //*************************************************** -void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) +void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) { - myFeaturesList = myTreeView->selectedFeatures(); - bool toEnable = myFeaturesList.size() > 0; - foreach(QAction* aCmd, actions()) { + myObjectsList = myTreeView->selectedObjects(); + bool toEnable = myObjectsList.size() == 1; + foreach(QAction* aCmd, actions()) + { aCmd->setEnabled(toEnable); } emit contextMenuRequested(theEvent); @@ -277,28 +283,30 @@ void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) //*************************************************** void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt) { - myFeaturesList.clear(); + myObjectsList.clear(); //Empty feature pointer means that selected root document - myFeaturesList.append(FeaturePtr()); + myObjectsList.append(ObjectPtr()); - foreach(QAction* aCmd, actions()) { + foreach(QAction* aCmd, actions()) + { aCmd->setEnabled(true); } - QContextMenuEvent aEvent( QContextMenuEvent::Mouse, thePnt, myActiveDocLbl->mapToGlobal(thePnt) ); + QContextMenuEvent aEvent(QContextMenuEvent::Mouse, thePnt, myActiveDocLbl->mapToGlobal(thePnt)); emit contextMenuRequested(&aEvent); } //*************************************************** void XGUI_ObjectsBrowser::onEditItem() { - if (myFeaturesList.size() > 0) { - FeaturePtr aFeature = myFeaturesList.first(); - if (aFeature) { // Selection happens in TreeView + if (myObjectsList.size() > 0) { + ObjectPtr aFeature = myObjectsList.first(); + if (aFeature) { // Selection happens in TreeView // Find index which corresponds the feature QModelIndex aIndex; - foreach(QModelIndex aIdx, selectedIndexes()) { - FeaturePtr aFea = dataModel()->feature(aIdx); - if (dataModel()->feature(aIdx)->isSame(aFeature)) { + foreach(QModelIndex aIdx, selectedIndexes()) + { + ObjectPtr aFea = dataModel()->object(aIdx); + if (dataModel()->object(aIdx)->isSame(aFeature)) { aIndex = aIdx; break; } @@ -307,7 +315,7 @@ void XGUI_ObjectsBrowser::onEditItem() myTreeView->setCurrentIndex(aIndex); myTreeView->edit(aIndex); } - } else { //Selection happens in Upper label + } else { //Selection happens in Upper label myActiveDocLbl->setReadOnly(false); myActiveDocLbl->setFocus(); myActiveDocLbl->selectAll(); @@ -315,4 +323,48 @@ void XGUI_ObjectsBrowser::onEditItem() myActiveDocLbl->setProperty("OldText", myActiveDocLbl->text()); } } -} \ No newline at end of file +} + +//*************************************************** +void XGUI_ObjectsBrowser::onSelectionChanged() +{ + myObjectsList = myTreeView->selectedObjects(); + emit selectionChanged(); +} + +//*************************************************** +void XGUI_ObjectsBrowser::rebuildDataTree() +{ + myDocModel->rebuildDataTree(); + update(); +} + +//*************************************************** +void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects) +{ + QList theIndexes; + QItemSelectionModel* aSelectModel = myTreeView->selectionModel(); + aSelectModel->clear(); + + foreach(ObjectPtr aFeature, theObjects) + { + QModelIndex aIndex = myDocModel->objectIndex(aFeature); + if (aIndex.isValid()) { + aSelectModel->select(aIndex, QItemSelectionModel::Select); + } + } +} + +//*************************************************** +void XGUI_ObjectsBrowser::processEvent(const std::shared_ptr& theMessage) +{ + myDocModel->processEvent(theMessage); +} + + +//*************************************************** +void XGUI_ObjectsBrowser::clearContent() +{ + myObjectsList.clear(); + myTreeView->clear(); +}