Files
qelectrotech-source-mirror/sources/cablelist/cablelistmodel.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

108 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 CABLELISTMODEL_H
#define CABLELISTMODEL_H
#include <QAbstractTableModel>
#include <QDomElement>
#include <QHash>
#include <QList>
#include <QMap>
#include <QPointer>
#include <QStringList>
#include <QVector>
class Cable;
class Diagram;
class Element;
class QETProject;
/**
@brief The CableListModel class
The rows of a cable list, shown by QetGraphicsTableItem the way the
project database model shows a nomenclature -- and shaped after it
on purpose: same roles, same header behaviour, same way of saving
itself to the project file, so that the table on the sheet treats
this model exactly like any other.
Whereas ProjectDBModel asks the project database, this model asks
CableList::rows(), straight from the cables of the project. It
refreshes itself whenever anything those rows are worked out from
changes: a cable edited, a cable added or removed, a folio added,
removed or re-informed (its title block carries the installation and
the place), a label typed over on a piece a cable lands on.
*/
class CableListModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit CableListModel(QETProject *project, QObject *parent = nullptr);
CableListModel(const CableListModel &other_model);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
bool setHeaderData(int section,
Qt::Orientation orientation,
const QVariant &value,
int role = Qt::EditRole) override;
QVariant headerData(int section,
Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index,
const QVariant &value,
int role = Qt::EditRole) override;
QVariant data(const QModelIndex &index,
int role = Qt::DisplayRole) const override;
/// The columns this table shows, in order: keys of CableList
void setFields(const QStringList &fields);
QStringList fields() const {return m_fields;}
/// The same, joined the way the project file stores it
QString queryString() const;
void setIdentifier(const QString &identifier) {m_identifier = identifier;}
QString identifier() const {return m_identifier;}
QETProject *project() const;
QDomElement toXml(QDomDocument &document) const;
void fromXml(const QDomElement &element);
static QString xmlTagName() {return QStringLiteral("cable_list_model");}
public slots:
/// Work the rows out again and tell whoever shows them
void refresh();
private:
/// Watch everything the rows are worked out from
void connectProject();
QPointer<QETProject> m_project;
QStringList m_fields;
QVector<QMap<QString, QString>> m_rows;
//First int = section, second int = Qt::role, QVariant = value
QHash<int, QHash<int, QVariant>> m_header_data;
QHash<int, QVariant> m_index_0_0_data;
QString m_identifier = QStringLiteral("cable_list");
/// The current watchers of this model, dropped and taken
/// again on every refresh
QList<QMetaObject::Connection> m_watchers;
};
#endif // CABLELISTMODEL_H