Salome HOME
Fix for the issue #1818: checking angle for fillet on Linux.
[modules/shaper.git] / src / XGUI / XGUI_ObjectsBrowser.cpp
index 3dccaf732679a81b3b00dcd5e219d0201bb2bb86..f1a119cf4105b28445f09a0ae64f5f809f975141 100644 (file)
@@ -8,12 +8,11 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Tools.h>
-#include <Events_Error.h>
 
 #include <ModuleBase_Tools.h>
 
 #include <QLayout>
-#include <QLabel>
+#include <QLineEdit>
 #include <QPixmap>
 #include <QEvent>
 #include <QMouseEvent>
@@ -135,9 +134,10 @@ void XGUI_DataTree::clear()
 
 void XGUI_DataTree::resizeEvent(QResizeEvent* theEvent)
 {
+  QTreeView::resizeEvent(theEvent);
   QSize aSize = theEvent->size();
   if (aSize.isValid()) {
-    setColumnWidth(0, aSize.width() - SECOND_COL_WIDTH);
+    setColumnWidth(0, aSize.width() - SECOND_COL_WIDTH - 6);
     setColumnWidth(1, SECOND_COL_WIDTH);
   }
 }
@@ -182,6 +182,7 @@ void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
   int aSize = aModel->rowCount(aParent);
   for (int i = 0; i < aSize; i++) {
     update(aModel->index(i, 0, aParent));
+    update(aModel->index(i, 1, aParent));
   }
 }
 
@@ -222,7 +223,7 @@ void XGUI_TreeViewStyle::drawPrimitive(PrimitiveElement theElement,
 //********************************************************************
 //********************************************************************
 XGUI_ActiveDocLbl::XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent )
-  : QLineEdit(theText, theParent), 
+  : QLabel(theText, theParent), 
   myPreSelectionStyle(""), 
   myNeutralStyle(""), 
   mySelectionStyle(""),
@@ -233,25 +234,27 @@ XGUI_ActiveDocLbl::XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent
 void XGUI_ActiveDocLbl::setTreeView(QTreeView* theView)
 {
   myTreeView = theView;
+  setFont(myTreeView->font());
+
   QPalette aPalet = myTreeView->palette();
   QColor aHighlight = aPalet.highlight().color();
   QColor aHighlightText = aPalet.highlightedText().color();
 
-  myPreSelectionStyle = "QLineEdit {background-color: ";
+  myPreSelectionStyle = "QLabel {background-color: ";
   myPreSelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 white, stop:1 " + aHighlight.lighter(170).name() + ");"; 
   myPreSelectionStyle += "border: 1px solid lightblue; border-radius: 2px }";
 
   QString aName = aPalet.color(QPalette::Base).name();
-  myNeutralStyle = "QLineEdit { border: 1px solid " + aName + " }";
+  myNeutralStyle = "QLabel { border: 1px solid " + aName + " }";
 
 
 #if (!defined HAVE_SALOME) && (defined WIN32)
-  mySelectionStyle = "QLineEdit {background-color: ";
+  mySelectionStyle = "QLabel {background-color: ";
   mySelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(236, 245, 255)";
   mySelectionStyle += ", stop:1 rgb(208, 229, 255));"; 
   mySelectionStyle += "border: 1px solid rgb(132, 172, 221); border-radius: 2px }";
 #else
-  mySelectionStyle = "QLineEdit {background-color: " + aHighlight.name();
+  mySelectionStyle = "QLabel {background-color: " + aHighlight.name();
   mySelectionStyle += "; color : " + aHighlightText.name() + "}";
 #endif
 
@@ -272,7 +275,7 @@ bool XGUI_ActiveDocLbl::event(QEvent* theEvent)
         setStyleSheet(myNeutralStyle);
       break;
   }
-  return QLineEdit::event(theEvent);
+  return QLabel::event(theEvent);
 }
 #endif
 
@@ -282,7 +285,7 @@ bool XGUI_ActiveDocLbl::eventFilter(QObject* theObj, QEvent* theEvent)
     if (theEvent->type() == QEvent::MouseButtonRelease)
       unselect();
   }
-  return QLineEdit::eventFilter(theObj, theEvent);
+  return QLabel::eventFilter(theObj, theEvent);
 }
 
 static bool MYClearing = false;
@@ -294,7 +297,7 @@ void XGUI_ActiveDocLbl::mouseReleaseEvent( QMouseEvent* e)
   // We can not block signals because on 
   // clear selection the View state will not be updated
   myTreeView->clearSelection();
-  QLineEdit::mouseReleaseEvent(e);
+  QLabel::mouseReleaseEvent(e);
   MYClearing = false;
 }
 
@@ -337,8 +340,8 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
   DocumentPtr aDoc = aMgr->moduleDocument();
 
   myActiveDocLbl = new XGUI_ActiveDocLbl(tr("Part set"), aLabelWgt);
-  myActiveDocLbl->setReadOnly(true);
-  myActiveDocLbl->setFrame(false);
+//  myActiveDocLbl->setReadOnly(true);
+//  myActiveDocLbl->setFrame(false);
   myActiveDocLbl->setContextMenuPolicy(Qt::CustomContextMenu);
 
   aLabelLay->addWidget(myActiveDocLbl);
@@ -357,14 +360,8 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
   aLabelWgt->setPalette(aPalet);
 
   myDocModel = new XGUI_DataModel(this);
-  myTreeView->setModel(myDocModel);
-
-  // It has to be done after setting of model
-  myActiveDocLbl->setTreeView(myTreeView);
-
-  QItemSelectionModel* aSelMod = myTreeView->selectionModel();
-  connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
-          this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
+  connect(myDocModel, SIGNAL(modelAboutToBeReset()), SLOT(onBeforeReset()));
+  connect(myDocModel, SIGNAL(treeRebuilt()), SLOT(onAfterModelReset()));
 
   connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
           SLOT(onContextMenuRequested(QContextMenuEvent*)));
@@ -375,6 +372,18 @@ XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
 {
 }
 
+void XGUI_ObjectsBrowser::setXMLReader(Config_DataModelReader* theReader)
+{ 
+  myDocModel->setXMLReader(theReader); 
+  myTreeView->setModel(myDocModel);
+
+  // It has to be done after setting of model
+  myActiveDocLbl->setTreeView(myTreeView);
+
+  QItemSelectionModel* aSelMod = myTreeView->selectionModel();
+  connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
+          this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
+}
 
 //***************************************************
 void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
@@ -414,19 +423,19 @@ void XGUI_ObjectsBrowser::onEditItem()
 {
   QObjectPtrList aSelectedData = selectedObjects();
   if (aSelectedData.size() > 0) {
-    ObjectPtr aFeature = aSelectedData.first();
-    if (aFeature) {  // Selection happens in TreeView
-      QObjectPtrList aList;
-      aList.append(aFeature);
-      // check whether the object can be deleted. There should not be parts which are not loaded
-      if (!XGUI_Tools::canRemoveOrRename((QWidget*)parent(), aList))
+    ObjectPtr anObject = aSelectedData.first();
+    if (anObject.get()) {  // Selection happens in TreeView
+      // check whether the object can be renamed. There should not be parts which are not loaded
+      std::set<FeaturePtr> aFeatures;
+      aFeatures.insert(ModelAPI_Feature::feature(anObject));
+      if (!XGUI_Tools::canRemoveOrRename((QWidget*)parent(), aFeatures))
         return;
 
       // Find index which corresponds the feature
       QModelIndex aIndex;
       foreach(QModelIndex aIdx, selectedIndexes()) {
         ObjectPtr aFea = dataModel()->object(aIdx);
-        if (dataModel()->object(aIdx)->isSame(aFeature)) {
+        if (dataModel()->object(aIdx)->isSame(anObject)) {
           aIndex = aIdx;
           break;
         }
@@ -440,6 +449,25 @@ void XGUI_ObjectsBrowser::onEditItem()
   }
 }
 
+//***************************************************
+QModelIndexList XGUI_ObjectsBrowser::expandedItems(const QModelIndex& theParent) const
+{
+  QModelIndexList aIndexes;
+  QModelIndex aIndex;
+  for (int i = 0; i < myDocModel->rowCount(theParent); i++) {
+    aIndex = myDocModel->index(i, 0, theParent);
+    if (myDocModel->hasChildren(aIndex)) {
+      if (myTreeView->isExpanded(aIndex)) {
+        aIndexes.append(aIndex);
+        QModelIndexList aSubIndexes = expandedItems(aIndex);
+        if (!aSubIndexes.isEmpty())
+          aIndexes.append(aSubIndexes);
+      }
+    }
+  }
+  return aIndexes;
+}
+
 //***************************************************
 void XGUI_ObjectsBrowser::rebuildDataTree()
 {
@@ -492,4 +520,16 @@ QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes)
     }
   }
   return aList;
-}
\ No newline at end of file
+}
+
+void XGUI_ObjectsBrowser::onBeforeReset()
+{
+  myExpandedItems = expandedItems();
+}
+
+void XGUI_ObjectsBrowser::onAfterModelReset()
+{
+  foreach(QModelIndex aIndex, myExpandedItems) {
+    myTreeView->setExpanded(aIndex, true);
+  }
+}