1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "barinstancing_p.h"
5
6BarInstancing::BarInstancing()
7{
8
9}
10
11BarInstancing::~BarInstancing()
12{
13 clearDataArray();
14}
15
16QByteArray BarInstancing::getInstanceBuffer(int *instanceCount)
17{
18 if (m_dirty) {
19 m_instanceData.resize(size: 0);
20 int instanceNumber = 0;
21
22 for (int i = 0; i < m_dataArray.size(); ++i) {
23 auto item = m_dataArray.at(i);
24 if (!item->selectedBar) {
25 auto entry = calculateTableEntry(position: item->position, scale: item->scale, eulerRotation: item->eulerRotation,
26 color: item->color);
27 m_instanceData.append(s: reinterpret_cast<char *>(&entry), len: sizeof(entry));
28 } else {
29 //Even selected bars need to be drawn in a very small scale.
30 //If this is not done, the program can't find the selected bars in the graph and
31 //detects the wrong bars as selected ones.
32 auto entry = calculateTableEntry(position: item->position, scale: QVector3D{.001f, .001f, .001f},
33 eulerRotation: item->eulerRotation, color: QColor(Qt::white));
34 m_instanceData.append(s: reinterpret_cast<char *>(&entry), len: sizeof(entry));
35 }
36 instanceNumber++;
37 }
38 m_instanceCount = instanceNumber;
39 m_dirty = false;
40 }
41
42 if (instanceCount)
43 *instanceCount = m_instanceCount;
44
45 return m_instanceData;
46}
47
48bool BarInstancing::rangeGradient() const
49{
50 return m_rangeGradient;
51}
52
53void BarInstancing::setRangeGradient(bool newRangeGradient)
54{
55 m_rangeGradient = newRangeGradient;
56}
57
58void BarInstancing::clearDataArray()
59{
60 m_dataArray.clear();
61 m_instanceData.clear();
62}
63
64void BarInstancing::markDataDirty()
65{
66 m_dirty = true;
67 markDirty();
68}
69
70QList<BarItemHolder *> BarInstancing::dataArray() const
71{
72 return m_dataArray;
73}
74
75void BarInstancing::setDataArray(const QList<BarItemHolder *> &newDataArray)
76{
77 m_dataArray = newDataArray;
78 markDataDirty();
79}
80

source code of qtgraphs/src/graphs/engine/barinstancing.cpp