@@ -49,18 +49,25 @@ auto model = new QtDataSync::DataStoreModel(this);
4949model->setTypeId<Person>();
5050@endcode
5151
52- To properly use it with widgets, you can use
53- [QObjectListModel's](https://github.com/Skycoder42/QObjectListModel) `QObjectProxyModel`. The code
54- below creates a model with 2 columns, where column 0 shows the "name" role and column 1 shows the
55- "age" role:
52+ One additional feature of the model is, that it can also serve as model for table/tree views by
53+ delegating properties to multiple columns. This way you can use the model from QML by using the
54+ property names, and from widgets by delegating the properties to extra columns. For the above
55+ sample, the following code will result in a model with 2 columns, presenting the name and age
56+ properties as the Qt::DisplayRole of each column:
57+
5658@code{.cpp}
57- auto proxy = new QObjectProxyModel({"name", "age"}, this);
58- proxy->setSourceModel(model);
59- proxy->addMapping(0, Qt::DisplayRole, "name");
60- proxy->addMapping(1, Qt::DisplayRole, "age");
59+ // setup first
60+ auto model = new QtDataSync::DataStoreModel(this);
61+ model->setTypeId<Person>();
62+
63+ // add the column config:
64+ auto col0 = model->addColumn("Name");
65+ model->addRole(col0, Qt::DisplayRole, "name");
66+ // or as shortcut for the above:
67+ model->addColumn("Age", "age");
6168@endcode
6269
63- @sa DataStore, [QObjectListModel](https://github.com/Skycoder42/QObjectListModel)
70+ @sa DataStore
6471*/
6572
6673/*!
@@ -79,9 +86,11 @@ properly.
7986@accessors{
8087 @readAc{typeId()}
8188 @writeAc{setTypeId()}
89+ @notifyAc{typeIdChanged()}
8290}
8391
84- @sa DataStoreModel::storeError, DataStoreModel::reload
92+ @sa DataStoreModel::storeError, DataStoreModel::reload, DataStoreModel::addColumn,
93+ DataStoreModel::addRole
8594*/
8695
8796/*!
@@ -165,3 +174,50 @@ DataStore::load.
165174@sa DataStoreModel::object, DataStore::load
166175*/
167176
177+ /*!
178+ @fn QVariant QtDataSync::DataStoreModel::addColumn(const QString &)
179+
180+ @param text The display name of the column header
181+ @returns The index of the newly created column
182+
183+ The method add a column to the model that can be used to present propeties from the underlying
184+ data as specific roles.
185+
186+ @attention If no custom columns have been added yet, the model with have a single column with
187+ the typeId class name as title. By calling this method the first time, this default column will
188+ be **replaced** by whatever column you specify. All subsequent columns are simply added as new
189+ columns.
190+
191+ @sa DataStoreModel, DataStoreModel::typeId, DataStore::addRole, DataStore::clearColumns
192+ */
193+
194+ /*!
195+ @fn QVariant QtDataSync::DataStoreModel::addColumn(const QString &, const char *)
196+
197+ @param text The display name of the column header
198+ @param propertyName The name of the property to presented as the display role of that column
199+ @returns The index of the newly created column
200+
201+ This method is basically a shortcut for:
202+
203+ @code{.cpp}
204+ auto column = model->addColumn(text);
205+ model->addRole(column, Qt::DisplayRole, propertyName
206+ @endcode
207+
208+ @sa DataStoreModel, DataStoreModel::typeId, DataStore::addRole, DataStore::clearColumns
209+ */
210+
211+ /*!
212+ @fn QVariant QtDataSync::DataStoreModel::addRole
213+
214+ @param column The existing column to add the role to
215+ @param role The role that should be added to the column
216+ @param propertyName The name of the property to presented as the give role of that column
217+
218+ This method adds a new role to an existing column. The new role will simply the the value of the
219+ given property of the object in each row. It's basically a delegate to the properties role.
220+
221+ @sa DataStoreModel, DataStoreModel::typeId, DataStore::addColumn, DataStore::clearColumns
222+ */
223+
0 commit comments