Salome HOME
The selection problem with an object deactivate:
[modules/shaper.git] / src / XGUI / XGUI_ObjectsBrowser.cpp
index 699d6e518e2dcd9b40810f1d0bd3970f7bd15c33..75f6c32a9d86d2f0c27e7bc1fd6793ef5bde89ea 100644 (file)
@@ -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 <ModelAPI_Document.h>
 #include <ModelAPI_Object.h>
 
+#include <ModuleBase_Tools.h>
+
 #include <QLayout>
 #include <QLabel>
 #include <QLineEdit>
 #include <QEvent>
 #include <QMouseEvent>
 #include <QAction>
+#include <QStyledItemDelegate>
+
+/**
+* \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<QLineEdit*>(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&)));
 }
@@ -58,7 +98,7 @@ void XGUI_DataTree::mouseDoubleClickEvent(QMouseEvent* theEvent)
     QModelIndex aIndex = currentIndex();
     XGUI_DocumentDataModel* aModel = dataModel();
     ObjectPtr aObject = aModel->object(aIndex);
-    ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
+    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
     if (aPart) {
       aPart->activate();
     }
@@ -78,7 +118,7 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
     QString aRes = aEditor->text();
     ObjectPtr aFeature = mySelectedData.first();
     SessionPtr aMgr = ModelAPI_Session::get();
-    aMgr->startOperation();
+    aMgr->startOperation("Rename");
     aFeature->data()->setName(qPrintable(aRes));
     aMgr->finishOperation();
   }
@@ -99,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);
@@ -110,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);
@@ -336,7 +376,7 @@ void XGUI_ObjectsBrowser::rebuildDataTree()
 }
 
 //***************************************************
-void XGUI_ObjectsBrowser::setObjectsSelected(const QList<ObjectPtr>& theObjects)
+void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects)
 {
   QList<QModelIndex> theIndexes;
   QItemSelectionModel* aSelectModel = myTreeView->selectionModel();
@@ -352,7 +392,7 @@ void XGUI_ObjectsBrowser::setObjectsSelected(const QList<ObjectPtr>& theObjects)
 }
 
 //***************************************************
-void XGUI_ObjectsBrowser::processEvent(const boost::shared_ptr<Events_Message>& theMessage)
+void XGUI_ObjectsBrowser::processEvent(const std::shared_ptr<Events_Message>& theMessage)
 { 
   myDocModel->processEvent(theMessage); 
 }