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 typedef QList<std::shared_ptr<Variable>> ListType;
29 explicit VariableListModel(QObject* parent = nullptr);
30
34 [[nodiscard]] int nameLevel() const;
35
39 void setNameLevel(int level);
40
45 [[nodiscard]] bool hasRowCheckBox() const;
46
51 void setRowCheckBox(bool enabled);
52
56 enum EField : int
57 {
62 cFlags
63 };
64
68 void setDelegates(QAbstractItemView* view);
69
73 void refresh();
74
80 EField getField(int column) const;
81
87 int getColumn(EField field) const;
88
95 void update(int row = -1, int column = -1, const QList<int>& roles = {});
96
103 void updateField(int row, EField field, const QList<int>& roles = {});
104
108 [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
109
113 [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
114
118 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
119
123 [[nodiscard]] int columnCount(const QModelIndex& parent = {}) const override;
124
128 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex& index) const override;
129
136
141 void addVariables(const Vector& list);
142
147 void addVariables(const PtrVector& list);
148
153 void setVariables(const Vector& list);
154
159 void setVariables(const PtrVector& list);
160
165
170 void setVariablesConvert(bool enable);
171
177
183
188 const ListType& getVariableList() const;
189
195 void addVariable(id_type id, bool desired = true);
201 void addVariables(const IdVector& ids, bool desired = true);
202
208 [[nodiscard]] Variable* getVariable(const QModelIndex& index) const;
209
213 bool setData(const QModelIndex& index, const QVariant& value, int role) override;
214
220 int getRow(Variable& link) const;
221
225 void setChecked(int row, bool checked);
226
231 // ReSharper disable once CppFunctionIsNotImplemented
232 Q_SIGNAL void changed(const Variable* var);
233
234 private:
238 void variableEventHandler(EEvent event, const Variable& caller, Variable& link, bool same_inst) override;
239
243 ListType _varList;
244
248 int _nameLevel;
252 bool _rowCheckBox;
256 QList<EField> _columns;
257};
258
259}// namespace sf
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:57
@ cValue
Definition VariableListModel.h:60
@ cName
Definition VariableListModel.h:59
@ cId
Definition VariableListModel.h:58
@ cUnit
Definition VariableListModel.h:61
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.
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.
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.
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 .
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
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