ViewSolutions 1.0.100.30ae2aa
View solutions of qml for quasarapp projects
Loading...
Searching...
No Matches
ViewSolutions::ListViewModel Class Reference

The ListViewModel class provides a QML list model with QObject data. More...

#include <listviewmodel.h>

Inheritance diagram for ViewSolutions::ListViewModel:
Inheritance graph
Collaboration diagram for ViewSolutions::ListViewModel:
Collaboration graph

Public Member Functions

 ListViewModel (QObject *ptr=nullptr)
 ~ListViewModel ()
int rowCount (const QModelIndex &parent=QModelIndex()) const
QVariant data (const QModelIndex &index, int role) const
QHash< int, QByteArray > roleNames () const
void setExternalSource (const QList< QObject * > *newData)
 setExternalSource sets a new external data list. The model does not take ownership of the list content.
void setSource (const QList< QObject * > &newData)
 setSource sets a new internal data list. The model takes ownership of the list content.
void addSource (QObject *data)
 addSource adds one new QObject to the data list.
void clear (bool fast=false)
 clear removes all data from the model and deletes the objects of the internal data list.
bool external () const
 external returns true if the model uses an external data list.

Detailed Description

The ListViewModel class provides a QML list model with QObject data.

The model can be filled with an internal list of QObject pointers or with an external list. In the external case the model does not own the data, the data must stay valid while the model is in use.

The model exposes one role: modelData (see ListViewModelRoles::ModelData).

Example:

// Internal data list (owned by the model):
model.addSource(myObject);
model.setSource({object1, object2});
// External data list (not owned by the model):
QList<QObject*> externalList = {object1, object2};
model.setExternalSource(&externalList);
The ListViewModel class provides a QML list model with QObject data.
void addSource(QObject *data)
addSource adds one new QObject to the data list.
void setExternalSource(const QList< QObject * > *newData)
setExternalSource sets a new external data list. The model does not take ownership of the list conten...
void setSource(const QList< QObject * > &newData)
setSource sets a new internal data list. The model takes ownership of the list content.

QML usage:

ListView {
model: listViewModel
delegate: Item {
property var data: modelData
}
}

Definition at line 56 of file listviewmodel.h.

Constructor & Destructor Documentation

◆ ListViewModel()

ViewSolutions::ListViewModel::ListViewModel ( QObject * ptr = nullptr)

Definition at line 11 of file listviewmodel.cpp.

◆ ~ListViewModel()

ViewSolutions::ListViewModel::~ListViewModel ( )

Definition at line 16 of file listviewmodel.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ addSource()

void ViewSolutions::ListViewModel::addSource ( QObject * data)

addSource adds one new QObject to the data list.

Parameters
datais the new data object.

Definition at line 76 of file listviewmodel.cpp.

Here is the call graph for this function:

◆ clear()

void ViewSolutions::ListViewModel::clear ( bool fast = false)

clear removes all data from the model and deletes the objects of the internal data list.

Parameters
fastif true the objects are deleted with deleteLater, otherwise they are deleted directly.

Definition at line 86 of file listviewmodel.cpp.

Here is the caller graph for this function:

◆ data()

QVariant ViewSolutions::ListViewModel::data ( const QModelIndex & index,
int role ) const

Definition at line 27 of file listviewmodel.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ external()

bool ViewSolutions::ListViewModel::external ( ) const

external returns true if the model uses an external data list.

Returns
true if the model uses an external data list.

Definition at line 98 of file listviewmodel.cpp.

Here is the caller graph for this function:

◆ roleNames()

QHash< int, QByteArray > ViewSolutions::ListViewModel::roleNames ( ) const

Definition at line 39 of file listviewmodel.cpp.

◆ rowCount()

int ViewSolutions::ListViewModel::rowCount ( const QModelIndex & parent = QModelIndex()) const

Definition at line 20 of file listviewmodel.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setExternalSource()

void ViewSolutions::ListViewModel::setExternalSource ( const QList< QObject * > * newData)

setExternalSource sets a new external data list. The model does not take ownership of the list content.

Parameters
newDatais pointer to the new external data list.

Definition at line 46 of file listviewmodel.cpp.

Here is the call graph for this function:

◆ setSource()

void ViewSolutions::ListViewModel::setSource ( const QList< QObject * > & newData)

setSource sets a new internal data list. The model takes ownership of the list content.

Parameters
newDatais the new internal data list.

Definition at line 59 of file listviewmodel.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: