mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-05 02:24:13 +02:00
Warn with a pop-up, not a box, when a wires-per-terminal rule is turned on
Review of #1272: scorpio810 asked for a warning box for users; the inline
box added in 9a55939bb is replaced by a pop-up, as the element editor
gives for unnamed terminals. When OK in Settings > General or in Project
properties turns a rule on (a limit where there was none, or one wire
per folio report), a warning says the rules are experimental, may change
with settings to redo if wires and conductors become separate objects,
and can all be turned off in Settings > General. OK goes on. Changing a
limit that was already on, or turning rules off, shows nothing.
tst_wiringrules: when the warning is due (WiringRules::turnsRuleOn()).
Checked in the GUI from both pages, and that a plain OK shows nothing.
English for translators: "Warning"; "The wires-per-terminal rules are an
experimental feature. They count wires as QElectroTech represents them
today. They could change, and your settings need redoing, if wires and
conductors become separate objects in a future version. All these rules
can be turned off in Configure QElectroTech > General."
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015FPuYPS4T7QuEwjNu22rXD
This commit is contained in:
@@ -118,7 +118,6 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) :
|
||||
ui->m_wiring_rules_cb->setChecked(WiringRules::masterEnabled());
|
||||
{
|
||||
//The rules every project follows unless it sets its own (#1158)
|
||||
ui->m_wiring_rules_warning_layout->addWidget(WiringRulesWarning::create(this));
|
||||
const WiringRules::Settings rules = WiringRules::applicationSettings();
|
||||
ui->m_wiring_max_wires_sb->setValue(rules.max_wires);
|
||||
ui->m_wiring_one_wire_per_report_cb->setChecked(rules.one_wire_per_report);
|
||||
@@ -353,10 +352,14 @@ void GeneralConfigurationPage::applyConf()
|
||||
settings.setValue("diagrameditor/conductor_properties_panel", ui->m_conductor_properties_panel->isChecked());
|
||||
WiringRules::setMasterEnabled(ui->m_wiring_rules_cb->isChecked());
|
||||
{
|
||||
WiringRules::Settings rules = WiringRules::applicationSettings();
|
||||
const WiringRules::Settings before = WiringRules::applicationSettings();
|
||||
WiringRules::Settings rules = before;
|
||||
rules.max_wires = ui->m_wiring_max_wires_sb->value();
|
||||
rules.one_wire_per_report = ui->m_wiring_one_wire_per_report_cb->isChecked();
|
||||
WiringRules::setApplicationSettings(rules);
|
||||
if (WiringRules::masterEnabled() && WiringRules::turnsRuleOn(before, rules)) {
|
||||
WiringRulesWarning::show(this);
|
||||
}
|
||||
}
|
||||
settings.setValue("diagrameditor/autosave-interval", ui->m_autosave_sb->value());
|
||||
|
||||
|
||||
@@ -83,13 +83,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="m_wiring_rules_warning_layout">
|
||||
<property name="leftMargin">
|
||||
<number>20</number>
|
||||
</property>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="m_wiring_max_wires_layout">
|
||||
<property name="leftMargin">
|
||||
|
||||
@@ -186,8 +186,13 @@ void ProjectMainConfigPage::applyProjectConf()
|
||||
wiring_rules.one_wire_per_report = one_wire_per_report_cb_ -> isChecked();
|
||||
}
|
||||
if (m_project -> projectWiringRules() != wiring_rules) {
|
||||
const WiringRules::Settings before = m_project -> wiringRules();
|
||||
m_project -> setWiringRules(wiring_rules);
|
||||
modified_project = true;
|
||||
if (WiringRules::masterEnabled()
|
||||
&& WiringRules::turnsRuleOn(before, m_project -> wiringRules())) {
|
||||
WiringRulesWarning::show(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (modified_project) {
|
||||
@@ -307,7 +312,6 @@ void ProjectMainConfigPage::initLayout()
|
||||
main_layout0 -> addSpacing(10);
|
||||
|
||||
QVBoxLayout *wiring_rules_layout = new QVBoxLayout(wiring_rules_gb_);
|
||||
wiring_rules_layout -> addWidget(WiringRulesWarning::create(wiring_rules_gb_));
|
||||
wiring_rules_layout -> addWidget(use_application_rules_cb_);
|
||||
QHBoxLayout *max_wires_layout = new QHBoxLayout();
|
||||
max_wires_layout -> addWidget(max_wires_label_);
|
||||
|
||||
@@ -19,41 +19,29 @@
|
||||
#include "wiringruleswarning.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QStyle>
|
||||
#include <QMessageBox>
|
||||
|
||||
/**
|
||||
@brief WiringRulesWarning::create
|
||||
A warning box shown wherever the wires-per-terminal rules are set
|
||||
(discussion #1158, review of #1272): the rules count wires on a terminal
|
||||
as QElectroTech models them today, and would have to be redesigned if
|
||||
wires and conductors become separate objects, so they are experimental.
|
||||
@brief WiringRulesWarning::show
|
||||
Warn, when a wires-per-terminal rule is turned on (discussion #1158,
|
||||
review of #1272), that the rules are experimental: they count wires on
|
||||
a terminal as QElectroTech models them today, and would have to be
|
||||
redesigned if wires and conductors become separate objects. A plain
|
||||
warning, as the element editor gives for unnamed terminals: OK goes on.
|
||||
@param parent
|
||||
@return the box, a framed icon and text
|
||||
*/
|
||||
QWidget *WiringRulesWarning::create(QWidget *parent)
|
||||
void WiringRulesWarning::show(QWidget *parent)
|
||||
{
|
||||
auto frame = new QFrame(parent);
|
||||
frame->setFrameShape(QFrame::StyledPanel);
|
||||
|
||||
auto icon = new QLabel(frame);
|
||||
const int size = frame->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
||||
icon->setPixmap(frame->style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(size, size));
|
||||
icon->setAlignment(Qt::AlignTop);
|
||||
|
||||
auto text = new QLabel(QApplication::translate(
|
||||
QMessageBox::warning(
|
||||
parent,
|
||||
QApplication::translate("WiringRulesWarning", "Avertissement"),
|
||||
QApplication::translate(
|
||||
"WiringRulesWarning",
|
||||
"Fonction expérimentale. Ces règles comptent les conducteurs tels "
|
||||
"que QElectroTech les représente aujourd'hui ; elles pourraient "
|
||||
"changer, et vos réglages devoir être refaits, si les fils et les "
|
||||
"conducteurs deviennent des objets distincts dans une version future."),
|
||||
frame);
|
||||
text->setWordWrap(true);
|
||||
|
||||
auto layout = new QHBoxLayout(frame);
|
||||
layout->addWidget(icon);
|
||||
layout->addWidget(text, 1);
|
||||
return frame;
|
||||
"<b>Les règles de conducteurs par borne sont une fonction expérimentale.</b>"
|
||||
"<br><br>Elles comptent les conducteurs tels que QElectroTech les représente "
|
||||
"aujourd'hui. Elles pourraient changer, et vos réglages devoir être refaits, "
|
||||
"si les fils et les conducteurs deviennent des objets distincts dans une "
|
||||
"version future."
|
||||
"<br><br>Toutes ces règles peuvent être désactivées dans Configurer "
|
||||
"QElectroTech > Général."));
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class QWidget;
|
||||
|
||||
namespace WiringRulesWarning
|
||||
{
|
||||
QWidget *create(QWidget *parent = nullptr);
|
||||
void show(QWidget *parent);
|
||||
}
|
||||
|
||||
#endif // WIRINGRULESWARNING_H
|
||||
|
||||
@@ -173,3 +173,15 @@ bool WiringRules::hasRoom(int limit, int wires)
|
||||
{
|
||||
return limit <= 0 || wires < limit;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief WiringRules::turnsRuleOn
|
||||
@param before, after : the rules in force before and after a change
|
||||
@return true if the change turns on a rule that was off: QElectroTech
|
||||
then warns that the rules are experimental (review of #1272).
|
||||
*/
|
||||
bool WiringRules::turnsRuleOn(const Settings &before, const Settings &after)
|
||||
{
|
||||
return (after.max_wires > 0 && before.max_wires <= 0)
|
||||
|| (after.one_wire_per_report && !before.one_wire_per_report);
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ namespace WiringRules
|
||||
Settings applicationSettings();
|
||||
void setApplicationSettings(const Settings &settings);
|
||||
Settings effective(const Settings &project, const Settings &application);
|
||||
bool turnsRuleOn(const Settings &before, const Settings &after);
|
||||
|
||||
Settings fromXml(const QDomElement &project_root);
|
||||
void toXml(const Settings &settings, QDomElement &project_root);
|
||||
|
||||
@@ -195,6 +195,23 @@ private slots:
|
||||
QCOMPARE(WiringRules::effective(own, application).max_wires, 6);
|
||||
}
|
||||
|
||||
void warnsWhenARuleIsTurnedOn()
|
||||
{
|
||||
WiringRules::Settings off;
|
||||
WiringRules::Settings limit;
|
||||
limit.max_wires = 4;
|
||||
WiringRules::Settings report;
|
||||
report.one_wire_per_report = true;
|
||||
|
||||
QVERIFY(WiringRules::turnsRuleOn(off, limit));
|
||||
QVERIFY(WiringRules::turnsRuleOn(off, report));
|
||||
QVERIFY(WiringRules::turnsRuleOn(limit, [&]{ auto s = limit; s.one_wire_per_report = true; return s; }()));
|
||||
// Changing a limit that was already on, or turning rules off: no warning
|
||||
QVERIFY(!WiringRules::turnsRuleOn(limit, [&]{ auto s = limit; s.max_wires = 2; return s; }()));
|
||||
QVERIFY(!WiringRules::turnsRuleOn(limit, off));
|
||||
QVERIFY(!WiringRules::turnsRuleOn(off, off));
|
||||
}
|
||||
|
||||
void xmlRoundTrip()
|
||||
{
|
||||
QDomDocument doc;
|
||||
|
||||
Reference in New Issue
Block a user