Merge pull request #888 from ispyisail/fix/879-remember-conductor-color

Remember the F2 conductor color for the rest of the session
This commit is contained in:
Laurent Trinques
2026-09-16 05:52:29 +02:00
committed by GitHub
4 changed files with 60 additions and 10 deletions
+5
View File
@@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#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);
}
}
});
+29
View File
@@ -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;
}
+14 -5
View File
@@ -19,20 +19,23 @@
#define LAST_USED_STYLE_H
#include <QBrush>
#include <QColor>
#include <QFont>
#include <QPen>
/**
@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
+12 -5
View File
@@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#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);
}
}
/**