1 #ifndef QTDATASYNC_DATASTOREMODEL_H 2 #define QTDATASYNC_DATASTOREMODEL_H 4 #include <QtCore/qabstractitemmodel.h> 6 #include "QtDataSync/qtdatasync_global.h" 7 #include "QtDataSync/datastore.h" 11 class DataStoreModelPrivate;
16 friend class DataStoreModelPrivate;
19 Q_PROPERTY(
int typeId READ typeId WRITE setTypeId NOTIFY typeIdChanged)
21 Q_PROPERTY(
bool editable READ isEditable WRITE setEditable NOTIFY editableChanged)
41 inline
void setTypeId(
bool resetColumns = true);
43 bool isEditable() const;
46 QVariant headerData(
int section,
Qt::Orientation orientation,
int role =
Qt::DisplayRole) const override;
50 int columnCount(const
QModelIndex &parent) const override;
52 bool canFetchMore(const
QModelIndex &parent) const override;
98 int addColumn(const
QString &text);
100 int addColumn(const
QString &text, const
char *propertyName);
102 void addRole(
int column,
int role, const
char *propertyName);
108 void setTypeId(
int typeId);
110 void setTypeId(
int typeId,
bool resetColumns);
112 void setEditable(
bool editable);
119 void storeError(const
QException &exception, QPrivateSignal);
121 void typeIdChanged(
int typeId, QPrivateSignal);
123 void editableChanged(
bool editable, QPrivateSignal);
132 void storeChanged(
int metaTypeId, const
QString &key,
bool wasDeleted);
133 void storeResetted();
141 template <typename T>
143 QTDATASYNC_STORE_ASSERT(T);
144 setTypeId(qMetaTypeId<T>(), resetColumns);
147 template <
typename T>
149 return idIndex(QVariant::fromValue<T>(
id).toString());
152 template <
typename T>
157 template <
typename T>
159 QTDATASYNC_STORE_ASSERT(T);
160 Q_ASSERT_X(qMetaTypeId<T>() == typeId(), Q_FUNC_INFO,
"object must be used with the stores typeId");
161 return object(index).value<T>();
164 template <
typename T>
166 QTDATASYNC_STORE_ASSERT(T);
167 Q_ASSERT_X(qMetaTypeId<T>() == typeId(), Q_FUNC_INFO,
"object must be used with the stores typeId");
168 return loadObject(index).value<T>();
173 #endif // QTDATASYNC_DATASTOREMODEL_H
Q_INVOKABLE QString key(const QModelIndex &index) const
Returns the key of the item at the given index.
Q_INVOKABLE QVariant loadObject(const QModelIndex &index) const
Loads the object at the given index from the store via DataStore::load.
Main store to generically access all stored data synchronously.
Q_INVOKABLE QVariant object(const QModelIndex &index) const
Returns the object at the given index.
The primary namespace of the QtDataSync library.
Q_INVOKABLE QModelIndex idIndex(const QString &id) const
Returns the index of the item with the given id.
A passive item model for a datasync data store.