[LyX/master] Properly update color combos wrt textclass colors
Juergen Spitzmueller <[email protected]>
| Newsgroups | gmane.editors.lyx.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 83383383ab1676bed0645475cce627b611bb2444 Author: Juergen Spitzmueller <[email protected]> Date: Tue Mar 17 15:03:17 2026 +0100 Properly update color combos wrt textclass colors --- src/frontends/qt/GuiView.cpp | 37 ++++++++++++++++++++++++++----------- src/frontends/qt/GuiView.h | 8 ++++++-- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp index 2e4af4fc69..c88cdd4f7b 100644 --- a/src/frontends/qt/GuiView.cpp +++ b/src/frontends/qt/GuiView.cpp @@ -1262,25 +1262,31 @@ void GuiView::addColorItem(QString const & item, QString const & guiname, QStandardItemModel * GuiView::viewColorsModel() { - int extracols = 0; - if (currentBufferView()) - extracols = currentBufferView()->buffer().masterParams().custom_colors.size() - + currentBufferView()->buffer().masterParams().documentClass().latexColors().size(); + int const num_tc = currentBufferView()->buffer().masterParams().documentClass().latexColors().size(); + int const num_cc = currentBufferView()->buffer().masterParams().custom_colors.size(); // if nothing has changed, we do not have to change the model - if (colors_model_->rowCount() > 0 && extracols == num_colors_) - return colors_model_; + if (colors_model_->rowCount() == 0 + || num_tc != num_tc_colors_ + || num_cc != num_custom_colors_) + fillColorsModel(); + + return colors_model_; +} + +void GuiView::fillColorsModel() const +{ colors_model_->clear(); // at first add the general values as required addColorItem("ignore", qt_("No change")); addColorItem("default", qt_("Default")); addColorItem("none", qt_("None[[color]]")); addColorItem("inherit", qt_("(Without)[[color]]")); - int nc = 0; + int ncc = 0, ntc = 0; if (currentBufferView()) { // then custom colors for (auto const & lc : currentBufferView()->buffer().masterParams().custom_colors) { - ++nc; + ++ncc; addColorItem(toqstr(lc.first), toqstr(lc.first), qt_("Custom Colors"), @@ -1289,7 +1295,7 @@ QStandardItemModel * GuiView::viewColorsModel() } // then textclass/module colors for (auto const & lc : currentBufferView()->buffer().masterParams().documentClass().latexColors()) { - ++nc; + ++ntc; addColorItem(toqstr(lc.first), toqstr(translateIfPossible(lc.second.guiname())), toqstr(translateIfPossible(lc.second.category())), @@ -1304,14 +1310,16 @@ QStandardItemModel * GuiView::viewColorsModel() toqstr(lc.second.hexname())); } - num_colors_ = nc; - return colors_model_; + num_custom_colors_ = ncc; + num_tc_colors_ = ntc; } void GuiView::updateColorsModel() const { bool changed = false; + int const num_tc = currentBufferView()->buffer().masterParams().documentClass().latexColors().size(); + // remove custom colors QList<QStandardItem *> cis = colors_model_->findItems("custom", Qt::MatchExactly, 3); for (int i = 0; i < cis.size(); ++i) { @@ -1331,6 +1339,13 @@ void GuiView::updateColorsModel() const changed = true; } } + + if (num_tc != num_tc_colors_) { + // if textclass colors changed, we need to + // refill the whole thing + fillColorsModel(); + changed = true; + } if (changed) Q_EMIT colorsModelChanged(); } diff --git a/src/frontends/qt/GuiView.h b/src/frontends/qt/GuiView.h index 5d3d242c52..b553013851 100644 --- a/src/frontends/qt/GuiView.h +++ b/src/frontends/qt/GuiView.h @@ -201,6 +201,8 @@ public: /// QStandardItemModel * viewColorsModel(); /// + void fillColorsModel() const; + /// void updateColorsModel() const; /// called on timeout @@ -593,8 +595,10 @@ private: /// QStandardItemModel * colors_model_; - /// Number of additional latex colors - int num_colors_ = 0; + /// Number of custom latex colors + mutable int num_custom_colors_ = 0; + /// Number of textclass colors + mutable int num_tc_colors_ = 0; }; -- lyx-cvs mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-cvs