QtPdCom  1.5.2
TableModel.h
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * Copyright (C) 2012-2022 Florian Pose <fp@igh.de>
4 * 2013 Dr. Wilhelm Hagemeister <hm@igh-essen.com>
5 *
6 * This file is part of the QtPdCom library.
7 *
8 * The QtPdCom library is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * The QtPdCom library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 * License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with the QtPdCom Library. If not, see <http://www.gnu.org/licenses/>.
20 *
21 ****************************************************************************/
22
23#ifndef QTPDCOM_TABLEMODEL_H
24#define QTPDCOM_TABLEMODEL_H
25
26#include "TableColumn.h"
27#include "ScalarVariable.h"
28
29#include <memory>
30#include <QAbstractTableModel>
31#include <QColor>
32#include <QLocale>
33
34namespace QtPdCom {
35
36/****************************************************************************/
37
42class QTPDCOM_PUBLIC TableModel: public QAbstractTableModel
43{
44 Q_OBJECT
45 Q_PROPERTY(bool editing READ isEditing NOTIFY editingChanged)
46
47 public:
48 TableModel(QObject *parent = nullptr);
50
51 void addColumn(TableColumn *);
52 void insertColumn(TableColumn *, int position);
54 void clearColumns();
55
56 bool isEditing() const;
57 unsigned int getRowCapacity() const;
58 bool hasVisibleRowsVariable() const;
59 virtual int rowCount(const QModelIndex &) const;
60 virtual int columnCount(const QModelIndex &) const;
61 virtual QVariant data(const QModelIndex &, int) const;
62 virtual QVariant headerData(int, Qt::Orientation, int) const;
63 virtual Qt::ItemFlags flags(const QModelIndex &) const;
64 virtual bool setData(const QModelIndex &, const QVariant &, int);
65
66 bool insertRows(
67 int position,
68 int count = 1,
69 const QModelIndex &parent = {}) override;
70 bool removeRows(
71 int row,
72 int count,
73 const QModelIndex &parent = {}) override;
74
78 void setHighlightRowVariable(
79 PdCom::Variable,
80 const PdCom::Selector & = {},
81 const Transmission & =
83 );
87 void setHighlightRowVariable(
88 PdCom::Process *,
89 const QString &,
90 const PdCom::Selector & = {},
91 const Transmission & =
93 );
94
95 void clearHighlightRowVariable();
96
104 Q_INVOKABLE QString toCsv(
105 bool includeHeader,
106 QChar seperator = QChar(','),
107 const QLocale &locale = QLocale::c()) const;
120 Q_INVOKABLE int fromCsv(
121 QString csvData,
122 QChar seperator = QChar(','),
123 int startRow = 0,
124 int startColumn = 0,
125 const QLocale &locale = QLocale::c());
126
131 void setVisibleRowsVariable(
132 PdCom::Variable pv,
133 const PdCom::Selector & = {},
134 const Transmission & =
136 );
137
142 void setVisibleRowsVariable(
143 PdCom::Process *,
144 const QString &,
145 const PdCom::Selector & = {},
146 const Transmission & =
148 );
149
150 void clearVisibleRowsVariable();
151
152 void setHighlightColor(QColor, int = -1);
153 void setDisabledColor(QColor, int = -1);
154
158 {
161 Exception(const QString &msg):
162 msg(msg)
163 {}
164 QString msg;
165 };
166
167 QHash<int, QByteArray> roleNames() const override; //rolenames in TableColumn!
168
169 signals:
170 void editingChanged(bool);
171
172 public slots:
173 void commit();
174 void revert(); // virtual from AbstractItemModel
175 void addRow();
176 void addRowAndCopyLast(); //vor intialization of the new row
177
178 void remRow(); // not to be mixed up with the removeRow()
179 // function from AbstractItemModel
180
181 private:
182 class Q_DECL_HIDDEN Impl;
183
184 std::unique_ptr<Impl> impl;
185
186 private slots:
187 void dimensionChanged();
188 void columnHeaderChanged();
189 void valueChanged();
190 void highlightRowChanged();
192};
193
194/****************************************************************************/
195
196} // namespace QtPdCom
197
198#endif
#define QTPDCOM_PUBLIC
Definition Export.h:30
Table Column.
Definition TableColumn.h:44
Table model.
Definition TableModelImpl.h:45
bool editing
Definition TableModel.h:45
virtual QVariant headerData(int, Qt::Orientation, int) const
Implements the Model interface.
Definition TableModel.cpp:237
void addColumn(TableColumn *)
Adds a column.
Definition TableModel.cpp:89
void addRowAndCopyLast()
updates the visibleRowCount variable with initialization.
Definition TableModel.cpp:533
void editingChanged(bool)
virtual int columnCount(const QModelIndex &) const
Implements the model interface.
Definition TableModel.cpp:209
unsigned int getRowCapacity() const
Definition TableModel.cpp:175
void highlightRowChanged()
Definition TableModel.cpp:717
void clearColumns()
Clears the Columns.
Definition TableModel.cpp:130
bool hasVisibleRowsVariable() const
Definition TableModel.cpp:182
bool insertRows(int position, int count=1, const QModelIndex &parent={}) override
updates the visibleRowCount variable.
Definition TableModel.cpp:575
void removeColumn(TableColumn *)
Definition TableModel.cpp:96
std::unique_ptr< Impl > impl
Definition TableModel.h:184
void dimensionChanged()
Reacts on process variable dimension changes.
Definition TableModel.cpp:676
void remRow()
Definition TableModel.cpp:611
TableModel(QObject *parent=nullptr)
Constructor.
Definition TableModel.cpp:34
void revert()
Reverts all edited data.
Definition TableModel.cpp:497
QHash< int, QByteArray > roleNames() const override
Definition TableModel.cpp:748
virtual bool setData(const QModelIndex &, const QVariant &, int)
Definition TableModel.cpp:264
void visibleRowCountChanged()
Definition TableModel.cpp:738
virtual int rowCount(const QModelIndex &) const
Implements the model interface.
Definition TableModel.cpp:193
void columnHeaderChanged()
Reacts on header data changes.
Definition TableModel.cpp:685
virtual Qt::ItemFlags flags(const QModelIndex &) const
Implements the Model interface.
Definition TableModel.cpp:250
void valueChanged()
Reacts on process variable changes.
Definition TableModel.cpp:699
void commit()
Commits all edited data.
Definition TableModel.cpp:479
virtual QVariant data(const QModelIndex &, int) const
Implements the Model interface.
Definition TableModel.cpp:223
void insertColumn(TableColumn *, int position)
Definition TableModel.cpp:60
bool isEditing() const
Definition TableModel.cpp:159
void addRow()
updates the visibleRowCount variable.
Definition TableModel.cpp:519
Definition BroadcastModel.h:32
constexpr struct QtPdCom::event_mode_tag event_mode
Exception(const QString &msg)
Constructor.
Definition TableModel.h:161
QString msg
Exception message.
Definition TableModel.h:164