mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-11 22:54:12 +02:00
Fix cable numbering rule questions: per project, and a first rule counts
Two defects found while re-testing the cable management after the upstream merge, plus one change of intent for the numbering question. The question "define a cable numbering rule now?" kept its answer in the program settings, so saying no once silenced every project of the program -- the exact opposite of what it should do. The answer now travels with the project itself, stored on the <cable_autonums> element as ask_numbering_rule="false"; a file which does not hold the answer asks again, and taking the rule away in the project properties or in the numbering window brings the question back for that project alone. Read-only projects are no longer asked at all, since there is nowhere in them to define a rule. The numbering window could not hand out the first rule of a project: it drew the rule, worked the numbers out with it, and only wrote the rule into the project together with those numbers -- while the planning refused to run on a project which had no rule saved yet. The counters of a cable rule are kept under its fixed name anyway, so planning now falls back to that name when the project holds no rule yet: a rule which is being drawn in the window counts from the moment it is complete, and the first renumbering of a project works.
This commit is contained in:
@@ -121,8 +121,18 @@ CableRenumberPlan CableRenumber::plan(QETProject *project,
|
||||
"être renumérotés.");
|
||||
return result;
|
||||
}
|
||||
const QString key = project->cableCurrentAutoNum();
|
||||
if (key.isEmpty() || rule.isEmpty())
|
||||
//The rule may be one the numbering window is drawing right now
|
||||
//and has not written into the project yet: the numbering writes
|
||||
//it together with the numbers themselves, so the project does
|
||||
//not have to hold it beforehand. What the counters are kept
|
||||
//under is the name the rule is stored with, which for cables is
|
||||
//fixed either way -- so numbering starts from a project which
|
||||
//has no rule saved yet just as well.
|
||||
QString key = project->cableCurrentAutoNum();
|
||||
if (key.isEmpty()) {
|
||||
key = QETProject::cableAutoNumRuleName();
|
||||
}
|
||||
if (rule.isEmpty())
|
||||
{
|
||||
result.error = QCoreApplication::translate(
|
||||
"CableRenumber",
|
||||
|
||||
@@ -2331,11 +2331,20 @@ void QETDiagramEditor::selectGroupTriggered(QAction *action)
|
||||
bool QETDiagramEditor::cableNumberingGate(Diagram *diagram)
|
||||
{
|
||||
if (!diagram || !diagram->project()) return true;
|
||||
if (diagram->project()->hasCableAutoNum()) return true;
|
||||
QETProject *project = diagram->project();
|
||||
if (project->hasCableAutoNum()) return true;
|
||||
|
||||
QSettings settings;
|
||||
const QString ask_key = QStringLiteral("cable-management/ask_numbering_rule");
|
||||
if (!settings.value(ask_key, true).toBool()) {
|
||||
//A read-only project is left alone without a question: there is
|
||||
//nowhere to define a rule in it, so asking whether he wants to
|
||||
//would be a way to nowhere. Its cables are drawn called W, the
|
||||
//same as any project without a rule.
|
||||
if (project->isReadOnly()) return true;
|
||||
|
||||
//Whether he has once answered no in THIS project. The answer is
|
||||
//kept with the project rather than in the program settings, so
|
||||
//one project being answered with no does not stop every other
|
||||
//project from being asked.
|
||||
if (!project->cableAskNumbering()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2358,9 +2367,11 @@ bool QETDiagramEditor::cableNumberingGate(Diagram *diagram)
|
||||
box.exec();
|
||||
|
||||
if (box.clickedButton() == later_button) {
|
||||
//For good, in the program settings: he has answered this
|
||||
//once and should not be asked again at every start.
|
||||
settings.setValue(ask_key, false);
|
||||
//With this project only: he has answered once here and
|
||||
//should not be asked again every time he picks the tool
|
||||
//up in this project -- another project is free to ask.
|
||||
project->setCableAskNumbering(false);
|
||||
project->setModified(true);
|
||||
return true;
|
||||
}
|
||||
if (box.clickedButton() != define_button) {
|
||||
|
||||
@@ -967,6 +967,32 @@ void QETProject::setCableXAxisFirst(bool x_axis_first)
|
||||
m_cable_axis_x_first = x_axis_first;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::cableAskNumbering
|
||||
@return true when the cable tool may still ask this project whether
|
||||
a numbering rule should be defined. The answer to that question is
|
||||
kept with the project rather than in the program settings, so that
|
||||
one project being answered with no does not stop every other
|
||||
project from asking.
|
||||
*/
|
||||
bool QETProject::cableAskNumbering() const
|
||||
{
|
||||
return m_cable_ask_numbering;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::setCableAskNumbering
|
||||
Take the answer he gave to the numbering question down with the
|
||||
project. False means he has said no once here and is not to be
|
||||
asked again in this project; taking the rule away puts it back to
|
||||
true so the question comes again.
|
||||
@param ask
|
||||
*/
|
||||
void QETProject::setCableAskNumbering(bool ask)
|
||||
{
|
||||
m_cable_ask_numbering = ask;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::renumberElementsBySchemeTitle
|
||||
Renumber existing elements by element autonumbering scheme title.
|
||||
@@ -2597,6 +2623,13 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project)
|
||||
m_cable_axis_x_first = cable_autonums.attribute(
|
||||
QStringLiteral("axis_priority"), QStringLiteral("x"))
|
||||
!= QLatin1String("y");
|
||||
//Whether the numbering question was already answered with
|
||||
//no in this project. A file which does not hold the answer
|
||||
//yet asks again rather than staying silent: it is his own
|
||||
//answer per project which is kept, not a default saying no.
|
||||
m_cable_ask_numbering = cable_autonums.attribute(
|
||||
QStringLiteral("ask_numbering_rule"), QStringLiteral("true"))
|
||||
!= QLatin1String("false");
|
||||
for (auto elmt : QET::findInDomElement(cable_autonums, QStringLiteral("cable_autonum")))
|
||||
{
|
||||
NumerotationContext nc;
|
||||
@@ -2865,6 +2898,12 @@ void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element)
|
||||
cable_autonums.setAttribute("current_autonum", m_current_cable_autonum);
|
||||
cable_autonums.setAttribute("axis_priority",
|
||||
m_cable_axis_x_first ? "x" : "y");
|
||||
//Only the no is written down: a project which has not answered
|
||||
//the numbering question yet asks again, so silence in the file
|
||||
//means asking rather than holding back.
|
||||
if (!m_cable_ask_numbering) {
|
||||
cable_autonums.setAttribute("ask_numbering_rule", "false");
|
||||
}
|
||||
QStringList cable_autonum_keys = cableAutoNum().keys();
|
||||
cable_autonum_keys.sort();
|
||||
for (const QString &key : std::as_const(cable_autonum_keys)) {
|
||||
|
||||
@@ -206,6 +206,19 @@ class QETProject : public QObject
|
||||
*/
|
||||
bool cableXAxisFirst() const;
|
||||
void setCableXAxisFirst(bool x_axis_first);
|
||||
/**
|
||||
Whether the cable tool asks this project whether a
|
||||
numbering rule should be defined, when he is picked up
|
||||
and the project has none. Saying no in that question is
|
||||
remembered with the project rather than in the program
|
||||
settings, so one project saying no does not silence
|
||||
every other one -- each project asks again until it
|
||||
has answered for itself, and taking the rule away
|
||||
brings the question back (see the cable tab of the
|
||||
project properties and the numbering window).
|
||||
*/
|
||||
bool cableAskNumbering() const;
|
||||
void setCableAskNumbering(bool ask);
|
||||
/**
|
||||
The name the single cable numbering rule is kept under.
|
||||
Fixed and never translated: it is a key which goes into
|
||||
@@ -449,6 +462,9 @@ class QETProject : public QObject
|
||||
QString m_current_cable_autonum;
|
||||
///< which axis the cables are numbered along (see cableXAxisFirst)
|
||||
bool m_cable_axis_x_first = true;
|
||||
///< whether the cable tool still asks about a numbering rule
|
||||
///< for this project (see cableAskNumbering)
|
||||
bool m_cable_ask_numbering = true;
|
||||
/// True when the loaded file had element numbering schemes
|
||||
/// saved without an id (written before ids existed)
|
||||
bool m_legacy_element_autonums = false;
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QSettings>
|
||||
#include <QUndoStack>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
@@ -214,11 +213,9 @@ void CableNumberingDialog::removeRule()
|
||||
//No rule left, so the button which takes one away goes too. And
|
||||
//having just taken the rule away means numbering cables by hand
|
||||
//again: the question of defining one comes back the next time a
|
||||
//cable is drawn, so it is not held back any more.
|
||||
//cable is drawn, so it is not held back in this project any more.
|
||||
m_rule->setRuleRemovable(false);
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("cable-management/ask_numbering_rule"),
|
||||
true);
|
||||
m_project->setCableAskNumbering(true);
|
||||
m_project->setModified(true);
|
||||
updateEnabling();
|
||||
}
|
||||
|
||||
@@ -480,13 +480,11 @@ void NewDiagramPage::removeAutoNumContext(AutoNumTab &tab)
|
||||
//A tab which keeps one single rule has no list to delete it
|
||||
//from, so this is where the button of its own goes away too.
|
||||
//And having just taken the rule away means numbering cables by
|
||||
//hand again: the question of defining one comes back the next
|
||||
//time a cable is drawn, so it is not held back any more.
|
||||
//hand again: every project of its own asks once more whether
|
||||
//one should be defined -- that answer is kept per project, so
|
||||
//there is nothing to take back here.
|
||||
if (!tab.fixed_name.isEmpty()) {
|
||||
tab.widget->setRuleRemovable(false);
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("cable-management/ask_numbering_rule"),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,6 @@
|
||||
#include "../titleblockpropertieswidget.h"
|
||||
#include "../xrefpropertieswidget.h"
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
//#include "ui_autonumberingmanagementw.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
@@ -1141,11 +1139,9 @@ void ProjectAutoNumConfigPage::removeContextCable()
|
||||
//No rule left, so the button which takes one away goes too. And
|
||||
//having just taken the rule away means numbering cables by hand
|
||||
//again: the question of defining one comes back the next time a
|
||||
//cable is drawn, so it is not held back any more.
|
||||
//cable is drawn, so it is not held back in this project any more.
|
||||
m_saw_cable->setRuleRemovable(false);
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("cable-management/ask_numbering_rule"),
|
||||
true);
|
||||
m_project->setCableAskNumbering(true);
|
||||
m_project->setModified(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user