From efd3407dd8a68a310959b784369c7e84f31929ce Mon Sep 17 00:00:00 2001 From: wandererfan Date: Tue, 5 Dec 2023 13:28:06 -0500 Subject: [PATCH] [TD]fix line standard drop downs --- src/Mod/TechDraw/App/LineGenerator.cpp | 8 ++ src/Mod/TechDraw/App/LineGenerator.h | 4 + src/Mod/TechDraw/App/Preferences.cpp | 6 ++ src/Mod/TechDraw/App/Preferences.h | 1 + .../Gui/DlgPrefsTechDrawAnnotation.ui | 15 ++++ .../Gui/DlgPrefsTechDrawAnnotationImp.cpp | 81 +++++++++++++------ .../Gui/DlgPrefsTechDrawAnnotationImp.h | 2 + 7 files changed, 92 insertions(+), 25 deletions(-) diff --git a/src/Mod/TechDraw/App/LineGenerator.cpp b/src/Mod/TechDraw/App/LineGenerator.cpp index fe98786a00..398eb28d2e 100644 --- a/src/Mod/TechDraw/App/LineGenerator.cpp +++ b/src/Mod/TechDraw/App/LineGenerator.cpp @@ -55,6 +55,14 @@ using namespace TechDraw; using DU = DrawUtil; LineGenerator::LineGenerator() +{ + reloadDescriptions(); +// m_elementDefs = loadElements(); +// m_lineDefs = getLineDefinitions(); +// m_lineDescs = getLineDescriptions(); +} + +void LineGenerator::reloadDescriptions() { m_elementDefs = loadElements(); m_lineDefs = getLineDefinitions(); diff --git a/src/Mod/TechDraw/App/LineGenerator.h b/src/Mod/TechDraw/App/LineGenerator.h index d400b3fef7..41013a8065 100644 --- a/src/Mod/TechDraw/App/LineGenerator.h +++ b/src/Mod/TechDraw/App/LineGenerator.h @@ -63,6 +63,10 @@ public: static std::vector getAvailableLineStandards(); static std::string getLineStandardsBody(); + //! if the line standard changes during a lineGenerator's life time + //! then the elements and line descriptions need to be reloaded using the + //! new standard. + void reloadDescriptions(); //! get line descriptions from memory std::vector getLoadedDescriptions(); //! get line descriptions from file diff --git a/src/Mod/TechDraw/App/Preferences.cpp b/src/Mod/TechDraw/App/Preferences.cpp index bbd94030b0..cb06122630 100644 --- a/src/Mod/TechDraw/App/Preferences.cpp +++ b/src/Mod/TechDraw/App/Preferences.cpp @@ -425,6 +425,12 @@ int Preferences::lineStandard() return getPreferenceGroup("Standards")->GetInt("LineStandard", 1); } +//! update the line standard preference. used in the preferences dialog. +void Preferences::setLineStandard(int index) +{ + getPreferenceGroup("Standards")->SetInt("LineStandard", index); +} + std::string Preferences::lineDefinitionLocation() { std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/LineGroup/"; diff --git a/src/Mod/TechDraw/App/Preferences.h b/src/Mod/TechDraw/App/Preferences.h index 40b34db064..3613712e38 100644 --- a/src/Mod/TechDraw/App/Preferences.h +++ b/src/Mod/TechDraw/App/Preferences.h @@ -107,6 +107,7 @@ public: static bool SectionUsePreviousCut(); static int lineStandard(); + static void setLineStandard(int index); static std::string lineDefinitionLocation(); static std::string lineElementsLocation(); diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui index 491d61d6ff..e488b15a07 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui @@ -537,6 +537,9 @@ 0 + + 6 + 32 @@ -574,6 +577,12 @@ 0 + + 6 + + + QComboBox::AdjustToContents + 32 @@ -608,6 +617,9 @@ 0 + + 6 + 32 @@ -736,6 +748,9 @@ 0 + + 6 + 32 diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.cpp b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.cpp index c78f93f986..0e7539ed5a 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.cpp +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.cpp @@ -49,15 +49,29 @@ DlgPrefsTechDrawAnnotationImp::DlgPrefsTechDrawAnnotationImp( QWidget* parent ) ui->pdsbBalloonKink->setUnit(Base::Unit::Length); ui->pdsbBalloonKink->setMinimum(0); + // stylesheet override to defeat behaviour of non-editable combobox to ignore + // maxVisibleItems property + QString ssOverride = QString::fromUtf8("combobox-popup: 0;"); + ui->pcbSectionStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ui->pcbSectionStyle->setStyleSheet(ssOverride); + ui->pcbCenterStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ui->pcbCenterStyle->setStyleSheet(ssOverride); + ui->pcbHighlightStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ui->pcbHighlightStyle->setStyleSheet(ssOverride); + ui->pcbHiddenStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ui->pcbHiddenStyle->setStyleSheet(ssOverride); + // connect the LineGroup the update the tooltip if index changed connect(ui->pcbLineGroup, qOverload(&QComboBox::currentIndexChanged), this, &DlgPrefsTechDrawAnnotationImp::onLineGroupChanged); + m_lineGenerator = new LineGenerator(); } DlgPrefsTechDrawAnnotationImp::~DlgPrefsTechDrawAnnotationImp() { // no need to delete child widgets, Qt does it all for us + delete m_lineGenerator; } void DlgPrefsTechDrawAnnotationImp::saveSettings() @@ -80,8 +94,6 @@ void DlgPrefsTechDrawAnnotationImp::saveSettings() ui->pcbHighlightStyle->onSave(); ui->cbEndCap->onSave(); ui->pcbHiddenStyle->onSave(); - - } void DlgPrefsTechDrawAnnotationImp::loadSettings() @@ -129,33 +141,16 @@ void DlgPrefsTechDrawAnnotationImp::loadSettings() if (ui->pcbLineStandard->count() > Preferences::lineStandard()) { ui->pcbLineStandard->setCurrentIndex(Preferences::lineStandard()); } + // we have to connect the slot after the inital load or the current standard will + // be set to index 0 when the widget is created + connect(ui->pcbLineStandard, qOverload(&QComboBox::currentIndexChanged), + this, &DlgPrefsTechDrawAnnotationImp::onLineStandardChanged); - // note: line numbering starts at 1, not 0. we set the preference to the - // currentIndex in saveSettings, Preferences returns the actual line number, - // so we need to subtract 1 here to get the index. ui->pcbSectionStyle->onRestore(); - DrawGuiUtil::loadLineStyleChoices(ui->pcbSectionStyle, m_lineGenerator); - if (ui->pcbSectionStyle->count() > Preferences::SectionLineStyle()) { - ui->pcbSectionStyle->setCurrentIndex(Preferences::SectionLineStyle() - 1); - } - ui->pcbCenterStyle->onRestore(); - DrawGuiUtil::loadLineStyleChoices(ui->pcbCenterStyle, m_lineGenerator); - if (ui->pcbCenterStyle->count() > Preferences::CenterLineStyle()) { - ui->pcbCenterStyle->setCurrentIndex(Preferences::CenterLineStyle() - 1); - } - ui->pcbHighlightStyle->onRestore(); - DrawGuiUtil::loadLineStyleChoices(ui->pcbHighlightStyle, m_lineGenerator); - if (ui->pcbHighlightStyle->count() > Preferences::HighlightLineStyle()) { - ui->pcbHighlightStyle->setCurrentIndex(Preferences::HighlightLineStyle() - 1); - } - ui->pcbHiddenStyle->onRestore(); - DrawGuiUtil::loadLineStyleChoices(ui->pcbHiddenStyle, m_lineGenerator); - if (ui->pcbHiddenStyle->count() > Preferences::HiddenLineStyle()) { - ui->pcbHiddenStyle->setCurrentIndex(Preferences::HiddenLineStyle() - 1); - } + loadLineStyleBoxes(); } /** @@ -195,7 +190,7 @@ void DlgPrefsTechDrawAnnotationImp::onLineGroupChanged(int index) lgNames.push_back(lgRecord); } ui->pcbLineGroup->setToolTip( - QObject::tr("%1 defines these line widths:\n thin: %2\n graphic: %3\n " + QObject::tr("%1 defines these line widths:\n thin: %2\n graphic: %3\n" "thick: %4") .arg(QString::fromStdString(lgNames.at(0).substr(1)), QString::fromStdString(lgNames.at(1)), @@ -203,4 +198,40 @@ void DlgPrefsTechDrawAnnotationImp::onLineGroupChanged(int index) QString::fromStdString(lgNames.at(3)))); } +//! we must save the current line group preference when it changes so that the +//! line style comboboxes are filled for the correct standard. +void DlgPrefsTechDrawAnnotationImp::onLineStandardChanged(int index) +{ + Preferences::setLineStandard(index); + m_lineGenerator->reloadDescriptions(); + loadLineStyleBoxes(); +} + +//! fill the various line style comboboxes +void DlgPrefsTechDrawAnnotationImp::loadLineStyleBoxes() +{ + // note: line numbering starts at 1, not 0. we set the preference to the + // currentIndex in saveSettings, Preferences returns the actual line number, + // so we need to subtract 1 here to get the index. + DrawGuiUtil::loadLineStyleChoices(ui->pcbSectionStyle, m_lineGenerator); + if (ui->pcbSectionStyle->count() > Preferences::SectionLineStyle()) { + ui->pcbSectionStyle->setCurrentIndex(Preferences::SectionLineStyle() - 1); + } + + DrawGuiUtil::loadLineStyleChoices(ui->pcbCenterStyle, m_lineGenerator); + if (ui->pcbCenterStyle->count() > Preferences::CenterLineStyle()) { + ui->pcbCenterStyle->setCurrentIndex(Preferences::CenterLineStyle() - 1); + } + + DrawGuiUtil::loadLineStyleChoices(ui->pcbHighlightStyle, m_lineGenerator); + if (ui->pcbHighlightStyle->count() > Preferences::HighlightLineStyle()) { + ui->pcbHighlightStyle->setCurrentIndex(Preferences::HighlightLineStyle() - 1); + } + + DrawGuiUtil::loadLineStyleChoices(ui->pcbHiddenStyle, m_lineGenerator); + if (ui->pcbHiddenStyle->count() > Preferences::HiddenLineStyle()) { + ui->pcbHiddenStyle->setCurrentIndex(Preferences::HiddenLineStyle() - 1); + } +} + #include diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.h b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.h index b465977c00..63c733dcd9 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.h +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.h @@ -46,6 +46,7 @@ public: public Q_SLOTS: void onLineGroupChanged(int); + void onLineStandardChanged(int); protected: void saveSettings() override; @@ -53,6 +54,7 @@ protected: void changeEvent(QEvent *e) override; int prefBalloonArrow() const; + void loadLineStyleBoxes(); private: std::unique_ptr ui;