Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
VariableListModel.h
Go to the documentation of this file.
1#pragma once
2#include "Namespace.h"
3
4#include <QAbstractItemView>
5#include <QAbstractListModel>
6#include <gii/gen/Variable.h>
7#include <gii/global.h>
8
9namespace sf
10{
11
16 : public QAbstractListModel
17 , protected VariableHandler
18{
19 Q_OBJECT
20
21 public:
25 explicit VariableListModel(QObject* parent = nullptr);
26
30 [[nodiscard]] int nameLevel() const;
31
35 void setNameLevel(int level);
36
41 [[nodiscard]] bool hasRowCheckBox() const;
42
47 void setRowCheckBox(bool enabled);
48
52 enum EField : int
53 {
58 cFlags
59 };
60
64 void setDelegates(QAbstractItemView* view);
65
69 void refresh();
70
76 EField getField(int column) const;
77
83 int getColumn(EField field) const;
84
91 void update(int row = -1, int column = -1, const QList<int>& roles = QList<int>());
92
99 void updateField(int row, EField field, const QList<int>& roles = QList<int>());
100
104 [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
105
109 [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
110
114 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
115
119 [[nodiscard]] int columnCount(const QModelIndex& parent = QModelIndex()) const override;
120
124 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex& index) const override;
125
131 void addVariable(const Variable& var);
132
137 void addVariables(const Vector& list);
138
143 void setVariables(const Vector& list);
144
149
154 void setVariablesConvert(bool enable);
155
161
167
173 void addVariable(id_type id, bool desired = true);
179 void addVariables(const IdVector& ids, bool desired = true);
180
186 [[nodiscard]] Variable* getVariable(const QModelIndex& index) const;
187
191 bool setData(const QModelIndex& index, const QVariant& value, int role) override;
192
198 int getRow(Variable& link) const;
199
203 void setChecked(int row, bool checked);
204
209 // ReSharper disable once CppFunctionIsNotImplemented
210 Q_SIGNAL void changed(const Variable* var);
211
212 private:
216 void variableEventHandler(EEvent event, const Variable& caller, Variable& link, bool same_inst) override;
217
221 QList<std::shared_ptr<Variable>> _varList;
225 int _nameLevel;
229 bool _rowCheckBox;
233 QList<EField> _columns;
234};
235
236}// namespace sf
unsigned long long id_type
Type used for the identifying integer (64-bits).
Definition InformationBase.h:30
Counted vector having additional methods and operators for ease of usage.
Definition TVector.h:25
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.
int nameLevel() const
Gets the levels of names displayed of the variables in the list.
EField
Displayable columns.
Definition VariableListModel.h:53
@ cValue
Definition VariableListModel.h:56
@ cName
Definition VariableListModel.h:55
@ cId
Definition VariableListModel.h:54
@ cUnit
Definition VariableListModel.h:57
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 update(int row=-1, int column=-1, const QList< int > &roles=QList< int >())
Update values in the given column and row.
void addVariables(const IdVector &ids, bool desired=true)
Adds local or global variables to this instance.
void addVariable(const Variable &var)
Adds local or global variable to this instance by pointer. Internally a client copy of the sf::Variab...
void updateField(int row, EField field, const QList< int > &roles=QList< int >())
Update the column for the given field for all rows.
void addVariable(id_type id, bool desired=true)
Adds global variable to this instance by id.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Overridden from base class to provide the amount of columns.
Qt::ItemFlags flags(const QModelIndex &index) const override
Overridden from base class to provide flags on an item by index.
void setVariablesConvert(bool enable)
Sets the variable conversion for floating point values.
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.
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.
void setDelegates(QAbstractItemView *view)
Creates a sf::CommonItemDelegate instance for the passed view.
EEvent
Events send to the handler set with sf::Variable::setHandler.
Definition VariableTypes.h:130
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