QElectroTech 0.200.1-dev
Loading...
Searching...
No Matches
terminalstripmodel.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2026 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef TERMINALSTRIPMODEL_H
19#define TERMINALSTRIPMODEL_H
20
21#include <QAbstractTableModel>
22#include <QObject>
23#include <QPointer>
24#include <QStyledItemDelegate>
25#include <QHash>
26#include <QColor>
27
28#include "../terminalstrip.h"
29#include "modelTerminalData.h"
30
31//Code to use QColor as key for QHash
32#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
33inline size_t qHash(const QColor &key, size_t seed = 0) {
34 return qHash(key.rgba(), seed);
35}
36#else
37inline uint qHash(const QColor &key, uint seed) {
38 return qHash(key.rgba(), seed);
39}
40#endif
41
42//needed to use QPointer<Element> as key of QHash
43inline uint qHash(const QPointer<Element> &key, uint seed) {
44 if (key)
45 return qHash(key->uuid(), seed);
46 else
47 return qHash(QUuid(), seed);
48}
49
50class TerminalStrip;
51
52class TerminalStripModel : public QAbstractTableModel
53{
54 public:
55 enum Column {
56 Pos = 0,
57 Level = 1,
58 Level0 = 2,
59 Level1 = 3,
60 Level2 = 4,
61 Level3 = 5,
62 Label = 6,
64 XRef = 8,
65 Cable = 9,
67 Type = 11,
69 Led = 13,
71 };
72
74 static TerminalStripModel::Column columnTypeForIndex(const QModelIndex &index);
75
76 Q_OBJECT
77 public:
78 TerminalStripModel(TerminalStrip *terminal_strip, QObject *parent = nullptr);
79 void setTerminalStrip(TerminalStrip *terminal_strip);
80
81 virtual int rowCount (const QModelIndex &parent = QModelIndex()) const override;
82 virtual int columnCount (const QModelIndex &parent = QModelIndex()) const override;
83 virtual QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
84 virtual bool setData (const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
85 virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
86 virtual Qt::ItemFlags flags (const QModelIndex &index) const override;
87 QVector<modelRealTerminalData> modifiedmodelRealTerminalData() const;
88
89 QVector<modelPhysicalTerminalData> modelPhysicalTerminalDataForIndex(QModelIndexList index_list) const;
90 QVector<modelRealTerminalData> modelRealTerminalDataForIndex(QModelIndexList index_list) const;
91 modelRealTerminalData modelRealTerminalDataForIndex(const QModelIndex &index) const;
92
93 void buildBridgePixmap(const QSize &pixmap_size);
94
95 void reload();
96
97 private:
99 modelRealTerminalData dataAtRow(int row) const;
102 modelRealTerminalData realDataAtIndex(int index) const;
103 QPixmap bridgePixmapFor(const QModelIndex &index) const;
104
105 private:
106 QPointer<TerminalStrip> m_terminal_strip;
107 QHash<QPointer<Element>, QVector<bool>> m_modified_cell;
108 QVector<modelPhysicalTerminalData> m_physical_data;
110 {
111 QPixmap top_,
115 };
116
117 QHash<QColor, BridgePixmap> m_bridges_pixmaps;
118
119};
120
121class TerminalStripModelDelegate : public QStyledItemDelegate
122{
123 Q_OBJECT
124
125 public:
126 TerminalStripModelDelegate(QObject *parent = Q_NULLPTR);
127
128 QWidget *createEditor(
129 QWidget *parent,
130 const QStyleOptionViewItem &option,
131 const QModelIndex &index) const override;
132 void setModelData(
133 QWidget *editor,
134 QAbstractItemModel *model,
135 const QModelIndex &index) const override;
136
137 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
138};
139
140#endif // TERMINALSTRIPMODEL_H
The TerminalStrip class This class hold all the datas and configurations of a terminal strip (but the...
Definition terminalstrip.h:45
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
TerminalStripModelDelegate::paint By default on a QTableView, Qt draw pixmap in cell with a little ma...
Definition terminalstripmodel.cpp:849
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Definition terminalstripmodel.cpp:819
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition terminalstripmodel.cpp:793
TerminalStripModelDelegate(QObject *parent=Q_NULLPTR)
Definition terminalstripmodel.cpp:789
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition terminalstripmodel.cpp:152
QHash< QPointer< Element >, QVector< bool > > m_modified_cell
Definition terminalstripmodel.h:107
modelRealTerminalData realDataAtIndex(int index) const
TerminalStripModel::realDataAtIndex.
Definition terminalstripmodel.cpp:632
QVector< modelPhysicalTerminalData > m_physical_data
Definition terminalstripmodel.h:108
static TerminalStripModel::Column columnTypeForIndex(const QModelIndex &index)
TerminalStripModel::columnTypeForIndex.
Definition terminalstripmodel.cpp:77
void setTerminalStrip(TerminalStrip *terminal_strip)
TerminalStripModel::setTerminalStrip set the current terminal strip of this model to terminal_strip.
Definition terminalstripmodel.cpp:124
static int levelForColumn(TerminalStripModel::Column column)
TerminalStripModel::levelForColumn Return the terminal level for column column or -1 if column is not...
Definition terminalstripmodel.cpp:61
TerminalStripModel(TerminalStrip *terminal_strip, QObject *parent=nullptr)
TerminalStripModel::TerminalStripModel.
Definition terminalstripmodel.cpp:107
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition terminalstripmodel.cpp:209
QPixmap bridgePixmapFor(const QModelIndex &index) const
Definition terminalstripmodel.cpp:653
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition terminalstripmodel.cpp:146
QVector< modelPhysicalTerminalData > modelPhysicalTerminalDataForIndex(QModelIndexList index_list) const
TerminalStripModel::terminalsForIndex.
Definition terminalstripmodel.cpp:350
QVector< modelRealTerminalData > modelRealTerminalDataForIndex(QModelIndexList index_list) const
TerminalStripModel::realTerminalDataForIndex.
Definition terminalstripmodel.cpp:382
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition terminalstripmodel.cpp:130
QPointer< TerminalStrip > m_terminal_strip
Definition terminalstripmodel.h:106
QHash< QColor, BridgePixmap > m_bridges_pixmaps
Definition terminalstripmodel.h:117
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition terminalstripmodel.cpp:276
modelPhysicalTerminalData physicalDataAtIndex(int index) const
TerminalStripModel::physicalDataAtIndex.
Definition terminalstripmodel.cpp:599
void replaceDataAtRow(modelRealTerminalData data, int row)
TerminalStripModel::replaceDataAtRow Replace the data at row row by data.
Definition terminalstripmodel.cpp:560
Column
Definition terminalstripmodel.h:55
@ Level3
Definition terminalstripmodel.h:61
@ Pos
Definition terminalstripmodel.h:56
@ Level2
Definition terminalstripmodel.h:60
@ Cable
Definition terminalstripmodel.h:65
@ Label
Definition terminalstripmodel.h:62
@ Invalid
Definition terminalstripmodel.h:70
@ Type
Definition terminalstripmodel.h:67
@ CableWire
Definition terminalstripmodel.h:66
@ Conductor
Definition terminalstripmodel.h:63
@ Level0
Definition terminalstripmodel.h:58
@ Function
Definition terminalstripmodel.h:68
@ Level
Definition terminalstripmodel.h:57
@ XRef
Definition terminalstripmodel.h:64
@ Led
Definition terminalstripmodel.h:69
@ Level1
Definition terminalstripmodel.h:59
void reload()
TerminalStripModel::reload Reload (reset) the model.
Definition terminalstripmodel.cpp:497
void fillPhysicalTerminalData()
Definition terminalstripmodel.cpp:506
void buildBridgePixmap(const QSize &pixmap_size)
TerminalStripModel::buildBridgePixmap Build the pixmap of bridge. You should call this method when yo...
Definition terminalstripmodel.cpp:428
QVector< modelRealTerminalData > modifiedmodelRealTerminalData() const
TerminalStripModel::modifiedRealTerminalData.
Definition terminalstripmodel.cpp:322
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
Definition terminalstripmodel.cpp:305
modelRealTerminalData dataAtRow(int row) const
Definition terminalstripmodel.cpp:530
Definition terminalstripmodel.h:110
QPixmap bottom_
Definition terminalstripmodel.h:113
QPixmap top_
Definition terminalstripmodel.h:111
QPixmap none_
Definition terminalstripmodel.h:114
QPixmap middle_
Definition terminalstripmodel.h:112
Definition modelTerminalData.h:66
Definition modelTerminalData.h:26
size_t qHash(const QColor &key, size_t seed=0)
Definition terminalstripmodel.h:33