X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_ObjectsBrowser.cpp;h=75f6c32a9d86d2f0c27e7bc1fd6793ef5bde89ea;hb=52a2aa0728f8694d5774a20bd1eeba8e5e2f8b27;hp=c128f3235d88ab3400f19b6facd8054faae04f77;hpb=489132d99e1d417d5c7ce93fed8fb8ee138befbc;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index c128f3235..75f6c32a9 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + #include "XGUI_ObjectsBrowser.h" #include "XGUI_DocumentDataModel.h" #include "XGUI_Tools.h" @@ -7,6 +9,8 @@ #include #include +#include + #include #include #include @@ -14,6 +18,40 @@ #include #include #include +#include + +/** +* \ingroup GUI +* Tree item delegate for definition of data in column items editor +*/ +class XGUI_TreeViewItemDelegate: public QStyledItemDelegate +{ +public: + /// Constructor + /// \param theParent a parent of the delegate + XGUI_TreeViewItemDelegate(XGUI_DataTree* theParent):QStyledItemDelegate(theParent), myTreedView(theParent) {} + + /// Set data for item editor (name of the item) + /// \param editor a widget of editor + /// \param index the tree item index + virtual void setEditorData ( QWidget* editor, const QModelIndex& index ) const + { + QLineEdit* aEditor = dynamic_cast(editor); + if (aEditor) { + XGUI_DocumentDataModel* aModel = myTreedView->dataModel(); + ObjectPtr aObj = aModel->object(index); + if (aObj.get() != NULL) { + aEditor->setText(aObj->data()->name().c_str()); + return; + } + } + QStyledItemDelegate::setEditorData(editor, index); + } + +private: + XGUI_DataTree* myTreedView; +}; + XGUI_DataTree::XGUI_DataTree(QWidget* theParent) : QTreeView(theParent) @@ -24,6 +62,8 @@ XGUI_DataTree::XGUI_DataTree(QWidget* theParent) setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::ExtendedSelection); + setItemDelegateForColumn(0, new XGUI_TreeViewItemDelegate(this)); + connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&))); } @@ -57,16 +97,10 @@ 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 QTreeView::mouseDoubleClickEvent(theEvent); @@ -84,12 +118,20 @@ void XGUI_DataTree::commitData(QWidget* theEditor) QString aRes = aEditor->text(); ObjectPtr aFeature = mySelectedData.first(); SessionPtr aMgr = ModelAPI_Session::get(); - aMgr->rootDocument()->startOperation(); + aMgr->startOperation("Rename"); aFeature->data()->setName(qPrintable(aRes)); - aMgr->rootDocument()->finishOperation(); + aMgr->finishOperation(); } } +void XGUI_DataTree::clear() +{ + mySelectedData.clear(); + XGUI_DocumentDataModel* aModel = dataModel(); + aModel->clear(); + reset(); +} + //******************************************************************** //******************************************************************** //******************************************************************** @@ -97,7 +139,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(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); @@ -108,7 +150,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); @@ -120,7 +162,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) aLabelLay->addWidget(aLbl); SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->rootDocument(); + DocumentPtr aDoc = aMgr->moduleDocument(); // TODO: Find a name of the root document myActiveDocLbl = new QLineEdit(tr("Part set"), aLabelWgt); @@ -227,7 +269,7 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave) if (toSave) { // TODO: Save the name of root document SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->rootDocument(); + DocumentPtr aDoc = aMgr->moduleDocument(); } else { myActiveDocLbl->setText(myActiveDocLbl->property("OldText").toString()); } @@ -266,7 +308,7 @@ void XGUI_ObjectsBrowser::activatePart(const ResultPartPtr& thePart) void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) { myObjectsList = myTreeView->selectedObjects(); - bool toEnable = myObjectsList.size() > 0; + bool toEnable = myObjectsList.size() == 1; foreach(QAction* aCmd, actions()) { aCmd->setEnabled(toEnable); @@ -334,7 +376,7 @@ void XGUI_ObjectsBrowser::rebuildDataTree() } //*************************************************** -void XGUI_ObjectsBrowser::setObjectsSelected(const QList& theObjects) +void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects) { QList theIndexes; QItemSelectionModel* aSelectModel = myTreeView->selectionModel(); @@ -348,3 +390,17 @@ void XGUI_ObjectsBrowser::setObjectsSelected(const QList& theObjects) } } } + +//*************************************************** +void XGUI_ObjectsBrowser::processEvent(const std::shared_ptr& theMessage) +{ + myDocModel->processEvent(theMessage); +} + + +//*************************************************** +void XGUI_ObjectsBrowser::clearContent() +{ + myObjectsList.clear(); + myTreeView->clear(); +}