ViewSolutions 1.0.100.30ae2aa
View solutions of qml for quasarapp projects
Loading...
Searching...
No Matches
ViewSolutions::BaseHashModel< KEY, DATA > Class Template Reference

The BaseHashModel class is the base class of all GUI hash models. More...

#include <basehashmodel.h>

Inheritance diagram for ViewSolutions::BaseHashModel< KEY, DATA >:
Inheritance graph
Collaboration diagram for ViewSolutions::BaseHashModel< KEY, DATA >:
Collaboration graph

Public Member Functions

 BaseHashModel (QObject *parent=nullptr)
int rowCount (const QModelIndex &parent) const override
QHash< int, QByteArray > roleNames () const override
QVariant data (const QModelIndex &index, int role) const override
virtual QVariant getByKey (const KEY &key)
 getByKey returns value by key
const QHash< KEY, DATA > & dateList () const
virtual void setByKey (const KEY &key, const DATA &data)
 setByKey update delegate by key
virtual void removeByKey (const KEY &key)
void setDataList (const QHash< KEY, DATA > &newData)
 setDataList sets new date of model, and reset all model;

Detailed Description

template<class KEY, class DATA>
class ViewSolutions::BaseHashModel< KEY, DATA >

The BaseHashModel class is the base class of all GUI hash models.

A BaseHashModel stores its items in a hash table and exposes them to QML as a list model. Every item can be accessed by a unique key.

Template Parameters
KEY- is type of hash table key,
DATA- is main stored delegate model of all list items.

Concepts and usage rules:

  • All models should provide delegate models based on QObject
  • If the model requires a fast solution, just implement a BaseListModel<T> model instead
Note
To access the delegate model use the Qt::EditRole role: it is available in QML by the delegateModel keyword.
The BaseHashModel does not support the QML space directly, for short access in QML use the BaseListModel instead.

Example of a model based on the BaseHashModel:

class IntStringModel: public ViewSolutions::BaseHashModel<int, QString>
{
Q_OBJECT
public:
IntStringModel(QObject* parent = nullptr):
ViewSolutions::BaseHashModel<int, QString>(parent) {}
};
The BaseHashModel class is the base class of all GUI hash models.
BaseHashModel(QObject *parent=nullptr)
The ViewSolutions namespace.

C++ usage:

IntStringModel model;
model.setByKey(1, "first");
model.setByKey(2, "second");
QString value = model.getByKey(1).toString(); // "first"
model.removeByKey(1);

Definition at line 58 of file basehashmodel.h.

Constructor & Destructor Documentation

◆ BaseHashModel()

template<class KEY, class DATA>
ViewSolutions::BaseHashModel< KEY, DATA >::BaseHashModel ( QObject * parent = nullptr)
inline

Definition at line 62 of file basehashmodel.h.

Member Function Documentation

◆ data()

template<class KEY, class DATA>
QVariant ViewSolutions::BaseHashModel< KEY, DATA >::data ( const QModelIndex & index,
int role ) const
inlineoverride

Definition at line 76 of file basehashmodel.h.

Here is the caller graph for this function:

◆ dateList()

template<class KEY, class DATA>
const QHash< KEY, DATA > & ViewSolutions::BaseHashModel< KEY, DATA >::dateList ( ) const
inline

Definition at line 133 of file basehashmodel.h.

◆ getByKey()

template<class KEY, class DATA>
virtual QVariant ViewSolutions::BaseHashModel< KEY, DATA >::getByKey ( const KEY & key)
inlinevirtual

getByKey returns value by key

Parameters
key
Returns

Definition at line 111 of file basehashmodel.h.

◆ removeByKey()

template<class KEY, class DATA>
virtual void ViewSolutions::BaseHashModel< KEY, DATA >::removeByKey ( const KEY & key)
inlinevirtual

Definition at line 152 of file basehashmodel.h.

◆ roleNames()

template<class KEY, class DATA>
QHash< int, QByteArray > ViewSolutions::BaseHashModel< KEY, DATA >::roleNames ( ) const
inlineoverride

Definition at line 70 of file basehashmodel.h.

◆ rowCount()

template<class KEY, class DATA>
int ViewSolutions::BaseHashModel< KEY, DATA >::rowCount ( const QModelIndex & parent) const
inlineoverride

Definition at line 66 of file basehashmodel.h.

◆ setByKey()

template<class KEY, class DATA>
virtual void ViewSolutions::BaseHashModel< KEY, DATA >::setByKey ( const KEY & key,
const DATA & data )
inlinevirtual

setByKey update delegate by key

Parameters
key
data

Definition at line 142 of file basehashmodel.h.

Here is the call graph for this function:

◆ setDataList()

template<class KEY, class DATA>
void ViewSolutions::BaseHashModel< KEY, DATA >::setDataList ( const QHash< KEY, DATA > & newData)
inline

setDataList sets new date of model, and reset all model;

Parameters
newData

Definition at line 167 of file basehashmodel.h.


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