From: vsv Date: Tue, 11 Feb 2020 09:08:54 +0000 (+0300) Subject: Make possible to use multiple filters X-Git-Tag: V9_5_0a1~14^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6f5bf3e04916acc2b5cef80733316e9738a43c0c;p=modules%2Fshaper.git Make possible to use multiple filters --- diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp index 500bd5b68..f812ac262 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp @@ -263,7 +263,6 @@ ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theP std::list::const_iterator aIt; for (aIt = allFilters.cbegin(); aIt != allFilters.cend(); aIt++) { aItems.push_back((*aIt)->name().c_str()); - myFilters.push_back(aSession->filters()->id(*aIt)); } myFiltersCombo->addItems(aItems); connect(myFiltersCombo, SIGNAL(currentIndexChanged(int)), SLOT(onAddFilter(int))); @@ -346,26 +345,28 @@ void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex) if (theIndex == 0) return; - std::list::iterator aIt; + ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters(); + std::list aFilters = aFactory->filters((GeomAPI_Shape::ShapeType) mySelectionType); + FiltersFeaturePtr aFiltersFeature = + std::dynamic_pointer_cast(myFeature); + + std::string aText = myFiltersCombo->itemText(theIndex).toStdString(); + + std::list::iterator aIt; int i; std::string aFilter; - for (aIt = myFilters.begin(), i = 0; aIt != myFilters.cend(); i++, aIt++) { - if (i == (theIndex - 1)) { - aFilter = (*aIt); + for (aIt = aFilters.begin(), i = 0; aIt != aFilters.cend(); i++, aIt++) { + if (aText == (*aIt)->name()) { + aFilter = aFactory->id(*aIt); break; } } - ModuleBase_FilterItem* aItem = onAddFilter(aFilter); - FiltersFeaturePtr aFiltersFeature = - std::dynamic_pointer_cast(myFeature); aFiltersFeature->addFilter(aFilter); - - myFiltersCombo->setCurrentIndex(0); - myFiltersCombo->removeItem(theIndex); updateObject(myFeature); - if (aItem && (aItem->widgets().size() > 0)) - aItem->widgets().first()->emitFocusInWidget(); + QList aList = itemsList(); + if (!aList.isEmpty() && (aList.last()->widgets().size() > 0)) + aList.last()->widgets().first()->emitFocusInWidget(); else emitFocusInWidget(); } @@ -374,13 +375,6 @@ ModuleBase_FilterItem* ModuleBase_WidgetSelectionFilter::onAddFilter(const std:: { if (theFilter.length() == 0) return 0; - std::list::const_iterator aIt; - for (aIt = myUseFilters.cbegin(); aIt != myUseFilters.cend(); aIt++) { - if (theFilter == (*aIt)) - return 0; - } - myFilters.remove(theFilter); - myUseFilters.push_back(theFilter); ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(theFilter, this); connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)), SLOT(onDeleteItem(ModuleBase_FilterItem*))); @@ -404,10 +398,11 @@ void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theIt myFiltersLayout->removeWidget(theItem); theItem->deleteLater(); - myUseFilters.remove(aFilter); - myFilters.push_back(aFilter); - myFiltersCombo->addItem(ModelAPI_Session::get()->filters()->filter(aFilter)->name().c_str()); - + ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters(); + if (!aFactory->filter(aFilter)->isMultiple()) { + //myFilters.push_back(aFilter); + myFiltersCombo->addItem(ModelAPI_Session::get()->filters()->filter(aFilter)->name().c_str()); + } FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast(myFeature); aFiltersFeature->removeFilter(aFilter); @@ -441,8 +436,6 @@ void ModuleBase_WidgetSelectionFilter::onReverseItem(ModuleBase_FilterItem* theI void ModuleBase_WidgetSelectionFilter::onSelect() { - if (myUseFilters.size() == 0) - return; Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext(); if (aCtx.IsNull()) return; @@ -550,7 +543,8 @@ void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow) void ModuleBase_WidgetSelectionFilter::updateSelectBtn() { - mySelectBtn->setEnabled(myUseFilters.size() > 0); + FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast(myFeature); + mySelectBtn->setEnabled(aFiltersFeature.get() && (aFiltersFeature->filters().size() > 0)); } void ModuleBase_WidgetSelectionFilter::updateNumberSelected() @@ -651,6 +645,12 @@ bool ModuleBase_WidgetSelectionFilter::storeValueCustom() return true; } +QList ModuleBase_WidgetSelectionFilter::itemsList() const +{ + return myFiltersWgt->findChildren(); +} + + bool ModuleBase_WidgetSelectionFilter::restoreValueCustom() { ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters(); @@ -662,23 +662,33 @@ bool ModuleBase_WidgetSelectionFilter::restoreValueCustom() aAttrList->setFilters(aFiltersFeature); } + QList aItemsList = itemsList(); std::list aFilters = aFiltersFeature->filters(); + std::list::const_iterator aIt; - for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++) { + int i = 0; + int aNbItems = aItemsList.size(); + ModuleBase_FilterItem* aItem = 0; + bool isBlocked = myFiltersCombo->blockSignals(true); + for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++, i++) { std::string aStr = (*aIt); - ModuleBase_FilterItem* aItem = onAddFilter(aStr); - FilterPtr aFilterObj = aFactory->filter(aStr); - int aId = myFiltersCombo->findText(aFilterObj->name().c_str()); - if (aId != -1) - myFiltersCombo->removeItem(aId); - - if (aItem) { - QList aSubList = aItem->widgets(); - foreach(ModuleBase_ModelWidget* aWgt, aSubList) { - aWgt->restoreValue(); + aItem = 0; + if (i >= aNbItems) { + aItem = onAddFilter(aStr); + FilterPtr aFilterObj = aFactory->filter(aStr); + int aId = myFiltersCombo->findText(aFilterObj->name().c_str()); + if ((aId != -1) && !aFilterObj->isMultiple()) + myFiltersCombo->removeItem(aId); + if (aItem) { + QList aSubList = aItem->widgets(); + foreach(ModuleBase_ModelWidget* aWgt, aSubList) { + aWgt->restoreValue(); + } } } } + myFiltersCombo->setCurrentIndex(0); + myFiltersCombo->blockSignals(isBlocked); return true; } @@ -698,7 +708,7 @@ void ModuleBase_WidgetSelectionFilter::onObjectUpdated() clearCurrentSelection(true); updateNumberSelected(); - QList aItemsList = myFiltersWgt->findChildren(); + QList aItemsList = itemsList(); foreach(ModuleBase_FilterItem* aItem, aItemsList) { QList aWidgetsList = aItem->widgets(); foreach(ModuleBase_ModelWidget* aWidget, aWidgetsList) { diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h index 4862581b8..011cbaaa1 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h @@ -217,6 +217,9 @@ private: /// Add a filter by name ModuleBase_FilterItem* onAddFilter(const std::string& theFilter); + /// Return currently created filter items + QList itemsList() const; + private: ModuleBase_IWorkshop* myWorkshop; @@ -231,12 +234,6 @@ private: /// Type of selection mode int mySelectionType; - /// List of non-used filters - std::list myFilters; - - /// List of used filters - std::list myUseFilters; - /// Result of filtering QList myValues;