Skip to content

Commit

Permalink
[TD]fix Prefs Annotation tab
Browse files Browse the repository at this point in the history
- prevent premature save of LineStandard
  • Loading branch information
WandererFan committed Feb 17, 2024
1 parent c4daf25 commit 609a786
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
52 changes: 38 additions & 14 deletions src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ DlgPrefsTechDrawAnnotationImp::DlgPrefsTechDrawAnnotationImp( QWidget* parent )
connect(ui->pcbLineGroup, qOverload<int>(&QComboBox::currentIndexChanged),
this, &DlgPrefsTechDrawAnnotationImp::onLineGroupChanged);

// NOTE that we block onChanged processing while loading the Line Standard combobox
connect(ui->pcbLineStandard, qOverload<int>(&QComboBox::currentIndexChanged),
this, &DlgPrefsTechDrawAnnotationImp::onLineStandardChanged);

m_lineGenerator = new LineGenerator();
}

Expand All @@ -87,13 +91,28 @@ void DlgPrefsTechDrawAnnotationImp::saveSettings()
ui->pdsbBalloonKink->onSave();
ui->cbCutSurface->onSave();

// don't save invalid parameter values
// the comboboxes are properly loaded.
ui->pcbLineGroup->onSave();
ui->pcbLineStandard->onSave();
ui->pcbSectionStyle->onSave();
ui->pcbCenterStyle->onSave();
ui->pcbHighlightStyle->onSave();
ui->cbEndCap->onSave();
ui->pcbHiddenStyle->onSave();
if (ui->pcbLineStandard->currentIndex() >= 0) {
ui->pcbLineStandard->onSave();
}
if (ui->pcbSectionStyle->currentIndex() >= 0) {
ui->pcbSectionStyle->onSave();
}
if (ui->pcbCenterStyle->currentIndex() >= 0) {
ui->pcbCenterStyle->onSave();
}
if (ui->pcbHighlightStyle->currentIndex() >= 0) {
ui->pcbHighlightStyle->onSave();
}
if (ui->cbEndCap->currentIndex() >= 0) {
ui->cbEndCap->onSave();
}
if (ui->pcbHiddenStyle->currentIndex() >= 0) {
ui->pcbHiddenStyle->onSave();
}

ui->pcbDetailMatting->onSave();
ui->pcbDetailHighlight->onSave();
}
Expand Down Expand Up @@ -141,15 +160,14 @@ void DlgPrefsTechDrawAnnotationImp::loadSettings()

ui->cbEndCap->onRestore();

ui->pcbLineStandard->onRestore();
// prevent onChanged processing while loading comboBox
ui->pcbLineStandard->blockSignals(true);
DrawGuiUtil::loadLineStandardsChoices(ui->pcbLineStandard);
ui->pcbLineStandard->blockSignals(false);

if (ui->pcbLineStandard->count() > Preferences::lineStandard()) {
ui->pcbLineStandard->setCurrentIndex(Preferences::lineStandard());
}
// we have to connect the slot after the initial load or the current standard will
// be set to index 0 when the widget is created
connect(ui->pcbLineStandard, qOverload<int>(&QComboBox::currentIndexChanged),
this, &DlgPrefsTechDrawAnnotationImp::onLineStandardChanged);

ui->pcbSectionStyle->onRestore();
ui->pcbCenterStyle->onRestore();
Expand All @@ -164,9 +182,11 @@ void DlgPrefsTechDrawAnnotationImp::loadSettings()
void DlgPrefsTechDrawAnnotationImp::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
saveSettings();
ui->pcbLineStandard->blockSignals(true);
int currentIndex = ui->pcbLineStandard->currentIndex();
ui->retranslateUi(this);
loadSettings();
ui->pcbLineStandard->setCurrentIndex(currentIndex);
ui->pcbLineStandard->blockSignals(false);
}
else {
QWidget::changeEvent(e);
Expand Down Expand Up @@ -203,10 +223,14 @@ void DlgPrefsTechDrawAnnotationImp::onLineGroupChanged(int index)
QString::fromStdString(lgNames.at(3))));
}

//! we must save the current line group preference when it changes so that the
//! we must set 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)
{
if (index < 0) {
// do not process invalid index
return;
}
Preferences::setLineStandard(index);
m_lineGenerator->reloadDescriptions();
loadLineStyleBoxes();
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public Q_SLOTS:
private:
std::unique_ptr<Ui_DlgPrefsTechDrawAnnotationImp> ui;
TechDraw::LineGenerator* m_lineGenerator;

bool m_blockLineStandardOnChanged{false};
};

} // namespace TechDrawGui
Expand Down

0 comments on commit 609a786

Please sign in to comment.