summaryrefslogtreecommitdiffstats
path: root/src/graphs3d/data/qbardataproxy.cpp
blob: 2b637c66e56e0143e82091e0946fe4a935357dde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "qbar3dseries_p.h"
#include "qbardataproxy_p.h"

QT_BEGIN_NAMESPACE

/*!
 * \class QBarDataProxy
 * \inmodule QtGraphs
 * \ingroup graphs_3D
 * \brief The QBarDataProxy class is the data proxy for a 3D bars graph.
 *
 * A bar data proxy handles adding, inserting, changing, and removing rows of
 * data.
 *
 * The data array is a list of vectors (rows) of QBarDataItem instances.
 * Each row can contain a different number of items or even be null.
 *
 * QBarDataProxy takes ownership of all QtGraphs::QBarDataRow objects
 * passed to it, whether directly or in a QtGraphs::QBarDataArray container.
 * If bar data row pointers are used to directly modify data after adding the
 * array to the proxy, the appropriate signal must be emitted to update the
 * graph.
 *
 * QBarDataProxy optionally keeps track of row and column labels, which
 * QCategory3DAxis can utilize to show axis labels.
 *
 * The row and column labels are stored in a separate array from the data in the
 * series rather. Row processing methods are available in the proxy and provide
 * alternative versions that do not affect row labels. This enables
 * the option of having row labels that relate to the position of the data in
 * the array rather than the data itself. Since the series holds the data and
 * row and column labels, it is necessary to create a series associated with the
 * proxy before using these functions for them.
 *
 * \sa {Qt Graphs Data Handling with 3D}
 */

/*!
 * \typealias QBarDataRow
 * \relates QBarDataProxy
 *
 * A list of \l {QBarDataItem} objects.
 */

/*!
 * \typealias QBarDataArray
 * \relates QBarDataProxy
 *
 * A list of pointers to \l {QBarDataRow} objects.
 */

/*!
 * \qmltype BarDataProxy
 * \inqmlmodule QtGraphs
 * \ingroup graphs_qml_3D
 * \nativetype QBarDataProxy
 * \inherits AbstractDataProxy
 * \brief The data proxy for a 3D bars graph.
 *
 * This type handles adding, inserting, changing, and removing rows of data with
 * Qt Quick 2.
 *
 * This type cannot be instantiated, but contains properties that are exposed via
 * subtypes.
 *
 * For a more complete description, see QBarDataProxy.
 *
 * \sa ItemModelBarDataProxy, {Qt Graphs Data Handling with 3D}
 */

/*!
 * \qmlproperty int BarDataProxy::rowCount
 * The number of rows in the array.
 */

/*!
 * \qmlproperty int BarDataProxy::colCount
 * The number of columns in the array.
 */

/*!
 * \qmlproperty Bar3DSeries BarDataProxy::series
 *
 * The series this proxy is attached to.
 */

/*!
    \qmlsignal BarDataProxy::itemChanged(int rowIndex, int columnIndex)

    This signal is emitted when the item at the position specified by \a rowIndex
    and \a columnIndex changes.
    If the item is changed in the array without calling setItem(),
    this signal needs to be emitted to update the graph.
*/

/*!
    \qmlsignal BarDataProxy::rowCountChanged(int count)

    This signal is emitted when rowCount changes to \a count.
*/

/*!
    \qmlsignal BarDataProxy::colCountChanged(int count)

    This signal is emitted when colCount changes to \a count.
*/

/*!
    \qmlsignal BarDataProxy::seriesChanged(Bar3DSeries series)

    This signal is emitted when \l series changes to \a series.
*/

/*!
 * Constructs a bar data proxy with the given \a parent.
 */
QBarDataProxy::QBarDataProxy(QObject *parent)
    : QAbstractDataProxy(*(new QBarDataProxyPrivate()), parent)
{}

/*!
 * \internal
 */
QBarDataProxy::QBarDataProxy(QBarDataProxyPrivate &d, QObject *parent)
    : QAbstractDataProxy(d, parent)
{}

/*!
 * Deletes the bar data proxy.
 */
QBarDataProxy::~QBarDataProxy() {}

/*!
 * \property QBarDataProxy::series
 *
 * \brief The series this proxy is attached to.
 */
QBar3DSeries *QBarDataProxy::series() const
{
    Q_D(const QBarDataProxy);
    if (!d->series())
        qWarning("Series needs to be created to access data members");
    return static_cast<QBar3DSeries *>(d->series());
}

/*!
 * Clears the existing array and row and column labels.
 */
void QBarDataProxy::resetArray()
{
    Q_D(QBarDataProxy);
    d->resetArray(QBarDataArray(), QStringList(), QStringList());
    emit rowCountChanged(rowCount());
    emit colCountChanged(colCount());
}

/*!
 * Takes ownership of the array \a newArray. Clears the existing array if the
 * new array differs from it. If the arrays are the same, this function
 * just triggers the arrayReset() signal.
 *
 * Passing a null array deletes the old array and creates a new empty array.
 * Row and column labels are not affected.
 */
void QBarDataProxy::resetArray(QBarDataArray newArray)
{
    Q_D(QBarDataProxy);
    if (!series())
        return;

    d->resetArray(std::move(newArray), QStringList(), QStringList());
    emit arrayReset();
    if (rowCount() && colCount()) {
        emit rowCountChanged(rowCount());
        emit colCountChanged(colCount());
    }
}

/*!
 * Takes ownership of the array \a newArray. Clears the existing array if the
 * new array differs from it. If the arrays are the same, this function
 * just triggers the arrayReset() signal.
 *
 * Passing a null array deletes the old array and creates a new empty array.
 *
 * The \a rowLabels and \a columnLabels lists specify the new labels for rows
 * and columns.
 */
void QBarDataProxy::resetArray(QBarDataArray newArray,
                               QStringList rowLabels,
                               QStringList columnLabels)
{
    Q_D(QBarDataProxy);
    if (!series())
        return;

    d->resetArray(std::move(newArray), std::move(rowLabels), std::move(columnLabels));
    emit arrayReset();
    emit rowCountChanged(rowCount());
    emit colCountChanged(colCount());
}

/*!
 * Changes an existing row by replacing the row at the position \a rowIndex
 * with the new row specified by \a row. The new row can be
 * the same as the existing row already stored at \a rowIndex.
 * Existing row labels are not affected.
 */
void QBarDataProxy::setRow(qsizetype rowIndex, QBarDataRow row)
{
    Q_D(QBarDataProxy);
    d->setRow(rowIndex, std::move(row), QString());
    emit rowsChanged(rowIndex, 1);
}

/*!
 * Changes an existing row by replacing the row at the position \a rowIndex
 * with the new row specified by \a row. The new row can be
 * the same as the existing row already stored at \a rowIndex.
 * Changes the row label to \a label.
 */
void QBarDataProxy::setRow(qsizetype rowIndex, QBarDataRow row, QString label)
{
    Q_D(QBarDataProxy);
    d->setRow(rowIndex, std::move(row), std::move(label));
    emit rowsChanged(rowIndex, 1);
}

/*!
 * Changes existing rows by replacing the rows starting at the position
 * \a rowIndex with the new rows specifies by \a rows.
 * Existing row labels are not affected. The rows in the \a rows array can be
 * the same as the existing rows already stored at \a rowIndex.
 */
void QBarDataProxy::setRows(qsizetype rowIndex, QBarDataArray rows)
{
    Q_D(QBarDataProxy);
    d->setRows(rowIndex, std::move(rows), QStringList());
    emit rowsChanged(rowIndex, rows.size());
}

/*!
 * Changes existing rows by replacing the rows starting at the position
 * \a rowIndex with the new rows specifies by \a rows.
 * The row labels are changed to \a labels. The rows in the \a rows array can be
 * the same as the existing rows already stored at \a rowIndex.
 */
void QBarDataProxy::setRows(qsizetype rowIndex, QBarDataArray rows, QStringList labels)
{
    Q_D(QBarDataProxy);
    d->setRows(rowIndex, std::move(rows), std::move(labels));
    emit rowsChanged(rowIndex, rows.size());
}

/*!
 * Changes a single item at the position specified by \a rowIndex and
 * \a columnIndex to the item \a item.
 */
void QBarDataProxy::setItem(qsizetype rowIndex, qsizetype columnIndex, QBarDataItem item)
{
    Q_D(QBarDataProxy);
    d->setItem(rowIndex, columnIndex, std::move(item));
    emit itemChanged(rowIndex, columnIndex);
}

/*!
 * Changes a single item at the position \a position to the item \a item.
 * The x-value of \a position indicates the row and the y-value indicates the
 * column.
 */
void QBarDataProxy::setItem(QPoint position, QBarDataItem item)
{
    setItem(position.x(), position.y(), item);
}

/*!
 * Adds the new row \a row to the end of an array.
 * Existing row labels are not affected.
 *
 * Returns the index of the added row.
 */
qsizetype QBarDataProxy::addRow(QBarDataRow row)
{
    Q_D(QBarDataProxy);
    qsizetype addIndex = d->addRow(std::move(row), QString());
    emit rowsAdded(addIndex, 1);
    emit rowCountChanged(rowCount());
    emit colCountChanged(colCount());
    return addIndex;
}

/*!
 * Adds a the new row \a row with the label \a label to the end of an array.
 *
 * Returns the index of the added row.
 */
qsizetype QBarDataProxy::addRow(QBarDataRow row, QString label)
{
    Q_D(QBarDataProxy);
    qsizetype addIndex = d->addRow(std::move(row), std::move(label));
    emit rowsAdded(addIndex, 1);
    emit rowCountChanged(rowCount());
    emit colCountChanged(colCount());
    return addIndex;
}

/*!
 * Adds the new \a rows to the end of an array.
 * Existing row labels are not affected.
 *
 * Returns the index of the first added row.
 */
qsizetype QBarDataProxy::addRows(QBarDataArray rows)
{
    Q_D(QBarDataProxy);
    qsizetype addIndex = d->addRows(std::move(rows), QStringList());
    emit rowsAdded(addIndex, rows.size());
    emit rowCountChanged(rowCount());
    emit colCountChanged(colCount());
    return addIndex;
}

/*!
 * Adds the new \a rows with \a labels to the end of the array.
 *
 * Returns the index of the first added row.
 */
qsizetype QBarDataProxy::addRows(QBarDataArray rows, QStringList labels)
{
    Q_D(QBarDataProxy);
    qsizetype addIndex = d->addRows(std::move(rows), std::move(labels));
    emit rowsAdded(addIndex, rows.size());
    emit rowCountChanged(rowCount());
    emit colCountChanged(colCount());
    return addIndex;
}

/*!
 * Inserts the new row \a row into \a rowIndex.
 * If \a rowIndex is equal to the array size, the rows are added to the end of
 * the array.
 * The existing row labels are not affected.
 * \note The row labels array will be out of sync with the row array after this
 * call if there were labeled rows beyond the inserted row.
 */
void QBarDataProxy::insertRow(qsizetype rowIndex, QBarDataRow row)
{
    Q_D(QBarDataProxy);
    d->insertRow(rowIndex, std::move(row), QString());
    emit rowsInserted(rowIndex, 1);
    emit rowCountChanged(rowCount());
    emit colCountChanged(colCount());
}

/*!
 * Inserts the new row \a row with the label \a label into \a rowIndex.
 * If \a rowIndex is equal to array size, rows are added to the end of the
 * array.
 */
void QBarDataProxy::insertRow(qsizetype rowIndex, QBarDataRow row, QString label)
{
    Q_D(QBarDataProxy);
    d->insertRow(rowIndex, std::move(row), std::move(label));
    emit rowsInserted(rowIndex, 1);
    emit rowCountChanged(rowCount());
    emit colCountChanged(colCount());
}

/*!
 * Inserts new \a rows into \a rowIndex.
 * If \a rowIndex is equal to the array size, the rows are added to the end of
 * the array. The existing row labels are not affected.
 * \note The row labels array will be out of sync with the row array after this
 * call if there were labeled rows beyond the inserted rows.
 */
void QBarDataProxy::insertRows(qsizetype rowIndex, QBarDataArray rows)
{
    Q_D(QBarDataProxy);
    d->insertRows(rowIndex, std::move(rows), QStringList());
    emit rowsInserted(rowIndex, rows.size());
    emit rowCountChanged(rowCount());
    emit colCountChanged(colCount());
}

/*!
 * Inserts new \a rows with \a labels into \a rowIndex.
 * If \a rowIndex is equal to the array size, the rows are added to the end of
 * the array.
 */
void QBarDataProxy::insertRows(qsizetype rowIndex, QBarDataArray rows, QStringList labels)
{
    Q_D(QBarDataProxy);
    d->insertRows(rowIndex, std::move(rows), std::move(labels));
    emit rowsInserted(rowIndex, rows.size());
    emit rowCountChanged(rowCount());
    emit colCountChanged(colCount());
}

/*!
 * Removes the number of rows specified by \a removeCount starting at the
 * position \a rowIndex. Attempting to remove rows past the end of the
 * array does nothing. If \a removeLabels is \c true, the corresponding row
 * labels are also removed. Otherwise, the row labels are not affected.
 * \note If \a removeLabels is \c false, the row labels array will be out of
 * sync with the row array if there are labeled rows beyond the removed rows.
 */
void QBarDataProxy::removeRows(qsizetype rowIndex, qsizetype removeCount, RemoveLabels removeLabels)
{
    Q_D(QBarDataProxy);
    if (rowIndex < rowCount() && removeCount >= 1) {
        d->removeRows(rowIndex, removeCount, removeLabels == RemoveLabels::No ? false : true);
        emit rowsRemoved(rowIndex, removeCount);
        emit rowCountChanged(rowCount());
        emit colCountChanged(colCount());
    }
}

/*!
 * \property QBarDataProxy::colCount
 *
 * \brief The number of columns in the array.
 */
qsizetype QBarDataProxy::colCount() const
{
    if (this->series() && this->series()->dataArray().size() > 0)
        return this->series()->dataArray().at(0).size();
    else
        return 0;
}

/*!
 * \property QBarDataProxy::rowCount
 *
 * \brief The number of rows in the array.
 */
qsizetype QBarDataProxy::rowCount() const
{
    if (this->series())
        return this->series()->dataArray().size();
    else
        return 0;
}

/*!
 * Returns the reference to the row at the position \a rowIndex. It is
 * guaranteed to be valid only until the next call that modifies data.
 */
const QBarDataRow &QBarDataProxy::rowAt(qsizetype rowIndex) const
{
    const QBarDataArray &dataArray = this->series()->dataArray();
    Q_ASSERT(rowIndex >= 0 && rowIndex < dataArray.size());
    return dataArray[rowIndex];
}

/*!
 * Returns the reference to the item at the position specified by \a rowIndex
 * and \a columnIndex. It is guaranteed to be valid only until the next call
 * that modifies data.
 */
const QBarDataItem &QBarDataProxy::itemAt(qsizetype rowIndex, qsizetype columnIndex) const
{
    const QBarDataArray &dataArray = this->series()->dataArray();
    Q_ASSERT(rowIndex >= 0 && rowIndex < dataArray.size());
    const QBarDataRow &dataRow = dataArray[rowIndex];
    Q_ASSERT(columnIndex >= 0 && columnIndex < dataRow.size());
    return dataRow.at(columnIndex);
}

/*!
 * Returns the reference to the item at the position \a position. The x-value of
 * \a position indicates the row and the y-value indicates the column. The item
 * is guaranteed to be valid only until the next call that modifies data.
 */
const QBarDataItem &QBarDataProxy::itemAt(QPoint position) const
{
    return itemAt(position.x(), position.y());
}

/*!
 * \fn void QBarDataProxy::arrayReset()
 *
 * This signal is emitted when the data array is reset.
 * If the contents of the whole array are changed without calling resetArray(),
 * this signal needs to be emitted to update the graph.
 */

/*!
 * \fn void QBarDataProxy::rowsAdded(qsizetype startIndex, qsizetype count)
 *
 * This signal is emitted when the number of rows specified by \a count is
 * added, starting at the position \a startIndex.
 * If rows are added to the array without calling addRow() or addRows(),
 * this signal needs to be emitted to update the graph.
 */

/*!
 * \fn void QBarDataProxy::rowsChanged(qsizetype startIndex, qsizetype count)
 *
 * This signal is emitted when the number of rows specified by \a count is
 * changed, starting at the position \a startIndex.
 * If rows are changed in the array without calling setRow() or setRows(),
 * this signal needs to be emitted to update the graph.
 */

/*!
 * \fn void QBarDataProxy::rowsRemoved(qsizetype startIndex, qsizetype count)
 *
 * This signal is emitted when the number of rows specified by \a count is
 * removed, starting at the position \a startIndex.
 *
 * The index is the current array size if the rows were removed from the end of
 * the array. If rows are removed from the array without calling removeRows(),
 * this signal needs to be emitted to update the graph.
 */

/*!
 * \fn void QBarDataProxy::rowsInserted(qsizetype startIndex, qsizetype count)
 *
 * This signal is emitted when the number of rows specified by \a count is
 * inserted at the position \a startIndex.
 *
 * If rows are inserted into the array without calling insertRow() or
 * insertRows(), this signal needs to be emitted to update the graph.
 */

/*!
 * \fn void QBarDataProxy::itemChanged(qsizetype rowIndex, qsizetype columnIndex)
 *
 * This signal is emitted when the item at the position specified by \a rowIndex
 * and \a columnIndex changes.
 * If the item is changed in the array without calling setItem(),
 * this signal needs to be emitted to update the graph.
 */

// QBarDataProxyPrivate

QBarDataProxyPrivate::QBarDataProxyPrivate()
    : QAbstractDataProxyPrivate(QAbstractDataProxy::DataType::Bar)
{}

QBarDataProxyPrivate::~QBarDataProxyPrivate() {}

void QBarDataProxyPrivate::resetArray(QBarDataArray &&newArray,
                                      QStringList &&rowLabels,
                                      QStringList &&columnLabels)
{
    auto *barSeries = static_cast<QBar3DSeries *>(series());
    barSeries->setRowLabels(rowLabels);
    barSeries->setColumnLabels(columnLabels);

    if (newArray.data() != barSeries->dataArray().data()) {
        barSeries->clearArray();
        barSeries->setDataArray(newArray);
    }
}

void QBarDataProxyPrivate::setRow(qsizetype rowIndex, QBarDataRow &&row, QString &&label)
{
    auto *barSeries = static_cast<QBar3DSeries *>(series());
    Q_ASSERT(rowIndex >= 0 && rowIndex < barSeries->dataArray().size());

    QBar3DSeriesPrivate::get(barSeries)->fixRowLabels(rowIndex, 1, QStringList(label), false);
    if (row.data() != barSeries->dataArray().at(rowIndex).data()) {
        barSeries->clearRow(rowIndex);
        QBarDataArray array = barSeries->dataArray();
        array[rowIndex] = row;
        barSeries->setDataArray(array);
    }
}

void QBarDataProxyPrivate::setRows(qsizetype rowIndex, QBarDataArray &&rows, QStringList &&labels)
{
    auto *barSeries = static_cast<QBar3DSeries *>(series());
    Q_ASSERT(rowIndex >= 0 && (rowIndex + rows.size()) <= barSeries->dataArray().size());

    QBar3DSeriesPrivate::get(barSeries)->fixRowLabels(rowIndex, rows.size(), labels, false);
    for (int i = 0; i < rows.size(); i++) {
        if (rows.at(i).data() != barSeries->dataArray().at(rowIndex).data()) {
            barSeries->clearRow(rowIndex);
            QBarDataArray array = barSeries->dataArray();
            array[rowIndex] = rows.at(i);
            barSeries->setDataArray(array);
        }
        rowIndex++;
    }
}

void QBarDataProxyPrivate::setItem(qsizetype rowIndex, qsizetype columnIndex, QBarDataItem &&item)
{
    auto *barSeries = static_cast<QBar3DSeries *>(series());
    Q_ASSERT(rowIndex >= 0 && rowIndex < barSeries->dataArray().size());
    QBarDataArray array = barSeries->dataArray();
    QBarDataRow &row = array[rowIndex];
    Q_ASSERT(columnIndex < row.size());
    row[columnIndex] = item;
    barSeries->setDataArray(array);
}

qsizetype QBarDataProxyPrivate::addRow(QBarDataRow &&row, QString &&label)
{
    auto *barSeries = static_cast<QBar3DSeries *>(series());
    qsizetype currentSize = barSeries->dataArray().size();
    QBar3DSeriesPrivate::get(barSeries)->fixRowLabels(currentSize, 1, QStringList(label), false);
    QBarDataArray array = barSeries->dataArray();
    array.append(row);
    barSeries->setDataArray(array);
    return currentSize;
}

qsizetype QBarDataProxyPrivate::addRows(QBarDataArray &&rows, QStringList &&labels)
{
    auto *barSeries = static_cast<QBar3DSeries *>(series());
    QBarDataArray array = barSeries->dataArray();
    qsizetype currentSize = array.size();
    QBar3DSeriesPrivate::get(barSeries)->fixRowLabels(currentSize, rows.size(), labels, false);
    for (int i = 0; i < rows.size(); i++)
        array.append(rows.at(i));
    barSeries->setDataArray(array);
    return currentSize;
}

void QBarDataProxyPrivate::insertRow(qsizetype rowIndex, QBarDataRow &&row, QString &&label)
{
    auto *barSeries = static_cast<QBar3DSeries *>(series());
    Q_ASSERT(rowIndex >= 0 && rowIndex <= barSeries->dataArray().size());
    QBar3DSeriesPrivate::get(barSeries)->fixRowLabels(rowIndex, 1, QStringList(label), true);
    QBarDataArray array = barSeries->dataArray();
    array.insert(rowIndex, row);
    barSeries->setDataArray(array);
}

void QBarDataProxyPrivate::insertRows(qsizetype rowIndex, QBarDataArray &&rows, QStringList &&labels)
{
    auto *barSeries = static_cast<QBar3DSeries *>(series());
    Q_ASSERT(rowIndex >= 0 && rowIndex <= barSeries->dataArray().size());
    QBarDataArray array = barSeries->dataArray();

    QBar3DSeriesPrivate::get(barSeries)->fixRowLabels(rowIndex, rows.size(), labels, true);
    for (int i = 0; i < rows.size(); i++)
        array.insert(rowIndex++, rows.at(i));
    barSeries->setDataArray(array);
}

void QBarDataProxyPrivate::removeRows(qsizetype rowIndex, qsizetype removeCount, bool removeLabels)
{
    auto *barSeries = static_cast<QBar3DSeries *>(series());
    Q_ASSERT(rowIndex >= 0);
    qsizetype maxRemoveCount = barSeries->dataArray().size() - rowIndex;
    removeCount = qMin(removeCount, maxRemoveCount);
    bool labelsChanged = false;
    QBarDataArray array = barSeries->dataArray();
    for (int i = 0; i < removeCount; i++) {
        barSeries->clearRow(rowIndex);
        array.removeAt(rowIndex);
        if (removeLabels && barSeries->rowLabels().size() > rowIndex) {
            auto rowLabels = barSeries->rowLabels();
            rowLabels.removeAt(rowIndex);
            barSeries->setRowLabels(rowLabels);
            labelsChanged = true;
        }
    }
    barSeries->setDataArray(array);
    if (labelsChanged)
        emit barSeries->rowLabelsChanged();
}

QPair<float, float> QBarDataProxyPrivate::limitValues(qsizetype startRow,
                                                      qsizetype endRow,
                                                      qsizetype startColumn,
                                                      qsizetype endColumn) const
{
    auto *barSeries = static_cast<QBar3DSeries *>(series());
    QPair<float, float> limits = qMakePair(0.0f, 0.0f);
    endRow = qMin(endRow, barSeries->dataArray().size() - 1);
    for (qsizetype i = startRow; i <= endRow; i++) {
        QBarDataRow row = barSeries->dataArray().at(i);
        qsizetype lastColumn = qMin(endColumn, row.size() - 1);
        for (qsizetype j = startColumn; j <= lastColumn; j++) {
            const QBarDataItem &item = row.at(j);
            float itemValue = item.value();
            if (limits.second < itemValue)
                limits.second = itemValue;
            if (limits.first > itemValue)
                limits.first = itemValue;
        }
    }
    return limits;
}

void QBarDataProxyPrivate::setSeries(QAbstract3DSeries *series)
{
    Q_Q(QBarDataProxy);
    QAbstractDataProxyPrivate::setSeries(series);
    QBar3DSeries *barSeries = static_cast<QBar3DSeries *>(series);
    emit q->seriesChanged(barSeries);
}

QT_END_NAMESPACE