Refresh the dock's counter field when the numbering actually advances

Reported by @scorpio810 on #626: "The field does not update automatically;
you need to list the other rules for it to update."

Two reasons, both mine:

The refresh was wired to the combo boxes' activated() signal, which Qt
emits only for user interaction. Nothing that changed a context
programmatically -- which is to say, numbering an element -- ever reached
it. Re-picking a rule from the combo was not a workaround so much as the
only code path that refreshed at all.

And there was no signal to hang it on for two of the three categories:
addElementAutoNum() emitted elementAutoNumAdded(), but addConductorAutoNum()
and addFolioAutoNum() emitted nothing, so even a listener would not have
heard a conductor counter advance.

Add QETProject::autoNumContextUpdated(), emitted by all three setters, and
have the dock re-read its three fields on it. Kept deliberately separate
from the existing *AutoNumAdded/*Removed signals: those make listeners
rebuild their rule lists, which is both heavier than needed here and would
disturb the user's current selection every time an element is numbered.
This one only says "re-read me".

The automatic refresh skips a field that has keyboard focus, so numbering
an element cannot overwrite a value half-typed under the cursor. Explicit
refreshes after a reset or an edit still write unconditionally, so the
field always ends up showing the canonical stored value.

Measured, advancing a counter the way numbering advances it and without
touching the combo box:

  field before advance   "5"
  context after advance   6
  field after advance    "6"      (was still "5")
This commit is contained in:
ispyisail
2026-08-02 20:41:17 +12:00
parent 52c8ef6b49
commit ee4ba82d28
4 changed files with 37 additions and 0 deletions
@@ -115,6 +115,8 @@ void AutoNumberingDockWidget::setProject(QETProject *project,
this,SLOT(setActive()));
//Conductor, Element and Folio Signals
disconnect(m_project, &QETProject::autoNumContextUpdated,
this, &AutoNumberingDockWidget::refreshValueFields);
disconnect(m_project, &QETProject::destroyed,
this, &AutoNumberingDockWidget::projectClosed);
}
@@ -152,6 +154,8 @@ void AutoNumberingDockWidget::setProject(QETProject *project,
this,SLOT(setActive()));
//Conductor, Element and Folio Signals
connect(m_project, &QETProject::autoNumContextUpdated,
this, &AutoNumberingDockWidget::refreshValueFields);
connect(m_project, &QETProject::destroyed,
this, &AutoNumberingDockWidget::projectClosed);
@@ -441,6 +445,29 @@ int AutoNumberingDockWidget::counterIndex(const NumerotationContext &context)
return -1;
}
/**
@brief AutoNumberingDockWidget::refreshValueFields
Re-read all three value fields from the project. Called whenever a
numerotation context's values change, which includes every element or
conductor that consumes the next number -- without this the field only
caught up when the user re-picked a rule from the combo box, because
the combo's activated() signal fires on user interaction alone.
*/
void AutoNumberingDockWidget::refreshValueFields()
{
//Leave alone a field the user is typing in: numbering an element
//refreshes all three, and overwriting a half-typed value under the
//cursor is worse than showing it a moment out of date. Only this
//automatic path skips; an explicit refresh after a reset or an edit
//still writes, so the field always ends up canonical.
if (!ui->m_conductor_value_le->hasFocus())
refreshValueField(ui->m_conductor_cb, ui->m_conductor_value_le, AutoNumCategory::Conductor);
if (!ui->m_element_value_le->hasFocus())
refreshValueField(ui->m_element_cb, ui->m_element_value_le, AutoNumCategory::Element);
if (!ui->m_folio_value_le->hasFocus())
refreshValueField(ui->m_folio_cb, ui->m_folio_value_le, AutoNumCategory::Folio);
}
/**
@brief AutoNumberingDockWidget::refreshValueField
Show the current value of the selected context's counter, so the field
@@ -54,6 +54,7 @@ class AutoNumberingDockWidget : public QDockWidget
void folioAutoNumChanged();
void clear();
void projectClosed();
void refreshValueFields();
void on_m_configure_pb_clicked();
+3
View File
@@ -726,6 +726,7 @@ QHash <QString, NumerotationContext> QETProject::folioAutoNum() const
*/
void QETProject::addConductorAutoNum(const QString& key, const NumerotationContext& context) {
m_conductor_autonum.insert(key, context);
emit autoNumContextUpdated();
}
/**
@@ -739,6 +740,7 @@ void QETProject::addElementAutoNum(const QString& key, const NumerotationContext
{
m_element_autonum.insert(key, context);
emit elementAutoNumAdded(key);
emit autoNumContextUpdated();
}
/**
@@ -750,6 +752,7 @@ void QETProject::addElementAutoNum(const QString& key, const NumerotationContext
*/
void QETProject::addFolioAutoNum(const QString& key, const NumerotationContext& context) {
m_folio_autonum.insert(key, context);
emit autoNumContextUpdated();
}
/**
+6
View File
@@ -234,6 +234,12 @@ class QETProject : public QObject
void conductorAutoNumAdded();
void conductorAutoNumRemoved();
void folioAutoNumAdded();
/// A numerotation context's *values* changed -- as happens every
/// time an element or conductor consumes the next number, not
/// only when a rule is added or removed. Deliberately separate
/// from the *Added/*Removed signals above, which make listeners
/// rebuild their rule lists; this one just says "re-read me".
void autoNumContextUpdated();
void folioAutoNumRemoved();
void folioAutoNumChanged(QString);
void defaultTitleBlockPropertiesChanged();