diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp index a53ca991d1..7c9304bf73 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp @@ -637,55 +637,48 @@ void ConstraintView::swapNamedOfSelectedItems() ConstraintFilterList::ConstraintFilterList(QWidget* parent) : QListWidget(parent) { - { - QSignalBlocker block(this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", "All"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", "Geometric"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Coincident"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Point on Object"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Vertical"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Horizontal"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Parallel"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Perpendicular"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Tangent"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Equality"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Symmetric"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Block"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", "Datums"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Horizontal Distance"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Vertical Distance"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Distance"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Radius"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Weight"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Diameter"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Angle"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", " - Snell's Law"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", "Named"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", "Reference"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", "Internal Alignment"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", "Selected constraints"), this); - new QListWidgetItem(QApplication::translate("ConstraintFilterList", "Associated constraints"), this); + for (auto const& filterItem : filterItems) { + Q_UNUSED(filterItem); + auto it = new QListWidgetItem(); - normalFilterCount = count() - 2; //All filter but selected and associated - selectedFilterIndex = normalFilterCount; - associatedFilterIndex = normalFilterCount + 1; - - for (int i = 0; i < count(); i++) { - QListWidgetItem* it = item(i); - - it->setFlags(it->flags() | Qt::ItemIsUserCheckable); - if(i < normalFilterCount) - it->setCheckState(Qt::Checked); - else //associated and selected should not be checked by default. - it->setCheckState(Qt::Unchecked); - } + it->setFlags(it->flags() | Qt::ItemIsUserCheckable); + if(row(it) < normalFilterCount) + it->setCheckState(Qt::Checked); + else //associated and selected should not be checked by default. + it->setCheckState(Qt::Unchecked); + addItem(it); } + languageChange(); + + normalFilterCount = count() - 2; //All filter but selected and associated + selectedFilterIndex = normalFilterCount; + associatedFilterIndex = normalFilterCount + 1; } ConstraintFilterList::~ConstraintFilterList() { } +void ConstraintFilterList::changeEvent(QEvent* e) +{ + if (e->type() == QEvent::LanguageChange) + languageChange(); + + QWidget::changeEvent(e); +} + +void ConstraintFilterList::languageChange() +{ + assert(static_cast(filterItems.size()) == count()); + int i = 0; + for (auto const& filterItem : filterItems) { + auto text = QStringLiteral(" ").repeated(filterItem.second - 1) + + (filterItem.second > 0 ? QStringLiteral("- ") : QStringLiteral("")) + + tr(filterItem.first); + item(i++)->setText(text); + } +} + FilterValueBitset ConstraintFilterList::getMultiFilter() { FilterValueBitset tmpBitset; diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.h b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.h index 3e56c856fb..30780832c9 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.h +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.h @@ -88,6 +88,41 @@ public: int normalFilterCount; //All filters but selected and associated int selectedFilterIndex; int associatedFilterIndex; + +protected: + void changeEvent(QEvent* e) override; + virtual void languageChange(); + +private: + using filterItemRepr = std::pair; // {filter item text, filter item level} + inline static const std::vector filterItems = { + {QT_TR_NOOP("All"),0}, + {QT_TR_NOOP("Geometric"),0}, + {QT_TR_NOOP("Coincident"),1}, + {QT_TR_NOOP("Point on Object"),1}, + {QT_TR_NOOP("Vertical"),1}, + {QT_TR_NOOP("Horizontal"),1}, + {QT_TR_NOOP("Parallel"),1}, + {QT_TR_NOOP("Perpendicular"),1}, + {QT_TR_NOOP("Tangent"),1}, + {QT_TR_NOOP("Equality"),1}, + {QT_TR_NOOP("Symmetric"),1}, + {QT_TR_NOOP("Block"),1}, + {QT_TR_NOOP("Datums"),0}, + {QT_TR_NOOP("Horizontal Distance"),1}, + {QT_TR_NOOP("Vertical Distance"),1}, + {QT_TR_NOOP("Distance"),1}, + {QT_TR_NOOP("Radius"),1}, + {QT_TR_NOOP("Weight"),1}, + {QT_TR_NOOP("Diameter"),1}, + {QT_TR_NOOP("Angle"),1}, + {QT_TR_NOOP("Snell's Law"),1}, + {QT_TR_NOOP("Named"),0}, + {QT_TR_NOOP("Reference"),0}, + {QT_TR_NOOP("Internal Alignment"),0}, + {QT_TR_NOOP("Selected constraints"),0}, + {QT_TR_NOOP("Associated constraints"),0}, + }; }; class TaskSketcherConstraints : public Gui::TaskView::TaskBox, public Gui::SelectionObserver