mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-23 23:44:13 +02:00
Add a Show name box to the selection properties of a terminal
The box hides the name of the terminal on the sheet only: the element keeps all of its data, and with the labelling split the terminal keeps its number, drawn once - in its own field when the symbol has one, alone in the label field when it has not. Only a terminal may have its name undrawn: the box is shown for the element type Terminal alone, and Element::labelShown() obeys the stored information for a terminal only. The choice is stored as the element information "label_shown" = "false" and only that, so files of every element which still draws its name stay exactly as they are. Multi-selection: the flag appears for terminals only and counts an absent information as "shown", so a mixed selection shows the box ticked only when every terminal has it ticked. Includes four test cases: hidden name keeps the stored data, keeps the number without a number field, leaves the number to its own field, and a non-terminal draws its name whatever the file says.
This commit is contained in:
@@ -2769,7 +2769,28 @@ QString Element::actualLabel()
|
||||
QString Element::labelForDisplay()
|
||||
{
|
||||
const QString label = actualLabel();
|
||||
if (!QetSettings::terminalLabelSplit()) {
|
||||
const bool split = QetSettings::terminalLabelSplit();
|
||||
|
||||
//The "Show name" box of the selection properties hides the name
|
||||
//of this element on the sheet only: the element keeps all of its
|
||||
//data, and a terminal keeps its number, drawn on its own while
|
||||
//the labelling is split.
|
||||
if (!labelShown())
|
||||
{
|
||||
if (!split) {
|
||||
return QString();
|
||||
}
|
||||
//The number alone in the label field, but only while the
|
||||
//symbol has no field of its own for it: the number is
|
||||
//drawn once, wherever it is drawn at all.
|
||||
const int hidden_colon = label.lastIndexOf(QLatin1Char(':'));
|
||||
if (hidden_colon < 0 || hasTerminalNumberText()) {
|
||||
return QString();
|
||||
}
|
||||
return label.mid(hidden_colon + 1);
|
||||
}
|
||||
|
||||
if (!split) {
|
||||
return label;
|
||||
}
|
||||
|
||||
@@ -2837,6 +2858,29 @@ bool Element::hasTerminalNumberText() const
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::labelShown
|
||||
@return whether the label of this element must be drawn on the sheet.
|
||||
The choice belongs to the element itself, set with the "Show name"
|
||||
box of the selection properties: an element whose name is not shown
|
||||
keeps all of its data, nothing is only not drawn. An element which
|
||||
never got the box unticked keeps drawing its name, which is why a
|
||||
missing information means true.
|
||||
*/
|
||||
bool Element::labelShown() const
|
||||
{
|
||||
//Only a terminal may have its name undrawn: an information
|
||||
//which says otherwise, from whatever source, is not obeyed.
|
||||
if (m_data.m_type != ElementData::Terminal) {
|
||||
return true;
|
||||
}
|
||||
if (!m_data.m_informations.contains(QStringLiteral("label_shown"))) {
|
||||
return true;
|
||||
}
|
||||
return QET::infoFlagIsTrue(
|
||||
m_data.m_informations.value(QStringLiteral("label_shown")).toString());
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::infoForDisplay
|
||||
@return what a text field bound to @p info_name must show: the label
|
||||
|
||||
Reference in New Issue
Block a user