Files
qelectrotech-source-mirror/sources/TerminalStrip/ui/modelTerminalData.h
T
Kellermorph dc92a57873 Add a Target column to the terminal strip editor
Reading where a cable lands meant going back to the drawing: the strip
editor said which cable a terminal carries and which core, but never
what the cable goes to. A single core (1x16) could not be followed
from the terminal to its piece at all.

The new Target column names it: Installation, Location and Label (BMK)
of the piece the wires land on, past this strip, joined in one line --
the very three fields the strip drawing writes in the box under its
cable, in the same order (RealTerminal::cableTarget()). It is worked
out of the project like the Cable cells and so follows their rule: a
target the drawing names is read only, for only the drawing decides
it, and a cell nothing is worked out for takes an edit, so a target
the drawing cannot find -- a cable landing on a piece with no
Installation, Location nor Label set, a cable going to another strip
-- is still worth naming by hand. The text typed in is stored in the
element (RealTerminal::cableTargetInfoKey()) and kept until a cable
works a target out again, and back once that cable goes, exactly like
a cable designation typed by hand: the automatic value is never
written, so no stale text can be left behind. The column takes the
width of its own text, so a long Installation is never cut off.

A text typed in is written the way the fields are shown in the column,
"Installation / Location / Label", and gives one line per field: the
box under the cable draws three lines without any slash in them, just
like a target worked out from the project, instead of one long line
carrying its separators as text.

tst_terminalcableauto checks the column is empty -- and editable --
without a cable, reads "Plant 7 / Cabinet 7 / -S7" with one, goes
empty -- and editable again -- when the core is removed, takes no edit
while the drawing names the target, and is headed "Target"; a second
case checks a target typed in by hand is taken by the cell, stored by
Apply, shown again by a fresh model, set aside for the read only
target of the drawing once a cable lands somewhere worth naming, and
back once that cable goes; a third one the line per field. tst_cable
target paints a strip whose cable ends on one field and the same strip
ending on three, the second box two lines deeper than the first.
2026-10-20 15:34:59 +02:00

122 lines
4.2 KiB
C

/*
Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MODELTERMINALDATA_H
#define MODELTERMINALDATA_H
#include <QColor>
#include <QString>
#include <QStringList>
#include "../../qetgraphicsitem/element.h"
#include "../realterminal.h"
struct modelRealTerminalData
{
///The Installation, Location and Label (BMK) of the piece the cable
///lands on, joined in one line : what the strip draws in the box
///under its cable (RealTerminal::cableTarget), in the same order.
///A target typed in by hand is one single line, and nothing is
///shown when the cable lands on nothing worth naming and no text
///was ever written in.
static QString targetText(const QVector<QString> &target_)
{
QStringList fields_;
for (const QString &field_ : target_)
{
if (!field_.isEmpty()) {
fields_ << field_;
}
}
return fields_.join(QStringLiteral(" / "));
}
static modelRealTerminalData data(const QSharedPointer<RealTerminal> &real_t)
{
modelRealTerminalData mrtd;
if (!real_t.isNull())
{
mrtd.level_ = real_t->level();
mrtd.label_ = real_t->label();
mrtd.Xref_ = real_t->Xref();
mrtd.cable_ = real_t->cable();
mrtd.cable_wire = real_t->cableWire();
mrtd.cable_target_ = targetText(real_t->cableTarget());
mrtd.cable_target_auto_ = real_t->cableTargetIsAutomatic();
mrtd.cable_auto_ = real_t->cableIsAutomatic();
mrtd.conductor_ = real_t->conductor();
mrtd.led_ = real_t->isLed();
mrtd.shield_ = real_t->isShield();
mrtd.separator_ = real_t->hasSeparatorAfter();
mrtd.color_ = real_t->color();
mrtd.stripe_color_ = real_t->stripeColor();
mrtd.section_ = real_t->section();
mrtd.width_mm_ = real_t->widthMm();
mrtd.catalog_entry_ = real_t->catalogEntry();
mrtd.type_ = real_t->type();
mrtd.function_ = real_t->function();
mrtd.element_ = real_t->element();
mrtd.real_terminal = real_t.toWeakRef();
mrtd.bridged_ = real_t->isBridged();
mrtd.spare_ = real_t->isSpare();
}
return mrtd;
}
int level_ = -1;
QString label_;
QString Xref_;
QString cable_;
QString cable_wire;
//Where the cable lands, past this strip : Installation / Location / Label
QString cable_target_;
//True when cable_target_ comes from the project (read only),
//false when it is empty or was typed in by hand (editable)
bool cable_target_auto_ = false;
bool cable_auto_ = false; //True when cable_ and cable_wire come from the cables of the project
QString conductor_;
bool led_ = false;
bool shield_ = false;
bool separator_ = false; //A separator plate is mounted after the terminal
QColor color_; //Invalid = no color set by the user
QColor stripe_color_; //Second color of a two-tone color, invalid if plain
qreal section_ = 0; //In mm2, 0 = no section set by the user
qreal width_mm_ = 0; //In mm, 0 = no width set by the user
QString catalog_entry_; //Terminal chosen in the catalog, empty if the width was typed
bool bridged_ = false;
bool spare_ = false; //Spare terminal, on no folio (RealTerminal::isSpare())
ElementData::TerminalType type_ = ElementData::TerminalType::TTGeneric;
ElementData::TerminalFunction function_ = ElementData::TerminalFunction::TFGeneric;
QPointer<Element> element_;
QWeakPointer<RealTerminal> real_terminal;
};
struct modelPhysicalTerminalData
{
QVector<modelRealTerminalData> real_data;
int pos_ = -1;
QUuid uuid_;
};
inline bool operator == (const modelPhysicalTerminalData &data_1, const modelPhysicalTerminalData &data_2) {
return data_1.uuid_ == data_2.uuid_;
}
#endif // MODELTERMINALDATA_H