diff options
author | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2023-02-09 13:54:07 +0200 |
---|---|---|
committer | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2023-02-23 11:22:54 +0200 |
commit | 00272ac80843d94217e4f1ea36392e22919afa22 (patch) | |
tree | f6befa6852760e8edd0ffe26546f719964c14647 /examples/datavisualization/customproxy/variantbardataproxy.cpp | |
parent | 351a282e8ed94d697ba4b43302249e7894d0e1a9 (diff) |
Combine 2 widget examples into graph gallery
Combine the 2 bar graph examples into graph gallery example.
Note: surface and scatter examples will be combined into graph gallery
in other commits, to avoid making one gigantic commit.
Pick-to: 6.5
Task-number: QTBUG-110698
Change-Id: Iadf32e4e4d13c06325c89cf9259393d0b9fbda0e
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'examples/datavisualization/customproxy/variantbardataproxy.cpp')
-rw-r--r-- | examples/datavisualization/customproxy/variantbardataproxy.cpp | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/examples/datavisualization/customproxy/variantbardataproxy.cpp b/examples/datavisualization/customproxy/variantbardataproxy.cpp deleted file mode 100644 index f94f37b5..00000000 --- a/examples/datavisualization/customproxy/variantbardataproxy.cpp +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "variantbardataproxy.h" - -VariantBarDataProxy::VariantBarDataProxy() : - QBarDataProxy() -{ -} - -VariantBarDataProxy::VariantBarDataProxy(VariantDataSet *newSet, - VariantBarDataMapping *mapping) : - QBarDataProxy() -{ - setDataSet(newSet); - setMapping(mapping); -} - -VariantBarDataProxy::~VariantBarDataProxy() -{ - delete m_dataSet; -} - -void VariantBarDataProxy::setDataSet(VariantDataSet *newSet) -{ - if (!m_dataSet.isNull()) - QObject::disconnect(m_dataSet.data(), 0, this, 0); - - m_dataSet = newSet; - - if (!m_dataSet.isNull()) { - QObject::connect(m_dataSet.data(), &VariantDataSet::itemsAdded, this, - &VariantBarDataProxy::handleItemsAdded); - QObject::connect(m_dataSet.data(), &VariantDataSet::dataCleared, this, - &VariantBarDataProxy::handleDataCleared); - } - resolveDataSet(); -} - -VariantDataSet *VariantBarDataProxy::dataSet() -{ - return m_dataSet.data(); -} - -void VariantBarDataProxy::setMapping(VariantBarDataMapping *mapping) -{ - if (!m_mapping.isNull()) - QObject::disconnect(m_mapping.data(), &VariantBarDataMapping::mappingChanged, this, - &VariantBarDataProxy::handleMappingChanged); - - m_mapping = mapping; - - if (!m_mapping.isNull()) - QObject::connect(m_mapping.data(), &VariantBarDataMapping::mappingChanged, this, - &VariantBarDataProxy::handleMappingChanged); - - resolveDataSet(); -} - -VariantBarDataMapping *VariantBarDataProxy::mapping() -{ - return m_mapping.data(); -} - -void VariantBarDataProxy::handleItemsAdded(int index, int count) -{ - Q_UNUSED(index); - Q_UNUSED(count); - - // Resolve new items - resolveDataSet(); -} - -void VariantBarDataProxy::handleDataCleared() -{ - // Data cleared, reset array - resetArray(0); -} - -void VariantBarDataProxy::handleMappingChanged() -{ - resolveDataSet(); -} - -// Resolve entire dataset into QBarDataArray. -//! [0] -void VariantBarDataProxy::resolveDataSet() -{ - // If we have no data or mapping, or the categories are not defined, simply clear the array - if (m_dataSet.isNull() || m_mapping.isNull() || !m_mapping->rowCategories().size() - || !m_mapping->columnCategories().size()) { - resetArray(0); - return; - } - const VariantDataItemList &itemList = m_dataSet->itemList(); - - int rowIndex = m_mapping->rowIndex(); - int columnIndex = m_mapping->columnIndex(); - int valueIndex = m_mapping->valueIndex(); - const QStringList &rowList = m_mapping->rowCategories(); - const QStringList &columnList = m_mapping->columnCategories(); - - // Sort values into rows and columns - typedef QHash<QString, float> ColumnValueMap; - QHash <QString, ColumnValueMap> itemValueMap; - foreach (const VariantDataItem *item, itemList) { - itemValueMap[item->at(rowIndex).toString()][item->at(columnIndex).toString()] - = item->at(valueIndex).toReal(); - } - - // Create a new data array in format the parent class understands - QBarDataArray *newProxyArray = new QBarDataArray; - foreach (QString rowKey, rowList) { - QBarDataRow *newProxyRow = new QBarDataRow(columnList.size()); - for (int i = 0; i < columnList.size(); i++) - (*newProxyRow)[i].setValue(itemValueMap[rowKey][columnList.at(i)]); - newProxyArray->append(newProxyRow); - } - - // Finally, reset the data array in the parent class - resetArray(newProxyArray); -} -//! [0] |