Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
ListModel.h
Go to the documentation of this file.
1#pragma once
2#include <QTreeView>
3#include <misc/global.h>
5
6namespace sf
7{
8
13class _MISC_CLASS ListModel : public QObject
14{
15 Q_OBJECT
16
17 public:
21 class Private;
22
26 class _MISC_CLASS Columns final : public QObject
27 {
28 public:
33 {
34 public:
38 QString name{};
42 int imageIndex{-1};
43
47 union
48 {
49 void* ptr{nullptr};
50 int64_t index;
51 } tag;
52
57 Qt::ItemFlags flags;
61 Qt::Alignment alignment{Qt::AlignLeft};
62 };
63
67 void clear();
68
74
79 Item* add(const QString& name, Qt::ItemFlags flags, Qt::Alignment alignment = Qt::AlignLeft);
80
84 const Item* getItem(int index) const;
85
89 int count() const;
90
91 protected:
95 explicit Columns(Private* prv);
96
97 private:
101 QList<QSharedPointer<Item>> _list;
105 Private* _model;
106
107 friend class Private;
108 };
109
114 explicit ListModel(QObject* parent);
115
119 ~ListModel() override;
120
125 void setTreeView(QTreeView* treeview);
126
130 QTreeView* getTreeView();
131
136
140 const Columns& getColumns() const;
141
145 QModelIndex currentIndex() const;
146
150 QModelIndex index(int row, int column = 0) const;
151
155 void setCurrentIndex(const QModelIndex& index);
156
160 void setCurrentIndex(int row, int column = 0);
161
165 void setRowCount(int count);
166
172 void update(const QModelIndex& index, const QList<int>& roles = {});
173
180 void update(int row = -1, int column = -1, const QList<int>& roles = {});
181
186 void removeRow(const QModelIndex& index);
187
193 void scrollTo(int row, int column = 0);
194
199 void scrollTo(const QModelIndex& index);
200
206 void removeRows(int row, int count = 1);
207
213 void insertRows(int row, int count);
214
220 void moveRow(int from, int to);
221
225 void refresh() const;
226
230 Q_SIGNAL void getRowData(const QModelIndex& index, int role, QVariant& value);
231
235 Q_SIGNAL void setRowData(const QModelIndex& index, int role, const QVariant& value);
236
240 Q_SIGNAL void contextMenuRequested(const QModelIndex& index, const QPoint& point);
241
245 Q_SIGNAL void currentRowChanged(int current, int previous);
246
247 private:
251 Private* _p;
252
253 // friend class Columns;
254};
255
256}// namespace sf
Holds column entry information.
Definition ListModel.h:33
Qt::ItemFlags flags
Additional flags for the column. Only 'ItemIsEditable', 'ItemIsUserCheckable' and 'ItemIsUserTristate...
Definition ListModel.h:57
int64_t index
Definition ListModel.h:50
Holds all columns information.
Definition ListModel.h:27
const Item * getItem(int index) const
Gets an item in the column list.
Item * add()
Adds a new column.
Item * add(const QString &name, Qt::ItemFlags flags, Qt::Alignment alignment=Qt::AlignLeft)
Adds a partially initialized new column.
void clear()
Clears all columns.
Columns(Private *prv)
Constructor passing the list model only for the list model to access.
int count() const
Gets the amount of columns.
Definition ListModel.h:14
void insertRows(int row, int count)
Insert rows into the list.
void setTreeView(QTreeView *treeview)
Attaches the given tree view and attached a new sf::CommonItemDelegate instance when the default is a...
Q_SIGNAL void setRowData(const QModelIndex &index, int role, const QVariant &value)
Signal emitted to set on the data source.
Columns & getColumns()
Gets the instance holding the column information.
const Columns & getColumns() const
Gets the constant instance holding the column information.
void removeRow(const QModelIndex &index)
Removes a row indicated by the index from the model.
void setCurrentIndex(int row, int column=0)
Sets the current focussed list entry by the given row and optional column.
QModelIndex currentIndex() const
Gets the current focussed list entry.
Q_SIGNAL void currentRowChanged(int current, int previous)
Signal emitted when the selected row changed.
Q_SIGNAL void contextMenuRequested(const QModelIndex &index, const QPoint &point)
Signal emitted when a context menu is requested.
void scrollTo(int row, int column=0)
Makes the associated tree view scroll to this row.
QTreeView * getTreeView()
Gets the current attached treeview.
void removeRows(int row, int count=1)
Removes rows from the list.
void setRowCount(int count)
Sets the row count.
void refresh() const
Makes the list refresh itself with by retrieving new data.
void update(int row=-1, int column=-1, const QList< int > &roles={})
Update values in the given column and row.
Q_SIGNAL void getRowData(const QModelIndex &index, int role, QVariant &value)
Signal emitted to retrieve data to populate the rows.
ListModel(QObject *parent)
QObject type of constructor. When the parent is a QTreeView or derived type the setTreeView is called...
void scrollTo(const QModelIndex &index)
Makes the associated tree view scroll to this index.
void moveRow(int from, int to)
Relocates a row to another location.
~ListModel() override
Virtual destructor.
void setCurrentIndex(const QModelIndex &index)
Sets the current focussed list entry by the given index.
void update(const QModelIndex &index, const QList< int > &roles={})
Update value in the field pointed at by the given index.
QModelIndex index(int row, int column=0) const
Creates an index from the given row and column.
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10