|
| | 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;
|
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:
{
Q_OBJECT
public:
IntStringModel(QObject* parent = nullptr):
};
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();
model.removeByKey(1);
Definition at line 58 of file basehashmodel.h.