1 | // Copyright (C) 2023 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qitemmodelsurfacedataproxy_p.h" |
5 | #include "surfaceitemmodelhandler_p.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | /*! |
10 | * \class QItemModelSurfaceDataProxy |
11 | * \inmodule QtGraphs |
12 | * \ingroup graphs_3D |
13 | * \brief Proxy class for presenting data in item models with Q3DSurfaceWidgetItem. |
14 | * |
15 | * QItemModelSurfaceDataProxy allows you to use QAbstractItemModel derived |
16 | * models as a data source for Q3DSurfaceWidgetItem. It uses the defined mappings to map |
17 | * data from the model to rows, columns, and surface points of Q3DSurfaceWidgetItem graph. |
18 | * |
19 | * Data is resolved asynchronously whenever the mapping or the model changes. |
20 | * QSurfaceDataProxy::arrayReset() is emitted when the data has been resolved. |
21 | * However, when useModelCategories property is set to \c true, single item |
22 | * changes are resolved synchronously, unless the same frame also contains a |
23 | * change that causes the whole model to be resolved. |
24 | * |
25 | * Mappings can be used in the following ways: |
26 | * |
27 | * \list |
28 | * \li If useModelCategories property is set to \c true, this proxy will map rows and |
29 | * columns of QAbstractItemModel to rows and columns of Q3DSurfaceWidgetItem, and uses the value returned for |
30 | * Qt::DisplayRole as Y-position by default. Row and column headers are used for Z-position and |
31 | * X-position by default, if they can be converted to floats. Otherwise row and column indices |
32 | * are used. |
33 | * The Y-position role to be used can be redefined if Qt::DisplayRole is not suitable. |
34 | * The Z-position and X-position roles to be used can be redefined if the headers or indices |
35 | * are not suitable. |
36 | * |
37 | * \li For models that do not have data already neatly sorted into rows and columns, such as |
38 | * QAbstractListModel based models, you can define a role from the model to map for each of the |
39 | * row, column and Y-position. |
40 | * |
41 | * \li If you do not want to include all data contained in the model, or the autogenerated rows and |
42 | * columns are not ordered as you wish, you can specify which rows and columns should be included |
43 | * and in which order by defining an explicit list of categories for either or both of rows and |
44 | * columns. |
45 | * \endlist |
46 | * |
47 | * For example, assume that you have a custom QAbstractItemModel storing surface topography data. |
48 | * Each item in the model has the roles "longitude", "latitude", and "height". |
49 | * The item model already contains the data properly sorted so that longitudes and latitudes are |
50 | * first encountered in correct order, which enables us to utilize the row and column category |
51 | * autogeneration. |
52 | * You could do the following to display the data in a surface graph: |
53 | * |
54 | * \snippet doc_src_qtgraphs.cpp surfacemodelproxy |
55 | * |
56 | * If the fields of the model do not contain the data in the exact format you |
57 | * need, you can specify a search pattern regular expression and a replace rule |
58 | * for each role to get the value in a format you need. For more information on how |
59 | * the replacement using regular expressions works, see QString::replace(const |
60 | * QRegularExpression &rx, const QString &after) function documentation. Note |
61 | * that using regular expressions has an impact on the performance, so it's more |
62 | * efficient to utilize item models where doing search and replace is not |
63 | * necessary to get the desired values. |
64 | * |
65 | * For example about using the search patterns in conjunction with the roles, |
66 | * see ItemModelBarDataProxy usage in \l{Simple Bar Graph}. |
67 | * |
68 | * \sa {Qt Graphs Data Handling with 3D} |
69 | */ |
70 | |
71 | /*! |
72 | * \qmltype ItemModelSurfaceDataProxy |
73 | * \inqmlmodule QtGraphs |
74 | * \ingroup graphs_qml_3D |
75 | * \nativetype QItemModelSurfaceDataProxy |
76 | * \inherits SurfaceDataProxy |
77 | * \brief Proxy class for presenting data in item models with Surface3D. |
78 | * |
79 | * This type allows you to use \c AbstractItemModel derived models as a data |
80 | * source for Surface3D. |
81 | * |
82 | * Data is resolved asynchronously whenever the mapping or the model changes. |
83 | * |
84 | * For ItemModelSurfaceDataProxy enums, see |
85 | * \l{QItemModelSurfaceDataProxy::MultiMatchBehavior}. |
86 | * |
87 | * For more details, see QItemModelSurfaceDataProxy documentation. |
88 | * |
89 | * Usage example: |
90 | * |
91 | * \snippet doc_src_qmlgraphs.cpp 9 |
92 | * |
93 | * \sa SurfaceDataProxy, {Qt Graphs Data Handling with 3D} |
94 | */ |
95 | |
96 | /*! |
97 | * \qmlproperty model ItemModelSurfaceDataProxy::itemModel |
98 | * The item model used as a data source for Surface3D. |
99 | */ |
100 | |
101 | /*! |
102 | * \qmlproperty string ItemModelSurfaceDataProxy::rowRole |
103 | * The item model role to map to the row category. |
104 | * In addition to defining which row the data belongs to, the value indicated by |
105 | * the row role is also set as the Z-coordinate value of QSurfaceDataItem when the |
106 | * model data is resolved, unless a separate z position role is also defined. |
107 | */ |
108 | |
109 | /*! |
110 | * \qmlproperty string ItemModelSurfaceDataProxy::columnRole |
111 | * The item model role to map to the column category. |
112 | * In addition to defining which column the data belongs to, the value indicated |
113 | * by the column role is also set as the X-coordinate value of QSurfaceDataItem |
114 | * when the model data is resolved, unless a separate x position role is also |
115 | * defined. |
116 | */ |
117 | |
118 | /*! |
119 | * \qmlproperty string ItemModelSurfaceDataProxy::xPosRole |
120 | * The item model role to map to the X position. If this role is not defined, |
121 | * columnRole is used to determine the X-coordinate value of the resolved \c |
122 | * QSurfaceDataItem items. |
123 | */ |
124 | |
125 | /*! |
126 | * \qmlproperty string ItemModelSurfaceDataProxy::yPosRole |
127 | * The item model role to map to the Y position. |
128 | */ |
129 | |
130 | /*! |
131 | * \qmlproperty string ItemModelSurfaceDataProxy::zPosRole |
132 | * The item model role to map to the Z position. If this role is not defined, |
133 | * rowRole is used to determine the Z-coordinate value of the resolved |
134 | * \c QSurfaceDataItem items. |
135 | */ |
136 | |
137 | /*! |
138 | * \qmlproperty list<String> ItemModelSurfaceDataProxy::rowCategories |
139 | * The row categories of the mapping. Only items with row roles that are found |
140 | * in this list are included when data is resolved. The rows are ordered in the |
141 | * same order as they are in this list. |
142 | */ |
143 | |
144 | /*! |
145 | * \qmlproperty list<String> ItemModelSurfaceDataProxy::columnCategories |
146 | * The column categories of the mapping. Only items with column roles that are |
147 | * found in this list are included when data is resolved. The columns are |
148 | * ordered in the same order as they are in this list. |
149 | */ |
150 | |
151 | /*! |
152 | * \qmlproperty bool ItemModelSurfaceDataProxy::useModelCategories |
153 | * When set to \c true, the mapping ignores row and column roles and categories, |
154 | * and uses the rows and columns from the model instead. Defaults to \c{false}. |
155 | */ |
156 | |
157 | /*! |
158 | * \qmlproperty bool ItemModelSurfaceDataProxy::autoRowCategories |
159 | * When set to \c true, the mapping ignores any explicitly set row categories |
160 | * and overwrites them with automatically generated ones whenever the |
161 | * data from the model is resolved. Proxy minimum and maximum row values are |
162 | * also autogenerated from the data when this is set to \c true. Defaults to |
163 | * \c{true}. |
164 | */ |
165 | |
166 | /*! |
167 | * \qmlproperty bool ItemModelSurfaceDataProxy::autoColumnCategories |
168 | * When set to \c true, the mapping ignores any explicitly set column categories |
169 | * and overwrites them with automatically generated ones whenever the |
170 | * data from the model is resolved. Proxy minimum and maximum column values are |
171 | * also autogenerated from the data when this is set to \c true. Defaults to |
172 | * \c{true}. |
173 | */ |
174 | |
175 | /*! |
176 | * \qmlproperty regExp ItemModelSurfaceDataProxy::rowRolePattern |
177 | * |
178 | * When set, a search and replace is done on the value mapped by the row role |
179 | * before it is used as a row category. This property specifies the regular |
180 | * expression to find the portion of the mapped value to replace, and the |
181 | * rowRoleReplace property contains the replacement string. |
182 | * |
183 | * \sa rowRole, rowRoleReplace |
184 | */ |
185 | |
186 | /*! |
187 | * \qmlproperty regExp ItemModelSurfaceDataProxy::columnRolePattern |
188 | * |
189 | * When set, a search and replace is done on the value mapped by the column role |
190 | * before it is used as a column category. This property specifies the regular |
191 | * expression to find the portion of the mapped value to replace, and the |
192 | * columnRoleReplace property contains the replacement string. |
193 | * |
194 | * \sa columnRole, columnRoleReplace |
195 | */ |
196 | |
197 | /*! |
198 | * \qmlproperty regExp ItemModelSurfaceDataProxy::xPosRolePattern |
199 | * |
200 | * When set, a search and replace is done on the value mapped by the x-position |
201 | * role before it is used as an item position value. This property specifies |
202 | * the regular expression to find the portion of the mapped value to replace, and |
203 | * the xPosRoleReplace property contains the replacement string. |
204 | * |
205 | * \sa xPosRole, xPosRoleReplace |
206 | */ |
207 | |
208 | /*! |
209 | * \qmlproperty regExp ItemModelSurfaceDataProxy::yPosRolePattern |
210 | * |
211 | * When set, a search and replace is done on the value mapped by the y-position |
212 | * role before it is used as an item position value. This property specifies |
213 | * the regular expression to find the portion of the mapped value to replace, and |
214 | * the yPosRoleReplace property contains the replacement string. |
215 | * |
216 | * \sa yPosRole, yPosRoleReplace |
217 | */ |
218 | |
219 | /*! |
220 | * \qmlproperty regExp ItemModelSurfaceDataProxy::zPosRolePattern |
221 | * |
222 | * When set, a search and replace is done on the value mapped by the z-position |
223 | * role before it is used as an item position value. This property specifies |
224 | * the regular expression to find the portion of the mapped value to replace, and |
225 | * the zPosRoleReplace property contains the replacement string. |
226 | * |
227 | * \sa zPosRole, zPosRoleReplace |
228 | */ |
229 | |
230 | /*! |
231 | * \qmlproperty string ItemModelSurfaceDataProxy::rowRoleReplace |
232 | * |
233 | * The replacement content to be used in conjunction with rowRolePattern. |
234 | * Defaults to an empty string. For more information on how the search and |
235 | * replace using regular expressions works, see the |
236 | * QString::replace(const QRegularExpression &rx, const QString &after) |
237 | * function documentation. |
238 | * |
239 | * \sa rowRole, rowRolePattern |
240 | */ |
241 | |
242 | /*! |
243 | * \qmlproperty string ItemModelSurfaceDataProxy::columnRoleReplace |
244 | * |
245 | * The replacement content to be used in conjunction with columnRolePattern. |
246 | * Defaults to an empty string. For more information on how the search and |
247 | * replace using regular expressions works, see the |
248 | * QString::replace(const QRegularExpression &rx, const QString &after) |
249 | * function documentation. |
250 | * |
251 | * \sa columnRole, columnRolePattern |
252 | */ |
253 | |
254 | /*! |
255 | * \qmlproperty string ItemModelSurfaceDataProxy::xPosRoleReplace |
256 | * |
257 | * The replacement content to be used in conjunction with xPosRolePattern. |
258 | * Defaults to an empty string. For more information on how the search and |
259 | * replace using regular expressions works, see the |
260 | * QString::replace(const QRegularExpression &rx, const QString &after) |
261 | * function documentation. |
262 | * |
263 | * \sa xPosRole, xPosRolePattern |
264 | */ |
265 | |
266 | /*! |
267 | * \qmlproperty string ItemModelSurfaceDataProxy::yPosRoleReplace |
268 | * |
269 | * The replacement content to be used in conjunction with yPosRolePattern. |
270 | * Defaults to an empty string. For more information on how the search and |
271 | * replace using regular expressions works, see the |
272 | * QString::replace(const QRegularExpression &rx, const QString &after) |
273 | * function documentation. |
274 | * |
275 | * \sa yPosRole, yPosRolePattern |
276 | */ |
277 | |
278 | /*! |
279 | * \qmlproperty string ItemModelSurfaceDataProxy::zPosRoleReplace |
280 | * |
281 | * The replacement content to be used in conjunction with zPosRolePattern. |
282 | * Defaults to an empty string. For more information on how the search and |
283 | * replace using regular expressions works, see the |
284 | * QString::replace(const QRegularExpression &rx, const QString &after) |
285 | * function documentation. |
286 | * |
287 | * \sa zPosRole, zPosRolePattern |
288 | */ |
289 | |
290 | /*! |
291 | * \qmlproperty enumeration ItemModelSurfaceDataProxy::multiMatchBehavior |
292 | * Defines how multiple matches for each row/column combination are handled. |
293 | * Defaults to |
294 | * \l{QItemModelSurfaceDataProxy::MultiMatchBehavior::Last} |
295 | * {ItemModelSurfaceDataProxy.MultiMatchBehavior.Last}. |
296 | * |
297 | * For example, you might have an item model with timestamped data taken at |
298 | * irregular intervals and you want to visualize an average position of data |
299 | * items on each hour with a surface graph. This can be done by specifying row |
300 | * and column categories so that each surface point represents an hour, and |
301 | * setting multiMatchBehavior to |
302 | * \l{QItemModelSurfaceDataProxy::MultiMatchBehavior::Average} |
303 | * {ItemModelSurfaceDataProxy.MultiMatchBehavior.Average}. |
304 | */ |
305 | |
306 | /*! |
307 | \qmlsignal ItemModelSurfaceDataProxy::itemModelChanged(model itemModel) |
308 | |
309 | This signal is emitted when itemModel changes to \a itemModel. |
310 | */ |
311 | |
312 | /*! |
313 | \qmlsignal ItemModelSurfaceDataProxy::rowRoleChanged(string role) |
314 | |
315 | This signal is emitted when rowRole changes to \a role. |
316 | */ |
317 | |
318 | /*! |
319 | \qmlsignal ItemModelSurfaceDataProxy::columnRoleChanged(string role) |
320 | |
321 | This signal is emitted when columnRole changes to \a role. |
322 | */ |
323 | |
324 | /*! |
325 | \qmlsignal ItemModelSurfaceDataProxy::xPosRoleChanged(string role) |
326 | |
327 | This signal is emitted when xPosRole changes to \a role. |
328 | */ |
329 | |
330 | /*! |
331 | \qmlsignal ItemModelSurfaceDataProxy::yPosRoleChanged(string role) |
332 | |
333 | This signal is emitted when yPosRole changes to \a role. |
334 | */ |
335 | |
336 | /*! |
337 | \qmlsignal ItemModelSurfaceDataProxy::zPosRoleChanged(string role) |
338 | |
339 | This signal is emitted when zPosRole changes to \a role. |
340 | */ |
341 | |
342 | /*! |
343 | \qmlsignal ItemModelSurfaceDataProxy::rowCategoriesChanged() |
344 | |
345 | This signal is emitted when rowCategories changes. |
346 | */ |
347 | |
348 | /*! |
349 | \qmlsignal ItemModelSurfaceDataProxy::columnCategoriesChanged() |
350 | |
351 | This signal is emitted when columnCategories changes. |
352 | */ |
353 | |
354 | /*! |
355 | \qmlsignal ItemModelSurfaceDataProxy::useModelCategoriesChanged(bool enable) |
356 | |
357 | This signal is emitted when useModelCategories changes to \a enable. |
358 | */ |
359 | |
360 | /*! |
361 | \qmlsignal ItemModelSurfaceDataProxy::autoRowCategoriesChanged(bool enable) |
362 | |
363 | This signal is emitted when autoRowCategories changes to \a enable. |
364 | */ |
365 | |
366 | /*! |
367 | \qmlsignal ItemModelSurfaceDataProxy::autoColumnCategoriesChanged(bool enable) |
368 | |
369 | This signal is emitted when autoColumnCategories changes to \a enable. |
370 | */ |
371 | |
372 | /*! |
373 | \qmlsignal ItemModelSurfaceDataProxy::rowRolePatternChanged(regExp pattern) |
374 | |
375 | This signal is emitted when rowRolePattern changes to \a pattern. |
376 | */ |
377 | |
378 | /*! |
379 | \qmlsignal ItemModelSurfaceDataProxy::columnRolePatternChanged(regExp pattern) |
380 | |
381 | This signal is emitted when columnRolePattern changes to \a pattern. |
382 | */ |
383 | |
384 | /*! |
385 | \qmlsignal ItemModelSurfaceDataProxy::xPosRolePatternChanged(regExp pattern) |
386 | |
387 | This signal is emitted when xPosRolePattern changes to \a pattern. |
388 | */ |
389 | |
390 | /*! |
391 | \qmlsignal ItemModelSurfaceDataProxy::yPosRolePatternChanged(regExp pattern) |
392 | |
393 | This signal is emitted when yPosRolePattern changes to \a pattern. |
394 | */ |
395 | |
396 | /*! |
397 | \qmlsignal ItemModelSurfaceDataProxy::zPosRolePatternChanged(regExp pattern) |
398 | |
399 | This signal is emitted when zPosRolePattern changes to \a pattern. |
400 | */ |
401 | |
402 | /*! |
403 | \qmlsignal ItemModelSurfaceDataProxy::rowRoleReplaceChanged(string replace) |
404 | |
405 | This signal is emitted when rowRoleReplace changes to \a replace. |
406 | */ |
407 | |
408 | /*! |
409 | \qmlsignal ItemModelSurfaceDataProxy::columnRoleReplaceChanged(string replace) |
410 | |
411 | This signal is emitted when columnRoleReplace changes to \a replace. |
412 | */ |
413 | |
414 | /*! |
415 | \qmlsignal ItemModelSurfaceDataProxy::xPosRoleReplaceChanged(string replace) |
416 | |
417 | This signal is emitted when xPosRoleReplace changes to \a replace. |
418 | */ |
419 | |
420 | /*! |
421 | \qmlsignal ItemModelSurfaceDataProxy::yPosRoleReplaceChanged(string replace) |
422 | |
423 | This signal is emitted when yPosRoleReplace changes to \a replace. |
424 | */ |
425 | |
426 | /*! |
427 | \qmlsignal ItemModelSurfaceDataProxy::zPosRoleReplaceChanged(string replace) |
428 | |
429 | This signal is emitted when zPosRoleReplace changes to \a replace. |
430 | */ |
431 | |
432 | /*! |
433 | \qmlsignal ItemModelSurfaceDataProxy::multiMatchBehaviorChanged(enumeration behavior) |
434 | |
435 | This signal is emitted when multiMatchBehavior changes to \a behavior. |
436 | */ |
437 | |
438 | /*! |
439 | * \enum QItemModelSurfaceDataProxy::MultiMatchBehavior |
440 | * |
441 | * Behavior types for QItemModelSurfaceDataProxy::multiMatchBehavior property. |
442 | * |
443 | * \value First |
444 | * The position values are taken from the first item in the item model that matches |
445 | * each row/column combination. |
446 | * \value Last |
447 | * The position values are taken from the last item in the item model that matches |
448 | * each row/column combination. |
449 | * \value Average |
450 | * The position values from all items matching each row/column combination are |
451 | * averaged together and the averages are used as the surface point position. |
452 | * \value CumulativeY |
453 | * For X and Z values this acts just like \c{Average}, but Y values are added together |
454 | * instead of averaged and the total is used as the surface point Y position. |
455 | */ |
456 | |
457 | /*! |
458 | * Constructs QItemModelSurfaceDataProxy with an optional \a parent. |
459 | */ |
460 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QObject *parent) |
461 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
462 | { |
463 | Q_D(QItemModelSurfaceDataProxy); |
464 | d->connectItemModelHandler(); |
465 | } |
466 | |
467 | /*! |
468 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
469 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
470 | * models are owned by other controls. |
471 | */ |
472 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
473 | QObject *parent) |
474 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
475 | { |
476 | Q_D(QItemModelSurfaceDataProxy); |
477 | d->m_itemModelHandler->setItemModel(itemModel); |
478 | d->connectItemModelHandler(); |
479 | } |
480 | |
481 | /*! |
482 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
483 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
484 | * models are owned by other controls. The yPosRole role is set to \a yPosRole. |
485 | * This constructor is meant to be used with models that have data properly |
486 | * sorted in rows and columns already, so it also sets useModelCategories |
487 | * property to \c true. |
488 | */ |
489 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
490 | const QString &yPosRole, |
491 | QObject *parent) |
492 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
493 | { |
494 | Q_D(QItemModelSurfaceDataProxy); |
495 | d->m_itemModelHandler->setItemModel(itemModel); |
496 | d->m_yPosRole = yPosRole; |
497 | d->m_useModelCategories = true; |
498 | d->connectItemModelHandler(); |
499 | } |
500 | |
501 | /*! |
502 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
503 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
504 | * models are owned by other controls. The role mappings are set with \a rowRole, |
505 | * \a columnRole, and \a yPosRole. The zPosRole and the xPosRole are |
506 | * set to \a rowRole and \a columnRole, respectively. |
507 | */ |
508 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
509 | const QString &rowRole, |
510 | const QString &columnRole, |
511 | const QString &yPosRole, |
512 | QObject *parent) |
513 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
514 | { |
515 | Q_D(QItemModelSurfaceDataProxy); |
516 | d->m_itemModelHandler->setItemModel(itemModel); |
517 | d->m_rowRole = rowRole; |
518 | d->m_columnRole = columnRole; |
519 | d->m_xPosRole = columnRole; |
520 | d->m_yPosRole = yPosRole; |
521 | d->m_zPosRole = rowRole; |
522 | d->connectItemModelHandler(); |
523 | } |
524 | |
525 | /*! |
526 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
527 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
528 | * models are owned by other controls. The role mappings are set with \a rowRole, |
529 | * \a columnRole, \a xPosRole, \a yPosRole, and \a zPosRole. |
530 | */ |
531 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
532 | const QString &rowRole, |
533 | const QString &columnRole, |
534 | const QString &xPosRole, |
535 | const QString &yPosRole, |
536 | const QString &zPosRole, |
537 | QObject *parent) |
538 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
539 | { |
540 | Q_D(QItemModelSurfaceDataProxy); |
541 | d->m_itemModelHandler->setItemModel(itemModel); |
542 | d->m_rowRole = rowRole; |
543 | d->m_columnRole = columnRole; |
544 | d->m_xPosRole = xPosRole; |
545 | d->m_yPosRole = yPosRole; |
546 | d->m_zPosRole = zPosRole; |
547 | d->connectItemModelHandler(); |
548 | } |
549 | |
550 | /*! |
551 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
552 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
553 | * models are owned by other controls. The role mappings are set with \a rowRole, |
554 | * \a columnRole, and \a yPosRole. The zPosRole and the xPosRole are |
555 | * set to \a rowRole and \a columnRole, respectively. Row and column categories |
556 | * are set with \a rowCategories and \a columnCategories. This constructor also |
557 | * sets autoRowCategories and autoColumnCategories to false. |
558 | */ |
559 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
560 | const QString &rowRole, |
561 | const QString &columnRole, |
562 | const QString &yPosRole, |
563 | const QStringList &rowCategories, |
564 | const QStringList &columnCategories, |
565 | QObject *parent) |
566 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
567 | { |
568 | Q_D(QItemModelSurfaceDataProxy); |
569 | d->m_itemModelHandler->setItemModel(itemModel); |
570 | d->m_rowRole = rowRole; |
571 | d->m_columnRole = columnRole; |
572 | d->m_xPosRole = columnRole; |
573 | d->m_yPosRole = yPosRole; |
574 | d->m_zPosRole = rowRole; |
575 | d->m_rowCategories = rowCategories; |
576 | d->m_columnCategories = columnCategories; |
577 | d->m_autoRowCategories = false; |
578 | d->m_autoColumnCategories = false; |
579 | d->connectItemModelHandler(); |
580 | } |
581 | |
582 | /*! |
583 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
584 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
585 | * models are owned by other controls. The role mappings are set with \a rowRole, |
586 | * \a columnRole, \a xPosRole, \a yPosRole, and \a zPosRole. Row and |
587 | * column categories are set with \a rowCategories and \a columnCategories. This |
588 | * constructor also sets autoRowCategories and autoColumnCategories to false. |
589 | */ |
590 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
591 | const QString &rowRole, |
592 | const QString &columnRole, |
593 | const QString &xPosRole, |
594 | const QString &yPosRole, |
595 | const QString &zPosRole, |
596 | const QStringList &rowCategories, |
597 | const QStringList &columnCategories, |
598 | QObject *parent) |
599 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
600 | { |
601 | Q_D(QItemModelSurfaceDataProxy); |
602 | d->m_itemModelHandler->setItemModel(itemModel); |
603 | d->m_rowRole = rowRole; |
604 | d->m_columnRole = columnRole; |
605 | d->m_xPosRole = xPosRole; |
606 | d->m_yPosRole = yPosRole; |
607 | d->m_zPosRole = zPosRole; |
608 | d->m_rowCategories = rowCategories; |
609 | d->m_columnCategories = columnCategories; |
610 | d->m_autoRowCategories = false; |
611 | d->m_autoColumnCategories = false; |
612 | d->connectItemModelHandler(); |
613 | } |
614 | |
615 | /*! |
616 | * Destroys QItemModelSurfaceDataProxy. |
617 | */ |
618 | QItemModelSurfaceDataProxy::~QItemModelSurfaceDataProxy() {} |
619 | |
620 | /*! |
621 | * \property QItemModelSurfaceDataProxy::itemModel |
622 | * |
623 | * \brief The item model used as a data source for the 3D surface. |
624 | */ |
625 | |
626 | /*! |
627 | * Sets the item model to \a itemModel. Does not take ownership of the model, |
628 | * but does connect to it to listen for changes. |
629 | */ |
630 | void QItemModelSurfaceDataProxy::setItemModel(QAbstractItemModel *itemModel) |
631 | { |
632 | Q_D(QItemModelSurfaceDataProxy); |
633 | d->m_itemModelHandler->setItemModel(itemModel); |
634 | } |
635 | |
636 | QAbstractItemModel *QItemModelSurfaceDataProxy::itemModel() const |
637 | { |
638 | Q_D(const QItemModelSurfaceDataProxy); |
639 | return d->m_itemModelHandler->itemModel(); |
640 | } |
641 | |
642 | /*! |
643 | * \property QItemModelSurfaceDataProxy::rowRole |
644 | * |
645 | * \brief The item model role to map to the row category. |
646 | * |
647 | * In addition to defining which row the data belongs to, the value indicated by |
648 | * the row role is also set as the Z-coordinate value of QSurfaceDataItem when |
649 | * model data is resolved, unless a separate z-position role is also defined. |
650 | */ |
651 | void QItemModelSurfaceDataProxy::setRowRole(const QString &role) |
652 | { |
653 | Q_D(QItemModelSurfaceDataProxy); |
654 | if (d->m_rowRole != role) { |
655 | d->m_rowRole = role; |
656 | emit rowRoleChanged(role); |
657 | } |
658 | } |
659 | |
660 | QString QItemModelSurfaceDataProxy::rowRole() const |
661 | { |
662 | Q_D(const QItemModelSurfaceDataProxy); |
663 | return d->m_rowRole; |
664 | } |
665 | |
666 | /*! |
667 | * \property QItemModelSurfaceDataProxy::columnRole |
668 | * |
669 | * \brief The item model role to map to the column category. |
670 | * |
671 | * In addition to defining which column the data belongs to, the value indicated |
672 | * by the column role is also set as the X-coordinate value of QSurfaceDataItem |
673 | * when model data is resolved, unless a separate x-position role is also |
674 | * defined. |
675 | */ |
676 | void QItemModelSurfaceDataProxy::setColumnRole(const QString &role) |
677 | { |
678 | Q_D(QItemModelSurfaceDataProxy); |
679 | if (d->m_columnRole != role) { |
680 | d->m_columnRole = role; |
681 | emit columnRoleChanged(role); |
682 | } |
683 | } |
684 | |
685 | QString QItemModelSurfaceDataProxy::columnRole() const |
686 | { |
687 | Q_D(const QItemModelSurfaceDataProxy); |
688 | return d->m_columnRole; |
689 | } |
690 | |
691 | /*! |
692 | * \property QItemModelSurfaceDataProxy::xPosRole |
693 | * |
694 | * \brief The item model role to map to the X position. |
695 | * |
696 | * If this role is not defined, columnRole is used to determine the X-coordinate |
697 | * value of the resolved \l{QSurfaceDataItem} objects. |
698 | */ |
699 | void QItemModelSurfaceDataProxy::setXPosRole(const QString &role) |
700 | { |
701 | Q_D(QItemModelSurfaceDataProxy); |
702 | if (d->m_xPosRole != role) { |
703 | d->m_xPosRole = role; |
704 | emit xPosRoleChanged(role); |
705 | } |
706 | } |
707 | |
708 | QString QItemModelSurfaceDataProxy::xPosRole() const |
709 | { |
710 | Q_D(const QItemModelSurfaceDataProxy); |
711 | return d->m_xPosRole; |
712 | } |
713 | |
714 | /*! |
715 | * \property QItemModelSurfaceDataProxy::yPosRole |
716 | * |
717 | * \brief The item model role to map to the Y position. |
718 | */ |
719 | void QItemModelSurfaceDataProxy::setYPosRole(const QString &role) |
720 | { |
721 | Q_D(QItemModelSurfaceDataProxy); |
722 | if (d->m_yPosRole != role) { |
723 | d->m_yPosRole = role; |
724 | emit yPosRoleChanged(role); |
725 | } |
726 | } |
727 | |
728 | QString QItemModelSurfaceDataProxy::yPosRole() const |
729 | { |
730 | Q_D(const QItemModelSurfaceDataProxy); |
731 | return d->m_yPosRole; |
732 | } |
733 | |
734 | /*! |
735 | * \property QItemModelSurfaceDataProxy::zPosRole |
736 | * |
737 | * \brief The item model role to map to the Z position. |
738 | * |
739 | * If this role is not defined, rowRole is used to determine the Z-coordinate |
740 | * value of resolved \l{QSurfaceDataItem} objects. |
741 | */ |
742 | void QItemModelSurfaceDataProxy::setZPosRole(const QString &role) |
743 | { |
744 | Q_D(QItemModelSurfaceDataProxy); |
745 | if (d->m_zPosRole != role) { |
746 | d->m_zPosRole = role; |
747 | emit zPosRoleChanged(role); |
748 | } |
749 | } |
750 | |
751 | QString QItemModelSurfaceDataProxy::zPosRole() const |
752 | { |
753 | Q_D(const QItemModelSurfaceDataProxy); |
754 | return d->m_zPosRole; |
755 | } |
756 | |
757 | /*! |
758 | * \property QItemModelSurfaceDataProxy::rowCategories |
759 | * |
760 | * \brief The row categories for the mapping. |
761 | */ |
762 | void QItemModelSurfaceDataProxy::setRowCategories(const QStringList &categories) |
763 | { |
764 | Q_D(QItemModelSurfaceDataProxy); |
765 | if (d->m_rowCategories != categories) { |
766 | d->m_rowCategories = categories; |
767 | emit rowCategoriesChanged(); |
768 | } |
769 | } |
770 | |
771 | QStringList QItemModelSurfaceDataProxy::rowCategories() const |
772 | { |
773 | Q_D(const QItemModelSurfaceDataProxy); |
774 | return d->m_rowCategories; |
775 | } |
776 | |
777 | /*! |
778 | * \property QItemModelSurfaceDataProxy::columnCategories |
779 | * |
780 | * \brief The column categories for the mapping. |
781 | */ |
782 | void QItemModelSurfaceDataProxy::setColumnCategories(const QStringList &categories) |
783 | { |
784 | Q_D(QItemModelSurfaceDataProxy); |
785 | if (d->m_columnCategories != categories) { |
786 | d->m_columnCategories = categories; |
787 | emit columnCategoriesChanged(); |
788 | } |
789 | } |
790 | |
791 | QStringList QItemModelSurfaceDataProxy::columnCategories() const |
792 | { |
793 | Q_D(const QItemModelSurfaceDataProxy); |
794 | return d->m_columnCategories; |
795 | } |
796 | |
797 | /*! |
798 | * \property QItemModelSurfaceDataProxy::useModelCategories |
799 | * |
800 | * \brief Whether row and column roles and categories are used for mapping. |
801 | * |
802 | * When set to \c true, the mapping ignores row and column roles and categories, |
803 | * and uses the rows and columns from the model instead. Defaults to \c{false}. |
804 | */ |
805 | void QItemModelSurfaceDataProxy::setUseModelCategories(bool enable) |
806 | { |
807 | Q_D(QItemModelSurfaceDataProxy); |
808 | if (d->m_useModelCategories != enable) { |
809 | d->m_useModelCategories = enable; |
810 | emit useModelCategoriesChanged(enable); |
811 | } |
812 | } |
813 | |
814 | bool QItemModelSurfaceDataProxy::useModelCategories() const |
815 | { |
816 | Q_D(const QItemModelSurfaceDataProxy); |
817 | return d->m_useModelCategories; |
818 | } |
819 | |
820 | /*! |
821 | * \property QItemModelSurfaceDataProxy::autoRowCategories |
822 | * |
823 | * \brief Whether row categories are generated automatically. |
824 | * |
825 | * When set to \c true, the mapping ignores any explicitly set row categories |
826 | * and overwrites them with automatically generated ones whenever the |
827 | * data from the model is resolved. Defaults to \c{true}. |
828 | */ |
829 | void QItemModelSurfaceDataProxy::setAutoRowCategories(bool enable) |
830 | { |
831 | Q_D(QItemModelSurfaceDataProxy); |
832 | if (d->m_autoRowCategories != enable) { |
833 | d->m_autoRowCategories = enable; |
834 | emit autoRowCategoriesChanged(enable); |
835 | } |
836 | } |
837 | |
838 | bool QItemModelSurfaceDataProxy::autoRowCategories() const |
839 | { |
840 | Q_D(const QItemModelSurfaceDataProxy); |
841 | return d->m_autoRowCategories; |
842 | } |
843 | |
844 | /*! |
845 | * \property QItemModelSurfaceDataProxy::autoColumnCategories |
846 | * |
847 | * \brief Whether column categories are generated automatically. |
848 | * |
849 | * When set to \c true, the mapping ignores any explicitly set column categories |
850 | * and overwrites them with automatically generated ones whenever the |
851 | * data from the model is resolved. Defaults to \c{true}. |
852 | */ |
853 | void QItemModelSurfaceDataProxy::setAutoColumnCategories(bool enable) |
854 | { |
855 | Q_D(QItemModelSurfaceDataProxy); |
856 | if (d->m_autoColumnCategories != enable) { |
857 | d->m_autoColumnCategories = enable; |
858 | emit autoColumnCategoriesChanged(enable); |
859 | } |
860 | } |
861 | |
862 | bool QItemModelSurfaceDataProxy::autoColumnCategories() const |
863 | { |
864 | Q_D(const QItemModelSurfaceDataProxy); |
865 | return d->m_autoColumnCategories; |
866 | } |
867 | |
868 | /*! |
869 | * Changes \a rowRole, \a columnRole, \a xPosRole, \a yPosRole, \a zPosRole, |
870 | * \a rowCategories and \a columnCategories to the mapping. |
871 | */ |
872 | void QItemModelSurfaceDataProxy::remap(const QString &rowRole, |
873 | const QString &columnRole, |
874 | const QString &xPosRole, |
875 | const QString &yPosRole, |
876 | const QString &zPosRole, |
877 | const QStringList &rowCategories, |
878 | const QStringList &columnCategories) |
879 | { |
880 | setRowRole(rowRole); |
881 | setColumnRole(columnRole); |
882 | setXPosRole(xPosRole); |
883 | setYPosRole(yPosRole); |
884 | setZPosRole(zPosRole); |
885 | setRowCategories(rowCategories); |
886 | setColumnCategories(columnCategories); |
887 | } |
888 | |
889 | /*! |
890 | * Returns the index of the specified \a category in the row categories list. |
891 | * If the row categories list is empty, -1 is returned. |
892 | * \note If the automatic row categories generation is in use, this method will |
893 | * not return a valid index before the data in the model is resolved for the |
894 | * first time. |
895 | */ |
896 | qsizetype QItemModelSurfaceDataProxy::rowCategoryIndex(const QString &category) |
897 | { |
898 | Q_D(QItemModelSurfaceDataProxy); |
899 | return d->m_rowCategories.indexOf(str: category); |
900 | } |
901 | |
902 | /*! |
903 | * Returns the index of the specified \a category in the column categories list. |
904 | * If the category is not found, -1 is returned. |
905 | * \note If the automatic column categories generation is in use, this method |
906 | * will not return a valid index before the data in the model is resolved for |
907 | * the first time. |
908 | */ |
909 | qsizetype QItemModelSurfaceDataProxy::columnCategoryIndex(const QString &category) |
910 | { |
911 | Q_D(QItemModelSurfaceDataProxy); |
912 | return d->m_columnCategories.indexOf(str: category); |
913 | } |
914 | |
915 | /*! |
916 | * \property QItemModelSurfaceDataProxy::rowRolePattern |
917 | * |
918 | * \brief Whether a search and replace is performed on the value mapped by the |
919 | * row role before it is used as a row category. |
920 | * |
921 | * This property specifies the regular expression to find the portion of the |
922 | * mapped value to replace and the rowRoleReplace property contains the |
923 | * replacement string. |
924 | * |
925 | * \sa rowRole, rowRoleReplace |
926 | */ |
927 | void QItemModelSurfaceDataProxy::setRowRolePattern(const QRegularExpression &pattern) |
928 | { |
929 | Q_D(QItemModelSurfaceDataProxy); |
930 | if (d->m_rowRolePattern != pattern) { |
931 | d->m_rowRolePattern = pattern; |
932 | emit rowRolePatternChanged(pattern); |
933 | } |
934 | } |
935 | |
936 | QRegularExpression QItemModelSurfaceDataProxy::rowRolePattern() const |
937 | { |
938 | Q_D(const QItemModelSurfaceDataProxy); |
939 | return d->m_rowRolePattern; |
940 | } |
941 | |
942 | /*! |
943 | * \property QItemModelSurfaceDataProxy::columnRolePattern |
944 | * |
945 | * \brief Whether a search and replace is done on the value mapped by the column |
946 | * role before it is used as a column category. |
947 | * |
948 | * This property specifies the regular expression to find the portion of the |
949 | * mapped value to replace and the columnRoleReplace property contains the |
950 | * replacement string. |
951 | * |
952 | * \sa columnRole, columnRoleReplace |
953 | */ |
954 | void QItemModelSurfaceDataProxy::setColumnRolePattern(const QRegularExpression &pattern) |
955 | { |
956 | Q_D(QItemModelSurfaceDataProxy); |
957 | if (d->m_columnRolePattern != pattern) { |
958 | d->m_columnRolePattern = pattern; |
959 | emit columnRolePatternChanged(pattern); |
960 | } |
961 | } |
962 | |
963 | QRegularExpression QItemModelSurfaceDataProxy::columnRolePattern() const |
964 | { |
965 | Q_D(const QItemModelSurfaceDataProxy); |
966 | return d->m_columnRolePattern; |
967 | } |
968 | |
969 | /*! |
970 | * \property QItemModelSurfaceDataProxy::xPosRolePattern |
971 | * |
972 | * \brief Whether a search and replace is done on the value mapped by the x |
973 | * position role before it is used as an item position value. |
974 | * |
975 | * This property specifies the regular expression to find the portion of the |
976 | * mapped value to replace and the xPosRoleReplace property contains the |
977 | * replacement string. |
978 | * |
979 | * \sa xPosRole, xPosRoleReplace |
980 | */ |
981 | void QItemModelSurfaceDataProxy::setXPosRolePattern(const QRegularExpression &pattern) |
982 | { |
983 | Q_D(QItemModelSurfaceDataProxy); |
984 | if (d->m_xPosRolePattern != pattern) { |
985 | d->m_xPosRolePattern = pattern; |
986 | emit xPosRolePatternChanged(pattern); |
987 | } |
988 | } |
989 | |
990 | QRegularExpression QItemModelSurfaceDataProxy::xPosRolePattern() const |
991 | { |
992 | Q_D(const QItemModelSurfaceDataProxy); |
993 | return d->m_xPosRolePattern; |
994 | } |
995 | |
996 | /*! |
997 | * \property QItemModelSurfaceDataProxy::yPosRolePattern |
998 | * |
999 | * \brief Whether a search and replace is done on the value mapped by the y |
1000 | * position role before it is used as an item position value. |
1001 | * |
1002 | * This property specifies the regular expression to find the portion of the |
1003 | * mapped value to replace and the yPosRoleReplace property contains the |
1004 | * replacement string. |
1005 | * |
1006 | * \sa yPosRole, yPosRoleReplace |
1007 | */ |
1008 | void QItemModelSurfaceDataProxy::setYPosRolePattern(const QRegularExpression &pattern) |
1009 | { |
1010 | Q_D(QItemModelSurfaceDataProxy); |
1011 | if (d->m_yPosRolePattern != pattern) { |
1012 | d->m_yPosRolePattern = pattern; |
1013 | emit yPosRolePatternChanged(pattern); |
1014 | } |
1015 | } |
1016 | |
1017 | QRegularExpression QItemModelSurfaceDataProxy::yPosRolePattern() const |
1018 | { |
1019 | Q_D(const QItemModelSurfaceDataProxy); |
1020 | return d->m_yPosRolePattern; |
1021 | } |
1022 | |
1023 | /*! |
1024 | * \property QItemModelSurfaceDataProxy::zPosRolePattern |
1025 | * |
1026 | * \brief Whether a search and replace is done on the value mapped by the z |
1027 | * position role before it is used as an item position value. |
1028 | * |
1029 | * This property specifies the regular expression to find the portion of the |
1030 | * mapped value to replace and the zPosRoleReplace property contains the |
1031 | * replacement string. |
1032 | * |
1033 | * \sa zPosRole, zPosRoleReplace |
1034 | */ |
1035 | void QItemModelSurfaceDataProxy::setZPosRolePattern(const QRegularExpression &pattern) |
1036 | { |
1037 | Q_D(QItemModelSurfaceDataProxy); |
1038 | if (d->m_zPosRolePattern != pattern) { |
1039 | d->m_zPosRolePattern = pattern; |
1040 | emit zPosRolePatternChanged(pattern); |
1041 | } |
1042 | } |
1043 | |
1044 | QRegularExpression QItemModelSurfaceDataProxy::zPosRolePattern() const |
1045 | { |
1046 | Q_D(const QItemModelSurfaceDataProxy); |
1047 | return d->m_zPosRolePattern; |
1048 | } |
1049 | |
1050 | /*! |
1051 | * \property QItemModelSurfaceDataProxy::rowRoleReplace |
1052 | * |
1053 | * \brief The replacement content to be used in conjunction with the row role |
1054 | * pattern. |
1055 | * |
1056 | * Defaults to an empty string. For more information on how the search and |
1057 | * replace using regular expressions works, see QString::replace(const |
1058 | * QRegularExpression &rx, const QString &after) function documentation. |
1059 | * |
1060 | * \sa rowRole, rowRolePattern |
1061 | */ |
1062 | void QItemModelSurfaceDataProxy::setRowRoleReplace(const QString &replace) |
1063 | { |
1064 | Q_D(QItemModelSurfaceDataProxy); |
1065 | if (d->m_rowRoleReplace != replace) { |
1066 | d->m_rowRoleReplace = replace; |
1067 | emit rowRoleReplaceChanged(replace); |
1068 | } |
1069 | } |
1070 | |
1071 | QString QItemModelSurfaceDataProxy::rowRoleReplace() const |
1072 | { |
1073 | Q_D(const QItemModelSurfaceDataProxy); |
1074 | return d->m_rowRoleReplace; |
1075 | } |
1076 | |
1077 | /*! |
1078 | * \property QItemModelSurfaceDataProxy::columnRoleReplace |
1079 | * |
1080 | * \brief The replacement content to be used in conjunction with a column role |
1081 | * pattern. |
1082 | * |
1083 | * Defaults to an empty string. For more information on how the search and |
1084 | * replace using regular expressions works, see the |
1085 | * QString::replace(const QRegularExpression &rx, const QString &after) |
1086 | * function documentation. |
1087 | * |
1088 | * \sa columnRole, columnRolePattern |
1089 | */ |
1090 | void QItemModelSurfaceDataProxy::setColumnRoleReplace(const QString &replace) |
1091 | { |
1092 | Q_D(QItemModelSurfaceDataProxy); |
1093 | if (d->m_columnRoleReplace != replace) { |
1094 | d->m_columnRoleReplace = replace; |
1095 | emit columnRoleReplaceChanged(replace); |
1096 | } |
1097 | } |
1098 | |
1099 | QString QItemModelSurfaceDataProxy::columnRoleReplace() const |
1100 | { |
1101 | Q_D(const QItemModelSurfaceDataProxy); |
1102 | return d->m_columnRoleReplace; |
1103 | } |
1104 | |
1105 | /*! |
1106 | * \property QItemModelSurfaceDataProxy::xPosRoleReplace |
1107 | * |
1108 | * \brief The replacement content to be used in conjunction with an x position role |
1109 | * pattern. |
1110 | * |
1111 | * Defaults to an empty string. For more information on how the search and |
1112 | * replace using regular expressions works, see the |
1113 | * QString::replace(const QRegularExpression &rx, const QString &after) |
1114 | * function documentation. |
1115 | * |
1116 | * \sa xPosRole, xPosRolePattern |
1117 | */ |
1118 | void QItemModelSurfaceDataProxy::setXPosRoleReplace(const QString &replace) |
1119 | { |
1120 | Q_D(QItemModelSurfaceDataProxy); |
1121 | if (d->m_xPosRoleReplace != replace) { |
1122 | d->m_xPosRoleReplace = replace; |
1123 | emit xPosRoleReplaceChanged(replace); |
1124 | } |
1125 | } |
1126 | |
1127 | QString QItemModelSurfaceDataProxy::xPosRoleReplace() const |
1128 | { |
1129 | Q_D(const QItemModelSurfaceDataProxy); |
1130 | return d->m_xPosRoleReplace; |
1131 | } |
1132 | |
1133 | /*! |
1134 | * \property QItemModelSurfaceDataProxy::yPosRoleReplace |
1135 | * |
1136 | * \brief The replacement content to be used in conjunction with an y position role |
1137 | * pattern. |
1138 | * |
1139 | * Defaults to an empty string. For more information on how the search and |
1140 | * replace using regular expressions works, see the |
1141 | * QString::replace(const QRegularExpression &rx, const QString &after) |
1142 | * function documentation. |
1143 | * |
1144 | * \sa yPosRole, yPosRolePattern |
1145 | */ |
1146 | void QItemModelSurfaceDataProxy::setYPosRoleReplace(const QString &replace) |
1147 | { |
1148 | Q_D(QItemModelSurfaceDataProxy); |
1149 | if (d->m_yPosRoleReplace != replace) { |
1150 | d->m_yPosRoleReplace = replace; |
1151 | emit yPosRoleReplaceChanged(replace); |
1152 | } |
1153 | } |
1154 | |
1155 | QString QItemModelSurfaceDataProxy::yPosRoleReplace() const |
1156 | { |
1157 | Q_D(const QItemModelSurfaceDataProxy); |
1158 | return d->m_yPosRoleReplace; |
1159 | } |
1160 | |
1161 | /*! |
1162 | * \property QItemModelSurfaceDataProxy::zPosRoleReplace |
1163 | * |
1164 | * \brief The replacement content to be used in conjunction with a z position role |
1165 | * pattern. |
1166 | * |
1167 | * Defaults to an empty string. For more information on how the search and |
1168 | * replace using regular expressions works, see the |
1169 | * QString::replace(const QRegularExpression &rx, const QString &after) |
1170 | * function documentation. |
1171 | * |
1172 | * \sa zPosRole, zPosRolePattern |
1173 | */ |
1174 | void QItemModelSurfaceDataProxy::setZPosRoleReplace(const QString &replace) |
1175 | { |
1176 | Q_D(QItemModelSurfaceDataProxy); |
1177 | if (d->m_zPosRoleReplace != replace) { |
1178 | d->m_zPosRoleReplace = replace; |
1179 | emit zPosRoleReplaceChanged(replace); |
1180 | } |
1181 | } |
1182 | |
1183 | QString QItemModelSurfaceDataProxy::zPosRoleReplace() const |
1184 | { |
1185 | Q_D(const QItemModelSurfaceDataProxy); |
1186 | return d->m_zPosRoleReplace; |
1187 | } |
1188 | |
1189 | /*! |
1190 | * \property QItemModelSurfaceDataProxy::multiMatchBehavior |
1191 | * |
1192 | * \brief How multiple matches for each row/column combination are handled. |
1193 | * |
1194 | * Defaults to Last. |
1195 | * |
1196 | * For example, you might have an item model with timestamped data taken at |
1197 | * irregular intervals and you want to visualize an average position of data |
1198 | * items on each hour with a surface graph. This can be done by specifying row |
1199 | * and column categories so that each surface point represents an hour, and |
1200 | * setting this property to Average. |
1201 | */ |
1202 | |
1203 | void QItemModelSurfaceDataProxy::setMultiMatchBehavior( |
1204 | QItemModelSurfaceDataProxy::MultiMatchBehavior behavior) |
1205 | { |
1206 | Q_D(QItemModelSurfaceDataProxy); |
1207 | if (d->m_multiMatchBehavior != behavior) { |
1208 | d->m_multiMatchBehavior = behavior; |
1209 | emit multiMatchBehaviorChanged(behavior); |
1210 | } |
1211 | } |
1212 | |
1213 | QItemModelSurfaceDataProxy::MultiMatchBehavior QItemModelSurfaceDataProxy::multiMatchBehavior() const |
1214 | { |
1215 | Q_D(const QItemModelSurfaceDataProxy); |
1216 | return d->m_multiMatchBehavior; |
1217 | } |
1218 | |
1219 | // QItemModelSurfaceDataProxyPrivate |
1220 | |
1221 | QItemModelSurfaceDataProxyPrivate::QItemModelSurfaceDataProxyPrivate(QItemModelSurfaceDataProxy *q) |
1222 | : m_itemModelHandler(new SurfaceItemModelHandler(q)) |
1223 | , m_useModelCategories(false) |
1224 | , m_autoRowCategories(true) |
1225 | , m_autoColumnCategories(true) |
1226 | , m_multiMatchBehavior(QItemModelSurfaceDataProxy::MultiMatchBehavior::Last) |
1227 | {} |
1228 | |
1229 | QItemModelSurfaceDataProxyPrivate::~QItemModelSurfaceDataProxyPrivate() |
1230 | { |
1231 | delete m_itemModelHandler; |
1232 | } |
1233 | |
1234 | void QItemModelSurfaceDataProxyPrivate::connectItemModelHandler() |
1235 | { |
1236 | Q_Q(QItemModelSurfaceDataProxy); |
1237 | QObject::connect(sender: m_itemModelHandler, |
1238 | signal: &SurfaceItemModelHandler::itemModelChanged, |
1239 | context: q, |
1240 | slot: &QItemModelSurfaceDataProxy::itemModelChanged); |
1241 | QObject::connect(sender: q, |
1242 | signal: &QItemModelSurfaceDataProxy::rowRoleChanged, |
1243 | context: m_itemModelHandler, |
1244 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1245 | QObject::connect(sender: q, |
1246 | signal: &QItemModelSurfaceDataProxy::columnRoleChanged, |
1247 | context: m_itemModelHandler, |
1248 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1249 | QObject::connect(sender: q, |
1250 | signal: &QItemModelSurfaceDataProxy::xPosRoleChanged, |
1251 | context: m_itemModelHandler, |
1252 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1253 | QObject::connect(sender: q, |
1254 | signal: &QItemModelSurfaceDataProxy::yPosRoleChanged, |
1255 | context: m_itemModelHandler, |
1256 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1257 | QObject::connect(sender: q, |
1258 | signal: &QItemModelSurfaceDataProxy::zPosRoleChanged, |
1259 | context: m_itemModelHandler, |
1260 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1261 | QObject::connect(sender: q, |
1262 | signal: &QItemModelSurfaceDataProxy::rowCategoriesChanged, |
1263 | context: m_itemModelHandler, |
1264 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1265 | QObject::connect(sender: q, |
1266 | signal: &QItemModelSurfaceDataProxy::columnCategoriesChanged, |
1267 | context: m_itemModelHandler, |
1268 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1269 | QObject::connect(sender: q, |
1270 | signal: &QItemModelSurfaceDataProxy::useModelCategoriesChanged, |
1271 | context: m_itemModelHandler, |
1272 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1273 | QObject::connect(sender: q, |
1274 | signal: &QItemModelSurfaceDataProxy::autoRowCategoriesChanged, |
1275 | context: m_itemModelHandler, |
1276 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1277 | QObject::connect(sender: q, |
1278 | signal: &QItemModelSurfaceDataProxy::autoColumnCategoriesChanged, |
1279 | context: m_itemModelHandler, |
1280 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1281 | QObject::connect(sender: q, |
1282 | signal: &QItemModelSurfaceDataProxy::rowRolePatternChanged, |
1283 | context: m_itemModelHandler, |
1284 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1285 | QObject::connect(sender: q, |
1286 | signal: &QItemModelSurfaceDataProxy::columnRolePatternChanged, |
1287 | context: m_itemModelHandler, |
1288 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1289 | QObject::connect(sender: q, |
1290 | signal: &QItemModelSurfaceDataProxy::xPosRolePatternChanged, |
1291 | context: m_itemModelHandler, |
1292 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1293 | QObject::connect(sender: q, |
1294 | signal: &QItemModelSurfaceDataProxy::yPosRolePatternChanged, |
1295 | context: m_itemModelHandler, |
1296 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1297 | QObject::connect(sender: q, |
1298 | signal: &QItemModelSurfaceDataProxy::zPosRolePatternChanged, |
1299 | context: m_itemModelHandler, |
1300 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1301 | QObject::connect(sender: q, |
1302 | signal: &QItemModelSurfaceDataProxy::rowRoleReplaceChanged, |
1303 | context: m_itemModelHandler, |
1304 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1305 | QObject::connect(sender: q, |
1306 | signal: &QItemModelSurfaceDataProxy::columnRoleReplaceChanged, |
1307 | context: m_itemModelHandler, |
1308 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1309 | QObject::connect(sender: q, |
1310 | signal: &QItemModelSurfaceDataProxy::xPosRoleReplaceChanged, |
1311 | context: m_itemModelHandler, |
1312 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1313 | QObject::connect(sender: q, |
1314 | signal: &QItemModelSurfaceDataProxy::yPosRoleReplaceChanged, |
1315 | context: m_itemModelHandler, |
1316 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1317 | QObject::connect(sender: q, |
1318 | signal: &QItemModelSurfaceDataProxy::zPosRoleReplaceChanged, |
1319 | context: m_itemModelHandler, |
1320 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1321 | QObject::connect(sender: q, |
1322 | signal: &QItemModelSurfaceDataProxy::multiMatchBehaviorChanged, |
1323 | context: m_itemModelHandler, |
1324 | slot: &AbstractItemModelHandler::handleMappingChanged); |
1325 | } |
1326 | |
1327 | QT_END_NAMESPACE |
1328 |
Definitions
- QItemModelSurfaceDataProxy
- QItemModelSurfaceDataProxy
- QItemModelSurfaceDataProxy
- QItemModelSurfaceDataProxy
- QItemModelSurfaceDataProxy
- QItemModelSurfaceDataProxy
- QItemModelSurfaceDataProxy
- ~QItemModelSurfaceDataProxy
- setItemModel
- itemModel
- setRowRole
- rowRole
- setColumnRole
- columnRole
- setXPosRole
- xPosRole
- setYPosRole
- yPosRole
- setZPosRole
- zPosRole
- setRowCategories
- rowCategories
- setColumnCategories
- columnCategories
- setUseModelCategories
- useModelCategories
- setAutoRowCategories
- autoRowCategories
- setAutoColumnCategories
- autoColumnCategories
- remap
- rowCategoryIndex
- columnCategoryIndex
- setRowRolePattern
- rowRolePattern
- setColumnRolePattern
- columnRolePattern
- setXPosRolePattern
- xPosRolePattern
- setYPosRolePattern
- yPosRolePattern
- setZPosRolePattern
- zPosRolePattern
- setRowRoleReplace
- rowRoleReplace
- setColumnRoleReplace
- columnRoleReplace
- setXPosRoleReplace
- xPosRoleReplace
- setYPosRoleReplace
- yPosRoleReplace
- setZPosRoleReplace
- zPosRoleReplace
- setMultiMatchBehavior
- multiMatchBehavior
- QItemModelSurfaceDataProxyPrivate
- ~QItemModelSurfaceDataProxyPrivate
Learn to use CMake with our Intro Training
Find out more