mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-06 03:04:13 +02:00
Set the wires-per-terminal limits for the application, a project can override
The limits were per project only. They are now set once in Settings > General, under the master switch: the most wires per terminal and "one wire per folio report". Every project follows them. Project properties > "Conducteurs par borne" gets "Utiliser les réglages de l'application", ticked by default, showing the application's values greyed. Unticked, the project keeps its own values, saved in the project as before, so a drawing that needs its own limit carries it to any computer. A project's own "no limit" overrides an application limit too. QETProject::wiringRules() now returns the rules in force (the project's own, or the application's), so the code that checks a wire is unchanged; projectWiringRules() returns what the project itself stores. A project that follows the application still writes nothing, so it saves exactly as before. tst_wiringrules: which rules win, the save round trip of a project's own "no rule", and through the real binary that the application's limit refuses a wire unless the project overrides it or the master switch is off (checked to fail with the application's rules ignored). ctest 55/55. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015FPuYPS4T7QuEwjNu22rXD
This commit is contained in:
+54
-5
@@ -30,6 +30,9 @@ namespace {
|
||||
//The master switch is read on every wire drawn, so it is read from
|
||||
//the settings once and kept; setMasterEnabled() keeps both in step.
|
||||
int master_cache = -1;
|
||||
//Same for the application's rules
|
||||
bool application_cached = false;
|
||||
WiringRules::Settings application_cache;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,11 +60,56 @@ void WiringRules::setMasterEnabled(bool enabled)
|
||||
master_cache = enabled ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief WiringRules::applicationSettings
|
||||
@return the rules set for every project in Settings > General; a
|
||||
project that sets its own (Settings::own) uses those instead.
|
||||
*/
|
||||
WiringRules::Settings WiringRules::applicationSettings()
|
||||
{
|
||||
if (!application_cached) {
|
||||
const QSettings settings;
|
||||
application_cache = Settings();
|
||||
application_cache.max_wires = qMax(0, settings.value(max_wires_key, 0).toInt());
|
||||
application_cache.one_wire_per_report = settings.value(one_wire_per_report_key, false).toBool();
|
||||
application_cached = true;
|
||||
}
|
||||
return application_cache;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief WiringRules::setApplicationSettings
|
||||
Save the rules set for every project.
|
||||
@param settings
|
||||
*/
|
||||
void WiringRules::setApplicationSettings(const Settings &settings)
|
||||
{
|
||||
QSettings qsettings;
|
||||
qsettings.setValue(max_wires_key, qMax(0, settings.max_wires));
|
||||
qsettings.setValue(one_wire_per_report_key, settings.one_wire_per_report);
|
||||
application_cache = settings;
|
||||
application_cache.own = false;
|
||||
application_cached = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief WiringRules::effective
|
||||
@return the rules that apply to a project: its own when it sets them,
|
||||
otherwise the application's.
|
||||
*/
|
||||
WiringRules::Settings WiringRules::effective(const Settings &project, const Settings &application)
|
||||
{
|
||||
Settings result = project.own ? project : application;
|
||||
result.own = project.own;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief WiringRules::fromXml
|
||||
@param project_root : the root element of a project
|
||||
@return the rules stored in the <wiring_rules> child of \a project_root,
|
||||
the default (no rule) when there is none.
|
||||
which the project then uses instead of the application's (Settings::own);
|
||||
the default, which follows the application, when there is none.
|
||||
*/
|
||||
WiringRules::Settings WiringRules::fromXml(const QDomElement &project_root)
|
||||
{
|
||||
@@ -70,6 +118,7 @@ WiringRules::Settings WiringRules::fromXml(const QDomElement &project_root)
|
||||
if (rules.isNull()) {
|
||||
return settings;
|
||||
}
|
||||
settings.own = true;
|
||||
settings.max_wires = qMax(0, rules.attribute(max_wires_attribute, QStringLiteral("0")).toInt());
|
||||
settings.one_wire_per_report = rules.attribute(report_attribute) == QLatin1String("true");
|
||||
return settings;
|
||||
@@ -77,13 +126,13 @@ WiringRules::Settings WiringRules::fromXml(const QDomElement &project_root)
|
||||
|
||||
/**
|
||||
@brief WiringRules::toXml
|
||||
Write \a settings as a <wiring_rules> child of \a project_root. Nothing
|
||||
is written when no rule is on, so a project that never used them saves
|
||||
exactly as before.
|
||||
Write \a settings as a <wiring_rules> child of \a project_root, only
|
||||
when the project sets its own rules: a project that follows the
|
||||
application's saves exactly as before.
|
||||
*/
|
||||
void WiringRules::toXml(const Settings &settings, QDomElement &project_root)
|
||||
{
|
||||
if (settings.isDefault()) {
|
||||
if (!settings.own) {
|
||||
return;
|
||||
}
|
||||
QDomElement rules = project_root.ownerDocument().createElement(element_name);
|
||||
|
||||
Reference in New Issue
Block a user