ViewSolutions 1.0.100.30ae2aa
View solutions of qml for quasarapp projects
Loading...
Searching...
No Matches
listviewmodel.h
Go to the documentation of this file.
1//#
2//# Copyright (C) 2020-2025 QuasarApp.
3//# Distributed under the GPLv3 software license, see the accompanying
4//# Everyone is permitted to copy and distribute verbatim copies
5//# of this license document, but changing it is not allowed.
6//#
7
8#ifndef LISTVIEWMODEL_H
9#define LISTVIEWMODEL_H
10#include <QAbstractItemModel>
12
13namespace ViewSolutions {
14
21 ModelData = Qt::UserRole
22};
23
56class VIEWSOLUTION_EXPORT ListViewModel: public QAbstractListModel
57{
58 Q_OBJECT
59public:
60 ListViewModel(QObject *ptr = nullptr);
62
63 int rowCount(const QModelIndex &parent = QModelIndex()) const;
64 QVariant data(const QModelIndex &index, int role) const;
65 QHash<int, QByteArray> roleNames() const;
66
72 void setExternalSource(const QList<QObject*>* newData);
73
79 void setSource(const QList<QObject*>& newData);
80
85 void addSource(QObject *data);
86
93 void clear(bool fast = false);
94
100 bool external() const;
101
102private:
103 void setExternal(bool external);
104
105 bool _external = false;
106 QList<QObject*> _data;
107 const QList<QObject*> *_externalData = nullptr;
108
109};
110
111}
112#endif // LISTVIEWMODEL_H
QHash< int, QByteArray > roleNames() const
void addSource(QObject *data)
addSource adds one new QObject to the data list.
bool external() const
external returns true if the model uses an external data list.
void clear(bool fast=false)
clear removes all data from the model and deletes the objects of the internal data list.
QVariant data(const QModelIndex &index, int role) const
void setExternalSource(const QList< QObject * > *newData)
setExternalSource sets a new external data list. The model does not take ownership of the list conten...
ListViewModel(QObject *ptr=nullptr)
int rowCount(const QModelIndex &parent=QModelIndex()) const
void setSource(const QList< QObject * > &newData)
setSource sets a new internal data list. The model takes ownership of the list content.
The ViewSolutions namespace.
ListViewModelRoles
The ListViewModelRoles enum defines the data roles of the ListViewModel.
@ ModelData
The Qt::UserRole role. Returns the QObject data of the list item.
#define VIEWSOLUTION_EXPORT
VIEWSOLUTION_EXPORT marks a symbol as part of the public ViewSolutions API.