mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-24 07:54:13 +02:00
Give new projects the terminal labelling of the settings
The labelling of the terminals is a setting of the project, so that the same file draws the same way on every machine which opens it. A new project has to start with something, though, and that is now a default of the application: Configure QElectroTech > New project, on the sheet tab, the same group box with the same two choices the project properties use -- what it saves is only what a new project starts with. Off unless the settings say otherwise, so a new project draws the whole label in one field, as it always did, and a project saved after that keeps its own choice (readTerminalLabelSplitXml()). The settings key starts with "diagrameditor/default", the prefix of the new-project part of a configuration profile, so the choice travels with the other defaults of a new project. The project gets the setting in its own properties and nowhere else: the page of the new sheets does not offer it, and the tests say so.
This commit is contained in:
@@ -96,6 +96,12 @@ m_project_properties_handler{this}
|
|||||||
//Read auto break conductor default from global settings
|
//Read auto break conductor default from global settings
|
||||||
setAutoBreakConductor(settings.value(QStringLiteral("diagrameditor/auto_break_conductor"), false).toBool());
|
setAutoBreakConductor(settings.value(QStringLiteral("diagrameditor/auto_break_conductor"), false).toBool());
|
||||||
|
|
||||||
|
//A new project draws its terminals the way the settings chose it
|
||||||
|
//for new projects (Configure QElectroTech > New project), off when
|
||||||
|
//they say nothing: the drawing is then the one it always was. Every
|
||||||
|
//project saved after that keeps its own choice (readTerminalLabelSplitXml())
|
||||||
|
setTerminalLabelSplit(settings.value(QStringLiteral("diagrameditor/defaultterminallabelling"), false).toBool());
|
||||||
|
|
||||||
int size = settings.beginReadArray(QStringLiteral("diagrameditor/defaultguides"));
|
int size = settings.beginReadArray(QStringLiteral("diagrameditor/defaultguides"));
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
settings.setArrayIndex(i);
|
settings.setArrayIndex(i);
|
||||||
|
|||||||
@@ -136,6 +136,43 @@ NewDiagramPage::NewDiagramPage(QETProject *project,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//How the terminals of a new project draw their label, built for
|
||||||
|
//the application's defaults only: per project this is a project
|
||||||
|
//property (project properties > General page), which is where the
|
||||||
|
//project gets it from. Same group box, same words, same choice as
|
||||||
|
//there -- only what a new project starts with is read and written
|
||||||
|
//here, in the settings (diagrameditor/defaultterminallabelling).
|
||||||
|
if (!m_project) {
|
||||||
|
m_terminal_label_gb = new QGroupBox(tr("Display of the terminal labelling", "group box title"));
|
||||||
|
m_terminal_label_combined_rb = new QRadioButton(
|
||||||
|
tr("Show the label and the terminal number in one field", "radio button label"));
|
||||||
|
m_terminal_label_combined_rb -> setToolTip(tr(
|
||||||
|
"A terminal's label (X1:1) is drawn as a whole, the way it has always been.",
|
||||||
|
"tooltip"));
|
||||||
|
m_terminal_label_split_rb = new QRadioButton(tr("Split the label and the terminal number",
|
||||||
|
"radio button label"));
|
||||||
|
m_terminal_label_split_rb -> setToolTip(tr(
|
||||||
|
"The label (X1) is drawn in one field and the terminal number (1) in another, "
|
||||||
|
"which a terminal symbol may place where it wants -- and hide when it must. "
|
||||||
|
"A symbol without such a field shows the two, one under the other.",
|
||||||
|
"tooltip"));
|
||||||
|
m_terminal_label_help = new QLabel(tr("Only the drawing changes: what is written in the element, "
|
||||||
|
"the numbering, the sorting and the exports keep the whole label.",
|
||||||
|
"informative label"));
|
||||||
|
m_terminal_label_help -> setWordWrap(true);
|
||||||
|
|
||||||
|
QVBoxLayout *terminal_label_layout = new QVBoxLayout(m_terminal_label_gb);
|
||||||
|
terminal_label_layout -> addWidget(m_terminal_label_combined_rb);
|
||||||
|
terminal_label_layout -> addWidget(m_terminal_label_split_rb);
|
||||||
|
terminal_label_layout -> addWidget(m_terminal_label_help);
|
||||||
|
|
||||||
|
if (settings.value(QStringLiteral("diagrameditor/defaultterminallabelling"), false).toBool()) {
|
||||||
|
m_terminal_label_split_rb -> setChecked(true);
|
||||||
|
} else {
|
||||||
|
m_terminal_label_combined_rb -> setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//If there is a project, we edit his properties
|
//If there is a project, we edit his properties
|
||||||
if (m_project) {
|
if (m_project) {
|
||||||
bpw -> setProperties (m_project -> defaultBorderProperties());
|
bpw -> setProperties (m_project -> defaultBorderProperties());
|
||||||
@@ -159,6 +196,11 @@ NewDiagramPage::NewDiagramPage(QETProject *project,
|
|||||||
|
|
||||||
diagram_layout -> addWidget(bpw);
|
diagram_layout -> addWidget(bpw);
|
||||||
diagram_layout -> addWidget(ipw);
|
diagram_layout -> addWidget(ipw);
|
||||||
|
//The default labelling of the terminals, application's defaults only
|
||||||
|
if (m_terminal_label_gb) {
|
||||||
|
diagram_layout -> addWidget(m_terminal_label_gb);
|
||||||
|
diagram_layout -> addStretch();
|
||||||
|
}
|
||||||
//A width only: a minimum height set by hand replaces the one the
|
//A width only: a minimum height set by hand replaces the one the
|
||||||
//tabs ask for, so on a low screen (1080p with display scaling,
|
//tabs ask for, so on a low screen (1080p with display scaling,
|
||||||
//#1562) the dialog's scroll area never scrolled and the tallest
|
//#1562) the dialog's scroll area never scrolled and the tallest
|
||||||
@@ -292,6 +334,13 @@ void NewDiagramPage::applyConf()
|
|||||||
}
|
}
|
||||||
settings.endArray();
|
settings.endArray();
|
||||||
|
|
||||||
|
// How a new project's terminals draw their label. Kept with the
|
||||||
|
// other defaults of a new project (the key starts with
|
||||||
|
// "diagrameditor/default", the prefix of that part of a
|
||||||
|
// configuration profile, see ConfigProfile::partOf())
|
||||||
|
settings.setValue(QStringLiteral("diagrameditor/defaultterminallabelling"),
|
||||||
|
m_terminal_label_split_rb -> isChecked());
|
||||||
|
|
||||||
// save global auto-numbering defaults
|
// save global auto-numbering defaults
|
||||||
//
|
//
|
||||||
// The cable rule is written here as well as by its own Apply
|
// The cable rule is written here as well as by its own Apply
|
||||||
|
|||||||
@@ -74,6 +74,14 @@ public slots:
|
|||||||
ReportPropertieWidget *rpw; ///< Widget to edit default report label
|
ReportPropertieWidget *rpw; ///< Widget to edit default report label
|
||||||
XRefPropertiesWidget *xrefpw; ///< Widget to edit default xref properties
|
XRefPropertiesWidget *xrefpw; ///< Widget to edit default xref properties
|
||||||
GuidesPropertiesWidget *m_gpw; ///< Widget to edit guides
|
GuidesPropertiesWidget *m_gpw; ///< Widget to edit guides
|
||||||
|
//How a new project's terminals draw their label, the application's
|
||||||
|
//default (Configure QElectroTech > New project). Per project it is
|
||||||
|
//a project property (project properties > General), so these are
|
||||||
|
//only built for the application's defaults, without a project.
|
||||||
|
QGroupBox *m_terminal_label_gb = nullptr;
|
||||||
|
QRadioButton *m_terminal_label_combined_rb = nullptr;
|
||||||
|
QRadioButton *m_terminal_label_split_rb = nullptr;
|
||||||
|
QLabel *m_terminal_label_help = nullptr;
|
||||||
TitleBlockProperties savedTbp; ///< Used to save current TBP and retrieve later
|
TitleBlockProperties savedTbp; ///< Used to save current TBP and retrieve later
|
||||||
QTabWidget *m_tab_widget; ///< Main tab widget (stored for later access)
|
QTabWidget *m_tab_widget; ///< Main tab widget (stored for later access)
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,15 @@
|
|||||||
#include "TerminalStrip/terminalstrip.h"
|
#include "TerminalStrip/terminalstrip.h"
|
||||||
#include "dataBase/ui/elementquerywidget.h"
|
#include "dataBase/ui/elementquerywidget.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
|
#include "ui/configpage/configpages.h"
|
||||||
#include "ui/elementinfopartwidget.h"
|
#include "ui/elementinfopartwidget.h"
|
||||||
#include "ui/elementinfowidget.h"
|
#include "ui/elementinfowidget.h"
|
||||||
#include "ui/multielementinfowidget.h"
|
#include "ui/multielementinfowidget.h"
|
||||||
|
#include <QGroupBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
|
#include <QRadioButton>
|
||||||
|
#include <QSettings>
|
||||||
#include "properties/elementdata.h"
|
#include "properties/elementdata.h"
|
||||||
#include "qetgraphicsitem/dynamicelementtextitem.h"
|
#include "qetgraphicsitem/dynamicelementtextitem.h"
|
||||||
#include "qetgraphicsitem/element.h"
|
#include "qetgraphicsitem/element.h"
|
||||||
@@ -481,6 +485,87 @@ private slots:
|
|||||||
QETInformation::translatedInfoKey(QETInformation::ELMT_TERMINAL_NUMBER)),
|
QETInformation::translatedInfoKey(QETInformation::ELMT_TERMINAL_NUMBER)),
|
||||||
"The terminal number is no property of the element");
|
"The terminal number is no property of the element");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//A new project starts with the labelling the settings chose for new
|
||||||
|
//projects (Configure QElectroTech > New project), and draws the whole
|
||||||
|
//label in one field when the settings say nothing
|
||||||
|
void newProjectStartsWithTheDefaultLabelling()
|
||||||
|
{
|
||||||
|
const QString key = QStringLiteral("diagrameditor/defaultterminallabelling");
|
||||||
|
|
||||||
|
QSettings().setValue(key, true);
|
||||||
|
{
|
||||||
|
QETProject fresh;
|
||||||
|
QVERIFY2(fresh.terminalLabelSplit(),
|
||||||
|
"A new project starts with the labelling the settings chose");
|
||||||
|
}
|
||||||
|
|
||||||
|
QSettings().setValue(key, false);
|
||||||
|
{
|
||||||
|
QETProject fresh;
|
||||||
|
QVERIFY(!fresh.terminalLabelSplit());
|
||||||
|
}
|
||||||
|
|
||||||
|
QSettings().remove(key);
|
||||||
|
{
|
||||||
|
QETProject fresh;
|
||||||
|
QVERIFY2(!fresh.terminalLabelSplit(),
|
||||||
|
"Without a setting in the settings, a new project draws as it always did");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//The default for new projects is offered in Configure QElectroTech >
|
||||||
|
//New project, as the same group box the project properties use, and
|
||||||
|
//saving the page keeps the choice for the next new project
|
||||||
|
void settingsOfferTheDefaultLabelling()
|
||||||
|
{
|
||||||
|
const QString key = QStringLiteral("diagrameditor/defaultterminallabelling");
|
||||||
|
QSettings().remove(key);
|
||||||
|
|
||||||
|
NewDiagramPage settings_page;
|
||||||
|
QGroupBox *group = nullptr;
|
||||||
|
const QList<QGroupBox *> groups = settings_page.findChildren<QGroupBox *>();
|
||||||
|
for (QGroupBox *gb : groups) {
|
||||||
|
if (gb->title() == QStringLiteral("Display of the terminal labelling")) group = gb;
|
||||||
|
}
|
||||||
|
QVERIFY2(group, "The settings for new projects offer the labelling");
|
||||||
|
|
||||||
|
const QList<QRadioButton *> radios = group->findChildren<QRadioButton *>();
|
||||||
|
QCOMPARE(radios.size(), 2);
|
||||||
|
QRadioButton *split = nullptr;
|
||||||
|
for (QRadioButton *rb : radios) {
|
||||||
|
if (rb->text() == QStringLiteral("Split the label and the terminal number")) split = rb;
|
||||||
|
}
|
||||||
|
QVERIFY2(split, "The same choice as in the project properties");
|
||||||
|
|
||||||
|
split->setChecked(true);
|
||||||
|
settings_page.applyConf();
|
||||||
|
QCOMPARE(QSettings().value(key).toBool(), true);
|
||||||
|
|
||||||
|
//And the next new project draws the way it was saved
|
||||||
|
QETProject fresh;
|
||||||
|
QVERIFY(fresh.terminalLabelSplit());
|
||||||
|
|
||||||
|
QSettings().remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
//The project keeps the one place to set it: its own properties (General
|
||||||
|
//page) are the only ones which change the drawing of a saved project,
|
||||||
|
//so the page of the new sheets does not offer the setting again
|
||||||
|
void projectSheetPageHasNoDefaultLabelling()
|
||||||
|
{
|
||||||
|
const QString fixture = QFINDTESTDATA("fixtures/every_feature.qet");
|
||||||
|
QETProject project(fixture);
|
||||||
|
QCOMPARE(project.state(), QETProject::Ok);
|
||||||
|
|
||||||
|
NewDiagramPage project_page(&project);
|
||||||
|
const QList<QGroupBox *> groups = project_page.findChildren<QGroupBox *>();
|
||||||
|
for (const QGroupBox *gb : groups) {
|
||||||
|
QVERIFY2(gb->title() != QStringLiteral("Display of the terminal labelling"),
|
||||||
|
"The labelling of a saved project is set in its own properties, "
|
||||||
|
"not in the defaults of its sheets");
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QET_APP_TEST_MAIN(tst_terminallabeldisplay)
|
QET_APP_TEST_MAIN(tst_terminallabeldisplay)
|
||||||
|
|||||||
Reference in New Issue
Block a user