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>
4
5namespace sf
6{
7
12class _MISC_CLASS ListModel : public QObject
13{
14 Q_OBJECT
15
16 public:
20 class Private;
21
25 class _MISC_CLASS Columns final : public QObject
26 {
27 public:
32 {
33 public:
37 QString name{};
41 int imageIndex{-1};
42
46 union
47 {
48 void* ptr{nullptr};
49 int64_t index;
50 } tag;
51
56 Qt::ItemFlags flags;
60 Qt::Alignment alignment{Qt::AlignLeft};
61 };
62
66 void clear();
67
72
76 const Item* getItem(int index) const;
77
81 int count() const;
82
83 protected:
87 explicit Columns(Private* prv);
88
89 private:
93 QList<QSharedPointer<Item>> _list;
97 Private* _model;
98
99 friend class Private;
100 };
101
106 explicit ListModel(QObject* parent);
107
111 ~ListModel() override;
112
117 void setTreeView(QTreeView* treeview);
118
122 QTreeView* getTreeView();
123
128
132 const Columns& getColumns() const;
133
137 QModelIndex currentIndex() const;
138
142 QModelIndex index(int row, int column = 0) const;
143
147 void setCurrentIndex(const QModelIndex& index);
148
152 void setCurrentIndex(int row, int column = 0);
153
157 void setRowCount(int count);
158
164 void update(const QModelIndex& index, const QList<int>& roles = {});
165
172 void update(int row, int column = -1, const QList<int>& roles = {});
173
178 void removeRow(const QModelIndex& index);
179 void scrollTo(const QModelIndex& index);
180
181 void removeRows(int row, int count = 1);
182 void insertRows(int row, int count);
183
184 void refresh() const;
185
186 void moveRow(int from, int to);
190 Q_SIGNAL void getRowData(const QModelIndex& index, int role, QVariant& data);
191
195 Q_SIGNAL void setRowData(const QModelIndex& index, int role, const QVariant& data);
196
200 Q_SIGNAL void contextMenuRequested(const QModelIndex& index, const QPoint& point);
201
205 Q_SIGNAL void currentRowChanged(int current, int previous);
206
207 private:
211 Private* _p;
212
213 // friend class Columns;
214};
215
216}// namespace sf
Holds column entry information.
Definition ListModel.h:32
Qt::ItemFlags flags
Additional flags for the column. Only 'ItemIsEditable', 'ItemIsUserCheckable' and 'ItemIsUserTristate...
Definition ListModel.h:56
int64_t index
Definition ListModel.h:49
Holds all columns information.
Definition ListModel.h:26
const Item * getItem(int index) const
Gets an item in the column list.
Item * add()
Adds a 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:13
void insertRows(int row, int count)
void setTreeView(QTreeView *treeview)
Attaches the given tree view but detaching the old one first.
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 update(int row, 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 &data)
Signal emitted to retrieve data to populate the rows.
QTreeView * getTreeView()
Gets the current attached treeview.
void removeRows(int row, int count=1)
void setRowCount(int count)
Sets the row count.
void refresh() const
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)
void moveRow(int from, int to)
~ListModel() override
Virtual destructor.
void setCurrentIndex(const QModelIndex &index)
Sets the current focussed list entryby 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.
Q_SIGNAL void setRowData(const QModelIndex &index, int role, const QVariant &data)
Signal emitted to set on the data source.
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10