From 95c2f6cf6d3fe966ed153b9c1f7a04284089f6d6 Mon Sep 17 00:00:00 2001 From: Shane Ringrose Date: Sat, 13 Jun 2026 08:19:35 +1200 Subject: [PATCH] proto: conductor properties in selection-properties dock (#500) --- cmake/qet_compilation_vars.cmake | 2 + sources/factory/propertieseditorfactory.cpp | 17 +++ .../ui/conductorpropertieseditorwidget.cpp | 126 ++++++++++++++++++ sources/ui/conductorpropertieseditorwidget.h | 58 ++++++++ 4 files changed, 203 insertions(+) create mode 100644 sources/ui/conductorpropertieseditorwidget.cpp create mode 100644 sources/ui/conductorpropertieseditorwidget.h diff --git a/cmake/qet_compilation_vars.cmake b/cmake/qet_compilation_vars.cmake index 7e150a6e7..95f471694 100644 --- a/cmake/qet_compilation_vars.cmake +++ b/cmake/qet_compilation_vars.cmake @@ -616,6 +616,8 @@ set(QET_SRC_FILES ${QET_DIR}/sources/ui/borderpropertieswidget.h ${QET_DIR}/sources/ui/compositetexteditdialog.cpp ${QET_DIR}/sources/ui/compositetexteditdialog.h + ${QET_DIR}/sources/ui/conductorpropertieseditorwidget.cpp + ${QET_DIR}/sources/ui/conductorpropertieseditorwidget.h ${QET_DIR}/sources/ui/conductorpropertiesdialog.cpp ${QET_DIR}/sources/ui/conductorpropertiesdialog.h ${QET_DIR}/sources/ui/conductorpropertieswidget.cpp diff --git a/sources/factory/propertieseditorfactory.cpp b/sources/factory/propertieseditorfactory.cpp index 6a18db924..f53ec4b1e 100644 --- a/sources/factory/propertieseditorfactory.cpp +++ b/sources/factory/propertieseditorfactory.cpp @@ -22,6 +22,7 @@ #include "../qetgraphicsitem/ViewItem/qetgraphicstableitem.h" #include "../qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h" #include "../qetgraphicsitem/ViewItem/ui/projectdbmodelpropertieswidget.h" +#include "../qetgraphicsitem/conductor.h" #include "../qetgraphicsitem/diagramimageitem.h" #include "../qetgraphicsitem/dynamicelementtextitem.h" #include "../qetgraphicsitem/element.h" @@ -30,6 +31,7 @@ #include "../qetgraphicsitem/qetshapeitem.h" #include "../ui/dynamicelementtextitemeditor.h" #include "../ui/elementpropertieswidget.h" +#include "../ui/conductorpropertieseditorwidget.h" #include "../ui/imagepropertieswidget.h" #include "../ui/inditextpropertieswidget.h" #include "../ui/shapegraphicsitempropertieswidget.h" @@ -100,6 +102,21 @@ PropertiesEditorWidget *PropertiesEditorFactory::propertiesEditor( switch (type_) { + case Conductor::Type: //1001 + { + //Prototype (#500): single-conductor editing in the dock. + if (count_ > 1) { + return nullptr; + } + auto conductor = static_cast(item); + + if (class_name == ConductorPropertiesEditorWidget::staticMetaObject.className()) + { + static_cast(editor)->setConductor(conductor); + return editor; + } + return new ConductorPropertiesEditorWidget(conductor, parent); + } case Element::Type: //1000 { if (count_ > 1) { diff --git a/sources/ui/conductorpropertieseditorwidget.cpp b/sources/ui/conductorpropertieseditorwidget.cpp new file mode 100644 index 000000000..33a73077d --- /dev/null +++ b/sources/ui/conductorpropertieseditorwidget.cpp @@ -0,0 +1,126 @@ +/* + Copyright 2006-2026 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "conductorpropertieseditorwidget.h" + +#include "../QPropertyUndoCommand/qpropertyundocommand.h" +#include "../diagram.h" +#include "../qetgraphicsitem/conductor.h" +#include "conductorpropertieswidget.h" + +#include + +/** + @brief ConductorPropertiesEditorWidget::ConductorPropertiesEditorWidget + @param conductor : conductor to edit + @param parent : parent widget +*/ +ConductorPropertiesEditorWidget::ConductorPropertiesEditorWidget( + Conductor *conductor, QWidget *parent) : + PropertiesEditorWidget(parent), + m_cpw(new ConductorPropertiesWidget(this)) +{ + auto *layout = new QVBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(m_cpw); + setDisabled(true); + setConductor(conductor); +} + +ConductorPropertiesEditorWidget::~ConductorPropertiesEditorWidget() +{} + +/** + @brief ConductorPropertiesEditorWidget::setConductor + Set (or change) the conductor whose properties are edited. + @param conductor +*/ +void ConductorPropertiesEditorWidget::setConductor(Conductor *conductor) +{ + if (!conductor) return; + m_conductor = conductor; + setEnabled(true); + updateUi(); +} + +/** + @brief ConductorPropertiesEditorWidget::apply + Push the edit onto the diagram's undo stack. +*/ +void ConductorPropertiesEditorWidget::apply() +{ + if (!m_conductor || !m_conductor->diagram()) return; + if (QUndoCommand *undo = associatedUndo()) + m_conductor->diagram()->undoStack().push(undo); + m_initial = m_conductor->properties(); +} + +/** + @brief ConductorPropertiesEditorWidget::reset + Discard the in-progress edit, restoring the conductor's current properties. +*/ +void ConductorPropertiesEditorWidget::reset() +{ + if (!m_conductor) return; + m_cpw->setProperties(m_initial); +} + +/** + @brief ConductorPropertiesEditorWidget::updateUi + Reload the widget from the conductor (e.g. when the selection changes). +*/ +void ConductorPropertiesEditorWidget::updateUi() +{ + if (!m_conductor) return; + m_initial = m_conductor->properties(); + m_cpw->setProperties(m_initial); +} + +/** + @brief ConductorPropertiesEditorWidget::associatedUndo + @return the edit as a QPropertyUndoCommand, or nullptr if unchanged. + + Prototype note: applies only to the selected conductor. The modal dialog + additionally offers to propagate to every conductor on the same potential + (relatedPotentialConductors()); whether/how to expose that in the dock is + the open design decision for #500. +*/ +QUndoCommand *ConductorPropertiesEditorWidget::associatedUndo() const +{ + if (!m_conductor) return nullptr; + + const ConductorProperties new_properties = m_cpw->properties(); + if (new_properties == m_conductor->properties()) return nullptr; + + QVariant old_value, new_value; + old_value.setValue(m_conductor->properties()); + new_value.setValue(new_properties); + + auto *undo = new QPropertyUndoCommand( + m_conductor, "properties", old_value, new_value); + undo->setText(tr("Modifier les propriétés d'un conducteur", "undo caption")); + return undo; +} + +/** + @brief ConductorPropertiesEditorWidget::title + @return the panel title. +*/ +QString ConductorPropertiesEditorWidget::title() const +{ + return tr("Conducteur"); +} diff --git a/sources/ui/conductorpropertieseditorwidget.h b/sources/ui/conductorpropertieseditorwidget.h new file mode 100644 index 000000000..365e34ff7 --- /dev/null +++ b/sources/ui/conductorpropertieseditorwidget.h @@ -0,0 +1,58 @@ +/* + Copyright 2006-2026 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef CONDUCTORPROPERTIESEDITORWIDGET_H +#define CONDUCTORPROPERTIESEDITORWIDGET_H + +#include "../PropertiesEditor/propertieseditorwidget.h" +#include "../conductorproperties.h" + +class Conductor; +class ConductorPropertiesWidget; + +/** + @brief The ConductorPropertiesEditorWidget class + Hosts the existing ConductorPropertiesWidget in the dockable selection- + properties panel, so a selected conductor can be edited in place like the + other item types, instead of only through the modal dialog (issue #500). + Prototype: single-conductor editing; applying to the whole potential is the + open design question (the modal dialog offers it via a prompt). +*/ +class ConductorPropertiesEditorWidget : public PropertiesEditorWidget +{ + Q_OBJECT + + public: + explicit ConductorPropertiesEditorWidget( + Conductor *conductor = nullptr, QWidget *parent = nullptr); + ~ConductorPropertiesEditorWidget() override; + + void setConductor(Conductor *conductor); + + void apply() override; + void reset() override; + void updateUi() override; + QUndoCommand *associatedUndo() const override; + QString title() const override; + + private: + ConductorPropertiesWidget *m_cpw = nullptr; + Conductor *m_conductor = nullptr; + ConductorProperties m_initial; +}; + +#endif // CONDUCTORPROPERTIESEDITORWIDGET_H