From 0555cd9045234907671674e13b9fef11285a42dc Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Thu, 18 Jun 2026 13:37:24 +0200 Subject: [PATCH] Address review feedback: double spinboxes, tabs, and fix export bug --- sources/cli_export.cpp | 3 + sources/diagram.cpp | 2 + sources/exportproperties.cpp | 5 + sources/exportproperties.h | 1 + sources/print/projectprintwindow.cpp | 1 + .../ui/configpage/guidespropertieswidget.cpp | 141 +++++++++--------- .../ui/configpage/guidespropertieswidget.h | 22 +-- 7 files changed, 94 insertions(+), 81 deletions(-) diff --git a/sources/cli_export.cpp b/sources/cli_export.cpp index c5215e9bb..56b049581 100644 --- a/sources/cli_export.cpp +++ b/sources/cli_export.cpp @@ -116,9 +116,12 @@ void renderDiagram(Diagram *diagram, QPainter &painter, const QRectF &target) // draw_grid_ is set (default true), so toggle it off around the render // and restore it afterwards. const bool was_drawing_grid = diagram->displayGrid(); + const bool was_drawing_guides = diagram->displayGuides(); diagram->setDisplayGrid(false); + diagram->setDisplayGuides(false); diagram->render(&painter, target, source, Qt::KeepAspectRatio); diagram->setDisplayGrid(was_drawing_grid); + diagram->setDisplayGuides(was_drawing_guides); } int exportPdf(QETProject &project, const QString &output) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 0cc2bbbd0..7072a95d6 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -2315,6 +2315,7 @@ ExportProperties Diagram::applyProperties( // exporte les options de rendu en cours ExportProperties old_properties; old_properties.draw_grid = displayGrid(); + old_properties.draw_guides = displayGuides(); old_properties.draw_border = border_and_titleblock.borderIsDisplayed(); old_properties.draw_titleblock = border_and_titleblock.titleBlockIsDisplayed(); old_properties.draw_terminals = drawTerminals(); @@ -2328,6 +2329,7 @@ ExportProperties Diagram::applyProperties( setDrawTerminals (new_properties.draw_terminals); setDrawColoredConductors (new_properties.draw_colored_conductors); setDisplayGrid (new_properties.draw_grid); + setDisplayGuides (new_properties.draw_guides); border_and_titleblock.displayBorder(new_properties.draw_border); border_and_titleblock.displayTitleBlock (new_properties.draw_titleblock); diff --git a/sources/exportproperties.cpp b/sources/exportproperties.cpp index ee929e0bc..941f894b5 100644 --- a/sources/exportproperties.cpp +++ b/sources/exportproperties.cpp @@ -30,6 +30,7 @@ ExportProperties::ExportProperties() : destination_directory(QETApp::documentDir()), format("PNG"), draw_grid(false), + draw_guides(false), draw_border(true), draw_titleblock(true), draw_terminals(false), @@ -61,6 +62,8 @@ void ExportProperties::toSettings(QSettings &settings, format); settings.setValue(prefix % "drawgrid", draw_grid); + settings.setValue(prefix % "drawguides", + draw_guides); settings.setValue(prefix % "drawborder", draw_border); settings.setValue(prefix % "drawtitleblock", @@ -94,6 +97,8 @@ void ExportProperties::fromSettings(QSettings &settings, draw_grid = settings.value(prefix % "drawgrid", false).toBool(); + draw_guides = settings.value(prefix % "drawguides", + false).toBool(); draw_border = settings.value(prefix % "drawborder", true ).toBool(); draw_titleblock = settings.value(prefix % "drawtitleblock", diff --git a/sources/exportproperties.h b/sources/exportproperties.h index 1245e9e04..f104a9c41 100644 --- a/sources/exportproperties.h +++ b/sources/exportproperties.h @@ -43,6 +43,7 @@ class ExportProperties { QDir destination_directory; ///< Target directory for generated files QString format; ///< Image format of generated files bool draw_grid; ///< Whether to render the diagram grid + bool draw_guides; ///< Whether to render the diagram guides bool draw_border; ///< Whether to render the border (along with rows/columns headers) bool draw_titleblock; ///< Whether to render the title block bool draw_terminals; ///< Whether to render terminals diff --git a/sources/print/projectprintwindow.cpp b/sources/print/projectprintwindow.cpp index 5333f1a64..c7e6a19d8 100644 --- a/sources/print/projectprintwindow.cpp +++ b/sources/print/projectprintwindow.cpp @@ -519,6 +519,7 @@ ExportProperties ProjectPrintWindow::exportProperties() const exp.draw_terminals = ui->m_draw_terminal_cb->isChecked(); exp.draw_colored_conductors = ui->m_keep_conductor_color_cb->isChecked(); exp.draw_grid = false; + exp.draw_guides = false; return exp; } diff --git a/sources/ui/configpage/guidespropertieswidget.cpp b/sources/ui/configpage/guidespropertieswidget.cpp index 7c9cb4a5b..73b3d3e96 100644 --- a/sources/ui/configpage/guidespropertieswidget.cpp +++ b/sources/ui/configpage/guidespropertieswidget.cpp @@ -5,108 +5,109 @@ #include #include #include -#include +#include #include GuidesPropertiesWidget::GuidesPropertiesWidget(QWidget *parent) : QWidget(parent) { - setupUi(); + setupUi(); } GuidesPropertiesWidget::~GuidesPropertiesWidget() {} void GuidesPropertiesWidget::setupUi() { - QVBoxLayout *main_layout = new QVBoxLayout(this); + QVBoxLayout *main_layout = new QVBoxLayout(this); - m_table = new QTableWidget(0, 3, this); - m_table->setHorizontalHeaderLabels({tr("Orientation"), tr("Position"), tr("Couleur")}); - m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); - m_table->setSelectionBehavior(QAbstractItemView::SelectRows); + m_table = new QTableWidget(0, 3, this); + m_table->setHorizontalHeaderLabels({tr("Orientation"), tr("Position"), tr("Couleur")}); + m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + m_table->setSelectionBehavior(QAbstractItemView::SelectRows); - m_add_btn = new QPushButton(tr("Ajouter"), this); - m_remove_btn = new QPushButton(tr("Supprimer"), this); + m_add_btn = new QPushButton(tr("Ajouter"), this); + m_remove_btn = new QPushButton(tr("Supprimer"), this); - QHBoxLayout *btn_layout = new QHBoxLayout(); - btn_layout->addWidget(m_add_btn); - btn_layout->addWidget(m_remove_btn); - btn_layout->addStretch(); + QHBoxLayout *btn_layout = new QHBoxLayout(); + btn_layout->addWidget(m_add_btn); + btn_layout->addWidget(m_remove_btn); + btn_layout->addStretch(); - main_layout->addWidget(m_table); - main_layout->addLayout(btn_layout); + main_layout->addWidget(m_table); + main_layout->addLayout(btn_layout); - connect(m_add_btn, &QPushButton::clicked, this, &GuidesPropertiesWidget::addGuide); - connect(m_remove_btn, &QPushButton::clicked, this, &GuidesPropertiesWidget::removeGuide); + connect(m_add_btn, &QPushButton::clicked, this, &GuidesPropertiesWidget::addGuide); + connect(m_remove_btn, &QPushButton::clicked, this, &GuidesPropertiesWidget::removeGuide); } QList GuidesPropertiesWidget::guides() const { - QList list; - for (int row = 0; row < m_table->rowCount(); ++row) { - QComboBox *combo = qobject_cast(m_table->cellWidget(row, 0)); - QSpinBox *spin = qobject_cast(m_table->cellWidget(row, 1)); - QPushButton *colorBtn = qobject_cast(m_table->cellWidget(row, 2)); + QList list; + for (int row = 0; row < m_table->rowCount(); ++row) { + QComboBox *combo = qobject_cast(m_table->cellWidget(row, 0)); + QDoubleSpinBox *spin = qobject_cast(m_table->cellWidget(row, 1)); + QPushButton *colorBtn = qobject_cast(m_table->cellWidget(row, 2)); - if (combo && spin && colorBtn) { - Diagram::Guide g; - g.orientation = (combo->currentIndex() == 0) ? Diagram::Guide::Horizontal : Diagram::Guide::Vertical; - g.position = spin->value(); - g.color = colorBtn->property("color").value(); - list.append(g); - } - } - return list; + if (combo && spin && colorBtn) { + Diagram::Guide g; + g.orientation = (combo->currentIndex() == 0) ? Diagram::Guide::Horizontal : Diagram::Guide::Vertical; + g.position = spin->value(); + g.color = colorBtn->property("color").value(); + list.append(g); + } + } + return list; } void GuidesPropertiesWidget::setGuides(const QList &guides) { - m_table->setRowCount(0); - for (const auto &g : guides) { - addGuide(); - int row = m_table->rowCount() - 1; + m_table->setRowCount(0); + for (const auto &g : guides) { + addGuide(); + int row = m_table->rowCount() - 1; - QComboBox *combo = qobject_cast(m_table->cellWidget(row, 0)); - QSpinBox *spin = qobject_cast(m_table->cellWidget(row, 1)); - QPushButton *colorBtn = qobject_cast(m_table->cellWidget(row, 2)); + QComboBox *combo = qobject_cast(m_table->cellWidget(row, 0)); + QDoubleSpinBox *spin = qobject_cast(m_table->cellWidget(row, 1)); + QPushButton *colorBtn = qobject_cast(m_table->cellWidget(row, 2)); - if (combo && spin && colorBtn) { - combo->setCurrentIndex(g.orientation == Diagram::Guide::Horizontal ? 0 : 1); - spin->setValue(qRound(g.position)); - colorBtn->setProperty("color", g.color); - colorBtn->setStyleSheet(QString("background-color: %1; color: white; font-weight: bold;").arg(g.color.name())); - } - } + if (combo && spin && colorBtn) { + combo->setCurrentIndex(g.orientation == Diagram::Guide::Horizontal ? 0 : 1); + spin->setValue(g.position); + colorBtn->setProperty("color", g.color); + colorBtn->setStyleSheet(QString("background-color: %1; color: white; font-weight: bold;").arg(g.color.name())); + } + } } void GuidesPropertiesWidget::addGuide() { - int row = m_table->rowCount(); - m_table->insertRow(row); + int row = m_table->rowCount(); + m_table->insertRow(row); - QComboBox *combo = new QComboBox(this); - combo->addItems({tr("Horizontal"), tr("Vertical")}); - m_table->setCellWidget(row, 0, combo); + QComboBox *combo = new QComboBox(this); + combo->addItems({tr("Horizontal"), tr("Vertical")}); + m_table->setCellWidget(row, 0, combo); - QSpinBox *spin = new QSpinBox(this); - spin->setRange(-10000, 10000); - spin->setValue(100); - m_table->setCellWidget(row, 1, spin); + QDoubleSpinBox *spin = new QDoubleSpinBox(this); + spin->setRange(-10000.0, 10000.0); + spin->setDecimals(2); + spin->setValue(100.0); + m_table->setCellWidget(row, 1, spin); - QPushButton *colorBtn = new QPushButton(tr("Couleur"), this); - QColor defaultColor = Qt::lightGray; - colorBtn->setProperty("color", defaultColor); - colorBtn->setStyleSheet(QString("background-color: %1; color: white; font-weight: bold;").arg(defaultColor.name())); + QPushButton *colorBtn = new QPushButton(tr("Couleur"), this); + QColor defaultColor = Qt::lightGray; + colorBtn->setProperty("color", defaultColor); + colorBtn->setStyleSheet(QString("background-color: %1; color: white; font-weight: bold;").arg(defaultColor.name())); - connect(colorBtn, &QPushButton::clicked, [this, colorBtn]() { - QColor c = QColorDialog::getColor(colorBtn->property("color").value(), this); - if (c.isValid()) { - colorBtn->setProperty("color", c); - colorBtn->setStyleSheet(QString("background-color: %1; color: white; font-weight: bold;").arg(c.name())); - } - }); - m_table->setCellWidget(row, 2, colorBtn); + connect(colorBtn, &QPushButton::clicked, [this, colorBtn]() { + QColor c = QColorDialog::getColor(colorBtn->property("color").value(), this); + if (c.isValid()) { + colorBtn->setProperty("color", c); + colorBtn->setStyleSheet(QString("background-color: %1; color: white; font-weight: bold;").arg(c.name())); + } + }); + m_table->setCellWidget(row, 2, colorBtn); } void GuidesPropertiesWidget::removeGuide() { - int row = m_table->currentRow(); - if (row >= 0) { - m_table->removeRow(row); - } + int row = m_table->currentRow(); + if (row >= 0) { + m_table->removeRow(row); + } } diff --git a/sources/ui/configpage/guidespropertieswidget.h b/sources/ui/configpage/guidespropertieswidget.h index 5c5af4fc1..1e4e599ec 100644 --- a/sources/ui/configpage/guidespropertieswidget.h +++ b/sources/ui/configpage/guidespropertieswidget.h @@ -9,24 +9,24 @@ class QTableWidget; class QPushButton; class GuidesPropertiesWidget : public QWidget { - Q_OBJECT + Q_OBJECT public: - explicit GuidesPropertiesWidget(QWidget *parent = nullptr); - ~GuidesPropertiesWidget() override; + explicit GuidesPropertiesWidget(QWidget *parent = nullptr); + ~GuidesPropertiesWidget() override; - QList guides() const; - void setGuides(const QList &guides); + QList guides() const; + void setGuides(const QList &guides); private slots: - void addGuide(); - void removeGuide(); + void addGuide(); + void removeGuide(); private: - void setupUi(); + void setupUi(); - QTableWidget *m_table; - QPushButton *m_add_btn; - QPushButton *m_remove_btn; + QTableWidget *m_table; + QPushButton *m_add_btn; + QPushButton *m_remove_btn; }; #endif // GUIDESPROPERTIESWIDGET_H