diff options
Diffstat (limited to 'src/datavisualizationqml/declarativeseries.cpp')
-rw-r--r-- | src/datavisualizationqml/declarativeseries.cpp | 131 |
1 files changed, 102 insertions, 29 deletions
diff --git a/src/datavisualizationqml/declarativeseries.cpp b/src/datavisualizationqml/declarativeseries.cpp index 38263a32..65c2cc76 100644 --- a/src/datavisualizationqml/declarativeseries.cpp +++ b/src/datavisualizationqml/declarativeseries.cpp @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Data Visualization module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "declarativeseries_p.h" #include <QtCore/QMetaMethod> @@ -103,7 +77,8 @@ DeclarativeBar3DSeries::DeclarativeBar3DSeries(QObject *parent) : QBar3DSeries(parent), m_baseGradient(0), m_singleHighlightGradient(0), - m_multiHighlightGradient(0) + m_multiHighlightGradient(0), + m_dummyColors(false) { QObject::connect(this, &QBar3DSeries::selectedBarChanged, this, &DeclarativeBar3DSeries::selectedBarChanged); @@ -171,6 +146,37 @@ ColorGradient *DeclarativeBar3DSeries::multiHighlightGradient() const return m_multiHighlightGradient; } +QQmlListProperty<DeclarativeColor> DeclarativeBar3DSeries::rowColors() +{ + return QQmlListProperty<DeclarativeColor>(this, this, + &DeclarativeBar3DSeries::appendRowColorsFunc, + &DeclarativeBar3DSeries::countRowColorsFunc, + &DeclarativeBar3DSeries::atRowColorsFunc, + &DeclarativeBar3DSeries::clearRowColorsFunc); +} + +void DeclarativeBar3DSeries::appendRowColorsFunc(QQmlListProperty<DeclarativeColor> *list, + DeclarativeColor *color) +{ + reinterpret_cast<DeclarativeBar3DSeries *>(list->data)->addColor(color); +} + +qsizetype DeclarativeBar3DSeries::countRowColorsFunc(QQmlListProperty<DeclarativeColor> *list) +{ + return reinterpret_cast<DeclarativeBar3DSeries *>(list->data)->colorList().size(); +} + +DeclarativeColor *DeclarativeBar3DSeries::atRowColorsFunc(QQmlListProperty<DeclarativeColor> *list, + qsizetype index) +{ + return reinterpret_cast<DeclarativeBar3DSeries *>(list->data)->colorList().at(index); +} + +void DeclarativeBar3DSeries::clearRowColorsFunc(QQmlListProperty<DeclarativeColor> *list) +{ + reinterpret_cast<DeclarativeBar3DSeries *>(list->data)->clearColors(); +} + void DeclarativeBar3DSeries::handleBaseGradientUpdate() { if (m_baseGradient) @@ -189,6 +195,73 @@ void DeclarativeBar3DSeries::handleMultiHighlightGradientUpdate() setSeriesGradient(this, *m_multiHighlightGradient, GradientTypeMulti); } +void DeclarativeBar3DSeries::handleRowColorUpdate() +{ + int colorCount = m_rowColors.size(); + int changed = 0; + + DeclarativeColor *color = qobject_cast<DeclarativeColor*>(QObject::sender()); + for (int i = 0; i < colorCount; i++) { + if (color == m_rowColors.at(i)) { + changed = i; + break; + } + } + QList<QColor> list = QBar3DSeries::rowColors(); + list[changed] = m_rowColors.at(changed)->color(); + QBar3DSeries::setRowColors(list); +} + +void DeclarativeBar3DSeries::addColor(DeclarativeColor *color) +{ + if (!color) { + qWarning("Color is invalid, use ThemeColor"); + return; + } + clearDummyColors(); + m_rowColors.append(color); + connect(color, &DeclarativeColor::colorChanged, this, + &DeclarativeBar3DSeries::handleRowColorUpdate); + QList<QColor> list = QBar3DSeries::rowColors(); + list.append(color->color()); + QBar3DSeries::setRowColors(list); +} + +QList<DeclarativeColor *> DeclarativeBar3DSeries::colorList() +{ + if (m_rowColors.isEmpty()) { + m_dummyColors = true; + const QList<QColor> list = QBar3DSeries::rowColors(); + for (const QColor &item : list) { + DeclarativeColor *color = new DeclarativeColor(this); + color->setColor(item); + m_rowColors.append(color); + connect(color, &DeclarativeColor::colorChanged, this, + &DeclarativeBar3DSeries::handleRowColorUpdate); + } + } + return m_rowColors; +} + +void DeclarativeBar3DSeries::clearColors() +{ + clearDummyColors(); + for (const auto color : std::as_const(m_rowColors)) + disconnect(color, 0, this, 0); + + m_rowColors.clear(); + QBar3DSeries::setRowColors(QList<QColor>()); +} + +void DeclarativeBar3DSeries::clearDummyColors() +{ + if (m_dummyColors) { + qDeleteAll(m_rowColors); + m_rowColors.clear(); + m_dummyColors = false; + } +} + DeclarativeScatter3DSeries::DeclarativeScatter3DSeries(QObject *parent) : QScatter3DSeries(parent), m_baseGradient(0), |