QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
terminalstripmodel.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 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
32inline uint qHash(const QColor &key, uint seed) {
33 return qHash(key.name(), seed);
34}
35
36//needed to use QPointer<Element> as key of QHash
37inline uint qHash(const QPointer<Element> &key, uint seed) {
38 if (key)
39 return qHash(key->uuid(), seed);
40 else
41 return qHash(QUuid(), seed);
42}
43
44class TerminalStrip;
45
46class TerminalStripModel : public QAbstractTableModel
47{
48 public:
49 enum Column {
50 Pos = 0,
51 Level = 1,
52 Level0 = 2,
53 Level1 = 3,
54 Level2 = 4,
55 Level3 = 5,
56 Label = 6,
58 XRef = 8,
59 Cable = 9,
61 Type = 11,
63 Led = 13,
64 Invalid = 99
65 };
66
68 static TerminalStripModel::Column columnTypeForIndex(const QModelIndex &index);
69
70 Q_OBJECT
71 public:
72 TerminalStripModel(TerminalStrip *terminal_strip, QObject *parent = nullptr);
73 void setTerminalStrip(TerminalStrip *terminal_strip);
74
75 virtual int rowCount (const QModelIndex &parent = QModelIndex()) const override;
76 virtual int columnCount (const QModelIndex &parent = QModelIndex()) const override;
77 virtual QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
78 virtual bool setData (const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
79 virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
80 virtual Qt::ItemFlags flags (const QModelIndex &index) const override;
81 QVector<modelRealTerminalData> modifiedmodelRealTerminalData() const;
82
83 QVector<modelPhysicalTerminalData> modelPhysicalTerminalDataForIndex(QModelIndexList index_list) const;
84 QVector<modelRealTerminalData> modelRealTerminalDataForIndex(QModelIndexList index_list) const;
85 modelRealTerminalData modelRealTerminalDataForIndex(const QModelIndex &index) const;
86
87 void buildBridgePixmap(const QSize &pixmap_size);
88
89 void reload();
90
91 private:
93 modelRealTerminalData dataAtRow(int row) const;
97 QPixmap bridgePixmapFor(const QModelIndex &index) const;
98
99 private:
100 QPointer<TerminalStrip> m_terminal_strip;
101 QHash<QPointer<Element>, QVector<bool>> m_modified_cell;
102 QVector<modelPhysicalTerminalData> m_physical_data;
104 {
105 QPixmap top_,
109 };
110
111 QHash<QColor, BridgePixmap> m_bridges_pixmaps;
112
113};
114
115class TerminalStripModelDelegate : public QStyledItemDelegate
116{
117 Q_OBJECT
118
119 public:
120 TerminalStripModelDelegate(QObject *parent = Q_NULLPTR);
121
122 QWidget *createEditor(
123 QWidget *parent,
124 const QStyleOptionViewItem &option,
125 const QModelIndex &index) const override;
126 void setModelData(
127 QWidget *editor,
128 QAbstractItemModel *model,
129 const QModelIndex &index) const override;
130
131 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
132};
133
134#endif // TERMINALSTRIPMODEL_H
Definition conductor.h:43
The TerminalStrip class This class hold all the datas and configurations of a terminal strip (but the...
Definition terminalstrip.h:45
Definition terminalstripmodel.h:116
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
Definition terminalstripmodel.h:47
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:101
modelRealTerminalData realDataAtIndex(int index) const
TerminalStripModel::realDataAtIndex.
Definition terminalstripmodel.cpp:632
QVector< modelPhysicalTerminalData > m_physical_data
Definition terminalstripmodel.h:102
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
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:100
QHash< QColor, BridgePixmap > m_bridges_pixmaps
Definition terminalstripmodel.h:111
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:49
@ Level3
Definition terminalstripmodel.h:55
@ Pos
Definition terminalstripmodel.h:50
@ Level2
Definition terminalstripmodel.h:54
@ Cable
Definition terminalstripmodel.h:59
@ Label
Definition terminalstripmodel.h:56
@ Invalid
Definition terminalstripmodel.h:64
@ Type
Definition terminalstripmodel.h:61
@ CableWire
Definition terminalstripmodel.h:60
@ Level0
Definition terminalstripmodel.h:52
@ Function
Definition terminalstripmodel.h:62
@ Level
Definition terminalstripmodel.h:51
@ XRef
Definition terminalstripmodel.h:58
@ Led
Definition terminalstripmodel.h:63
@ Level1
Definition terminalstripmodel.h:53
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:104
QPixmap bottom_
Definition terminalstripmodel.h:107
QPixmap top_
Definition terminalstripmodel.h:105
QPixmap none_
Definition terminalstripmodel.h:108
QPixmap middle_
Definition terminalstripmodel.h:106
Definition modelTerminalData.h:66
Definition modelTerminalData.h:26
uint qHash(const QColor &key, uint seed)
Definition terminalstripmodel.h:32