From 1ec4f56a50c4442333e7f29da59baf9effdde8c4 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Wed, 16 Sep 2026 15:40:41 +1200 Subject: [PATCH] Remember the F2 conductor color for the rest of the session (#879) The F2 color editor recolors one conductor, but the next one drawn falls straight back to defaultConductorProperties -- the choice made via F2 is lost the moment you place another wire, and lost again on restart. LastUsedStyle already solves the same problem for shapes (pen/brush) and free text (font), session-scoped and deliberately not QSettings-backed; this extends it with a conductor color, following the identical has/get/set shape. F2's handler records the color after pushing its undo command. Conductor's constructor -- the one place a new conductor's properties are set from defaultConductorProperties -- overrides just the color field when a session color has been recorded, leaving every other default (style, thickness, text) alone. Verified: build clean, ctest 6/6. Could not get a reliable headless GUI trace of "F2 one wire, draw a new one, see it inherit the color" -- drag-and-drop element placement under Xvfb was unreliable in this environment (one attempt did nothing, another drew an unintended long conductor undo didn't fully clear). The code path is otherwise identical to the already-shipped shape/text mechanism this mirrors. Refs #461. Co-Authored-By: Claude Sonnet 5 --- sources/diagramview.cpp | 5 +++++ sources/lastusedstyle.cpp | 29 +++++++++++++++++++++++++++ sources/lastusedstyle.h | 19 +++++++++++++----- sources/qetgraphicsitem/conductor.cpp | 17 +++++++++++----- 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 3c1841c2e..b07b03924 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -16,6 +16,7 @@ along with QElectroTech. If not, see . */ #include "diagramview.h" +#include "lastusedstyle.h" #include "qetproject.h" #include "QPropertyUndoCommand/qpropertyundocommand.h" #include "diagramcommands.h" @@ -143,6 +144,10 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QPropertyUndoCommand *undo = new QPropertyUndoCommand(edited_conductor, "properties", old_value, new_value); undo->setText(tr("Modifier les propriétés d'un conducteur", "undo caption")); m_diagram->undoStack().push(undo); + + // remember it for the next conductor drawn this session, + // the way LastUsedStyle already does for shapes (#879) + LastUsedStyle::setConductorColor(new_color); } } }); diff --git a/sources/lastusedstyle.cpp b/sources/lastusedstyle.cpp index 0dad351a8..168843231 100644 --- a/sources/lastusedstyle.cpp +++ b/sources/lastusedstyle.cpp @@ -23,6 +23,8 @@ QBrush LastUsedStyle::m_shape_brush; bool LastUsedStyle::m_has_shape_brush = false; QFont LastUsedStyle::m_text_font; bool LastUsedStyle::m_has_text_font = false; +QColor LastUsedStyle::m_conductor_color; +bool LastUsedStyle::m_has_conductor_color = false; /** @return true if a shape pen was set this session @@ -104,3 +106,30 @@ void LastUsedStyle::setTextFont(const QFont &font) m_text_font = font; m_has_text_font = true; } + +/** + @return true if a conductor color was set this session +*/ +bool LastUsedStyle::hasConductorColor() +{ + return m_has_conductor_color; +} + +/** + @return the last color applied to a conductor this session +*/ +QColor LastUsedStyle::conductorColor() +{ + return m_conductor_color; +} + +/** + @brief LastUsedStyle::setConductorColor + Record @a color as the last-used conductor color for this session + @param color +*/ +void LastUsedStyle::setConductorColor(const QColor &color) +{ + m_conductor_color = color; + m_has_conductor_color = true; +} diff --git a/sources/lastusedstyle.h b/sources/lastusedstyle.h index 17c1f50b3..4cca3b1b3 100644 --- a/sources/lastusedstyle.h +++ b/sources/lastusedstyle.h @@ -19,20 +19,23 @@ #define LAST_USED_STYLE_H #include +#include #include #include /** @brief The LastUsedStyle class - Session-scoped "last used" style for new shapes and free text created - on the diagram canvas: whatever pen/brush/font was last applied through - the properties editors becomes the starting point for the next new - item of that type, the way most drawing tools behave. + Session-scoped "last used" style for new shapes, free text and + conductors created on the diagram canvas: whatever pen/brush/font/color + was last applied through the properties editors becomes the starting + point for the next new item of that type, the way most drawing tools + behave. Deliberately in-memory only, not QSettings-backed: this is a live "what did I just use" value for the current editing session, not an app-wide default (that's already covered by the Preferences dialog's - font setting, read as the fallback when nothing has been set yet). + font setting, read as the fallback when nothing has been set yet, and + by the project's default conductor color, read the same way). */ class LastUsedStyle { @@ -49,6 +52,10 @@ class LastUsedStyle static QFont textFont(); static void setTextFont(const QFont &font); + static bool hasConductorColor(); + static QColor conductorColor(); + static void setConductorColor(const QColor &color); + private: LastUsedStyle() = delete; @@ -58,6 +65,8 @@ class LastUsedStyle static bool m_has_shape_brush; static QFont m_text_font; static bool m_has_text_font; + static QColor m_conductor_color; + static bool m_has_conductor_color; }; #endif // LAST_USED_STYLE_H diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 9d37ac387..049ac36d8 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -16,6 +16,7 @@ along with QElectroTech. If not, see . */ #include "../qetgraphicsitem/conductor.h" +#include "../lastusedstyle.h" #include "../qetproject.h" #include "../QPropertyUndoCommand/qpropertyundocommand.h" #include "../autoNum/numerotationcontextcommands.h" @@ -127,11 +128,17 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) : m_text_item = new ConductorTextItem(m_properties.text, this); connect(m_text_item, &ConductorTextItem::textEdited, this, &Conductor::displayedTextChanged); - //Set the default conductor properties. - if (p1->diagram()) - setProperties(p1->diagram()->defaultConductorProperties); - else if (p2->diagram()) - setProperties(p2->diagram()->defaultConductorProperties); + //Set the default conductor properties. The color, specifically, is + //overridden by the last one applied via the F2 color editor this + //session (#879), the same way LastUsedStyle already does for shapes. + Diagram *dia = p1->diagram() ? p1->diagram() : p2->diagram(); + if (dia) + { + ConductorProperties properties = dia->defaultConductorProperties; + if (LastUsedStyle::hasConductorColor()) + properties.color = LastUsedStyle::conductorColor(); + setProperties(properties); + } } /**