Files
qelectrotech-source-mirror/sources/cablelist/cablelistrows.h
T
Kellermorph bf9b34398d Add cable management: drawing, cores, numbering, cross-references and cable list
Cables are drawn line objects (toolbar button next to the auto
break/reconnect button, click-move-click, right click cancels), not
components. The type comes from a CSV catalog following the material
list pattern (designation, cores, core colours, editable through the
entry dialog with "Nouvelle entrée" / "Modifier l'entrée").

Each core is bound to the wire its colour label stands on, and the
cable reference is generated per core and written into the Conductor
entry via Conductor::setCableReference(label, cable uuid, slot). The
conductor entry is where it has to live because the terminal strip
plan (Klemmenplan) consumes it in the next step.

Numbering: "Cables" rule under Programmeinstellungen/Neues
Projekt/Nummerierung auto (mirrored in project properties), literal
"W" fallback without a rule, French gate dialog when no rule exists,
Nummerierung menu with the renumber dialog (preferred axis, per-folio
counter, rule and counter state written back, hand-typed names ask,
whole-project scope).

Also included: label block and under-line texts with per-text font and
alignment plus the material-list cell margins, free-core placement and
right-click removal, claim questions for wires of other cables,
multi-selection drag as one undo step, type change with confirmation,
cross-references for type "Cable" (%f-%l%c, own font, clickable links
in exported PDFs), report propagation of the cable definition,
Listes menu (table of contents, material list, terminal strip manager,
terminal generator plugin, cable list), cable list with freely
selectable columns (installation/localisation of cable, start and end,
Blatt start/end, length, used cores...), CSV export dialog with column
pick and preview in the Projekt menu, script API (addTable kind
"cable_list", exportCableList) and a unit test for the type catalog.
2026-10-08 15:56:00 +02:00

102 lines
3.7 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 3 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 CABLELISTROWS_H
#define CABLELISTROWS_H
#include <QByteArray>
#include <QCoreApplication>
#include <QMap>
#include <QString>
#include <QStringList>
#include <QVector>
class QETProject;
/**
@brief The CableList class
The columns and the rows of the cable list (menu "Listes": the entry
which puts such a table on a sheet, and the CSV export which writes
the same table to a file).
Everything which decides what a cable list row says lives here, so
that the table drawn on the sheet and the exported CSV can never
disagree: one row per cable, worked out once and read twice.
The two ends of a cable are worked out the way the user asked for
it:
- wherever the cores of the cable land on a real piece (a terminal
strip, a device) is an end. Several cores landing on the same
piece are one end. A core which ends on a folio report is not an
end at all -- the cable goes on over there, and the landing on the
far sheet is the end instead, which is what makes a cable running
over several sheets show its start on the earlier sheet and its
target on the later one;
- ends are ordered by sheet first (the earlier sheet wins), then by
height in the plan (the higher one wins), then left to right;
the first end is the start, the last one the target;
- a cable whose cores never landed anywhere (not drawn yet, or only
wired in the middle) falls back to the two free ends of its drawn
line; when there is only one landing, the other side falls back to
the line end farthest away from it.
*/
class CableList
{
Q_DECLARE_TR_FUNCTIONS(CableList)
public:
struct Column
{
/// The name the row hash, the saved file and the CSV use
QString key;
/// What the header over the column says
QString label;
};
/// Every column the list can offer, in the order they are
/// offered and exported
static const QList<Column> &allColumns();
/// The columns a fresh list starts with: all of them but the
/// ones marked optional above
static const QStringList &defaultKeys();
/// The header text of one column, empty when the key is not
/// a column of this list
static QString labelOf(const QString &key);
/// One row per cable, sorted: first by the sheet its start
/// lies on, then from the top of that sheet down, the number
/// column filled in along the way
static QVector<QMap<QString, QString>> rows(QETProject *project);
/// The whole list as CSV bytes, in the format every CSV
/// export of this program writes (UTF-8 BOM, ';', every
/// field quoted): every column, every cable, the line of
/// column names included
static QByteArray toCsv(QETProject *project);
/// The same, but only the given columns, in the given
/// order, and only with the line of column names when asked
/// for -- what the export dialog writes. Unknown keys are
/// dropped, and no usable key at all falls back to the
/// default columns
static QByteArray toCsv(QETProject *project, const QStringList &keys,
bool include_headers);
};
#endif // CABLELISTROWS_H