Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
VariableListModel.h
Go to the documentation of this file.
1#pragma once
2#include <QAbstractItemView>
3#include <QAbstractListModel>
4#include <gii/gen/Variable.h>
5#include <gii/global.h>
6#include <gii/qt/Namespace.h>
7
8namespace sf
9{
10class CommonItemDelegate;
11
16 : public QAbstractListModel
17 , protected VariableHandler
18{
19 Q_OBJECT
20
21 public:
25 typedef QList<std::shared_ptr<Variable>> ListType;
29 explicit VariableListModel(QObject* parent = nullptr);
30
34 int nameLevel() const;
35
39 void setNameLevel(int level);
40
45 bool hasRowCheckBox() const;
46
50 void setReadOnly(bool flag);
51
55 bool isReadOnly() const;
56
61 void setRowCheckBox(bool enabled);
62
66 enum EField : int
67 {
72 cFlags
73 };
74
78 void refresh();
79
85 EField getField(int column) const;
86
92 int getColumn(EField field) const;
93
100 void update(int row = -1, int column = -1, const QList<int>& roles = {});
101
108 void updateField(int row, EField field, const QList<int>& roles = {});
109
113 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
114
118 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
119
123 QVariant data(const QModelIndex& index, int role) const override;
124
128 int columnCount(const QModelIndex& parent = {}) const override;
129
134 QAbstractItemDelegate* itemDelegate();
135
139 Qt::ItemFlags flags(const QModelIndex& index) const override;
140
147
152 void addVariables(const Vector& list);
153
158 void addVariables(const PtrVector& list);
159
164 void setVariables(const Vector& list);
165
170 void setVariables(const PtrVector& list);
171
176
181 void setVariablesConvert(bool enable);
182
188
194
199 const ListType& getVariableList() const;
200
206 void addVariable(id_type id, bool desired = true);
212 void addVariables(const IdVector& ids, bool desired = true);
213
219 Variable* getVariable(const QModelIndex& index) const;
220
224 bool setData(const QModelIndex& index, const QVariant& value, int role) override;
225
231 int getRow(Variable& link) const;
232
236 void setChecked(int row, bool checked);
237
242 // ReSharper disable once CppFunctionIsNotImplemented
243 Q_SIGNAL void changed(const Variable* var);
244
245 private:
249 void variableEventHandler(EEvent event, const Variable& caller, Variable& link, bool same_inst) override;
251 ListType _varList;
253 int _nameLevel;
255 bool _rowCheckBox;
257 QList<EField> _columns;
259 CommonItemDelegate* _itemDelegate;
261 bool _readOnly;
262};
263
264}// namespace sf
Allows a list model to determine the editor for a field.
Definition CommonItemDelegate.h:13
unsigned long long id_type
Type used for the identifying integer (64-bits).
Definition InformationBase.h:30
Base class used for giving a Variable instance access to a member functions of a derived class....
Definition VariableHandler.h:14
List model for a sf::Variable list.
Definition VariableListModel.h:18
VariableListModel(QObject *parent=nullptr)
Constructor.
void clearVariables()
Clear the variables added.
void addVariables(const PtrVector &list)
Adds local or global variables to this instance.
int nameLevel() const
Gets the levels of names displayed of the variables in the list.
EField
Displayable columns.
Definition VariableListModel.h:67
@ cValue
Definition VariableListModel.h:70
@ cName
Definition VariableListModel.h:69
@ cId
Definition VariableListModel.h:68
@ cUnit
Definition VariableListModel.h:71
Variable & addVariable(const Variable &var)
Adds local or global variable to this instance by pointer. Internally a client copy of the sf::Variab...
QVariant data(const QModelIndex &index, int role) const override
Overridden from base class to provide the data to present.
Q_SIGNAL void changed(const Variable *var)
Signals a change of the Variable's property.
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Overridden from base class to provide column display names.
void setRowCheckBox(bool enabled)
Enables the selection of rows. The sf::Variable::getData() returns true when selected.
int getRow(Variable &link) const
Finds the row beloning to the given variable.
void updateField(int row, EField field, const QList< int > &roles={})
Update the column for the given field for all rows.
void addVariables(const IdVector &ids, bool desired=true)
Adds local or global variables to this instance.
void setReadOnly(bool flag)
Sets the read-only flag to make the all entries read-only.
int columnCount(const QModelIndex &parent={}) const override
Overridden from base class to provide the amount of columns.
void addVariable(id_type id, bool desired=true)
Adds global variable to this instance by id.
QAbstractItemDelegate * itemDelegate()
Gets the item delegate associated with the model. Used to pass to QAbstractItemView::setItemDelegate(...
Qt::ItemFlags flags(const QModelIndex &index) const override
Overridden from base class to provide flags on an item by index.
void update(int row=-1, int column=-1, const QList< int > &roles={})
Update values in the given column and row.
void setVariablesConvert(bool enable)
Sets the variable conversion for floating point values.
bool isReadOnly() const
Gets the read-only flag.
void setVariables(const PtrVector &list)
Set local or global variables to this instance.
void setVariables(const Vector &list)
Set local or global variables to this instance.
IdVector getVariablesChecked() const
Gets the Variable id's of all checked items in the list.
bool hasRowCheckBox() const
Gets if the row selection is enabled. By default, the row selection is enabled.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Overridden from base class to provide the amount of rows.
int getColumn(EField field) const
Gets the column position or number where the field is displayed.
void setChecked(int row, bool checked)
Sets or unsets the checkbox of a row.
Variable * getVariable(const QModelIndex &index) const
Gets the underlying variable pointer.
EField getField(int column) const
Gets the field displayed in the column.
void setNameLevel(int level)
Sets the levels of names displayed of the variables in the list.
QList< std::shared_ptr< Variable > > ListType
Type for containing the variables for this model.
Definition VariableListModel.h:25
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Overridden from base class to provide assignment of an item when edited.
void setVariablesChecked(const IdVector &ids)
Gets the Variable id's of all checked items in the list. Returns a list of id numbers to the passed r...
void addVariables(const Vector &list)
Adds local or global variables to this instance.
void refresh()
Refresh the attached viewer.
const ListType & getVariableList() const
Gets the variable list .
EEvent
Events send to the handler set with sf::Variable::setHandler.
Definition VariableTypes.h:130
TVector< Variable > Vector
Vector for instances of variables.
Definition VariableTypes.h:36
Class for creating and referencing global or local created parameters or settings called variables....
Definition Variable.h:16
#define _GII_CLASS
Definition gii/global.h:38
Definition Application.h:10