QtPdCom  1.3.3
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 
34 namespace QtPdCom {
35 
36 /****************************************************************************/
37 
42 class 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);
49  ~TableModel();
50 
51  void addColumn(TableColumn *);
52  void insertColumn(TableColumn *, int position);
53  void removeColumn(TableColumn *);
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 
157  struct Exception
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();
191  void visibleRowCountChanged();
192 };
193 
194 /****************************************************************************/
195 
196 } // namespace QtPdCom
197 
198 #endif
Table Column.
Definition: TableColumn.h:43
Exception type.
Definition: TableModel.h:157
Definition: BroadcastModel.h:32
Table model.
Definition: TableModelImpl.h:44
std::unique_ptr< Impl > impl
Definition: TableModel.h:184
Exception(const QString &msg)
Constructor.
Definition: TableModel.h:161
Table model.
Definition: TableModel.h:42
#define QTPDCOM_PUBLIC
Definition: Export.h:30
QString msg
Exception message.
Definition: TableModel.h:164
constexpr struct QtPdCom::event_mode_tag event_mode