Salome HOME
Issue #3073: Show filters for Group feature in information panel.
authorvsv <vsv@opencascade.com>
Fri, 6 Dec 2019 08:22:20 +0000 (11:22 +0300)
committervsv <vsv@opencascade.com>
Fri, 6 Dec 2019 08:22:20 +0000 (11:22 +0300)
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp
src/ModuleBase/ModuleBase_WidgetSelectionFilter.h
src/XGUI/XGUI_InspectionPanel.cpp

index 268dcaf229ba3844251834f4fd3efbc7646600a3..4060181c0d412c27e0e812e9dc8393c2b1168ec4 100644 (file)
@@ -313,6 +313,10 @@ Q_OBJECT
   /// Returns True if data of its attribute was modified
   virtual bool isModified() const { return false; }
 
+  virtual void setReadOnly(bool isReadOnly) { setEnabled(!isReadOnly); }
+
+  virtual bool isReadOnly() const { return !isEnabled(); }
+
 signals:
   /// The signal about widget values are to be changed
   void beforeValuesChanged();
index 1ccee34fd266af3ab292b78113e5512030c09467..33f14a17ec64014ab79ecf2543b408320d7690da 100644 (file)
@@ -114,7 +114,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
                                                                const Config_WidgetAPI* theData)
 : ModuleBase_WidgetSelector(theParent, theWorkshop, theData),
   myIsSetSelectionBlocked(false), myCurrentHistoryIndex(-1),
-  myIsFirst(true), myFiltersWgt(0)
+  myIsFirst(true), myFiltersWgt(0), myShowOnlyBtn(0)
 {
   std::string aPropertyTypes = theData->getProperty("shape_types");
   QString aTypesStr = aPropertyTypes.c_str();
@@ -125,8 +125,8 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
   if (!aAllowedList.isEmpty())
     myAllowedObjects = aAllowedList.split(' ', QString::SkipEmptyParts);
 
-  QVBoxLayout* aMainLay = new QVBoxLayout(this);
-  ModuleBase_Tools::adjustMargins(aMainLay);
+  myMainLayout = new QVBoxLayout(this);
+  ModuleBase_Tools::adjustMargins(myMainLayout);
 
   QStringList aIconsList = getIconsList(myShapeTypes);
   myTypeCtrl = new ModuleBase_ChoiceCtrl(this, myShapeTypes, aIconsList);
@@ -135,7 +135,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
     myTypeCtrl->setValue(0);
     myDefMode = myShapeTypes.first().toStdString();
   }
-  aMainLay->addWidget(myTypeCtrl);
+  myMainLayout->addWidget(myTypeCtrl);
 
   // There is no sense to parameterize list of types while we can not parameterize selection mode
   // if the xml definition contains one type, the controls to select a type should not be shown
@@ -148,7 +148,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
     QWidget* aLabelWgt = new QWidget(this);
     QHBoxLayout* aLabelLayout = new QHBoxLayout(aLabelWgt);
     aLabelLayout->setContentsMargins(0, 0, 0, 0);
-    aMainLay->addWidget(aLabelWgt);
+    myMainLayout->addWidget(aLabelWgt);
 
     QLabel* aListLabel = new QLabel(aLabelText, this);
     aLabelLayout->addWidget(aListLabel);
@@ -172,32 +172,32 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
   connect(myListView, SIGNAL(deleteActionClicked()), SLOT(onDeleteItem()));
   connect(myListView, SIGNAL(listActivated()), SLOT(onListActivated()));
 
-  aMainLay->addWidget(myListView->getControl());
+  myMainLayout->addWidget(myListView->getControl());
   connect(myTypeCtrl, SIGNAL(valueChanged(int)), this, SLOT(onSelectionTypeChanged()));
 
-  std::string aUseFilters = theData->getProperty("use_filters");
-  if (aUseFilters.length() > 0) {
+  myUseFilters = theData->getProperty("use_filters");
+  if (myUseFilters.length() > 0) {
     QWidget* aFltrWgt = new QWidget(this);
     QHBoxLayout* aFltrLayout = new QHBoxLayout(aFltrWgt);
 
-    myFiltersWgt = new ModuleBase_FilterStarter(aUseFilters.c_str(), aFltrWgt, theWorkshop);
+    myFiltersWgt = new ModuleBase_FilterStarter(myUseFilters, aFltrWgt, theWorkshop);
     aFltrLayout->addWidget(myFiltersWgt);
 
     aFltrLayout->addStretch();
 
-    QPushButton* aShowBtn = new QPushButton(tr("Show only"), aFltrWgt);
-    aShowBtn->setCheckable(true);
-    aShowBtn->setChecked(false);
-    connect(aShowBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
-    aFltrLayout->addWidget(aShowBtn);
+    myShowOnlyBtn = new QPushButton(tr("Show only"), aFltrWgt);
+    myShowOnlyBtn->setCheckable(true);
+    myShowOnlyBtn->setChecked(false);
+    connect(myShowOnlyBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
+    aFltrLayout->addWidget(myShowOnlyBtn);
 
-    aMainLay->addWidget(aFltrWgt);
+    myMainLayout->addWidget(aFltrWgt);
   }
 
   bool aSameTop = theData->getBooleanAttribute("same_topology", false);
   if (aSameTop) {
     myGeomCheck = new QCheckBox(tr("Add elements that share the same topology"), this);
-    aMainLay->addWidget(myGeomCheck);
+    myMainLayout->addWidget(myGeomCheck);
     connect(myGeomCheck, SIGNAL(toggled(bool)), SLOT(onSameTopology(bool)));
   }
   else
@@ -1185,4 +1185,34 @@ void ModuleBase_WidgetMultiSelector::onShowOnly(bool theChecked)
 bool ModuleBase_WidgetMultiSelector::isModified() const
 {
   return myListView->getControl()->count() > 0;
-}
\ No newline at end of file
+}
+
+
+void ModuleBase_WidgetMultiSelector::setReadOnly(bool isReadOnly)
+{
+  ModuleBase_WidgetSelector::setReadOnly(isReadOnly);
+  if (myShowOnlyBtn)
+    myShowOnlyBtn->hide();
+  if (myFiltersWgt) {
+    myFiltersWgt->hide();
+
+    AttributeSelectionListPtr aAttrList = feature()->selectionList(attributeID());
+    if (aAttrList.get()) {
+      FiltersFeaturePtr aFilters = aAttrList->filters();
+      if (aFilters.get()) {
+        ModuleBase_WidgetSelectionFilter::SelectorFeature = feature();
+        ModuleBase_WidgetSelectionFilter::AttributeId = attributeID();
+
+        std::string aXmlCfg, aDescription;
+        myWorkshop->module()->getXMLRepresentation(myUseFilters, aXmlCfg, aDescription);
+
+        ModuleBase_WidgetSelectionFilter* aWgt =
+          new ModuleBase_WidgetSelectionFilter(this, myWorkshop,
+            new Config_WidgetAPI(aDescription), true);
+        aWgt->setFeature(aFilters);
+        aWgt->restoreValue();
+        myMainLayout->addWidget(aWgt);
+      }
+    }
+  }
+}
index 08aa13a39934db9b5cfa04a447d812df8de86790..d54f557d57b4939180f51b2f1c0a186c332124ef 100644 (file)
@@ -37,7 +37,8 @@
 
 class QWidget;
 class QCheckBox;
-//class QComboBox;
+class QPushButton;
+class QVBoxLayout;
 class ModuleBase_ListView;
 class ModuleBase_IWorkshop;
 class ModuleBase_ChoiceCtrl;
@@ -118,6 +119,8 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge
   /// Returns True if data of its feature was modified during operation
   virtual bool isModified() const;
 
+  virtual void setReadOnly(bool isReadOnly);
+
 public slots:
   /// Slot is called on selection type changed
   void onSelectionTypeChanged();
@@ -256,12 +259,15 @@ protected:
   bool myIsFirst;
   std::string myDefMode;
 
+  QVBoxLayout* myMainLayout;
   QCheckBox* myGeomCheck;
   ModuleBase_FilterStarter* myFiltersWgt;
+  QPushButton* myShowOnlyBtn;
 
   QObjectPtrList myVisibleObjects;
   QStringList myAllowedObjects;
   QStringList myTmpAllowed;
+  std::string myUseFilters;
 };
 
 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
index 963861a31497f2ef726b5a7687481994844ee032..500bd5b68ff21f3737233b55515e9469d0c6038f 100644 (file)
@@ -55,8 +55,8 @@
 #include <QCheckBox>
 #include <QDir>
 
-static FeaturePtr SelectorFeature;
-static std::string AttributeId;
+FeaturePtr ModuleBase_WidgetSelectionFilter::SelectorFeature;
+std::string ModuleBase_WidgetSelectionFilter::AttributeId;
 
 
 GeomAPI_Shape::ShapeType selectionType(const QString& theType)
@@ -118,14 +118,16 @@ void ModuleBase_FilterStarter::onFiltersLaunch()
   }
   if (!aSelector)
     return;
-  SelectorFeature = aSelector->feature();
-  AttributeId = aSelector->attributeID();
+  ModuleBase_WidgetSelectionFilter::SelectorFeature = aSelector->feature();
+  ModuleBase_WidgetSelectionFilter::AttributeId = aSelector->attributeID();
 
   // Launch Filters operation
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
     (myWorkshop->module()->createOperation(myFeatureName));
 
-  AttributeSelectionListPtr aAttrList = SelectorFeature->selectionList(AttributeId);
+  AttributeSelectionListPtr aAttrList =
+    ModuleBase_WidgetSelectionFilter::SelectorFeature->selectionList(
+      ModuleBase_WidgetSelectionFilter::AttributeId);
   FiltersFeaturePtr aFilters = aAttrList->filters();
   if (aFilters.get())
     aFOperation->setFeature(aFilters);
@@ -225,16 +227,18 @@ void ModuleBase_FilterItem::onDelete()
 //*****************************************************************************
 //*****************************************************************************
 ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theParent,
-  ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData)
+  ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, bool theReadOnly)
   : ModuleBase_ModelWidget(theParent, theData),
   myWorkshop(theWorkshop),
-  mySelectorFeature(SelectorFeature),
-  mySelectorAttribute(AttributeId)
+  mySelectorFeature(ModuleBase_WidgetSelectionFilter::SelectorFeature),
+  mySelectorAttribute(ModuleBase_WidgetSelectionFilter::AttributeId)
 {
   // Clear Old selection
-  AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
-  mySelectionType = selectionType(aAttrList->selectionType().c_str());
-  aAttrList->clear();
+    AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
+    mySelectionType = selectionType(aAttrList->selectionType().c_str());
+  if (!theReadOnly) {
+    aAttrList->clear();
+  }
 
   // Define widgets
   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
@@ -300,6 +304,12 @@ ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theP
   aMainLayout->addStretch(1);
 
   updateSelectBtn();
+  if (theReadOnly) {
+    myFiltersCombo->hide();
+    mySelectBtn->hide();
+    aLblWgt->hide();
+    myShowBtn->hide();
+  }
 }
 
 ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter()
@@ -645,28 +655,28 @@ bool ModuleBase_WidgetSelectionFilter::restoreValueCustom()
 {
   ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
   FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
+
+  // Init filters member of the parent attribute
+  AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
+  if (aAttrList->filters() != aFiltersFeature) {
+    aAttrList->setFilters(aFiltersFeature);
+  }
+
   std::list<std::string> aFilters = aFiltersFeature->filters();
   std::list<std::string>::const_iterator aIt;
   for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++) {
     std::string aStr = (*aIt);
-    onAddFilter(aStr);
+    ModuleBase_FilterItem* aItem = onAddFilter(aStr);
     FilterPtr aFilterObj = aFactory->filter(aStr);
     int aId = myFiltersCombo->findText(aFilterObj->name().c_str());
     if (aId != -1)
       myFiltersCombo->removeItem(aId);
-  }
-  // Init filters member of the parent attribute
-  AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
-  if (aAttrList->filters() != aFiltersFeature) {
-    aAttrList->setFilters(aFiltersFeature);
-  }
 
-  QList<QWidget*> aWidgets;
-  QList<ModuleBase_FilterItem*> aItems = myFiltersLayout->findChildren<ModuleBase_FilterItem*>();
-  foreach(ModuleBase_FilterItem* aItem, aItems) {
-    QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
-    foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
-      aWgt->restoreValue();
+    if (aItem) {
+      QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
+      foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
+        aWgt->restoreValue();
+      }
     }
   }
   return true;
index 30eb1b342c6040ffb2571c3343816f1802c1d5b6..4862581b89559f93174489232afa4137d16117e0 100644 (file)
@@ -139,13 +139,16 @@ class ModuleBase_WidgetSelectionFilter : public ModuleBase_ModelWidget
 {
   Q_OBJECT
 public:
+  static FeaturePtr SelectorFeature;
+  static std::string AttributeId;
+
 
   /// Constructor
   /// \param theParent the parent object
   /// \param theData the widget configuration. The attribute of the model widget is obtained from
   /// a low-level API for reading xml definitions of widgets
   ModuleBase_WidgetSelectionFilter(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
-    const Config_WidgetAPI* theData);
+    const Config_WidgetAPI* theData, bool theReadOnly = false);
 
   /// Destructor
   ~ModuleBase_WidgetSelectionFilter();
index 038f5f172136a2af8b199280c6d27b7c34a7e56d..95ae953a1bbe81cdc0dee04e8904c31ae4a4382d 100644 (file)
@@ -759,8 +759,8 @@ void XGUI_InspectionPanel::buildFeaturePane(const FeaturePtr& theFeature)
     }
     foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
       if (aWgt->isInformative()) {
-        aWgt->setEnabled(false);
         aWgt->setFeature(theFeature, false, false);
+        aWgt->setReadOnly(true);
         aWgt->setEditingMode(true);
         aWgt->restoreValue();
         aWgt->showInformativePage();