mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-23 23:44:13 +02:00
Draw a terminal's label and its number apart, when asked to
A terminal's label is written as it is read off the plan, "X1:1", and
the symbol draws it as one field. On a long strip that field is long
enough to reach into the next terminal, and a user who wants the number
next to the screw and the label out of the way has no way to say so.
Settings > General > Appearance now has a "Display of the terminal
labelling" group with two choices: the label and its terminal number in
one field, the way it has always been drawn, or the two split. The
first is what every drawing gets, so nothing moves until the user asks
for it, and choosing the other one redraws the drawings already open --
nothing needs to be closed and opened again.
A symbol made for the split carries a text field bound to the new
"Terminal number" information (in the element editor's list, next to
the label, and as the %{terminal_number} variable of a composite text):
the label field then shows "X1" and the number field "1", each placed
where the symbol wants it, and hideable when it must be. A symbol which
has no such field -- every symbol drawn until now -- gets the number on
its own line inside the label field, so switching the setting on can
never make a number vanish, and never needs a symbol to be touched
first. A field which becomes, or stops being, the number field tells
the label fields of its symbol to draw themselves again.
Only the drawing reacts. What the element stores, the numbering, the
sorting in the terminal strip editor, the automatic strip import and
every export keep the whole label: the split is read where the text is
drawn (Element::labelForDisplay() and friends), not where the label is
made.
The new test covers both choices, with and without the number field, a
label with no colon at all, and the way back to the whole label. The
full test suite passes (124/124).
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include "../properties/terminaldata.h"
|
||||
#include "../properties/xrefproperties.h"
|
||||
#include "../qetinformation.h"
|
||||
#include "../utils/qetsettings.h"
|
||||
#include "../qetgraphicsitem/conductor.h"
|
||||
#include "../qetgraphicsitem/terminal.h"
|
||||
#include "../ui/elementpropertieswidget.h"
|
||||
@@ -1689,6 +1690,13 @@ void Element::addDynamicTextItem(DynamicElementTextItem *deti)
|
||||
|
||||
m_dynamic_text_list.append(deti);
|
||||
|
||||
//A field of its own for the terminal number is what the label
|
||||
//leaves the number to: the fields which draw the label follow
|
||||
//when such a field lands on the symbol
|
||||
if (deti->infoName() == QETInformation::ELMT_TERMINAL_NUMBER) {
|
||||
refreshLabelFields();
|
||||
}
|
||||
|
||||
//On a mirrored element, the mirror of the text depends on the size
|
||||
//and the rotation of the text, see keepReadable()
|
||||
connect(deti->document()->documentLayout(),
|
||||
@@ -1724,6 +1732,9 @@ void Element::removeDynamicTextItem(DynamicElementTextItem *deti)
|
||||
m_dynamic_text_list.removeOne(deti);
|
||||
deti->setParentItem(nullptr);
|
||||
forget();
|
||||
if (deti->infoName() == QETInformation::ELMT_TERMINAL_NUMBER) {
|
||||
refreshLabelFields();
|
||||
}
|
||||
emit textRemoved(deti);
|
||||
return;
|
||||
}
|
||||
@@ -1736,12 +1747,36 @@ void Element::removeDynamicTextItem(DynamicElementTextItem *deti)
|
||||
m_dynamic_text_list.removeOne(deti);
|
||||
deti->setParentItem(nullptr);
|
||||
forget();
|
||||
if (deti->infoName() == QETInformation::ELMT_TERMINAL_NUMBER) {
|
||||
refreshLabelFields();
|
||||
}
|
||||
emit textRemoved(deti);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::refreshLabelFields
|
||||
The fields which draw the label draw it again: what they show of the
|
||||
label has changed under them (a field for the terminal number added
|
||||
or removed, @sa Element::hasTerminalNumberText), or the terminal
|
||||
labelling setting was switched (@sa QetSettings::terminalLabelSplit).
|
||||
Only the fields which draw a label are refreshed, every other field
|
||||
follows its own information.
|
||||
*/
|
||||
void Element::refreshLabelFields()
|
||||
{
|
||||
for (DynamicElementTextItem *text : m_dynamic_text_list) {
|
||||
text->refreshLabelConnection();
|
||||
}
|
||||
for (ElementTextItemGroup *group : m_texts_group) {
|
||||
for (DynamicElementTextItem *text : group->texts()) {
|
||||
text->refreshLabelConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::dynamicTextItems
|
||||
@return all dynamic text items of this element directly child of this element.
|
||||
@@ -2721,6 +2756,105 @@ QString Element::actualLabel()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::labelForDisplay
|
||||
@return the label as the drawing must show it, the settings of the
|
||||
moment being read (@sa QetSettings::terminalLabelSplit): the whole
|
||||
label ("X1:1") while the labelling is shown in one field; the label
|
||||
alone ("X1") when it is shown split and this symbol has a text field
|
||||
of its own for the terminal number; and the two one under the other
|
||||
when it is split without such a field -- so a symbol drawn before
|
||||
the setting existed still shows all of its label, only shorter.
|
||||
*/
|
||||
QString Element::labelForDisplay()
|
||||
{
|
||||
const QString label = actualLabel();
|
||||
if (!QetSettings::terminalLabelSplit()) {
|
||||
return label;
|
||||
}
|
||||
|
||||
const int colon = label.lastIndexOf(QLatin1Char(':'));
|
||||
if (colon < 0) {
|
||||
return label;
|
||||
}
|
||||
|
||||
if (hasTerminalNumberText()) {
|
||||
return label.left(colon);
|
||||
}
|
||||
|
||||
return label.left(colon) + QLatin1Char('\n') + label.mid(colon + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::terminalNumberForDisplay
|
||||
@return the part of the label behind its last colon ("1" in "X1:1"),
|
||||
or an empty string while the labelling is shown in one field: the
|
||||
number is already there with the label, showing it twice would only
|
||||
be noise. @sa labelForDisplay
|
||||
*/
|
||||
QString Element::terminalNumberForDisplay()
|
||||
{
|
||||
if (!QetSettings::terminalLabelSplit()) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
const QString label = actualLabel();
|
||||
const int colon = label.lastIndexOf(QLatin1Char(':'));
|
||||
if (colon < 0) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
return label.mid(colon + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::hasTerminalNumberText
|
||||
@return whether this symbol has a text field bound to the terminal
|
||||
number, the field labelForDisplay() leaves the number to.
|
||||
*/
|
||||
bool Element::hasTerminalNumberText() const
|
||||
{
|
||||
auto is_number_field = [](const DynamicElementTextItem *text) {
|
||||
return text
|
||||
&& text->textFrom() == DynamicElementTextItem::ElementInfo
|
||||
&& text->infoName() == QETInformation::ELMT_TERMINAL_NUMBER;
|
||||
};
|
||||
|
||||
for (const DynamicElementTextItem *text : dynamicTextItems()) {
|
||||
if (is_number_field(text)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//The field may just as well live in a text group of the symbol
|
||||
for (const ElementTextItemGroup *group : m_texts_group) {
|
||||
for (const DynamicElementTextItem *text : group->texts()) {
|
||||
if (is_number_field(text)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::infoForDisplay
|
||||
@return what a text field bound to @p info_name must show: the label
|
||||
and the terminal number follow how the labelling is drawn, every
|
||||
other information is the stored one. @sa labelForDisplay
|
||||
*/
|
||||
QString Element::infoForDisplay(const QString &info_name)
|
||||
{
|
||||
if (info_name == QETInformation::ELMT_LABEL) {
|
||||
return labelForDisplay();
|
||||
}
|
||||
if (info_name == QETInformation::ELMT_TERMINAL_NUMBER) {
|
||||
return terminalNumberForDisplay();
|
||||
}
|
||||
|
||||
return m_data.m_informations.value(info_name).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::name
|
||||
@return the human name of this element
|
||||
|
||||
Reference in New Issue
Block a user