Salome HOME
According to "operation-widget_factory-property"
[modules/shaper.git] / src / XGUI / XGUI_ObjectsBrowser.cpp
index f526690b4bb886028b4f9988cace376080d2f26a..27b92756283b4e6304239e698a03adb627b4ba26 100644 (file)
@@ -1,9 +1,11 @@
 #include "XGUI_ObjectsBrowser.h"
 #include "XGUI_DocumentDataModel.h"
+#include "XGUI_Tools.h"
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Document.h>
+#include <ModelAPI_Object.h>
 
 #include <QLayout>
 #include <QLabel>
@@ -20,6 +22,7 @@ XGUI_DataTree::XGUI_DataTree(QWidget* theParent)
 {
   setHeaderHidden(true);
   setModel(new XGUI_DocumentDataModel(this));
+  setEditTriggers(QAbstractItemView::NoEditTriggers);
 
   connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), 
           this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
@@ -81,7 +84,13 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
   if (aEditor) {
     QString aRes = aEditor->text();
     FeaturePtr aFeature = mySelectedData.first();
-    aFeature->data()->setName(qPrintable(aRes));
+    PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+    aMgr->rootDocument()->startOperation();
+    if (!XGUI_Tools::isModelObject(aFeature))
+      aFeature->data()->setName(qPrintable(aRes));
+    else
+      boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->setName(qPrintable(aRes));
+    aMgr->rootDocument()->finishOperation();
   }
 }
 
@@ -137,7 +146,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
   aLabelWgt->setFrameShape(myTreeView->frameShape());
   aLabelWgt->setFrameShadow(myTreeView->frameShadow());
 
-  connect(myTreeView, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
+  connect(myTreeView, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
   connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr)));
   connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr)));
 
@@ -149,7 +158,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
   onActivePartChanged(FeaturePtr());
 
   // Create internal actions
-  QAction* aAction = new QAction(tr("Rename"), this);
+  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);
@@ -191,7 +200,7 @@ bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent)
         QMouseEvent* aEvent = (QMouseEvent*) theEvent;
         QPoint aPnt = mapFromGlobal(aEvent->globalPos());
         if (childAt(aPnt) != myActiveDocLbl) {
-          closeDocNameEditing(false);
+          closeDocNameEditing(true);
         }
       } else if (theEvent->type() == QEvent::KeyRelease) {
         QKeyEvent* aEvent = (QKeyEvent*) theEvent;
@@ -226,10 +235,10 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave)
 }
 
 //***************************************************
-void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate)
+void XGUI_ObjectsBrowser::activatePart(const FeaturePtr& thePart)
 {
-  if (toActivate) {
-    QModelIndex aIndex = myTreeView->currentIndex();
+  if (thePart) {
+    QModelIndex aIndex = myDocModel->partIndex(thePart);
 
     if ((myDocModel->activePartIndex() != aIndex) && myDocModel->activePartIndex().isValid()) {
       myTreeView->setExpanded(myDocModel->activePartIndex(), false);
@@ -237,6 +246,7 @@ void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate)
     bool isChanged = myDocModel->activatedIndex(aIndex);
     if (isChanged) {
       if (myDocModel->activePartIndex().isValid()) {
+        myTreeView->setExpanded(aIndex.parent(), true);
         myTreeView->setExpanded(aIndex, true);
         onActivePartChanged(myDocModel->feature(aIndex));
       } else {
@@ -287,7 +297,8 @@ void XGUI_ObjectsBrowser::onEditItem()
       // Find index which corresponds the feature
       QModelIndex aIndex;
       foreach(QModelIndex aIdx, selectedIndexes()) {
-        if (dataModel()->feature(aIdx) == aFeature) {
+        FeaturePtr aFea = dataModel()->feature(aIdx);
+        if (dataModel()->feature(aIdx)->isSame(aFeature)) {
           aIndex = aIdx;
           break;
         }
@@ -304,4 +315,33 @@ void XGUI_ObjectsBrowser::onEditItem()
       myActiveDocLbl->setProperty("OldText", myActiveDocLbl->text());
     }
   }
-}
\ No newline at end of file
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::onSelectionChanged()
+{
+  myFeaturesList = myTreeView->selectedFeatures();
+  emit selectionChanged();
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::rebuildDataTree()
+{
+  myDocModel->rebuildDataTree();
+  update();
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::setFeaturesSelected(const QFeatureList& theFeatures)
+{
+  QList<QModelIndex> theIndexes;
+  QItemSelectionModel* aSelectModel = myTreeView->selectionModel();
+  aSelectModel->clear();
+
+  foreach(FeaturePtr aFeature, theFeatures) {
+    QModelIndex aIndex = myDocModel->featureIndex(aFeature);
+    if (aIndex.isValid()) {
+      aSelectModel->select(aIndex, QItemSelectionModel::Select);
+    }
+  }
+}