diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-12-09 10:49:49 +0200 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-12-10 09:01:45 +0200 |
commit | 3573055abe42ff283d011d8550bc8495156338a1 (patch) | |
tree | bb45d4f7e32a0c63329d9f52639081162b34e17e /src/datavisualization | |
parent | 22557b312570cbefde584466a28f2b9bfcc570ba (diff) |
Move series specific visual elements to series, part 4
Colors to series
- Multiselection labels in bar slices still buggy
- Selection in bars doesn't work correctly if not all
series have items in that grid
Task-number: QTRD-2557
Change-Id: Icd38428e5337a26b8410476104bb1f1f784cdc7f
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization')
31 files changed, 990 insertions, 1016 deletions
diff --git a/src/datavisualization/data/qabstract3dseries.cpp b/src/datavisualization/data/qabstract3dseries.cpp index 93ce7fb0..46224813 100644 --- a/src/datavisualization/data/qabstract3dseries.cpp +++ b/src/datavisualization/data/qabstract3dseries.cpp @@ -91,6 +91,74 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE */ /*! + * \qmlproperty Theme3D.ColorStyle Abstract3DSeries::colorStyle + * + * Sets the color \a style for the series. + * See \l{Theme3D::colorStyle}{Theme3D.colorStyle} + * documentation for more information. + */ + +/*! + * \qmlproperty Color Abstract3DSeries::baseColor + * + * Sets the base \c color of the series. + * See \l{Theme3D::baseColor}{Theme3D.baseColor} + * documentation for more information. + * + * \sa colorStyle + */ + +/*! + * \qmlproperty ColorGradient Abstract3DSeries::baseGradient + * + * Sets the base \c gradient of the series. + * See \l{Theme3D::baseGradient}{Theme3D.baseGradient} + * documentation for more information. + * + * \sa colorStyle + */ + +/*! + * \qmlproperty Color Abstract3DSeries::singleHighlightColor + * + * Sets the single item highlight \c color of the series. + * See \l{Theme3D::singleHighlightColor}{Theme3D.singleHighlightColor} + * documentation for more information. + * + * \sa colorStyle + */ + +/*! + * \qmlproperty ColorGradient Abstract3DSeries::singleHighlightGradient + * + * Sets the single item highlight \c gradient of the series. + * See \l{Theme3D::singleHighlightGradient}{Theme3D.singleHighlightGradient} + * documentation for more information. + * + * \sa colorStyle + */ + +/*! + * \qmlproperty Color Abstract3DSeries::multiHighlightColor + * + * Sets the multiple item highlight \c color of the series. + * See \l{Theme3D::multiHighlightColor}{Theme3D.multiHighlightColor} + * documentation for more information. + * + * \sa colorStyle + */ + +/*! + * \qmlproperty ColorGradient Abstract3DSeries::multiHighlightGradient + * + * Sets the multiple item highlight \c gradient of the series. + * See \l{Theme3D::multiHighlightGradient}{Theme3D.multiHighlightGradient} + * documentation for more information. + * + * \sa colorStyle + */ + +/*! * \enum QAbstract3DSeries::SeriesType * * Type of the series. @@ -266,6 +334,158 @@ QString QAbstract3DSeries::userDefinedMesh() const return d_ptr->m_userDefinedMesh; } +/*! + * \property QAbstract3DSeries::colorStyle + * + * Sets the color \a style for the series. + * See Q3DTheme::ColorStyle documentation for more information. + */ +void QAbstract3DSeries::setColorStyle(Q3DTheme::ColorStyle style) +{ + if (d_ptr->m_colorStyle != style) { + d_ptr->setColorStyle(style); + emit colorStyleChanged(style); + } + d_ptr->m_themeTracker.colorStyleOverride = true; +} + +Q3DTheme::ColorStyle QAbstract3DSeries::colorStyle() const +{ + return d_ptr->m_colorStyle; +} + +/*! + * \property QAbstract3DSeries::baseColor + * + * Sets the base \c color of the series. + * See Q3DTheme::baseColor documentation for more information. + * + * \sa colorStyle + */ +void QAbstract3DSeries::setBaseColor(const QColor &color) +{ + if (d_ptr->m_baseColor != color) { + d_ptr->setBaseColor(color); + emit baseColorChanged(color); + } + d_ptr->m_themeTracker.baseColorOverride = true; +} + +QColor QAbstract3DSeries::baseColor() const +{ + return d_ptr->m_baseColor; +} + +/*! + * \property QAbstract3DSeries::baseGradient + * + * Sets the base \c gradient of the series. + * See Q3DTheme::baseGradient documentation for more information. + * + * \sa colorStyle + */ +void QAbstract3DSeries::setBaseGradient(const QLinearGradient &gradient) +{ + if (d_ptr->m_baseGradient != gradient) { + d_ptr->setBaseGradient(gradient); + emit baseGradientChanged(gradient); + } + d_ptr->m_themeTracker.baseGradientOverride = true; +} + +QLinearGradient QAbstract3DSeries::baseGradient() const +{ + return d_ptr->m_baseGradient; +} + +/*! + * \property QAbstract3DSeries::singleHighlightColor + * + * Sets the single item highlight \c color of the series. + * See Q3DTheme::singleHighlightColor documentation for more information. + * + * \sa colorStyle + */ +void QAbstract3DSeries::setSingleHighlightColor(const QColor &color) +{ + if (d_ptr->m_singleHighlightColor != color) { + d_ptr->setSingleHighlightColor(color); + emit singleHighlightColorChanged(color); + } + d_ptr->m_themeTracker.singleHighlightColorOverride = true; +} + +QColor QAbstract3DSeries::singleHighlightColor() const +{ + return d_ptr->m_singleHighlightColor; +} + +/*! + * \property QAbstract3DSeries::singleHighlightGradient + * + * Sets the single item highlight \c gradient of the series. + * See Q3DTheme::singleHighlightGradient documentation for more information. + * + * \sa colorStyle + */ +void QAbstract3DSeries::setSingleHighlightGradient(const QLinearGradient &gradient) +{ + if (d_ptr->m_singleHighlightGradient != gradient) { + d_ptr->setSingleHighlightGradient(gradient); + emit singleHighlightGradientChanged(gradient); + } + d_ptr->m_themeTracker.singleHighlightGradientOverride = true; +} + +QLinearGradient QAbstract3DSeries::singleHighlightGradient() const +{ + return d_ptr->m_singleHighlightGradient; +} + +/*! + * \property QAbstract3DSeries::multiHighlightColor + * + * Sets the multiple item highlight \c color of the series. + * See Q3DTheme::multiHighlightColor documentation for more information. + * + * \sa colorStyle + */ +void QAbstract3DSeries::setMultiHighlightColor(const QColor &color) +{ + if (d_ptr->m_multiHighlightColor != color) { + d_ptr->setMultiHighlightColor(color); + emit multiHighlightColorChanged(color); + } + d_ptr->m_themeTracker.multiHighlightColorOverride = true; +} + +QColor QAbstract3DSeries::multiHighlightColor() const +{ + return d_ptr->m_multiHighlightColor; +} + +/*! + * \property QAbstract3DSeries::multiHighlightGradient + * + * Sets the multiple item highlight \c gradient of the series. + * See Q3DTheme::multiHighlightGradient documentation for more information. + * + * \sa colorStyle + */ +void QAbstract3DSeries::setMultiHighlightGradient(const QLinearGradient &gradient) +{ + if (d_ptr->m_multiHighlightGradient != gradient) { + d_ptr->setMultiHighlightGradient(gradient); + emit multiHighlightGradientChanged(gradient); + } + d_ptr->m_themeTracker.multiHighlightGradientOverride = true; +} + +QLinearGradient QAbstract3DSeries::multiHighlightGradient() const +{ + return d_ptr->m_multiHighlightGradient; +} + // QAbstract3DSeriesPrivate QAbstract3DSeriesPrivate::QAbstract3DSeriesPrivate(QAbstract3DSeries *q, QAbstract3DSeries::SeriesType type) @@ -350,4 +570,95 @@ void QAbstract3DSeriesPrivate::setUserDefinedMesh(const QString &meshFile) m_controller->markSeriesVisualsDirty(); } +void QAbstract3DSeriesPrivate::setColorStyle(Q3DTheme::ColorStyle style) +{ + m_colorStyle = style; + m_changeTracker.colorStyleChanged = true; + if (m_controller) + m_controller->markSeriesVisualsDirty(); +} + +void QAbstract3DSeriesPrivate::setBaseColor(const QColor &color) +{ + m_baseColor = color; + m_changeTracker.baseColorChanged = true; + if (m_controller) + m_controller->markSeriesVisualsDirty(); +} + +void QAbstract3DSeriesPrivate::setBaseGradient(const QLinearGradient &gradient) +{ + m_baseGradient = gradient; + m_changeTracker.baseGradientChanged = true; + if (m_controller) + m_controller->markSeriesVisualsDirty(); +} + +void QAbstract3DSeriesPrivate::setSingleHighlightColor(const QColor &color) +{ + m_singleHighlightColor = color; + m_changeTracker.singleHighlightColorChanged = true; + if (m_controller) + m_controller->markSeriesVisualsDirty(); +} + +void QAbstract3DSeriesPrivate::setSingleHighlightGradient(const QLinearGradient &gradient) +{ + m_singleHighlightGradient = gradient; + m_changeTracker.singleHighlightGradientChanged = true; + if (m_controller) + m_controller->markSeriesVisualsDirty(); +} + +void QAbstract3DSeriesPrivate::setMultiHighlightColor(const QColor &color) +{ + m_multiHighlightColor = color; + m_changeTracker.multiHighlightColorChanged = true; + if (m_controller) + m_controller->markSeriesVisualsDirty(); +} + +void QAbstract3DSeriesPrivate::setMultiHighlightGradient(const QLinearGradient &gradient) +{ + m_multiHighlightGradient = gradient; + m_changeTracker.multiHighlightGradientChanged = true; + if (m_controller) + m_controller->markSeriesVisualsDirty(); +} + +void QAbstract3DSeriesPrivate::resetToTheme(const Q3DTheme &theme, int seriesIndex, bool force) +{ + // TODO: seriesIndex indicates which color from theme is required + Q_UNUSED(seriesIndex) + + if (force || !m_themeTracker.colorStyleOverride) { + q_ptr->setColorStyle(theme.colorStyle()); + m_themeTracker.colorStyleOverride = false; + } + if (force || !m_themeTracker.baseColorOverride) { + q_ptr->setBaseColor(theme.baseColor()); + m_themeTracker.baseColorOverride = false; + } + if (force || !m_themeTracker.baseGradientOverride) { + q_ptr->setBaseGradient(theme.baseGradient()); + m_themeTracker.baseGradientOverride = false; + } + if (force || !m_themeTracker.singleHighlightColorOverride) { + q_ptr->setSingleHighlightColor(theme.singleHighlightColor()); + m_themeTracker.singleHighlightColorOverride = false; + } + if (force || !m_themeTracker.singleHighlightGradientOverride) { + q_ptr->setSingleHighlightGradient(theme.singleHighlightGradient()); + m_themeTracker.singleHighlightGradientOverride = false; + } + if (force || !m_themeTracker.multiHighlightColorOverride) { + q_ptr->setMultiHighlightColor(theme.multiHighlightColor()); + m_themeTracker.multiHighlightColorOverride = false; + } + if (force || !m_themeTracker.multiHighlightGradientOverride) { + q_ptr->setMultiHighlightGradient(theme.multiHighlightGradient()); + m_themeTracker.multiHighlightGradientOverride = false; + } +} + QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/data/qabstract3dseries.h b/src/datavisualization/data/qabstract3dseries.h index f5dfcf09..ebe73510 100644 --- a/src/datavisualization/data/qabstract3dseries.h +++ b/src/datavisualization/data/qabstract3dseries.h @@ -20,8 +20,10 @@ #define QABSTRACT3DSERIES_H #include <QtDataVisualization/qdatavisualizationenums.h> +#include <QtDataVisualization/q3dtheme.h> #include <QObject> #include <QScopedPointer> +#include <QLinearGradient> QT_DATAVISUALIZATION_BEGIN_NAMESPACE @@ -38,6 +40,13 @@ class QT_DATAVISUALIZATION_EXPORT QAbstract3DSeries : public QObject Q_PROPERTY(Mesh mesh READ mesh WRITE setMesh NOTIFY meshChanged) Q_PROPERTY(bool meshSmooth READ isMeshSmooth WRITE setMeshSmooth NOTIFY meshSmoothChanged) Q_PROPERTY(QString userDefinedMesh READ userDefinedMesh WRITE setUserDefinedMesh NOTIFY userDefinedMeshChanged) + Q_PROPERTY(QtDataVisualization::Q3DTheme::ColorStyle colorStyle READ colorStyle WRITE setColorStyle NOTIFY colorStyleChanged) + Q_PROPERTY(QColor baseColor READ baseColor WRITE setBaseColor NOTIFY baseColorChanged) + Q_PROPERTY(QLinearGradient baseGradient READ baseGradient WRITE setBaseGradient NOTIFY baseGradientChanged) + Q_PROPERTY(QColor singleHighlightColor READ singleHighlightColor WRITE setSingleHighlightColor NOTIFY singleHighlightColorChanged) + Q_PROPERTY(QLinearGradient singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged) + Q_PROPERTY(QColor multiHighlightColor READ multiHighlightColor WRITE setMultiHighlightColor NOTIFY multiHighlightColorChanged) + Q_PROPERTY(QLinearGradient multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged) public: enum SeriesType { @@ -84,24 +93,38 @@ public: void setUserDefinedMesh(const QString &fileName); QString userDefinedMesh() const; + void setColorStyle(Q3DTheme::ColorStyle style); + Q3DTheme::ColorStyle colorStyle() const; + void setBaseColor(const QColor &color); + QColor baseColor() const; + void setBaseGradient(const QLinearGradient &gradient); + QLinearGradient baseGradient() const; + void setSingleHighlightColor(const QColor &color); + QColor singleHighlightColor() const; + void setSingleHighlightGradient(const QLinearGradient &gradient); + QLinearGradient singleHighlightGradient() const; + void setMultiHighlightColor(const QColor &color); + QColor multiHighlightColor() const; + void setMultiHighlightGradient(const QLinearGradient &gradient); + QLinearGradient multiHighlightGradient() const; + signals: void itemLabelFormatChanged(QString format); void visibilityChanged(bool visible); void meshChanged(Mesh mesh); void meshSmoothChanged(bool enabled); void userDefinedMeshChanged(QString fileName); + void colorStyleChanged(Q3DTheme::ColorStyle style); + void baseColorChanged(QColor color); + void baseGradientChanged(QLinearGradient gradient); + void singleHighlightColorChanged(QColor color); + void singleHighlightGradientChanged(QLinearGradient gradient); + void multiHighlightColorChanged(QColor color); + void multiHighlightGradientChanged(QLinearGradient gradient); protected: QScopedPointer<QAbstract3DSeriesPrivate> d_ptr; -// Q3DTheme::ColorStyle m_colorStyle; -// QColor m_objectColor; -// QLinearGradient m_objectGradient; -// QColor m_singleHighlightColor; -// QLinearGradient m_singleHighlightGradient; -// QColor m_multiHighlightColor; -// QLinearGradient m_multiHighlightGradient; - private: Q_DISABLE_COPY(QAbstract3DSeries) diff --git a/src/datavisualization/data/qabstract3dseries_p.h b/src/datavisualization/data/qabstract3dseries_p.h index d37df562..7b2ea2e6 100644 --- a/src/datavisualization/data/qabstract3dseries_p.h +++ b/src/datavisualization/data/qabstract3dseries_p.h @@ -39,16 +39,51 @@ class QAbstractDataProxy; class Abstract3DController; struct QAbstract3DSeriesChangeBitField { - bool itemLabelFormatChanged : 1; - bool meshChanged : 1; - bool meshSmoothChanged : 1; - bool userDefinedMeshChanged : 1; + bool itemLabelFormatChanged : 1; + bool meshChanged : 1; + bool meshSmoothChanged : 1; + bool userDefinedMeshChanged : 1; + bool colorStyleChanged : 1; + bool baseColorChanged : 1; + bool baseGradientChanged : 1; + bool singleHighlightColorChanged : 1; + bool singleHighlightGradientChanged : 1; + bool multiHighlightColorChanged : 1; + bool multiHighlightGradientChanged : 1; QAbstract3DSeriesChangeBitField() : itemLabelFormatChanged(true), meshChanged(true), meshSmoothChanged(true), - userDefinedMeshChanged(true) + userDefinedMeshChanged(true), + colorStyleChanged(true), + baseColorChanged(true), + baseGradientChanged(true), + singleHighlightColorChanged(true), + singleHighlightGradientChanged(true), + multiHighlightColorChanged(true), + multiHighlightGradientChanged(true) + { + } +}; + +struct QAbstract3DSeriesThemeOverrideBitField { + bool colorStyleOverride : 1; + bool baseColorOverride : 1; + bool baseGradientOverride : 1; + bool singleHighlightColorOverride : 1; + bool singleHighlightGradientOverride : 1; + bool multiHighlightColorOverride : 1; + bool multiHighlightGradientOverride : 1; + + QAbstract3DSeriesThemeOverrideBitField() + : colorStyleOverride(false), + baseColorOverride(false), + baseGradientOverride(false), + singleHighlightColorOverride(false), + singleHighlightGradientOverride(false), + multiHighlightColorOverride(false), + multiHighlightGradientOverride(false) { } }; @@ -71,7 +106,18 @@ public: void setMeshSmooth(bool enable); void setUserDefinedMesh(const QString &meshFile); + void setColorStyle(Q3DTheme::ColorStyle style); + void setBaseColor(const QColor &color); + void setBaseGradient(const QLinearGradient &gradient); + void setSingleHighlightColor(const QColor &color); + void setSingleHighlightGradient(const QLinearGradient &gradient); + void setMultiHighlightColor(const QColor &color); + void setMultiHighlightGradient(const QLinearGradient &gradient); + + void resetToTheme(const Q3DTheme &theme, int seriesIndex, bool force); + QAbstract3DSeriesChangeBitField m_changeTracker; + QAbstract3DSeriesThemeOverrideBitField m_themeTracker; QAbstract3DSeries *q_ptr; QAbstract3DSeries::SeriesType m_type; QString m_itemLabelFormat; @@ -81,6 +127,15 @@ public: QAbstract3DSeries::Mesh m_mesh; bool m_meshSmooth; QString m_userDefinedMesh; + + Q3DTheme::ColorStyle m_colorStyle; + QColor m_baseColor; + QLinearGradient m_baseGradient; + QColor m_singleHighlightColor; + QLinearGradient m_singleHighlightGradient; + QColor m_multiHighlightColor; + QLinearGradient m_multiHighlightGradient; + }; QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/data/qscatterdataproxy.cpp b/src/datavisualization/data/qscatterdataproxy.cpp index 791e5dd6..e0876d64 100644 --- a/src/datavisualization/data/qscatterdataproxy.cpp +++ b/src/datavisualization/data/qscatterdataproxy.cpp @@ -183,6 +183,9 @@ void QScatterDataProxy::insertItems(int index, const QScatterDataArray &items) */ void QScatterDataProxy::removeItems(int index, int removeCount) { + if (index >= dptr()->m_dataArray->size()) + return; + dptr()->removeItems(index, removeCount); emit itemsRemoved(index, removeCount); emit itemCountChanged(itemCount()); diff --git a/src/datavisualization/engine/abstract3dcontroller.cpp b/src/datavisualization/engine/abstract3dcontroller.cpp index 915a0bc7..a1ad9191 100644 --- a/src/datavisualization/engine/abstract3dcontroller.cpp +++ b/src/datavisualization/engine/abstract3dcontroller.cpp @@ -41,7 +41,6 @@ Abstract3DController::Abstract3DController(QRect boundRect, QObject *parent) : m_selectionMode(QDataVis::SelectionItem), m_shadowQuality(QDataVis::ShadowQualityMedium), m_scene(new Q3DScene()), - m_colorStyle(Q3DTheme::ColorStyleUniform), m_activeInputHandler(0), m_axisX(0), m_axisY(0), @@ -95,12 +94,14 @@ void Abstract3DController::setRenderer(Abstract3DRenderer *renderer) void Abstract3DController::addSeries(QAbstract3DSeries *series) { if (series && !m_seriesList.contains(series)) { + int oldSize = m_seriesList.size(); m_seriesList.append(series); series->d_ptr->setController(this); QObject::connect(series, &QAbstract3DSeries::visibilityChanged, this, &Abstract3DController::handleSeriesVisibilityChanged); if (series->isVisible()) handleSeriesVisibilityChangedBySender(series); + series->d_ptr->resetToTheme(*m_themeManager->theme(), oldSize, false); } } @@ -146,42 +147,6 @@ void Abstract3DController::synchDataToRenderer() m_renderer->updateTheme(m_themeManager->theme()); - // TODO: Rethink these after color api has been moveed to series (QTRD-2200/2557) - if (m_changeTracker.colorStyleChanged) { - m_renderer->updateColorStyle(m_colorStyle); - m_changeTracker.colorStyleChanged = false; - } - - if (m_changeTracker.objectColorChanged) { - m_renderer->updateObjectColor(m_objectColor); - m_changeTracker.objectColorChanged = false; - } - - if (m_changeTracker.objectGradientChanged) { - m_renderer->updateObjectGradient(m_objectGradient); - m_changeTracker.objectGradientChanged = false; - } - - if (m_changeTracker.singleHighlightColorChanged) { - m_renderer->updateSingleHighlightColor(m_singleHighlightColor); - m_changeTracker.singleHighlightColorChanged = false; - } - - if (m_changeTracker.singleHighlightGradientChanged) { - m_renderer->updateSingleHighlightGradient(m_singleHighlightGradient); - m_changeTracker.singleHighlightGradientChanged = false; - } - - if (m_changeTracker.multiHighlightColorChanged) { - m_renderer->updateMultiHighlightColor(m_multiHighlightColor); - m_changeTracker.multiHighlightColorChanged = false; - } - - if (m_changeTracker.multiHighlightGradientChanged) { - m_renderer->updateMultiHighlightGradient(m_multiHighlightGradient); - m_changeTracker.multiHighlightGradientChanged = false; - } - if (m_changeTracker.shadowQualityChanged) { m_renderer->updateShadowQuality(m_shadowQuality); m_changeTracker.shadowQualityChanged = false; @@ -497,6 +462,90 @@ void Abstract3DController::handlePixelRatioChanged(float ratio) emitNeedRender(); } +void Abstract3DController::handleThemeColorStyleChanged(Q3DTheme::ColorStyle style) +{ + // Set value for series that have not explicitly set this value + foreach (QAbstract3DSeries *series, m_seriesList) { + if (!series->d_ptr->m_themeTracker.colorStyleOverride) { + series->setColorStyle(style); + series->d_ptr->m_themeTracker.colorStyleOverride = false; + } + } + markSeriesVisualsDirty(); +} + +void Abstract3DController::handleThemeBaseColorChanged(const QColor &color) +{ + // Set value for series that have not explicitly set this value + foreach (QAbstract3DSeries *series, m_seriesList) { + if (!series->d_ptr->m_themeTracker.baseColorOverride) { + series->setBaseColor(color); + series->d_ptr->m_themeTracker.baseColorOverride = false; + } + } + markSeriesVisualsDirty(); +} + +void Abstract3DController::handleThemeBaseGradientChanged(const QLinearGradient &gradient) +{ + // Set value for series that have not explicitly set this value + foreach (QAbstract3DSeries *series, m_seriesList) { + if (!series->d_ptr->m_themeTracker.baseGradientOverride) { + series->setBaseGradient(gradient); + series->d_ptr->m_themeTracker.baseGradientOverride = false; + } + } + markSeriesVisualsDirty(); +} + +void Abstract3DController::handleThemeSingleHighlightColorChanged(const QColor &color) +{ + // Set value for series that have not explicitly set this value + foreach (QAbstract3DSeries *series, m_seriesList) { + if (!series->d_ptr->m_themeTracker.singleHighlightColorOverride) { + series->setSingleHighlightColor(color); + series->d_ptr->m_themeTracker.singleHighlightColorOverride = false; + } + } + markSeriesVisualsDirty(); +} + +void Abstract3DController::handleThemeSingleHighlightGradientChanged(const QLinearGradient &gradient) +{ + // Set value for series that have not explicitly set this value + foreach (QAbstract3DSeries *series, m_seriesList) { + if (!series->d_ptr->m_themeTracker.singleHighlightGradientOverride) { + series->setSingleHighlightGradient(gradient); + series->d_ptr->m_themeTracker.singleHighlightGradientOverride = false; + } + } + markSeriesVisualsDirty(); +} + +void Abstract3DController::handleThemeMultiHighlightColorChanged(const QColor &color) +{ + // Set value for series that have not explicitly set this value + foreach (QAbstract3DSeries *series, m_seriesList) { + if (!series->d_ptr->m_themeTracker.multiHighlightColorOverride) { + series->setMultiHighlightColor(color); + series->d_ptr->m_themeTracker.multiHighlightColorOverride = false; + } + } + markSeriesVisualsDirty(); +} + +void Abstract3DController::handleThemeMultiHighlightGradientChanged(const QLinearGradient &gradient) +{ + // Set value for series that have not explicitly set this value + foreach (QAbstract3DSeries *series, m_seriesList) { + if (!series->d_ptr->m_themeTracker.multiHighlightGradientOverride) { + series->setMultiHighlightGradient(gradient); + series->d_ptr->m_themeTracker.multiHighlightGradientOverride = false; + } + } + markSeriesVisualsDirty(); +} + void Abstract3DController::setAxisX(Q3DAbstractAxis *axis) { setAxisHelper(Q3DAbstractAxis::AxisOrientationX, axis, &m_axisX); @@ -646,130 +695,15 @@ void Abstract3DController::setZoomLevel(int zoomLevel) emitNeedRender(); } -void Abstract3DController::setColorStyle(Q3DTheme::ColorStyle style) -{ - if (style != m_colorStyle || m_changeTracker.themeChanged) { - Q3DTheme *theme = m_themeManager->theme(); - if (style == Q3DTheme::ColorStyleUniform) { - setBaseColor(theme->baseColor()); - setSingleHighlightColor(theme->singleHighlightColor()); - setMultiHighlightColor(theme->multiHighlightColor()); - } else { - setBaseGradient(theme->baseGradient()); - setSingleHighlightGradient(theme->singleHighlightGradient()); - setMultiHighlightGradient(theme->multiHighlightGradient()); - } - } - if (style != m_colorStyle) { - m_colorStyle = style; - m_changeTracker.colorStyleChanged = true; - emitNeedRender(); - emit colorStyleChanged(style); - } -} - -Q3DTheme::ColorStyle Abstract3DController::colorStyle() const -{ - return m_colorStyle; -} - -void Abstract3DController::setBaseColor(const QColor &color) -{ - if (color != m_objectColor) { - m_objectColor = color; - m_changeTracker.objectColorChanged = true; - emitNeedRender(); - emit objectColorChanged(color); - } -} - -QColor Abstract3DController::baseColor() const -{ - return m_objectColor; -} - -void Abstract3DController::setBaseGradient(const QLinearGradient &gradient) -{ - if (gradient != m_objectGradient) { - m_objectGradient = gradient; - m_changeTracker.objectGradientChanged = true; - emitNeedRender(); - emit objectGradientChanged(gradient); - } -} - -QLinearGradient Abstract3DController::baseGradient() const -{ - return m_objectGradient; -} - -void Abstract3DController::setSingleHighlightColor(const QColor &color) -{ - if (color != m_singleHighlightColor) { - m_singleHighlightColor = color; - m_changeTracker.singleHighlightColorChanged = true; - emitNeedRender(); - emit singleHighlightColorChanged(color); - } -} - -QColor Abstract3DController::singleHighlightColor() const -{ - return m_singleHighlightColor; -} - -void Abstract3DController::setSingleHighlightGradient(const QLinearGradient &gradient) -{ - if (gradient != m_singleHighlightGradient) { - m_singleHighlightGradient = gradient; - m_changeTracker.singleHighlightGradientChanged = true; - emitNeedRender(); - emit singleHighlightGradientChanged(gradient); - } -} - -QLinearGradient Abstract3DController::singleHighlightGradient() const -{ - return m_singleHighlightGradient; -} - -void Abstract3DController::setMultiHighlightColor(const QColor &color) -{ - if (color != m_multiHighlightColor) { - m_multiHighlightColor = color; - m_changeTracker.multiHighlightColorChanged = true; - emitNeedRender(); - emit multiHighlightColorChanged(color); - } -} - -QColor Abstract3DController::multiHighlightColor() const -{ - return m_multiHighlightColor; -} - -void Abstract3DController::setMultiHighlightGradient(const QLinearGradient &gradient) -{ - if (gradient != m_multiHighlightGradient) { - m_multiHighlightGradient = gradient; - m_changeTracker.multiHighlightGradientChanged = true; - emitNeedRender(); - emit multiHighlightGradientChanged(gradient); - } -} - -QLinearGradient Abstract3DController::multiHighlightGradient() const -{ - return m_multiHighlightGradient; -} - void Abstract3DController::setTheme(Q3DTheme *theme) { if (theme != m_themeManager->theme()) { m_themeManager->setTheme(theme); m_changeTracker.themeChanged = true; - // TODO: Rethink this once color api has been moved to series (QTRD-2200/2557) - setColorStyle(theme->colorStyle()); + // Reset all attached series to the new theme + for (int i = 0; i < m_seriesList.size(); i++) + m_seriesList.at(i)->d_ptr->resetToTheme(*theme, i, true); + markSeriesVisualsDirty(); emit themeChanged(theme); } } diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h index 2874cbcb..934aa7f5 100644 --- a/src/datavisualization/engine/abstract3dcontroller_p.h +++ b/src/datavisualization/engine/abstract3dcontroller_p.h @@ -81,13 +81,6 @@ struct Abstract3DChangeBitField { bool axisZLabelFormatChanged : 1; bool inputStateChanged : 1; bool inputPositionChanged : 1; - bool colorStyleChanged : 1; - bool objectColorChanged : 1; - bool objectGradientChanged : 1; - bool singleHighlightColorChanged : 1; - bool singleHighlightGradientChanged: 1; - bool multiHighlightColorChanged : 1; - bool multiHighlightGradientChanged : 1; Abstract3DChangeBitField() : positionChanged(true), @@ -118,15 +111,7 @@ struct Abstract3DChangeBitField { axisZSubSegmentCountChanged(true), axisXLabelFormatChanged(true), axisYLabelFormatChanged(true), - axisZLabelFormatChanged(true), - // Items that override values from theme default to false since we default to theme - colorStyleChanged(false), - objectColorChanged(false), - objectGradientChanged(false), - singleHighlightColorChanged(false), - singleHighlightGradientChanged(false), - multiHighlightColorChanged(false), - multiHighlightGradientChanged(false) + axisZLabelFormatChanged(true) { } }; @@ -161,13 +146,6 @@ private: QDataVis::SelectionFlags m_selectionMode; QDataVis::ShadowQuality m_shadowQuality; Q3DScene *m_scene; - Q3DTheme::ColorStyle m_colorStyle; - QColor m_objectColor; - QLinearGradient m_objectGradient; - QColor m_singleHighlightColor; - QLinearGradient m_singleHighlightGradient; - QColor m_multiHighlightColor; - QLinearGradient m_multiHighlightGradient; protected: QList<QAbstract3DInputHandler *> m_inputHandlers; // List of all added input handlers @@ -237,23 +215,6 @@ public: virtual void setTheme(Q3DTheme *theme); virtual Q3DTheme *theme() const; - // Properties from color api - // TODO: Rethink these after color api has been moveed to series (QTRD-2200/2557) - virtual void setColorStyle(Q3DTheme::ColorStyle style); - virtual Q3DTheme::ColorStyle colorStyle() const; - virtual void setBaseColor(const QColor &color); - virtual QColor baseColor() const; - virtual void setBaseGradient(const QLinearGradient &gradient); - virtual QLinearGradient baseGradient() const; - virtual void setSingleHighlightColor(const QColor &color); - virtual QColor singleHighlightColor() const; - virtual void setSingleHighlightGradient(const QLinearGradient &gradient); - virtual QLinearGradient singleHighlightGradient() const; - virtual void setMultiHighlightColor(const QColor &color); - virtual QColor multiHighlightColor() const; - virtual void setMultiHighlightGradient(const QLinearGradient &gradient); - virtual QLinearGradient multiHighlightGradient() const; - virtual void setSelectionMode(QDataVis::SelectionFlags mode); virtual QDataVis::SelectionFlags selectionMode() const; @@ -300,6 +261,14 @@ public slots: void handleSeriesVisibilityChanged(bool visible); void handlePixelRatioChanged(float ratio); + void handleThemeColorStyleChanged(Q3DTheme::ColorStyle style); + void handleThemeBaseColorChanged(const QColor &color); + void handleThemeBaseGradientChanged(const QLinearGradient &gradient); + void handleThemeSingleHighlightColorChanged(const QColor &color); + void handleThemeSingleHighlightGradientChanged(const QLinearGradient &gradient); + void handleThemeMultiHighlightColorChanged(const QColor &color); + void handleThemeMultiHighlightGradientChanged(const QLinearGradient &gradient); + // Renderer callback handlers void handleRequestShadowQuality(QDataVis::ShadowQuality quality); @@ -309,13 +278,6 @@ signals: void themeChanged(Q3DTheme *theme); void selectionModeChanged(QDataVis::SelectionFlags mode); void needRender(); - void colorStyleChanged(Q3DTheme::ColorStyle style); - void objectColorChanged(QColor color); - void objectGradientChanged(QLinearGradient gradient); - void singleHighlightColorChanged(QColor color); - void singleHighlightGradientChanged(QLinearGradient gradient); - void multiHighlightColorChanged(QColor color); - void multiHighlightGradientChanged(QLinearGradient gradient); protected: virtual Q3DAbstractAxis *createDefaultAxis(Q3DAbstractAxis::AxisOrientation orientation); diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp index bafe6727..3ef01b71 100644 --- a/src/datavisualization/engine/abstract3drenderer.cpp +++ b/src/datavisualization/engine/abstract3drenderer.cpp @@ -40,10 +40,6 @@ Abstract3DRenderer::Abstract3DRenderer(Abstract3DController *controller) m_cachedShadowQuality(QDataVis::ShadowQualityMedium), m_autoScaleAdjustment(1.0f), m_cachedSelectionMode(QDataVis::SelectionNone), - m_cachedColorStyle(Q3DTheme::ColorStyleUniform), - m_objectGradientTexture(0), - m_singleHighlightGradientTexture(0), - m_multiHighlightGradientTexture(0), m_textureHelper(0), m_cachedScene(new Q3DScene()), m_selectionDirty(true), @@ -63,17 +59,12 @@ Abstract3DRenderer::Abstract3DRenderer(Abstract3DController *controller) Abstract3DRenderer::~Abstract3DRenderer() { - if (m_textureHelper) { - m_textureHelper->deleteTexture(&m_objectGradientTexture); - m_textureHelper->deleteTexture(&m_singleHighlightGradientTexture); - m_textureHelper->deleteTexture(&m_multiHighlightGradientTexture); - } + for (int i = 0; i < m_visibleSeriesList.size(); i++) + m_visibleSeriesList[i].cleanup(m_textureHelper); delete m_drawer; delete m_textureHelper; delete m_cachedScene; - for (int i = 0; i < m_visibleSeriesList.size(); i++) - delete m_visibleSeriesList.at(i).object(); } void Abstract3DRenderer::initializeOpenGL() @@ -153,6 +144,13 @@ void Abstract3DRenderer::updateInputPosition(const QPoint &position) m_inputPosition = position; } +void Abstract3DRenderer::initGradientShaders(const QString &vertexShader, const QString &fragmentShader) +{ + // Do nothing by default + Q_UNUSED(vertexShader) + Q_UNUSED(fragmentShader) +} + void Abstract3DRenderer::updateBoundingRect(const QRect &boundingRect) { m_cachedBoundingRect = boundingRect; @@ -210,34 +208,25 @@ void Abstract3DRenderer::reInitShaders() { #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { - if (m_cachedColorStyle != Q3DTheme::ColorStyleUniform) { - initShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY")); - } else { - initShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadowNoTex")); - } + initGradientShaders(QStringLiteral(":/shaders/vertexShadow"), + QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY")); + initShaders(QStringLiteral(":/shaders/vertexShadow"), + QStringLiteral(":/shaders/fragmentShadowNoTex")); initBackgroundShaders(QStringLiteral(":/shaders/vertexShadow"), QStringLiteral(":/shaders/fragmentShadowNoTex")); } else { - if (m_cachedColorStyle != Q3DTheme::ColorStyleUniform) { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragmentColorOnY")); - } else { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragment")); - } + initGradientShaders(QStringLiteral(":/shaders/vertex"), + QStringLiteral(":/shaders/fragmentColorOnY")); + initShaders(QStringLiteral(":/shaders/vertex"), + QStringLiteral(":/shaders/fragment")); initBackgroundShaders(QStringLiteral(":/shaders/vertex"), QStringLiteral(":/shaders/fragment")); } #else - if (m_cachedColorStyle != Q3DTheme::ColorStyleUniform) { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragmentColorOnYES2")); - } else { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragmentES2")); - } + initGradientShaders(QStringLiteral(":/shaders/vertex"), + QStringLiteral(":/shaders/fragmentColorOnYES2")); + initShaders(QStringLiteral(":/shaders/vertex"), + QStringLiteral(":/shaders/fragmentES2")); initBackgroundShaders(QStringLiteral(":/shaders/vertex"), QStringLiteral(":/shaders/fragmentES2")); #endif @@ -320,49 +309,6 @@ void Abstract3DRenderer::updateAxisLabelFormat(Q3DAbstractAxis::AxisOrientation axisCacheForOrientation(orientation).setLabelFormat(format); } -void Abstract3DRenderer::updateColorStyle(Q3DTheme::ColorStyle style) -{ - bool changed = (m_cachedColorStyle != style); - - m_cachedColorStyle = style; - - if (changed) - reInitShaders(); -} - -void Abstract3DRenderer::updateObjectColor(const QColor &color) -{ - m_cachedObjectColor = color; -} - -void Abstract3DRenderer::updateObjectGradient(const QLinearGradient &gradient) -{ - m_cachedObjectGradient = gradient; - fixGradient(&m_cachedObjectGradient, &m_objectGradientTexture); -} - -void Abstract3DRenderer::updateSingleHighlightColor(const QColor &color) -{ - m_cachedSingleHighlightColor = color; -} - -void Abstract3DRenderer::updateSingleHighlightGradient(const QLinearGradient &gradient) -{ - m_cachedSingleHighlightGradient = gradient; - fixGradient(&m_cachedSingleHighlightGradient, &m_singleHighlightGradientTexture); -} - -void Abstract3DRenderer::updateMultiHighlightColor(const QColor &color) -{ - m_cachedMultiHighlightColor = color; -} - -void Abstract3DRenderer::updateMultiHighlightGradient(const QLinearGradient &gradient) -{ - m_cachedMultiHighlightGradient = gradient; - fixGradient(&m_cachedMultiHighlightGradient, &m_multiHighlightGradientTexture); -} - void Abstract3DRenderer::fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh mesh) { // Default implementation does nothing. @@ -375,12 +321,20 @@ void Abstract3DRenderer::updateSeries(const QList<QAbstract3DSeries *> &seriesLi { int visibleCount = 0; if (updateVisibility) { + int oldSize = m_visibleSeriesList.size(); foreach (QAbstract3DSeries *current, seriesList) { if (current->isVisible()) visibleCount++; } - if (visibleCount != m_visibleSeriesList.size()) + // Clean up series caches that are about to be permanently deleted. + // Can't just use cache destructor, as resize will call that to all items. + if (visibleCount < oldSize) { + for (int i = visibleCount; i < oldSize; i++) + m_visibleSeriesList[i].cleanup(m_textureHelper); + } + + if (visibleCount != oldSize) m_visibleSeriesList.resize(visibleCount); visibleCount = 0; diff --git a/src/datavisualization/engine/abstract3drenderer_p.h b/src/datavisualization/engine/abstract3drenderer_p.h index 98e3face..6ba21285 100644 --- a/src/datavisualization/engine/abstract3drenderer_p.h +++ b/src/datavisualization/engine/abstract3drenderer_p.h @@ -68,17 +68,6 @@ protected: QDataVis::SelectionFlags m_cachedSelectionMode; - Q3DTheme::ColorStyle m_cachedColorStyle; - QColor m_cachedObjectColor; - QLinearGradient m_cachedObjectGradient; - GLuint m_objectGradientTexture; - QColor m_cachedSingleHighlightColor; - QLinearGradient m_cachedSingleHighlightGradient; - GLuint m_singleHighlightGradientTexture; - QColor m_cachedMultiHighlightColor; - QLinearGradient m_cachedMultiHighlightGradient; - GLuint m_multiHighlightGradientTexture; - AxisRenderCache m_axisCacheX; AxisRenderCache m_axisCacheY; AxisRenderCache m_axisCacheZ; @@ -123,6 +112,7 @@ public: #endif virtual void updateShadowQuality(QDataVis::ShadowQuality quality) = 0; virtual void initShaders(const QString &vertexShader, const QString &fragmentShader) = 0; + virtual void initGradientShaders(const QString &vertexShader, const QString &fragmentShader); virtual void initBackgroundShaders(const QString &vertexShader, const QString &fragmentShader) = 0; virtual void updateAxisType(Q3DAbstractAxis::AxisOrientation orientation, Q3DAbstractAxis::AxisType type); virtual void updateAxisTitle(Q3DAbstractAxis::AxisOrientation orientation, const QString &title); @@ -131,15 +121,9 @@ public: virtual void updateAxisSegmentCount(Q3DAbstractAxis::AxisOrientation orientation, int count); virtual void updateAxisSubSegmentCount(Q3DAbstractAxis::AxisOrientation orientation, int count); virtual void updateAxisLabelFormat(Q3DAbstractAxis::AxisOrientation orientation, const QString &format); - virtual void updateColorStyle(Q3DTheme::ColorStyle style); - virtual void updateObjectColor(const QColor &color); - virtual void updateObjectGradient(const QLinearGradient &gradient); - virtual void updateSingleHighlightColor(const QColor &color); - virtual void updateSingleHighlightGradient(const QLinearGradient &gradient); - virtual void updateMultiHighlightColor(const QColor &color); - virtual void updateMultiHighlightGradient(const QLinearGradient &gradient); virtual void fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh mesh); + void fixGradient(QLinearGradient *gradient, GLuint *gradientTexture); signals: void needRender(); // Emit this if something in renderer causes need for another render pass. @@ -157,8 +141,6 @@ protected: AxisRenderCache &axisCacheForOrientation(Q3DAbstractAxis::AxisOrientation orientation); virtual void lowerShadowQuality(); - - void fixGradient(QLinearGradient *gradient, GLuint *gradientTexture); }; QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp index 5b582273..19f5d68b 100644 --- a/src/datavisualization/engine/bars3drenderer.cpp +++ b/src/datavisualization/engine/bars3drenderer.cpp @@ -60,6 +60,7 @@ Bars3DRenderer::Bars3DRenderer(Bars3DController *controller) m_yFlipped(false), m_updateLabels(false), m_barShader(0), + m_barGradientShader(0), m_depthShader(0), m_selectionShader(0), m_backgroundShader(0), @@ -110,6 +111,7 @@ Bars3DRenderer::~Bars3DRenderer() delete m_sliceSelection; } delete m_barShader; + delete m_barGradientShader; delete m_depthShader; delete m_selectionShader; delete m_backgroundShader; @@ -335,8 +337,6 @@ void Bars3DRenderer::drawSlicedScene() barPosYAdjustment = 0.2f; // Both -> translate to 0.0 + 0.2 for row/column labels } QMatrix4x4 projectionViewMatrix = projectionMatrix * viewMatrix; - QVector3D barHighlightColor(Utils::vectorFromColor(m_cachedSingleHighlightColor)); - QVector3D rowHighlightColor(Utils::vectorFromColor(m_cachedMultiHighlightColor)); bool rowMode = m_cachedSelectionMode.testFlag(QDataVis::SelectionRow); bool itemMode = m_cachedSelectionMode.testFlag(QDataVis::SelectionItem); @@ -419,8 +419,6 @@ void Bars3DRenderer::drawSlicedScene() m_drawer->drawObject(lineShader, m_gridLineObj); } } - // Release line shader - lineShader->release(); // TODO: Make user controllable (QTRD-2546) if (sliceGridLabels) { @@ -455,17 +453,10 @@ void Bars3DRenderer::drawSlicedScene() glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); - - // Release label shader - m_labelShader->release(); } } // Draw bars - // Bind bar shader - m_barShader->bind(); - - GLuint gradientTexture = 0; QVector3D modelMatrixScaler(m_scaleX, 0.0f, m_scaleZ); if (rowMode) modelMatrixScaler.setX(m_scaleX * m_seriesScale); @@ -473,18 +464,34 @@ void Bars3DRenderer::drawSlicedScene() modelMatrixScaler.setZ(m_scaleZ * m_seriesScale); // Set common bar shader bindings + m_barShader->bind(); m_barShader->setUniformValue(m_barShader->lightP(), lightPos); m_barShader->setUniformValue(m_barShader->view(), viewMatrix); m_barShader->setUniformValue(m_barShader->lightS(), 0.5f); m_barShader->setUniformValue(m_barShader->ambientS(), m_cachedTheme->ambientLightStrength() * 2.0f); - if (m_cachedColorStyle != Q3DTheme::ColorStyleUniform) { - m_barShader->setUniformValue(m_barShader->gradientMin(), 0.0f); - if (m_cachedColorStyle == Q3DTheme::ColorStyleObjectGradient) - m_barShader->setUniformValue(m_barShader->gradientHeight(), 0.5f); - - gradientTexture = m_objectGradientTexture; - } + m_barGradientShader->bind(); + m_barGradientShader->setUniformValue(m_barGradientShader->lightP(), lightPos); + m_barGradientShader->setUniformValue(m_barGradientShader->view(), viewMatrix); + m_barGradientShader->setUniformValue(m_barGradientShader->lightS(), 0.5f); + m_barGradientShader->setUniformValue(m_barGradientShader->ambientS(), + m_cachedTheme->ambientLightStrength() * 2.0f); + m_barGradientShader->setUniformValue(m_barGradientShader->gradientMin(), 0.0f); + + // Default to uniform shader + ShaderHelper *barShader = m_barShader; + barShader->bind(); + + int currentSeriesIndex = -1; + Q3DTheme::ColorStyle previousColorStyle = Q3DTheme::ColorStyleUniform; + Q3DTheme::ColorStyle colorStyle = Q3DTheme::ColorStyleUniform; + ObjectHelper *barObj = 0; + QVector3D barHighlightColor; + QVector3D rowHighlightColor; + GLuint barGradientTexture = 0; + GLuint rowGradientTexture = 0; + const SeriesRenderCache *currentSeries = 0; + bool colorStyleIsUniform = true; int stopBar = m_sliceSelection->size(); for (int bar = 0; bar < stopBar; bar++) { @@ -492,6 +499,38 @@ void Bars3DRenderer::drawSlicedScene() if (!item) continue; + if (item->seriesIndex() != currentSeriesIndex) { + currentSeriesIndex = item->seriesIndex(); + currentSeries = &(m_visibleSeriesList.at(currentSeriesIndex)); + barObj = currentSeries->object(); + colorStyle = currentSeries->colorStyle(); + colorStyleIsUniform = (colorStyle == Q3DTheme::ColorStyleUniform); + if (colorStyleIsUniform) { + barHighlightColor = currentSeries->singleHighlightColor(); + rowHighlightColor = currentSeries->multiHighlightColor(); + } else { + barGradientTexture = currentSeries->singleHighlightGradientTexture(); + rowGradientTexture = currentSeries->multiHighlightGradientTexture(); + } + + // Rebind shader if it has changed + if (colorStyleIsUniform != (previousColorStyle == Q3DTheme::ColorStyleUniform)) { + if (colorStyleIsUniform) + barShader = m_barShader; + else + barShader = m_barGradientShader; + barShader->bind(); + + } + + if (!colorStyleIsUniform && (previousColorStyle != colorStyle) + && (colorStyle == Q3DTheme::ColorStyleObjectGradient)) { + m_barGradientShader->setUniformValue(m_barGradientShader->gradientHeight(), 0.5f); + } + + previousColorStyle = colorStyle; + } + if (item->height() < 0) glCullFace(GL_FRONT); else @@ -520,43 +559,41 @@ void Bars3DRenderer::drawSlicedScene() MVPMatrix = projectionViewMatrix * modelMatrix; QVector3D barColor; - // TODO: Get color from correct series + GLuint gradientTexture = 0; + if (itemMode && m_visualSelectedBarPos.x() == item->position().x() && m_visualSelectedBarPos.y() == item->position().y()) { - if (m_cachedColorStyle == Q3DTheme::ColorStyleUniform) + if (colorStyleIsUniform) barColor = barHighlightColor; else - gradientTexture = m_singleHighlightGradientTexture; + gradientTexture = barGradientTexture; } else { - if (m_cachedColorStyle == Q3DTheme::ColorStyleUniform) + if (colorStyleIsUniform) barColor = rowHighlightColor; else - gradientTexture = m_multiHighlightGradientTexture; + gradientTexture = rowGradientTexture; } if (item->height() != 0) { // Set shader bindings - m_barShader->setUniformValue(m_barShader->model(), modelMatrix); - m_barShader->setUniformValue(m_barShader->nModel(), - itModelMatrix.inverted().transposed()); - m_barShader->setUniformValue(m_barShader->MVP(), MVPMatrix); - if (m_cachedColorStyle == Q3DTheme::ColorStyleUniform) { - m_barShader->setUniformValue(m_barShader->color(), barColor); - } else if (m_cachedColorStyle == Q3DTheme::ColorStyleRangeGradient) { - m_barShader->setUniformValue(m_barShader->gradientHeight(), - (qAbs(item->height()) / m_gradientFraction)); + barShader->setUniformValue(barShader->model(), modelMatrix); + barShader->setUniformValue(barShader->nModel(), + itModelMatrix.inverted().transposed()); + barShader->setUniformValue(barShader->MVP(), MVPMatrix); + if (colorStyleIsUniform) { + barShader->setUniformValue(barShader->color(), barColor); + } else if (colorStyle == Q3DTheme::ColorStyleRangeGradient) { + barShader->setUniformValue(barShader->gradientHeight(), + (qAbs(item->height()) / m_gradientFraction)); } // Draw the object - m_drawer->drawObject(m_barShader, - m_visibleSeriesList.at(item->seriesIndex()).object(), + m_drawer->drawObject(barShader, + barObj, gradientTexture); } } - // Release bar shader - m_barShader->release(); - // Draw labels m_labelShader->bind(); glDisable(GL_DEPTH_TEST); @@ -662,8 +699,8 @@ void Bars3DRenderer::drawSlicedScene() glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); - // Release label shader - m_labelShader->release(); + // Release shader + glUseProgram(0); } void Bars3DRenderer::drawScene(GLuint defaultFboHandle) @@ -784,15 +821,15 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) // Draw bars to depth buffer QVector3D shadowScaler(m_scaleX * m_seriesScale * 0.9f, 0.0f, m_scaleZ * 0.9f); - for (int row = startRow; row != stopRow; row += stepRow) { - for (int bar = startBar; bar != stopBar; bar += stepBar) { - GLfloat shadowOffset = 0.0f; - float seriesPos = m_seriesStart; - for (int series = 0; series < seriesCount; series++) { + float seriesPos = m_seriesStart; + for (int series = 0; series < seriesCount; series++) { + ObjectHelper *barObj = m_visibleSeriesList.at(series).object(); + for (int row = startRow; row != stopRow; row += stepRow) { + for (int bar = startBar; bar != stopBar; bar += stepBar) { + GLfloat shadowOffset = 0.0f; const BarRenderItem &item = m_renderingArrays.at(series).at(row).at(bar); if (!item.value()) continue; - ObjectHelper *barObj = m_visibleSeriesList.at(series).object(); // Set front face culling for negative valued bars and back face culling for // positive valued bars to remove peter-panning issues if (item.height() > 0) { @@ -842,17 +879,14 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glBindBuffer(GL_ARRAY_BUFFER, 0); glDisableVertexAttribArray(m_depthShader->posAtt()); - seriesPos += m_seriesStep; } } + seriesPos += m_seriesStep; } // Disable drawing to depth framebuffer (= enable drawing to screen) glBindFramebuffer(GL_FRAMEBUFFER, defaultFboHandle); - // Release depth shader - m_depthShader->release(); - #if 0 // Use this if you want to see what is being drawn to the framebuffer // You'll also have to comment out GL_COMPARE_R_TO_TEXTURE -line in texturehelper (if using it) m_labelShader->bind(); @@ -865,7 +899,6 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, m_depthTexture); glDisable(GL_TEXTURE_2D); - m_labelShader->release(); #endif // Reset culling to normal glCullFace(GL_BACK); @@ -889,16 +922,16 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Set clear color to white (= selectionSkipColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Needed for clearing the frame buffer glDisable(GL_DITHER); // disable dithering, it may affect colors if enabled - for (int row = startRow; row != stopRow; row += stepRow) { - for (int bar = startBar; bar != stopBar; bar += stepBar) { - float seriesPos = m_seriesStart; - for (int series = 0; series < seriesCount; series++) { + float seriesPos = m_seriesStart; + for (int series = 0; series < seriesCount; series++) { + ObjectHelper *barObj = m_visibleSeriesList.at(series).object(); + for (int row = startRow; row != stopRow; row += stepRow) { + for (int bar = startBar; bar != stopBar; bar += stepBar) { const BarRenderItem &item = m_renderingArrays.at(series).at(row).at(bar); if (!item.value()) { seriesPos += m_seriesStep; continue; } - ObjectHelper *barObj = m_visibleSeriesList.at(series).object(); if (item.height() < 0) glCullFace(GL_FRONT); @@ -951,10 +984,9 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glBindBuffer(GL_ARRAY_BUFFER, 0); glDisableVertexAttribArray(m_selectionShader->posAtt()); - - seriesPos += m_seriesStep; } } + seriesPos += m_seriesStep; } glEnable(GL_DITHER); @@ -965,9 +997,6 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glBindFramebuffer(GL_FRAMEBUFFER, defaultFboHandle); - // Release selection shader - m_selectionShader->release(); - #if 0 // Use this if you want to see what is being drawn to the framebuffer glCullFace(GL_BACK); m_labelShader->bind(); @@ -980,29 +1009,45 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, m_selectionTexture); glDisable(GL_TEXTURE_2D); - m_labelShader->release(); #endif } // Enable texturing glEnable(GL_TEXTURE_2D); - // Bind bar shader - m_barShader->bind(); - + ShaderHelper *barShader = 0; GLuint gradientTexture = 0; + Q3DTheme::ColorStyle previousColorStyle = Q3DTheme::ColorStyleUniform; + bool haveUniformColorSeries = false; + bool haveGradientSeries = false; - // Set common bar shader bindings - m_barShader->setUniformValue(m_barShader->lightP(), lightPos); - m_barShader->setUniformValue(m_barShader->view(), viewMatrix); - m_barShader->setUniformValue(m_barShader->ambientS(), - m_cachedTheme->ambientLightStrength()); - if (m_cachedColorStyle != Q3DTheme::ColorStyleUniform) { - m_barShader->setUniformValue(m_barShader->gradientMin(), 0.0f); - if (m_cachedColorStyle == Q3DTheme::ColorStyleObjectGradient) - m_barShader->setUniformValue(m_barShader->gradientHeight(), 0.5f); + for (int i = 0; i < seriesCount; i++) { + if (m_visibleSeriesList.at(i).colorStyle() == Q3DTheme::ColorStyleUniform) + haveUniformColorSeries = true; + else + haveGradientSeries = true; + } + + // Set unchanging shader bindings + if (haveGradientSeries) { + m_barGradientShader->bind(); + m_barGradientShader->setUniformValue(m_barGradientShader->lightP(), lightPos); + m_barGradientShader->setUniformValue(m_barGradientShader->view(), viewMatrix); + m_barGradientShader->setUniformValue(m_barGradientShader->ambientS(), + m_cachedTheme->ambientLightStrength()); + m_barGradientShader->setUniformValue(m_barGradientShader->gradientMin(), 0.0f); + } - gradientTexture = m_objectGradientTexture; + if (haveUniformColorSeries) { + m_barShader->bind(); + m_barShader->setUniformValue(m_barShader->lightP(), lightPos); + m_barShader->setUniformValue(m_barShader->view(), viewMatrix); + m_barShader->setUniformValue(m_barShader->ambientS(), + m_cachedTheme->ambientLightStrength()); + barShader = m_barShader; + } else { + barShader = m_barGradientShader; + previousColorStyle = Q3DTheme::ColorStyleRangeGradient; } if (m_selectionDirty) { @@ -1029,10 +1074,6 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } // Draw bars - QVector3D barHighlightColor(Utils::vectorFromColor(m_cachedSingleHighlightColor)); - QVector3D rowHighlightColor(Utils::vectorFromColor(m_cachedMultiHighlightColor)); - QVector3D baseColor(Utils::vectorFromColor(m_cachedObjectColor)); - QVector3D barColor = baseColor; GLfloat adjustedLightStrength = m_cachedTheme->lightStrength() / 10.0f; GLfloat adjustedHighlightStrength = m_cachedTheme->highlightLightStrength() / 10.0f; @@ -1040,13 +1081,45 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) bool barSelectionFound = false; BarRenderItem *selectedBar(0); + QVector3D baseColor; + QVector3D barColor; QVector3D modelScaler(m_scaleX * m_seriesScale, 0.0f, m_scaleZ); bool somethingSelected = (m_visualSelectedBarPos != Bars3DController::invalidSelectionPosition()); - for (int row = startRow; row != stopRow; row += stepRow) { - for (int bar = startBar; bar != stopBar; bar += stepBar) { - float seriesPos = m_seriesStart; - for (int series = 0; series < seriesCount; series++) { - ObjectHelper *barObj = m_visibleSeriesList.at(series).object(); + float seriesPos = m_seriesStart; + for (int series = 0; series < seriesCount; series++) { + const SeriesRenderCache ¤tSeries = m_visibleSeriesList.at(series); + ObjectHelper *barObj = currentSeries.object(); + Q3DTheme::ColorStyle colorStyle = currentSeries.colorStyle(); + bool colorStyleIsUniform = (colorStyle == Q3DTheme::ColorStyleUniform); + + // Rebind shader if it has changed + if (colorStyleIsUniform != (previousColorStyle == Q3DTheme::ColorStyleUniform)) { + if (colorStyleIsUniform) + barShader = m_barShader; + else + barShader = m_barGradientShader; + barShader->bind(); + } + + if (colorStyleIsUniform) { + baseColor = currentSeries.baseColor(); + } else if ((previousColorStyle != colorStyle) + && (colorStyle == Q3DTheme::ColorStyleObjectGradient)) { + m_barGradientShader->setUniformValue(m_barGradientShader->gradientHeight(), 0.5f); + } + + // Always use base color when no selection mode + if (m_cachedSelectionMode == QDataVis::SelectionNone) { + if (colorStyleIsUniform) + barColor = baseColor; + else + gradientTexture = currentSeries.baseGradientTexture(); + } + + previousColorStyle = colorStyle; + + for (int row = startRow; row != stopRow; row += stepRow) { + for (int bar = startBar; bar != stopBar; bar += stepBar) { BarRenderItem &item = m_renderingArrays[series][row][bar]; if (item.height() < 0) @@ -1072,12 +1145,6 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) #else MVPMatrix = projectionViewMatrix * modelMatrix; #endif - - if (m_cachedColorStyle == Q3DTheme::ColorStyleUniform) - barColor = baseColor; - else - gradientTexture = m_objectGradientTexture; - GLfloat lightStrength = m_cachedTheme->lightStrength(); GLfloat shadowLightStrength = adjustedLightStrength; @@ -1088,10 +1155,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) switch (selectionType) { case Bars3DController::SelectionItem: { - if (m_cachedColorStyle == Q3DTheme::ColorStyleUniform) - barColor = barHighlightColor; + if (colorStyleIsUniform) + barColor = currentSeries.singleHighlightColor(); else - gradientTexture = m_singleHighlightGradientTexture; + gradientTexture = currentSeries.singleHighlightGradientTexture(); lightStrength = m_cachedTheme->highlightLightStrength(); shadowLightStrength = adjustedHighlightStrength; @@ -1120,10 +1187,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } case Bars3DController::SelectionRow: { // Current bar is on the same row as the selected bar - if (m_cachedColorStyle == Q3DTheme::ColorStyleUniform) - barColor = rowHighlightColor; + if (colorStyleIsUniform) + barColor = currentSeries.multiHighlightColor(); else - gradientTexture = m_multiHighlightGradientTexture; + gradientTexture = currentSeries.multiHighlightGradientTexture(); lightStrength = m_cachedTheme->highlightLightStrength(); shadowLightStrength = adjustedHighlightStrength; @@ -1141,10 +1208,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } case Bars3DController::SelectionColumn: { // Current bar is on the same column as the selected bar - if (m_cachedColorStyle == Q3DTheme::ColorStyleUniform) - barColor = rowHighlightColor; + if (colorStyleIsUniform) + barColor = currentSeries.multiHighlightColor(); else - gradientTexture = m_multiHighlightGradientTexture; + gradientTexture = currentSeries.multiHighlightGradientTexture(); lightStrength = m_cachedTheme->highlightLightStrength(); shadowLightStrength = adjustedHighlightStrength; @@ -1168,54 +1235,54 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } case Bars3DController::SelectionNone: { // Current bar is not selected, nor on a row or column - // do nothing + if (colorStyleIsUniform) + barColor = baseColor; + else + gradientTexture = currentSeries.baseGradientTexture(); break; } } } - // Skip drawing of 0 -height bars + // Skip drawing of 0-height bars if (item.height() != 0) { // Set shader bindings - m_barShader->setUniformValue(m_barShader->model(), modelMatrix); - m_barShader->setUniformValue(m_barShader->nModel(), - itModelMatrix.transposed().inverted()); - m_barShader->setUniformValue(m_barShader->MVP(), MVPMatrix); - if (m_cachedColorStyle == Q3DTheme::ColorStyleUniform) { - m_barShader->setUniformValue(m_barShader->color(), barColor); - } else if (m_cachedColorStyle == Q3DTheme::ColorStyleRangeGradient) { - m_barShader->setUniformValue(m_barShader->gradientHeight(), - qAbs(item.height()) / m_gradientFraction); + barShader->setUniformValue(barShader->model(), modelMatrix); + barShader->setUniformValue(barShader->nModel(), + itModelMatrix.transposed().inverted()); + barShader->setUniformValue(barShader->MVP(), MVPMatrix); + if (colorStyleIsUniform) { + barShader->setUniformValue(barShader->color(), barColor); + } else if (colorStyle == Q3DTheme::ColorStyleRangeGradient) { + barShader->setUniformValue(barShader->gradientHeight(), + qAbs(item.height()) / m_gradientFraction); } #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; - m_barShader->setUniformValue(m_barShader->shadowQ(), m_shadowQualityToShader); - m_barShader->setUniformValue(m_barShader->depth(), depthMVPMatrix); - m_barShader->setUniformValue(m_barShader->lightS(), shadowLightStrength); + barShader->setUniformValue(barShader->shadowQ(), m_shadowQualityToShader); + barShader->setUniformValue(barShader->depth(), depthMVPMatrix); + barShader->setUniformValue(barShader->lightS(), shadowLightStrength); // Draw the object - m_drawer->drawObject(m_barShader, barObj, gradientTexture, m_depthTexture); + m_drawer->drawObject(barShader, barObj, gradientTexture, m_depthTexture); } else #endif { // Set shadowless shader bindings - m_barShader->setUniformValue(m_barShader->lightS(), lightStrength); + barShader->setUniformValue(barShader->lightS(), lightStrength); // Draw the object - m_drawer->drawObject(m_barShader, barObj, gradientTexture); + m_drawer->drawObject(barShader, barObj, gradientTexture); } } - seriesPos += m_seriesStep; } } + seriesPos += m_seriesStep; } - // Release bar shader - m_barShader->release(); - // Bind background shader m_backgroundShader->bind(); @@ -1325,9 +1392,6 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } } - // Release background shader - m_backgroundShader->release(); - // Disable textures glDisable(GL_TEXTURE_2D); @@ -1553,8 +1617,6 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) lineHeight += heightStep; } } - // Release bar shader - lineShader->release(); } // Bind label shader @@ -1788,8 +1850,8 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); - // Release label shader - m_labelShader->release(); + // Release shader + glUseProgram(0); m_selectionDirty = false; } @@ -2098,6 +2160,14 @@ void Bars3DRenderer::initShaders(const QString &vertexShader, const QString &fra m_barShader->initialize(); } +void Bars3DRenderer::initGradientShaders(const QString &vertexShader, const QString &fragmentShader) +{ + if (m_barGradientShader) + delete m_barGradientShader; + m_barGradientShader = new ShaderHelper(this, vertexShader, fragmentShader); + m_barGradientShader->initialize(); +} + void Bars3DRenderer::initSelectionShader() { if (m_selectionShader) diff --git a/src/datavisualization/engine/bars3drenderer_p.h b/src/datavisualization/engine/bars3drenderer_p.h index e3f8af4f..44330e42 100644 --- a/src/datavisualization/engine/bars3drenderer_p.h +++ b/src/datavisualization/engine/bars3drenderer_p.h @@ -70,6 +70,7 @@ private: QRect m_sliceViewPort; bool m_updateLabels; ShaderHelper *m_barShader; + ShaderHelper *m_barGradientShader; ShaderHelper *m_depthShader; ShaderHelper *m_selectionShader; ShaderHelper *m_backgroundShader; @@ -135,6 +136,7 @@ signals: private: virtual void initShaders(const QString &vertexShader, const QString &fragmentShader); + virtual void initGradientShaders(const QString &vertexShader, const QString &fragmentShader); virtual void updateShadowQuality(QDataVis::ShadowQuality quality); virtual void updateTextures(); virtual void fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh mesh); diff --git a/src/datavisualization/engine/drawer.cpp b/src/datavisualization/engine/drawer.cpp index f88b1f49..14f0b315 100644 --- a/src/datavisualization/engine/drawer.cpp +++ b/src/datavisualization/engine/drawer.cpp @@ -148,10 +148,14 @@ void Drawer::drawObject(ShaderHelper *shader, AbstractObjectHelper *object, GLui glDisableVertexAttribArray(shader->posAtt()); // Release textures - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, 0); + if (depthTextureId) { + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, 0); + } + if (textureId) { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, 0); + } } void Drawer::drawSurfaceGrid(ShaderHelper *shader, SurfaceObject *object) diff --git a/src/datavisualization/engine/q3dbars.cpp b/src/datavisualization/engine/q3dbars.cpp index 1eece537..d84b0cac 100644 --- a/src/datavisualization/engine/q3dbars.cpp +++ b/src/datavisualization/engine/q3dbars.cpp @@ -108,20 +108,6 @@ Q3DBars::Q3DBars() &Q3DBars::shadowQualityChanged); QObject::connect(d_ptr->m_shared, &Abstract3DController::themeChanged, this, &Q3DBars::themeChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::colorStyleChanged, this, - &Q3DBars::colorStyleChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::objectColorChanged, this, - &Q3DBars::barColorChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::objectGradientChanged, this, - &Q3DBars::barGradientChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::singleHighlightColorChanged, this, - &Q3DBars::singleHighlightColorChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::singleHighlightGradientChanged, this, - &Q3DBars::singleHighlightGradientChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::multiHighlightColorChanged, this, - &Q3DBars::multiHighlightColorChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::multiHighlightGradientChanged, this, - &Q3DBars::multiHighlightGradientChanged); QObject::connect(d_ptr->m_shared, &Abstract3DController::needRender, this, &Q3DWindow::renderLater); } @@ -361,135 +347,6 @@ QDataVis::ShadowQuality Q3DBars::shadowQuality() const } /*! - * \property Q3DBars::colorStyle - * - * Sets the color \a style used to render bars. - * Defaults to true. - * - * \sa barColor, barGradient - */ -void Q3DBars::setColorStyle(Q3DTheme::ColorStyle style) -{ - d_ptr->m_shared->setColorStyle(style); -} - -Q3DTheme::ColorStyle Q3DBars::colorStyle() const -{ - return d_ptr->m_shared->colorStyle(); -} - -/*! - * \property Q3DBars::barColor - * - * Set bar color to the \a color for this set. Overrides any previously set bar gradient for this - * set, as well as any bar gradient or color from the theme. - * - * \sa theme, barGradient - */ -void Q3DBars::setBarColor(const QColor &color) -{ - d_ptr->m_shared->setBaseColor(color); -} - -QColor Q3DBars::barColor() const -{ - return d_ptr->m_shared->baseColor(); -} - -/*! - * \property Q3DBars::barGradient - * - * Set bar gradient to the \a gradient for this set. Overrides any previously set bar color for this - * set, as well as any bar gradient or color from the theme. - * - * \sa theme, barColor, colorStyle - */ -void Q3DBars::setBarGradient(const QLinearGradient &gradient) -{ - d_ptr->m_shared->setBaseGradient(gradient); -} - -QLinearGradient Q3DBars::barGradient() const -{ - return d_ptr->m_shared->baseGradient(); -} - -/*! - * \property Q3DBars::singleHighlightColor - * - * Set single bar highlight color to the \a color for this set. Overrides any previously set single - * bar highlight gradient for this set, as well as any single bar highlight gradient or color from the theme. - * - * \sa theme, singleHighlightGradient - */ -void Q3DBars::setSingleHighlightColor(const QColor &color) -{ - d_ptr->m_shared->setSingleHighlightColor(color); -} - -QColor Q3DBars::singleHighlightColor() const -{ - return d_ptr->m_shared->singleHighlightColor(); -} - -/*! - * \property Q3DBars::singleHighlightGradient - * - * Set single bar highlight gradient to the \a gradient for this set. - * Overrides any previously set single bar highlight color for this - * set, as well as any single bar highlight gradient or color from the theme. - * - * \sa theme, singleHighlightColor, colorStyle - */ -void Q3DBars::setSingleHighlightGradient(const QLinearGradient &gradient) -{ - d_ptr->m_shared->setSingleHighlightGradient(gradient); -} - -QLinearGradient Q3DBars::singleHighlightGradient() const -{ - return d_ptr->m_shared->singleHighlightGradient(); -} - -/*! - * \property Q3DBars::multiHighlightColor - * - * Set multiple bar highlight (e.g. row/column highlight) color to the \a color for this set. - * Overrides any previously set multiple bar highlight gradient for this set, as well as any - * multiple bar highlight gradient or color from the theme. - * - * \sa theme, multiHighlightGradient - */ -void Q3DBars::setMultiHighlightColor(const QColor &color) -{ - d_ptr->m_shared->setMultiHighlightColor(color); -} - -QColor Q3DBars::multiHighlightColor() const -{ - return d_ptr->m_shared->multiHighlightColor(); -} - -/*! - * \property Q3DBars::multiHighlightGradient - * - * Set multiple bar highlight (e.g. row/column highlight) gradient to the \a gradient for this set. - * Overrides any previously set multiple bar highlight color for this - * set, as well as any multiple bar highlight gradient or color from the theme. - * - * \sa theme, multiHighlightColor, colorStyle - */ -void Q3DBars::setMultiHighlightGradient(const QLinearGradient &gradient) -{ - d_ptr->m_shared->setMultiHighlightGradient(gradient); -} - -QLinearGradient Q3DBars::multiHighlightGradient() const -{ - return d_ptr->m_shared->multiHighlightGradient(); -} - -/*! * Sets a user-defined row \a axis. Implicitly calls addAxis() to transfer ownership of * the \a axis to this graph. * diff --git a/src/datavisualization/engine/q3dbars.h b/src/datavisualization/engine/q3dbars.h index cdb0d9a7..25172993 100644 --- a/src/datavisualization/engine/q3dbars.h +++ b/src/datavisualization/engine/q3dbars.h @@ -44,13 +44,6 @@ class QT_DATAVISUALIZATION_EXPORT Q3DBars : public Q3DWindow Q_PROPERTY(bool barSpacingRelative READ isBarSpacingRelative WRITE setBarSpacingRelative NOTIFY barSpacingRelativeChanged) Q_PROPERTY(Q3DTheme* theme READ theme WRITE setTheme NOTIFY themeChanged) Q_PROPERTY(Q3DScene* scene READ scene) - Q_PROPERTY(QtDataVisualization::Q3DTheme::ColorStyle colorStyle READ colorStyle WRITE setColorStyle NOTIFY colorStyleChanged) - Q_PROPERTY(QColor barColor READ barColor WRITE setBarColor NOTIFY barColorChanged) - Q_PROPERTY(QLinearGradient barGradient READ barGradient WRITE setBarGradient NOTIFY barGradientChanged) - Q_PROPERTY(QColor singleHighlightColor READ singleHighlightColor WRITE setSingleHighlightColor NOTIFY singleHighlightColorChanged) - Q_PROPERTY(QLinearGradient singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged) - Q_PROPERTY(QColor multiHighlightColor READ multiHighlightColor WRITE setMultiHighlightColor NOTIFY multiHighlightColorChanged) - Q_PROPERTY(QLinearGradient multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged) public: explicit Q3DBars(); @@ -83,22 +76,6 @@ public: void setShadowQuality(QDataVis::ShadowQuality quality); QDataVis::ShadowQuality shadowQuality() const; - // TODO: Move to dataset object once that is done QTRD-2121 - void setColorStyle(Q3DTheme::ColorStyle style); - Q3DTheme::ColorStyle colorStyle() const; - void setBarColor(const QColor &color); - QColor barColor() const; - void setBarGradient(const QLinearGradient &gradient); - QLinearGradient barGradient() const; - void setSingleHighlightColor(const QColor &color); - QColor singleHighlightColor() const; - void setSingleHighlightGradient(const QLinearGradient &gradient); - QLinearGradient singleHighlightGradient() const; - void setMultiHighlightColor(const QColor &color); - QColor multiHighlightColor() const; - void setMultiHighlightGradient(const QLinearGradient &gradient); - QLinearGradient multiHighlightGradient() const; - void setRowAxis(Q3DCategoryAxis *axis); Q3DCategoryAxis *rowAxis() const; void setColumnAxis(Q3DCategoryAxis *axis); @@ -116,13 +93,6 @@ signals: void barSpacingChanged(QSizeF spacing); void barSpacingRelativeChanged(bool relative); void themeChanged(Q3DTheme *theme); - void colorStyleChanged(Q3DTheme::ColorStyle style); - void barColorChanged(QColor color); - void barGradientChanged(QLinearGradient gradient); - void singleHighlightColorChanged(QColor color); - void singleHighlightGradientChanged(QLinearGradient gradient); - void multiHighlightColorChanged(QColor color); - void multiHighlightGradientChanged(QLinearGradient gradient); protected: diff --git a/src/datavisualization/engine/q3dscatter.cpp b/src/datavisualization/engine/q3dscatter.cpp index e65aef0f..0c3a88af 100644 --- a/src/datavisualization/engine/q3dscatter.cpp +++ b/src/datavisualization/engine/q3dscatter.cpp @@ -92,20 +92,6 @@ Q3DScatter::Q3DScatter() &Q3DScatter::shadowQualityChanged); QObject::connect(d_ptr->m_shared, &Abstract3DController::themeChanged, this, &Q3DScatter::themeChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::colorStyleChanged, this, - &Q3DScatter::colorStyleChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::objectColorChanged, this, - &Q3DScatter::itemColorChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::objectGradientChanged, this, - &Q3DScatter::itemGradientChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::singleHighlightColorChanged, this, - &Q3DScatter::singleHighlightColorChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::singleHighlightGradientChanged, this, - &Q3DScatter::singleHighlightGradientChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::multiHighlightColorChanged, this, - &Q3DScatter::multiHighlightColorChanged); - QObject::connect(d_ptr->m_shared, &Abstract3DController::multiHighlightGradientChanged, this, - &Q3DScatter::multiHighlightGradientChanged); QObject::connect(d_ptr->m_shared, &Abstract3DController::needRender, this, &Q3DWindow::renderLater); } @@ -284,135 +270,6 @@ QDataVis::ShadowQuality Q3DScatter::shadowQuality() const } /*! - * \property Q3DScatter::colorStyle - * - * Sets the color \a style used to render items. - * Defaults to true. - * - * \sa itemColor, itemGradient - */ -void Q3DScatter::setColorStyle(Q3DTheme::ColorStyle style) -{ - d_ptr->m_shared->setColorStyle(style); -} - -Q3DTheme::ColorStyle Q3DScatter::colorStyle() const -{ - return d_ptr->m_shared->colorStyle(); -} - -/*! - * \property Q3DScatter::itemColor - * - * Set item color to the \a color for this set. Overrides any previously set item gradient for this - * set, as well as any item gradient or color from the theme. - * - * \sa theme, itemGradient - */ -void Q3DScatter::setItemColor(const QColor &color) -{ - d_ptr->m_shared->setBaseColor(color); -} - -QColor Q3DScatter::itemColor() const -{ - return d_ptr->m_shared->baseColor(); -} - -/*! - * \property Q3DScatter::itemGradient - * - * Set item gradient to the \a gradient for this set. Overrides any previously set item color for this - * set, as well as any item gradient or color from the theme. - * - * \sa theme, itemColor, colorStyle - */ -void Q3DScatter::setItemGradient(const QLinearGradient &gradient) -{ - d_ptr->m_shared->setBaseGradient(gradient); -} - -QLinearGradient Q3DScatter::itemGradient() const -{ - return d_ptr->m_shared->baseGradient(); -} - -/*! - * \property Q3DScatter::singleHighlightColor - * - * Set single item highlight color to the \a color for this set. Overrides any previously set single - * item highlight gradient for this set, as well as any single item highlight gradient or color from the theme. - * - * \sa theme, singleHighlightGradient - */ -void Q3DScatter::setSingleHighlightColor(const QColor &color) -{ - d_ptr->m_shared->setSingleHighlightColor(color); -} - -QColor Q3DScatter::singleHighlightColor() const -{ - return d_ptr->m_shared->singleHighlightColor(); -} - -/*! - * \property Q3DScatter::singleHighlightGradient - * - * Set single item highlight gradient to the \a gradient for this set. - * Overrides any previously set single item highlight color for this - * set, as well as any single item highlight gradient or color from the theme. - * - * \sa theme, singleHighlightColor, colorStyle - */ -void Q3DScatter::setSingleHighlightGradient(const QLinearGradient &gradient) -{ - d_ptr->m_shared->setSingleHighlightGradient(gradient); -} - -QLinearGradient Q3DScatter::singleHighlightGradient() const -{ - return d_ptr->m_shared->singleHighlightGradient(); -} - -/*! - * \property Q3DScatter::multiHighlightColor - * - * Set multiple item highlight (e.g. row/column highlight) color to the \a color for this set. - * Overrides any previously set multiple item highlight gradient for this set, as well as any - * multiple item highlight gradient or color from the theme. - * - * \sa theme, multiHighlightGradient - */ -void Q3DScatter::setMultiHighlightColor(const QColor &color) -{ - d_ptr->m_shared->setMultiHighlightColor(color); -} - -QColor Q3DScatter::multiHighlightColor() const -{ - return d_ptr->m_shared->multiHighlightColor(); -} - -/*! - * \property Q3DScatter::multiHighlightGradient - * - * Set multiple item highlight (e.g. row/column highlight) gradient to the \a gradient for this set. - * Overrides any previously set multiple item highlight color for this - * set, as well as any multiple item highlight gradient or color from the theme. - * - * \sa theme, multiHighlightColor, colorStyle - */ -void Q3DScatter::setMultiHighlightGradient(const QLinearGradient &gradient) -{ - d_ptr->m_shared->setMultiHighlightGradient(gradient); -} - -QLinearGradient Q3DScatter::multiHighlightGradient() const -{ - return d_ptr->m_shared->multiHighlightGradient(); -} - -/*! * Sets a user-defined X-axis. Implicitly calls addAxis() to transfer ownership * of the \a axis to this graph. * diff --git a/src/datavisualization/engine/q3dscatter.h b/src/datavisualization/engine/q3dscatter.h index 96ccf69b..ad0da053 100644 --- a/src/datavisualization/engine/q3dscatter.h +++ b/src/datavisualization/engine/q3dscatter.h @@ -42,13 +42,6 @@ class QT_DATAVISUALIZATION_EXPORT Q3DScatter : public Q3DWindow Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged) Q_PROPERTY(Q3DTheme* theme READ theme WRITE setTheme NOTIFY themeChanged) Q_PROPERTY(Q3DScene* scene READ scene) - Q_PROPERTY(QtDataVisualization::Q3DTheme::ColorStyle colorStyle READ colorStyle WRITE setColorStyle NOTIFY colorStyleChanged) - Q_PROPERTY(QColor itemColor READ itemColor WRITE setItemColor NOTIFY itemColorChanged) - Q_PROPERTY(QLinearGradient itemGradient READ itemGradient WRITE setItemGradient NOTIFY itemGradientChanged) - Q_PROPERTY(QColor singleHighlightColor READ singleHighlightColor WRITE setSingleHighlightColor NOTIFY singleHighlightColorChanged) - Q_PROPERTY(QLinearGradient singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged) - Q_PROPERTY(QColor multiHighlightColor READ multiHighlightColor WRITE setMultiHighlightColor NOTIFY multiHighlightColorChanged) - Q_PROPERTY(QLinearGradient multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged) public: explicit Q3DScatter(); @@ -72,22 +65,6 @@ public: void setShadowQuality(QDataVis::ShadowQuality quality); QDataVis::ShadowQuality shadowQuality() const; - // TODO: Move to dataset object once that is done QTRD-2121 - void setColorStyle(Q3DTheme::ColorStyle style); - Q3DTheme::ColorStyle colorStyle() const; - void setItemColor(const QColor &color); - QColor itemColor() const; - void setItemGradient(const QLinearGradient &gradient); - QLinearGradient itemGradient() const; - void setSingleHighlightColor(const QColor &color); - QColor singleHighlightColor() const; - void setSingleHighlightGradient(const QLinearGradient &gradient); - QLinearGradient singleHighlightGradient() const; - void setMultiHighlightColor(const QColor &color); - QColor multiHighlightColor() const; - void setMultiHighlightGradient(const QLinearGradient &gradient); - QLinearGradient multiHighlightGradient() const; - void setAxisX(Q3DValueAxis *axis); Q3DValueAxis *axisX() const; void setAxisY(Q3DValueAxis *axis); @@ -102,13 +79,6 @@ signals: void selectionModeChanged(QDataVis::SelectionFlags mode); void shadowQualityChanged(QDataVis::ShadowQuality quality); void themeChanged(Q3DTheme* theme); - void colorStyleChanged(Q3DTheme::ColorStyle style); - void itemColorChanged(QColor color); - void itemGradientChanged(QLinearGradient gradient); - void singleHighlightColorChanged(QColor color); - void singleHighlightGradientChanged(QLinearGradient gradient); - void multiHighlightColorChanged(QColor color); - void multiHighlightGradientChanged(QLinearGradient gradient); protected: void mouseDoubleClickEvent(QMouseEvent *event); diff --git a/src/datavisualization/engine/q3dsurface.cpp b/src/datavisualization/engine/q3dsurface.cpp index 9a0fcd03..63d94a29 100644 --- a/src/datavisualization/engine/q3dsurface.cpp +++ b/src/datavisualization/engine/q3dsurface.cpp @@ -34,9 +34,8 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE * \since Qt Data Visualization 1.0 * * This class enables developers to render 3D surface plots and to view them by rotating the scene - * freely. The class provides configurable gradient texture to illustrate the height on the data. The - * surface plotting includes also gridline that can be set on or off. The visual appearance of the - * surface can be changed by controlling the smooth status. + * freely. The surface plotting includes also gridline that can be set on or off. + * The visual appearance of the surface can be changed by controlling the smooth status. * * The Q3DSurface supports selection by showing a highlighted ball on the data point where the user has clicked * with left mouse button (when default input handler is in use) or selected via QSurface3DSeries. @@ -257,22 +256,6 @@ QDataVis::SelectionFlags Q3DSurface::selectionMode() const } /*! - * \property Q3DSurface::gradient - * - * The current surface gradient. Setting this property replaces the previous gradient with - * the given \a gradient. - */ -void Q3DSurface::setGradient(const QLinearGradient &gradient) -{ - d_ptr->m_shared->setGradient(gradient); -} - -QLinearGradient Q3DSurface::gradient() const -{ - return d_ptr->m_shared->gradient(); -} - -/*! * \property Q3DSurface::scene * * This property contains the read only Q3DScene that can be used to access, for example, a camera object. @@ -391,15 +374,6 @@ QList<Q3DValueAxis *> Q3DSurface::axes() const return retList; } -/*! - * Modifies the current surface gradient. Sets gradient color to \a color at \a pos. - */ -// TODO: Surface gradient should use base color of series -void Q3DSurface::setGradientColorAt(qreal pos, const QColor &color) -{ - d_ptr->m_shared->setGradientColorAt(pos, color); -} - /////////////////// PRIVATE /////////////////////////////////// Q3DSurfacePrivate::Q3DSurfacePrivate(Q3DSurface *q, QRect rect) diff --git a/src/datavisualization/engine/q3dsurface.h b/src/datavisualization/engine/q3dsurface.h index bbe2d47a..f23841b7 100644 --- a/src/datavisualization/engine/q3dsurface.h +++ b/src/datavisualization/engine/q3dsurface.h @@ -23,7 +23,6 @@ #include <QtDataVisualization/q3dwindow.h> #include <QtDataVisualization/q3dscene.h> #include <QFont> -#include <QLinearGradient> QT_DATAVISUALIZATION_BEGIN_NAMESPACE @@ -38,7 +37,6 @@ class QT_DATAVISUALIZATION_EXPORT Q3DSurface : public Q3DWindow Q_PROPERTY(QtDataVisualization::QDataVis::SelectionFlags selectionMode READ selectionMode WRITE setSelectionMode NOTIFY selectionModeChanged) Q_PROPERTY(Q3DTheme* theme READ theme WRITE setTheme NOTIFY themeChanged) Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged) - Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient) Q_PROPERTY(Q3DScene* scene READ scene) public: @@ -57,10 +55,6 @@ public: void setSelectionMode(QDataVis::SelectionFlags mode); QDataVis::SelectionFlags selectionMode() const; - void setGradient(const QLinearGradient &gradient); - QLinearGradient gradient() const; - - void setGradientColorAt(qreal pos, const QColor &color); // Axes void setAxisX(Q3DValueAxis *axis); diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp index 92e9e9d5..237fb398 100644 --- a/src/datavisualization/engine/scatter3drenderer.cpp +++ b/src/datavisualization/engine/scatter3drenderer.cpp @@ -61,6 +61,7 @@ Scatter3DRenderer::Scatter3DRenderer(Scatter3DController *controller) m_yFlipped(false), m_updateLabels(false), m_dotShader(0), + m_dotGradientShader(0), #if defined(QT_OPENGL_ES_2) m_pointShader(0), #endif @@ -103,6 +104,7 @@ Scatter3DRenderer::~Scatter3DRenderer() m_textureHelper->glDeleteFramebuffers(1, &m_depthFrameBuffer); m_textureHelper->deleteTexture(&m_bgrTexture); delete m_dotShader; + delete m_dotGradientShader; delete m_depthShader; delete m_selectionShader; delete m_backgroundShader; @@ -303,11 +305,18 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) // Check if we have any series with points bool havePointSeries = false; bool haveMeshSeries = false; + bool haveUniformColorMeshSeries = false; + bool haveGradientMeshSeries = false; for (int i = 0; i < seriesCount; i++) { - if (m_visibleSeriesList.at(i).mesh() == QAbstract3DSeries::MeshPoint) + if (m_visibleSeriesList.at(i).mesh() == QAbstract3DSeries::MeshPoint) { havePointSeries = true; - else + } else { haveMeshSeries = true; + if (m_visibleSeriesList.at(i).colorStyle() == Q3DTheme::ColorStyleUniform) + haveUniformColorMeshSeries = true; + else + haveGradientMeshSeries = true; + } } #if !defined(QT_OPENGL_ES_2) @@ -362,6 +371,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) ObjectHelper *dotObj = m_visibleSeriesList.at(series).object(); bool drawingPoints = (m_visibleSeriesList.at(series).mesh() == QAbstract3DSeries::MeshPoint); + // TODO: Accessing series directly during rendering float itemSize = static_cast<QScatter3DSeries *>(m_visibleSeriesList.at(series).series())->itemSize() / itemScaler; @@ -420,9 +430,6 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) // Reset culling to normal glCullFace(GL_BACK); - // Release depth shader - m_depthShader->release(); - // Revert to original viewport glViewport(m_mainViewPort.x(), m_mainViewPort.y(), m_mainViewPort.width(), m_mainViewPort.height()); @@ -438,7 +445,6 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, m_depthTexture); glDisable(GL_TEXTURE_2D); - m_labelShader->release(); #endif } @@ -468,6 +474,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) ObjectHelper *dotObj = m_visibleSeriesList.at(series).object(); bool drawingPoints = (m_visibleSeriesList.at(series).mesh() == QAbstract3DSeries::MeshPoint); + // TODO: Accessing series directly during rendering float itemSize = static_cast<QScatter3DSeries *>(m_visibleSeriesList.at(series).series())->itemSize() / itemScaler; @@ -482,8 +489,6 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) // Rebind selection shader if it has changed if (drawingPoints != previousDrawingPoints) { previousDrawingPoints = drawingPoints; - if (series) // Don't release for first series - selectionShader->release(); if (drawingPoints) selectionShader = pointSelectionShader; else @@ -554,10 +559,6 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) glBindFramebuffer(GL_FRAMEBUFFER, defaultFboHandle); - // Release selection shader - if (seriesCount) - selectionShader->release(); - #if 0 // Use this if you want to see what is being drawn to the framebuffer m_labelShader->bind(); glDisable(GL_DEPTH_TEST); @@ -569,7 +570,6 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, m_selectionTexture); glDisable(GL_TEXTURE_2D); - m_labelShader->release(); #endif } @@ -579,40 +579,48 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) bool dotSelectionFound = false; ScatterRenderItem *selectedItem(0); int dotNo = 0; + QVector3D baseColor; + QVector3D dotColor; bool previousDrawingPoints = false; + Q3DTheme::ColorStyle previousMeshColorStyle = Q3DTheme::ColorStyleUniform; if (haveMeshSeries) { - dotShader = m_dotShader; - dotShader->bind(); - // Set unchanging shader bindings - dotShader->setUniformValue(dotShader->lightP(), lightPos); - dotShader->setUniformValue(dotShader->view(), viewMatrix); - dotShader->setUniformValue(dotShader->ambientS(), m_cachedTheme->ambientLightStrength()); - if (m_cachedColorStyle != Q3DTheme::ColorStyleUniform) { - if (m_cachedColorStyle == Q3DTheme::ColorStyleObjectGradient) { - dotShader->setUniformValue(dotShader->gradientMin(), 0.0f); - dotShader->setUniformValue(dotShader->gradientHeight(), 0.5f); - } else { - // Each ball is of uniform color according to its Y-coordinate - dotShader->setUniformValue(dotShader->gradientHeight(), 0.0f); - } - gradientTexture = m_objectGradientTexture; + if (haveGradientMeshSeries) { + m_dotGradientShader->bind(); + m_dotGradientShader->setUniformValue(m_dotGradientShader->lightP(), lightPos); + m_dotGradientShader->setUniformValue(m_dotGradientShader->view(), viewMatrix); + m_dotGradientShader->setUniformValue(m_dotGradientShader->ambientS(), m_cachedTheme->ambientLightStrength()); + } + if (haveUniformColorMeshSeries) { + m_dotShader->bind(); + m_dotShader->setUniformValue(m_dotShader->lightP(), lightPos); + m_dotShader->setUniformValue(m_dotShader->view(), viewMatrix); + m_dotShader->setUniformValue(m_dotShader->ambientS(), m_cachedTheme->ambientLightStrength()); + dotShader = m_dotShader; + } else { + dotShader = m_dotGradientShader; + previousMeshColorStyle = Q3DTheme::ColorStyleRangeGradient; + m_dotGradientShader->setUniformValue(m_dotGradientShader->gradientHeight(), 0.0f); } - glEnable(GL_TEXTURE_2D); } else { dotShader = pointSelectionShader; - dotShader->bind(); previousDrawingPoints = true; + dotShader->bind(); } for (int series = 0; series < seriesCount; series++) { - ObjectHelper *dotObj = m_visibleSeriesList.at(series).object(); - bool drawingPoints = (m_visibleSeriesList.at(series).mesh() == QAbstract3DSeries::MeshPoint); - + const SeriesRenderCache ¤tSeries = m_visibleSeriesList.at(series); + ObjectHelper *dotObj = currentSeries.object(); + bool drawingPoints = (currentSeries.mesh() == QAbstract3DSeries::MeshPoint); + Q3DTheme::ColorStyle colorStyle = currentSeries.colorStyle(); + bool colorStyleIsUniform = (colorStyle == Q3DTheme::ColorStyleUniform); + bool useColor = colorStyleIsUniform || drawingPoints; + + // TODO: Accessing series directly during rendering float itemSize = - static_cast<QScatter3DSeries *>(m_visibleSeriesList.at(series).series())->itemSize() + static_cast<QScatter3DSeries *>(currentSeries.series())->itemSize() / itemScaler; if (itemSize == 0.0f) itemSize = m_dotSizeScale; @@ -622,22 +630,42 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #endif QVector3D modelScaler(itemSize, itemSize, itemSize); - // Rebind selection shader if it has changed - if (drawingPoints != previousDrawingPoints) { + // Rebind shader if it has changed + if (drawingPoints != previousDrawingPoints + || (!drawingPoints && + (colorStyleIsUniform != (previousMeshColorStyle == Q3DTheme::ColorStyleUniform)))) { previousDrawingPoints = drawingPoints; - dotShader->release(); - if (drawingPoints) + if (drawingPoints) { dotShader = pointSelectionShader; - else - dotShader = m_dotShader; + } else { + if (colorStyleIsUniform) + dotShader = m_dotShader; + else + dotShader = m_dotGradientShader; + } dotShader->bind(); } - // TODO: Color per series. Let's just hack it while testing with 2 series QTRD-2557 - QVector3D baseColor = Utils::vectorFromColor(m_cachedObjectColor) * (series + 0.25f); - QVector3D dotColor = baseColor; + if (!drawingPoints && !colorStyleIsUniform && previousMeshColorStyle != colorStyle) { + if (colorStyle == Q3DTheme::ColorStyleObjectGradient) { + m_dotGradientShader->setUniformValue(m_dotGradientShader->gradientMin(), 0.0f); + m_dotGradientShader->setUniformValue(m_dotGradientShader->gradientHeight(), 0.5f); + } else { + // Each ball is of uniform color according to its Y-coordinate + m_dotGradientShader->setUniformValue(m_dotGradientShader->gradientHeight(), 0.0f); + } + } + + if (!drawingPoints) + previousMeshColorStyle = colorStyle; + + if (useColor) { + baseColor = currentSeries.baseColor(); + dotColor = baseColor; + } - for (int dot = 0; dot < m_renderingArrays.at(series).size(); dot++) { + int seriesSize = m_renderingArrays.at(series).size(); + for (int dot = 0; dot < seriesSize; dot++) { ScatterRenderItem &item = m_renderingArrays[series][dot]; if (!item.isVisible()) continue; @@ -657,17 +685,17 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) MVPMatrix = projectionViewMatrix * modelMatrix; #endif - if (m_cachedColorStyle == Q3DTheme::ColorStyleUniform || drawingPoints) + if (useColor) dotColor = baseColor; else - gradientTexture = m_objectGradientTexture; + gradientTexture = currentSeries.baseGradientTexture(); GLfloat lightStrength = m_cachedTheme->lightStrength(); if (m_cachedSelectionMode > QDataVis::SelectionNone && (m_selectedItemTotalIndex == dotNo)) { - if (m_cachedColorStyle == Q3DTheme::ColorStyleUniform || drawingPoints) - dotColor = Utils::vectorFromColor(m_cachedSingleHighlightColor); + if (useColor) + dotColor = currentSeries.singleHighlightColor(); else - gradientTexture = m_singleHighlightGradientTexture; + gradientTexture = currentSeries.singleHighlightGradientTexture(); lightStrength = m_cachedTheme->highlightLightStrength(); // Insert data to ScatterRenderItem. We have no ownership, don't delete the previous one selectedItem = &item; @@ -681,9 +709,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) itModelMatrix.inverted().transposed()); } dotShader->setUniformValue(dotShader->MVP(), MVPMatrix); - if (m_cachedColorStyle == Q3DTheme::ColorStyleUniform || drawingPoints) { + if (useColor) { dotShader->setUniformValue(dotShader->color(), dotColor); - } else if (m_cachedColorStyle == Q3DTheme::ColorStyleRangeGradient) { + } else if (colorStyle == Q3DTheme::ColorStyleRangeGradient) { dotShader->setUniformValue(dotShader->gradientMin(), (item.position().y() + 1.0f) / 2.0f); } @@ -719,9 +747,6 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) } } - // Release dot shader - dotShader->release(); - #if !defined(QT_OPENGL_ES_2) if (havePointSeries) { glDisable(GL_POINT_SMOOTH); @@ -805,9 +830,6 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) } } - // Release background shader - m_backgroundShader->release(); - // Disable textures glDisable(GL_TEXTURE_2D); @@ -1208,9 +1230,6 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) linePos += lineStep; } } - - // Release line shader - lineShader->release(); } // Draw axis labels @@ -1497,8 +1516,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); - // Release label shader - m_labelShader->release(); + // Release shader + glUseProgram(0); m_selectionDirty = false; } @@ -1656,6 +1675,14 @@ void Scatter3DRenderer::initShaders(const QString &vertexShader, const QString & m_dotShader->initialize(); } +void Scatter3DRenderer::initGradientShaders(const QString &vertexShader, const QString &fragmentShader) +{ + if (m_dotGradientShader) + delete m_dotGradientShader; + m_dotGradientShader = new ShaderHelper(this, vertexShader, fragmentShader); + m_dotGradientShader->initialize(); +} + void Scatter3DRenderer::initSelectionShader() { if (m_selectionShader) diff --git a/src/datavisualization/engine/scatter3drenderer_p.h b/src/datavisualization/engine/scatter3drenderer_p.h index 989e3016..7423488f 100644 --- a/src/datavisualization/engine/scatter3drenderer_p.h +++ b/src/datavisualization/engine/scatter3drenderer_p.h @@ -60,6 +60,7 @@ private: QRect m_mainViewPort; bool m_updateLabels; ShaderHelper *m_dotShader; + ShaderHelper *m_dotGradientShader; #if defined(QT_OPENGL_ES_2) ShaderHelper *m_pointShader; #endif @@ -108,6 +109,7 @@ protected: private: virtual void initShaders(const QString &vertexShader, const QString &fragmentShader); + virtual void initGradientShaders(const QString &vertexShader, const QString &fragmentShader); virtual void updateShadowQuality(QDataVis::ShadowQuality quality); virtual void updateTextures(); virtual void fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh mesh); diff --git a/src/datavisualization/engine/selectionpointer.cpp b/src/datavisualization/engine/selectionpointer.cpp index c37e9886..c4eced30 100644 --- a/src/datavisualization/engine/selectionpointer.cpp +++ b/src/datavisualization/engine/selectionpointer.cpp @@ -132,16 +132,13 @@ void SelectionPointer::render(GLuint defaultFboHandle) m_pointShader->setUniformValue(m_pointShader->view(), viewMatrix); m_pointShader->setUniformValue(m_pointShader->model(), modelMatrix); m_pointShader->setUniformValue(m_pointShader->nModel(), itModelMatrix.inverted().transposed()); - m_pointShader->setUniformValue(m_pointShader->color(), - Utils::vectorFromColor(m_cachedTheme->singleHighlightColor())); + m_pointShader->setUniformValue(m_pointShader->color(), m_highlightColor); m_pointShader->setUniformValue(m_pointShader->MVP(), MVPMatrix); m_pointShader->setUniformValue(m_pointShader->ambientS(), m_cachedTheme->ambientLightStrength()); m_pointShader->setUniformValue(m_pointShader->lightS(), m_cachedTheme->lightStrength() * 2.0f); m_drawer->drawObject(m_pointShader, m_pointObj); - m_pointShader->release(); - // // Draw the label // @@ -180,7 +177,8 @@ void SelectionPointer::render(GLuint defaultFboHandle) // Draw the object m_drawer->drawObject(m_labelShader, m_labelObj, m_labelItem.textureId()); - m_labelShader->release(); + // Release shader + glUseProgram(0); // Disable textures glDisable(GL_TEXTURE_2D); @@ -203,6 +201,11 @@ void SelectionPointer::updateSliceData(bool sliceActivated, GLfloat autoScaleAdj m_autoScaleAdjustment = autoScaleAdjustment; } +void SelectionPointer::setHighlightColor(QVector3D colorVector) +{ + m_highlightColor = colorVector; +} + void SelectionPointer::setLabel(const QString &label) { m_label = label; diff --git a/src/datavisualization/engine/selectionpointer_p.h b/src/datavisualization/engine/selectionpointer_p.h index 46903fd2..e4f6c699 100644 --- a/src/datavisualization/engine/selectionpointer_p.h +++ b/src/datavisualization/engine/selectionpointer_p.h @@ -67,6 +67,7 @@ public: void updateBoundingRect(QRect rect); void updateScene(Q3DScene *scene); void updateSliceData(bool sliceActivated, GLfloat autoScaleAdjustment); + void setHighlightColor(QVector3D colorVector); private: void initializeOpenGL(); @@ -89,6 +90,7 @@ private: QString m_label; bool m_cachedIsSlicingActivated; GLfloat m_autoScaleAdjustment; + QVector3D m_highlightColor; }; QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/engine/seriesrendercache.cpp b/src/datavisualization/engine/seriesrendercache.cpp index 7a4c0a14..b1c78c24 100644 --- a/src/datavisualization/engine/seriesrendercache.cpp +++ b/src/datavisualization/engine/seriesrendercache.cpp @@ -19,6 +19,8 @@ #include "seriesrendercache_p.h" #include "objecthelper_p.h" #include "abstract3drenderer_p.h" +#include "texturehelper_p.h" +#include "utils_p.h" QT_DATAVISUALIZATION_BEGIN_NAMESPACE @@ -119,7 +121,50 @@ void SeriesRenderCache::populate(QAbstract3DSeries *series, Abstract3DRenderer * } } - // TODO: Add other visual element extractions + if (seriesChanged || changeTracker.colorStyleChanged) { + m_colorStyle = series->colorStyle(); + changeTracker.colorStyleChanged = false; + } + + if (seriesChanged || changeTracker.baseColorChanged) { + m_baseColor = Utils::vectorFromColor(series->baseColor()); + changeTracker.baseColorChanged = false; + } + + if (seriesChanged || changeTracker.baseGradientChanged) { + renderer->fixGradient(&series->baseGradient(), &m_baseGradientTexture); + changeTracker.baseGradientChanged = false; + } + + if (seriesChanged || changeTracker.singleHighlightColorChanged) { + m_singleHighlightColor = Utils::vectorFromColor(series->singleHighlightColor()); + changeTracker.singleHighlightColorChanged = false; + } + + if (seriesChanged || changeTracker.singleHighlightGradientChanged) { + renderer->fixGradient(&series->singleHighlightGradient(), + &m_singleHighlightGradientTexture); + changeTracker.singleHighlightGradientChanged = false; + } + + if (seriesChanged || changeTracker.multiHighlightColorChanged) { + m_multiHighlightColor = Utils::vectorFromColor(series->multiHighlightColor()); + changeTracker.multiHighlightColorChanged = false; + } + + if (seriesChanged || changeTracker.multiHighlightGradientChanged) { + renderer->fixGradient(&series->multiHighlightGradient(), + &m_multiHighlightGradientTexture); + changeTracker.multiHighlightGradientChanged = false; + } +} + +void SeriesRenderCache::cleanup(TextureHelper *texHelper) +{ + delete m_object; + texHelper->deleteTexture(&m_baseGradientTexture); + texHelper->deleteTexture(&m_singleHighlightGradientTexture); + texHelper->deleteTexture(&m_multiHighlightGradientTexture); } QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/engine/seriesrendercache_p.h b/src/datavisualization/engine/seriesrendercache_p.h index 976b69c3..906a6c0d 100644 --- a/src/datavisualization/engine/seriesrendercache_p.h +++ b/src/datavisualization/engine/seriesrendercache_p.h @@ -36,6 +36,7 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE class Abstract3DRenderer; class ObjectHelper; +class TextureHelper; class SeriesRenderCache { @@ -44,6 +45,7 @@ public: virtual ~SeriesRenderCache(); void populate(QAbstract3DSeries *series, Abstract3DRenderer *renderer); + void cleanup(TextureHelper *texHelper); // NOTE: Series pointer can only be used to access the series when syncing with controller. // It is not guaranteed to be valid while rendering and should only be used as an identifier. @@ -52,14 +54,27 @@ public: inline const QString &itemLabelFormat() const { return m_itemLabelFormat; } inline const QAbstract3DSeries::Mesh &mesh() const { return m_mesh; } inline ObjectHelper *object() const { return m_object; } - - // TODO: Add other visual elements + inline const Q3DTheme::ColorStyle &colorStyle() const { return m_colorStyle; } + inline const QVector3D &baseColor() const { return m_baseColor; } + inline const GLuint &baseGradientTexture() const { return m_baseGradientTexture; } + inline const QVector3D &singleHighlightColor() const { return m_singleHighlightColor; } + inline const GLuint &singleHighlightGradientTexture() const { return m_singleHighlightGradientTexture; } + inline const QVector3D &multiHighlightColor() const { return m_multiHighlightColor; } + inline const GLuint &multiHighlightGradientTexture() const { return m_multiHighlightGradientTexture; } protected: QAbstract3DSeries *m_series; QString m_itemLabelFormat; ObjectHelper *m_object; QAbstract3DSeries::Mesh m_mesh; + + Q3DTheme::ColorStyle m_colorStyle; + QVector3D m_baseColor; + GLuint m_baseGradientTexture; + QVector3D m_singleHighlightColor; + GLuint m_singleHighlightGradientTexture; + QVector3D m_multiHighlightColor; + GLuint m_multiHighlightGradientTexture; }; QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/engine/surface3dcontroller.cpp b/src/datavisualization/engine/surface3dcontroller.cpp index 0a1bdc4e..1ceb75e2 100644 --- a/src/datavisualization/engine/surface3dcontroller.cpp +++ b/src/datavisualization/engine/surface3dcontroller.cpp @@ -45,9 +45,6 @@ Surface3DController::Surface3DController(QRect rect) setAxisX(0); setAxisY(0); setAxisZ(0); - - // Set the default from the theme - m_userDefinedGradient = theme()->baseGradient(); } Surface3DController::~Surface3DController() @@ -76,11 +73,6 @@ void Surface3DController::synchDataToRenderer() Abstract3DController::synchDataToRenderer(); // Notify changes to renderer - if (m_changeTracker.gradientColorChanged) { - m_renderer->updateSurfaceGradient(m_userDefinedGradient); - m_changeTracker.gradientColorChanged = false; - } - if (m_changeTracker.rowsChanged) { m_renderer->updateRows(m_changedRows); m_changeTracker.rowsChanged = false; @@ -177,27 +169,6 @@ QList<QSurface3DSeries *> Surface3DController::surfaceSeriesList() return surfaceSeriesList; } -void Surface3DController::setGradient(const QLinearGradient &gradient) -{ - if (gradient != m_userDefinedGradient) { - m_userDefinedGradient = gradient; - m_changeTracker.gradientColorChanged = true; - emitNeedRender(); - } -} - -QLinearGradient Surface3DController::gradient() const -{ - return m_userDefinedGradient; -} - -void Surface3DController::setGradientColorAt(qreal pos, const QColor &color) -{ - m_userDefinedGradient.setColorAt(pos, color); - m_changeTracker.gradientColorChanged = true; - emitNeedRender(); -} - void Surface3DController::setSelectionMode(QDataVis::SelectionFlags mode) { // Currently surface only supports row and column modes when also slicing diff --git a/src/datavisualization/engine/surface3dcontroller_p.h b/src/datavisualization/engine/surface3dcontroller_p.h index 1dfd9dc2..714420a4 100644 --- a/src/datavisualization/engine/surface3dcontroller_p.h +++ b/src/datavisualization/engine/surface3dcontroller_p.h @@ -32,7 +32,6 @@ #include "abstract3dcontroller_p.h" #include "datavisualizationglobal_p.h" -#include <QLinearGradient> QT_DATAVISUALIZATION_BEGIN_NAMESPACE @@ -40,7 +39,6 @@ class Surface3DRenderer; class QSurface3DSeries; struct Surface3DChangeBitField { - bool gradientColorChanged : 1; bool smoothStatusChanged : 1; bool surfaceGridChanged : 1; bool selectedPointChanged : 1; @@ -48,7 +46,6 @@ struct Surface3DChangeBitField { bool itemChanged : 1; Surface3DChangeBitField() : - gradientColorChanged(false), // Set to false, as it is initially set in theme smoothStatusChanged(true), surfaceGridChanged(true), selectedPointChanged(true), @@ -65,7 +62,6 @@ class QT_DATAVISUALIZATION_EXPORT Surface3DController : public Abstract3DControl private: Surface3DChangeBitField m_changeTracker; Surface3DRenderer *m_renderer; - QLinearGradient m_userDefinedGradient; QPoint m_selectedPoint; QSurface3DSeries *m_selectedSeries; // Points to the series for which the point is selected in // single series selection cases. @@ -80,11 +76,6 @@ public: virtual void initializeOpenGL(); virtual void synchDataToRenderer(); - void setGradient(const QLinearGradient &gradient); - QLinearGradient gradient() const; - - void setGradientColorAt(qreal pos, const QColor &color); - void setSelectionMode(QDataVis::SelectionFlags mode); void setSelectedPoint(const QPoint &position, QSurface3DSeries *series); diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index 81da15da..ecb9696b 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -34,8 +34,6 @@ #include <QMouseEvent> #include <qmath.h> -#include <QLinearGradient> - #include <QDebug> static const int ID_TO_RGBA_MASK = 0xff; @@ -95,7 +93,6 @@ Surface3DRenderer::Surface3DRenderer(Surface3DController *controller) m_depthFrameBuffer(0), m_selectionFrameBuffer(0), m_selectionDepthBuffer(0), - m_gradientTexture(0), m_selectionTexture(0), m_selectionResultTexture(0), m_shadowQualityToShader(33.3f), @@ -113,7 +110,8 @@ Surface3DRenderer::Surface3DRenderer(Surface3DController *controller) m_clickedPointId(invalidSelectionId), m_hasHeightAdjustmentChanged(true), m_selectedPoint(Surface3DController::invalidSelectionPosition()), - m_selectedSeries(0) + m_selectedSeries(0), + m_uniformGradientTexture(0) { // Check if flat feature is supported ShaderHelper tester(this, QStringLiteral(":/shaders/vertexSurfaceFlat"), @@ -129,6 +127,9 @@ Surface3DRenderer::Surface3DRenderer(Surface3DController *controller) initializeOpenGLFunctions(); initializeOpenGL(); + + // Create initial uniform gradient + generateUniformGradient(m_uniformGradientTextureColor); } Surface3DRenderer::~Surface3DRenderer() @@ -139,9 +140,9 @@ Surface3DRenderer::~Surface3DRenderer() m_textureHelper->deleteTexture(&m_depthTexture); m_textureHelper->deleteTexture(&m_depthModelTexture); - m_textureHelper->deleteTexture(&m_gradientTexture); m_textureHelper->deleteTexture(&m_selectionTexture); m_textureHelper->deleteTexture(&m_selectionResultTexture); + m_textureHelper->deleteTexture(&m_uniformGradientTexture); delete m_shader; delete m_depthShader; @@ -282,6 +283,11 @@ void Surface3DRenderer::updateSeries(const QList<QAbstract3DSeries *> &seriesLis QSurface3DSeries *series = static_cast<QSurface3DSeries *>(m_visibleSeriesList.at(0).series()); updateFlatStatus(series->isFlatShadingEnabled()); updateSurfaceGridStatus(series->isSurfaceGridEnabled()); + QVector3D seriesColor = Utils::vectorFromColor(series->baseColor()); + if (m_uniformGradientTextureColor != seriesColor) + generateUniformGradient(seriesColor); + if (m_selectionPointer) + m_selectionPointer->setHighlightColor(Utils::vectorFromColor(series->singleHighlightColor())); } } @@ -634,8 +640,6 @@ void Surface3DRenderer::drawSlicedScene() m_cachedTheme->ambientLightStrength() * 2.0f); m_drawer->drawObject(surfaceShader, m_sliceSurfaceObj); - - surfaceShader->release(); } // Draw surface grid @@ -645,7 +649,6 @@ void Surface3DRenderer::drawSlicedScene() Utils::vectorFromColor(m_cachedTheme->gridLineColor())); m_surfaceGridShader->setUniformValue(m_surfaceGridShader->MVP(), MVPMatrix); m_drawer->drawSurfaceGrid(m_surfaceGridShader, m_sliceSurfaceObj); - m_surfaceGridShader->release(); glDisable(GL_POLYGON_OFFSET_FILL); } @@ -739,9 +742,6 @@ void Surface3DRenderer::drawSlicedScene() linePos += lineStep; } - - // Release line shader - lineShader->release(); } // Draw axis labels @@ -821,8 +821,8 @@ void Surface3DRenderer::drawSlicedScene() glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); - // Release label shader - m_labelShader->release(); + // Release shader + glUseProgram(0); } void Surface3DRenderer::drawScene(GLuint defaultFboHandle) @@ -957,9 +957,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) // Disable drawing to depth framebuffer (= enable drawing to screen) glBindFramebuffer(GL_FRAMEBUFFER, defaultFboHandle); - // Release depth shader - m_depthShader->release(); - // Revert to original viewport glViewport(m_mainViewPort.x(), m_mainViewPort.y(), m_mainViewPort.width(), m_mainViewPort.height()); @@ -980,7 +977,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, m_depthTexture); glDisable(GL_TEXTURE_2D); - m_labelShader->release(); } #endif } @@ -1022,9 +1018,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) glBindFramebuffer(GL_FRAMEBUFFER, defaultFboHandle); - // Release selection shader - m_selectionShader->release(); - // Put the RGBA value back to uint #if !defined(QT_OPENGL_ES_2) uint selectionId = pixel[0] + pixel[1] * 256 + pixel[2] * 65536 + pixel[3] * 16777216; @@ -1071,6 +1064,13 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) m_surfaceShader->setUniformValue(m_surfaceShader->ambientS(), m_cachedTheme->ambientLightStrength()); + // TODO: Do properly when multiseries support implemented QTRD-2657 + GLuint gradientTexture; + if (m_visibleSeriesList.at(0).colorStyle() == Q3DTheme::ColorStyleUniform) + gradientTexture = m_uniformGradientTexture; + else + gradientTexture = m_visibleSeriesList.at(0).baseGradientTexture(); + #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings @@ -1080,7 +1080,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) m_surfaceShader->setUniformValue(m_surfaceShader->lightS(), adjustedLightStrength); // Draw the object - m_drawer->drawObject(m_surfaceShader, m_surfaceObj, m_gradientTexture, m_depthModelTexture); + m_drawer->drawObject(m_surfaceShader, m_surfaceObj, gradientTexture, m_depthModelTexture); } else #endif { @@ -1089,11 +1089,8 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) m_cachedTheme->lightStrength()); // Draw the object - m_drawer->drawObject(m_surfaceShader, m_surfaceObj, m_gradientTexture); + m_drawer->drawObject(m_surfaceShader, m_surfaceObj, gradientTexture); } - - m_surfaceShader->release(); - glEnable(GL_CULL_FACE); } @@ -1104,7 +1101,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) Utils::vectorFromColor(m_cachedTheme->gridLineColor())); m_surfaceGridShader->setUniformValue(m_surfaceGridShader->MVP(), MVPMatrix); m_drawer->drawSurfaceGrid(m_surfaceGridShader, m_surfaceObj); - m_surfaceGridShader->release(); glDisable(GL_POLYGON_OFFSET_FILL); } @@ -1176,9 +1172,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) } } - // Release background shader - m_backgroundShader->release(); - // Draw grid lines QVector3D gridLineScaleX(m_scaleXWithBackground, gridLineWidth, gridLineWidth); QVector3D gridLineScaleZ(gridLineWidth, gridLineWidth, m_scaleZWithBackground); @@ -1502,9 +1495,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) linePos += lineStep; } } - - // Release line shader - lineShader->release(); } // Draw axis labels @@ -1679,8 +1669,8 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); - // Release label shader - m_labelShader->release(); + // Release shader + glUseProgram(0); // Selection handling if (m_selectionDirty) { @@ -1710,20 +1700,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) } } -void Surface3DRenderer::updateSurfaceGradient(const QLinearGradient &gradient) -{ - if (m_gradientTexture) { - m_textureHelper->deleteTexture(&m_gradientTexture); - m_gradientTexture = 0; - } - - QLinearGradient adjustedGradient = gradient; - adjustedGradient.setStart(qreal(gradientTextureWidth), qreal(gradientTextureHeight)); - adjustedGradient.setFinalStop(0.0, 0.0); - - m_gradientTexture = m_textureHelper->createGradientTexture(adjustedGradient); -} - // This one needs to be called when the data size changes void Surface3DRenderer::updateSelectionTexture() { @@ -1811,11 +1787,6 @@ void Surface3DRenderer::idToRGBA(uint id, uchar *r, uchar *g, uchar *b, uchar *a *a = (id >> 24) & ID_TO_RGBA_MASK; } -void Surface3DRenderer::updateTextures() -{ - updateSurfaceGradient(m_cachedTheme->baseGradient()); -} - void Surface3DRenderer::calculateSceneScalingFactors() { // Calculate scene scaling and translation factors @@ -1954,6 +1925,7 @@ void Surface3DRenderer::surfacePointSelected(const QPoint &point) m_selectionPointer->setLabel(createSelectionLabel(value, column, row)); // TODO: Get pointer object from correct series once multiseries support implemented m_selectionPointer->setPointerObject(m_visibleSeriesList.at(0).object()); + m_selectionPointer->setHighlightColor(m_visibleSeriesList.at(0).singleHighlightColor()); m_selectionPointer->updateScene(m_cachedScene); } @@ -2049,6 +2021,11 @@ void Surface3DRenderer::updateShadowQuality(QDataVis::ShadowQuality quality) #endif } +void Surface3DRenderer::updateTextures() +{ + // Do nothing, but required as it is pure virtual on parent +} + void Surface3DRenderer::updateSlicingActive(bool isSlicing) { if (m_cachedIsSlicingActivated == isSlicing) @@ -2098,6 +2075,7 @@ void Surface3DRenderer::loadLabelMesh() void Surface3DRenderer::initShaders(const QString &vertexShader, const QString &fragmentShader) { + // m_shader is used slice view surface only. if (m_shader) delete m_shader; m_shader = new ShaderHelper(this, vertexShader, fragmentShader); @@ -2201,6 +2179,19 @@ void Surface3DRenderer::updateDepthBuffer() lowerShadowQuality(); } } + +void Surface3DRenderer::generateUniformGradient(const QVector3D newColor) +{ + if (m_visibleSeriesList.size()) { + // TODO: move uniform gradient to render cache when multiseries support implemented QTRD-2657 + QColor newQColor = Utils::colorFromVector(newColor); + m_uniformGradientTextureColor = newColor; + QLinearGradient newGradient; + newGradient.setColorAt(0.0, newQColor); + newGradient.setColorAt(1.0, newQColor); + fixGradient(&newGradient, &m_uniformGradientTexture); + } +} #endif QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/engine/surface3drenderer_p.h b/src/datavisualization/engine/surface3drenderer_p.h index 37adb0b9..f1eeb088 100644 --- a/src/datavisualization/engine/surface3drenderer_p.h +++ b/src/datavisualization/engine/surface3drenderer_p.h @@ -33,7 +33,6 @@ #include <QtCore/QObject> #include <QtGui/QOpenGLFunctions> #include <QtGui/QFont> -#include <QLinearGradient> #include <QWindow> #include "datavisualizationglobal_p.h" @@ -105,7 +104,6 @@ private: GLuint m_depthFrameBuffer; GLuint m_selectionFrameBuffer; GLuint m_selectionDepthBuffer; - GLuint m_gradientTexture; GLuint m_selectionTexture; GLuint m_selectionResultTexture; GLfloat m_shadowQualityToShader; @@ -128,6 +126,8 @@ private: bool m_hasHeightAdjustmentChanged; QPoint m_selectedPoint; const QSurface3DSeries *m_selectedSeries; + GLuint m_uniformGradientTexture; + QVector3D m_uniformGradientTextureColor; public: explicit Surface3DRenderer(Surface3DController *controller); @@ -140,7 +140,6 @@ public: void updateScene(Q3DScene *scene); bool updateFlatStatus(bool enable); void updateSurfaceGridStatus(bool enable); - void updateSurfaceGradient(const QLinearGradient &gradient); void updateSlicingActive(bool isSlicing); void updateSelectedPoint(const QPoint &position, const QSurface3DSeries *series); @@ -185,6 +184,7 @@ private: void updateDepthBuffer(); #endif void emitSelectedPointChanged(QPoint position); + void generateUniformGradient(const QVector3D newColor); Q_DISABLE_COPY(Surface3DRenderer) }; diff --git a/src/datavisualization/theme/q3dtheme.cpp b/src/datavisualization/theme/q3dtheme.cpp index 1d7aac5e..f138dfc1 100644 --- a/src/datavisualization/theme/q3dtheme.cpp +++ b/src/datavisualization/theme/q3dtheme.cpp @@ -422,8 +422,8 @@ Q3DTheme::~Q3DTheme() */ void Q3DTheme::setBaseColor(const QColor &color) { + d_ptr->m_dirtyBits.baseColorDirty = true; if (d_ptr->m_baseColor != color) { - d_ptr->m_dirtyBits.baseColorDirty = true; d_ptr->m_baseColor = color; emit baseColorChanged(color); } @@ -441,8 +441,8 @@ QColor Q3DTheme::baseColor() const */ void Q3DTheme::setBackgroundColor(const QColor &color) { + d_ptr->m_dirtyBits.backgroundColorDirty = true; if (d_ptr->m_backgroundColor != color) { - d_ptr->m_dirtyBits.backgroundColorDirty = true; d_ptr->m_backgroundColor = color; emit backgroundColorChanged(color); emit d_ptr->needRender(); @@ -461,8 +461,8 @@ QColor Q3DTheme::backgroundColor() const */ void Q3DTheme::setWindowColor(const QColor &color) { + d_ptr->m_dirtyBits.windowColorDirty = true; if (d_ptr->m_windowColor != color) { - d_ptr->m_dirtyBits.windowColorDirty = true; d_ptr->m_windowColor = color; emit windowColorChanged(color); emit d_ptr->needRender(); @@ -481,8 +481,8 @@ QColor Q3DTheme::windowColor() const */ void Q3DTheme::setLabelTextColor(const QColor &color) { + d_ptr->m_dirtyBits.labelTextColorDirty = true; if (d_ptr->m_textColor != color) { - d_ptr->m_dirtyBits.labelTextColorDirty = true; d_ptr->m_textColor = color; emit labelTextColorChanged(color); emit d_ptr->needRender(); @@ -501,8 +501,8 @@ QColor Q3DTheme::labelTextColor() const */ void Q3DTheme::setLabelBackgroundColor(const QColor &color) { + d_ptr->m_dirtyBits.labelBackgroundColorDirty = true; if (d_ptr->m_textBackgroundColor != color) { - d_ptr->m_dirtyBits.labelBackgroundColorDirty = true; d_ptr->m_textBackgroundColor = color; emit labelBackgroundColorChanged(color); emit d_ptr->needRender(); @@ -521,8 +521,8 @@ QColor Q3DTheme::labelBackgroundColor() const */ void Q3DTheme::setGridLineColor(const QColor &color) { + d_ptr->m_dirtyBits.gridLineColorDirty = true; if (d_ptr->m_gridLineColor != color) { - d_ptr->m_dirtyBits.gridLineColorDirty = true; d_ptr->m_gridLineColor = color; emit gridLineColorChanged(color); emit d_ptr->needRender(); @@ -542,8 +542,8 @@ QColor Q3DTheme::gridLineColor() const */ void Q3DTheme::setSingleHighlightColor(const QColor &color) { + d_ptr->m_dirtyBits.singleHighlightColorDirty = true; if (d_ptr->m_singleHighlightColor != color) { - d_ptr->m_dirtyBits.singleHighlightColorDirty = true; d_ptr->m_singleHighlightColor = color; emit singleHighlightColorChanged(color); } @@ -562,8 +562,8 @@ QColor Q3DTheme::singleHighlightColor() const */ void Q3DTheme::setMultiHighlightColor(const QColor &color) { + d_ptr->m_dirtyBits.multiHighlightColorDirty = true; if (d_ptr->m_multiHighlightColor != color) { - d_ptr->m_dirtyBits.multiHighlightColorDirty = true; d_ptr->m_multiHighlightColor = color; emit multiHighlightColorChanged(color); } @@ -583,8 +583,8 @@ QColor Q3DTheme::multiHighlightColor() const */ void Q3DTheme::setLightColor(const QColor &color) { + d_ptr->m_dirtyBits.lightColorDirty = true; if (d_ptr->m_lightColor != color) { - d_ptr->m_dirtyBits.lightColorDirty = true; d_ptr->m_lightColor = color; emit lightColorChanged(color); emit d_ptr->needRender(); @@ -605,8 +605,8 @@ QColor Q3DTheme::lightColor() const */ void Q3DTheme::setBaseGradient(const QLinearGradient &gradient) { + d_ptr->m_dirtyBits.baseGradientDirty = true; if (d_ptr->m_baseGradient != gradient) { - d_ptr->m_dirtyBits.baseGradientDirty = true; d_ptr->m_baseGradient = gradient; emit baseGradientChanged(gradient); } @@ -625,8 +625,8 @@ QLinearGradient Q3DTheme::baseGradient() const */ void Q3DTheme::setSingleHighlightGradient(const QLinearGradient &gradient) { + d_ptr->m_dirtyBits.singleHighlightGradientDirty = true; if (d_ptr->m_singleHighlightGradient != gradient) { - d_ptr->m_dirtyBits.singleHighlightGradientDirty = true; d_ptr->m_singleHighlightGradient = gradient; emit singleHighlightGradientChanged(gradient); } @@ -645,8 +645,8 @@ QLinearGradient Q3DTheme::singleHighlightGradient() const */ void Q3DTheme::setMultiHighlightGradient(const QLinearGradient &gradient) { + d_ptr->m_dirtyBits.multiHighlightGradientDirty = true; if (d_ptr->m_multiHighlightGradient != gradient) { - d_ptr->m_dirtyBits.multiHighlightGradientDirty = true; d_ptr->m_multiHighlightGradient = gradient; emit multiHighlightGradientChanged(gradient); } @@ -664,10 +664,10 @@ QLinearGradient Q3DTheme::multiHighlightGradient() const */ void Q3DTheme::setLightStrength(float strength) { + d_ptr->m_dirtyBits.lightStrengthDirty = true; if (strength < 0.0f || strength > 10.0f) { qWarning("Invalid value. Valid range for lightStrength is between 0.0f and 10.0f"); } else if (d_ptr->m_lightStrength != strength) { - d_ptr->m_dirtyBits.lightStrengthDirty = true; d_ptr->m_lightStrength = strength; emit lightStrengthChanged(strength); emit d_ptr->needRender(); @@ -686,10 +686,10 @@ float Q3DTheme::lightStrength() const */ void Q3DTheme::setAmbientLightStrength(float strength) { + d_ptr->m_dirtyBits.ambientLightStrengthDirty = true; if (strength < 0.0f || strength > 1.0f) { qWarning("Invalid value. Valid range for ambientLightStrength is between 0.0f and 1.0f"); } else if (d_ptr->m_ambientLightStrength != strength) { - d_ptr->m_dirtyBits.ambientLightStrengthDirty = true; d_ptr->m_ambientLightStrength = strength; emit ambientLightStrengthChanged(strength); emit d_ptr->needRender(); @@ -708,10 +708,10 @@ float Q3DTheme::ambientLightStrength() const */ void Q3DTheme::setHighlightLightStrength(float strength) { + d_ptr->m_dirtyBits.highlightLightStrengthDirty = true; if (strength < 0.0f || strength > 10.0f) { qWarning("Invalid value. Valid range for highlightLightStrength is between 0.0f and 10.0f"); } else if (d_ptr->m_highlightLightStrength != strength) { - d_ptr->m_dirtyBits.highlightLightStrengthDirty = true; d_ptr->m_highlightLightStrength = strength; emit highlightLightStrengthChanged(strength); emit d_ptr->needRender(); @@ -730,8 +730,8 @@ float Q3DTheme::highlightLightStrength() const */ void Q3DTheme::setLabelBorderEnabled(bool enabled) { + d_ptr->m_dirtyBits.labelBorderEnabledDirty = true; if (d_ptr->m_labelBorders != enabled) { - d_ptr->m_dirtyBits.labelBorderEnabledDirty = true; d_ptr->m_labelBorders = enabled; emit labelBorderEnabledChanged(enabled); emit d_ptr->needRender(); @@ -750,8 +750,8 @@ bool Q3DTheme::isLabelBorderEnabled() const */ void Q3DTheme::setFont(const QFont &font) { + d_ptr->m_dirtyBits.fontDirty = true; if (d_ptr->m_font != font) { - d_ptr->m_dirtyBits.fontDirty = true; d_ptr->m_font = font; emit fontChanged(font); emit d_ptr->needRender(); @@ -770,8 +770,8 @@ QFont Q3DTheme::font() const */ void Q3DTheme::setBackgroundEnabled(bool enabled) { + d_ptr->m_dirtyBits.backgroundEnabledDirty = true; if (d_ptr->m_backgoundEnabled != enabled) { - d_ptr->m_dirtyBits.backgroundEnabledDirty = true; d_ptr->m_backgoundEnabled = enabled; emit backgroundEnabledChanged(enabled); emit d_ptr->needRender(); @@ -790,8 +790,8 @@ bool Q3DTheme::isBackgroundEnabled() const */ void Q3DTheme::setGridEnabled(bool enabled) { + d_ptr->m_dirtyBits.gridEnabledDirty = true; if (d_ptr->m_gridEnabled != enabled) { - d_ptr->m_dirtyBits.gridEnabledDirty = true; d_ptr->m_gridEnabled = enabled; emit gridEnabledChanged(enabled); emit d_ptr->needRender(); @@ -810,8 +810,8 @@ bool Q3DTheme::isGridEnabled() const */ void Q3DTheme::setLabelBackgroundEnabled(bool enabled) { + d_ptr->m_dirtyBits.labelBackgroundEnabledDirty = true; if (d_ptr->m_labelBackground != enabled) { - d_ptr->m_dirtyBits.labelBackgroundEnabledDirty = true; d_ptr->m_labelBackground = enabled; emit labelBackgroundEnabledChanged(enabled); emit d_ptr->needRender(); @@ -830,8 +830,8 @@ bool Q3DTheme::isLabelBackgroundEnabled() const */ void Q3DTheme::setColorStyle(ColorStyle style) { + d_ptr->m_dirtyBits.colorStyleDirty = true; if (d_ptr->m_colorStyle != style) { - d_ptr->m_dirtyBits.colorStyleDirty = true; d_ptr->m_colorStyle = style; emit colorStyleChanged(style); } @@ -850,8 +850,8 @@ Q3DTheme::ColorStyle Q3DTheme::colorStyle() const */ void Q3DTheme::setType(Theme themeType) { + d_ptr->m_dirtyBits.themeIdDirty = true; if (d_ptr->m_themeId != themeType) { - d_ptr->m_dirtyBits.themeIdDirty = true; d_ptr->m_themeId = themeType; emit typeChanged(themeType); } diff --git a/src/datavisualization/theme/thememanager.cpp b/src/datavisualization/theme/thememanager.cpp index 644cedc9..9ab82441 100644 --- a/src/datavisualization/theme/thememanager.cpp +++ b/src/datavisualization/theme/thememanager.cpp @@ -66,21 +66,20 @@ Q3DTheme *ThemeManager::theme() const void ThemeManager::connectThemeSignals() { - // TODO: Rethink these once color api is added to series (QTRD-2200/2557) connect(m_theme.data(), &Q3DTheme::colorStyleChanged, - m_controller, &Abstract3DController::setColorStyle); + m_controller, &Abstract3DController::handleThemeColorStyleChanged); connect(m_theme.data(), &Q3DTheme::baseColorChanged, - m_controller, &Abstract3DController::setBaseColor); + m_controller, &Abstract3DController::handleThemeBaseColorChanged); connect(m_theme.data(), &Q3DTheme::singleHighlightColorChanged, - m_controller, &Abstract3DController::setSingleHighlightColor); + m_controller, &Abstract3DController::handleThemeSingleHighlightColorChanged); connect(m_theme.data(), &Q3DTheme::multiHighlightColorChanged, - m_controller, &Abstract3DController::setMultiHighlightColor); + m_controller, &Abstract3DController::handleThemeMultiHighlightColorChanged); connect(m_theme.data(), &Q3DTheme::baseGradientChanged, - m_controller, &Abstract3DController::setBaseGradient); + m_controller, &Abstract3DController::handleThemeBaseGradientChanged); connect(m_theme.data(), &Q3DTheme::singleHighlightGradientChanged, - m_controller, &Abstract3DController::setSingleHighlightGradient); + m_controller, &Abstract3DController::handleThemeSingleHighlightGradientChanged); connect(m_theme.data(), &Q3DTheme::multiHighlightGradientChanged, - m_controller, &Abstract3DController::setMultiHighlightGradient); + m_controller, &Abstract3DController::handleThemeMultiHighlightGradientChanged); connect(m_theme->d_ptr.data(), &Q3DThemePrivate::needRender, m_controller, &Abstract3DController::needRender); diff --git a/src/datavisualization/utils/utils.cpp b/src/datavisualization/utils/utils.cpp index 2adc9409..bb280504 100644 --- a/src/datavisualization/utils/utils.cpp +++ b/src/datavisualization/utils/utils.cpp @@ -44,6 +44,11 @@ QVector3D Utils::vectorFromColor(const QColor &color) return QVector3D(color.redF(), color.greenF(), color.blueF()); } +QColor Utils::colorFromVector(const QVector3D &colorVector) +{ + return QColor(colorVector.x(), colorVector.y(), colorVector.z()); +} + QImage Utils::printTextToImage(const QFont &font, const QString &text, const QColor &bgrColor, const QColor &txtColor, bool labelBackground, bool borders, int maxLabelWidth) diff --git a/src/datavisualization/utils/utils_p.h b/src/datavisualization/utils/utils_p.h index b713db94..3142e4c2 100644 --- a/src/datavisualization/utils/utils_p.h +++ b/src/datavisualization/utils/utils_p.h @@ -53,6 +53,7 @@ public: static GLuint getNearestPowerOfTwo(GLuint value, GLuint &padding); static QVector3D vectorFromColor(const QColor &color); + static QColor colorFromVector(const QVector3D &colorVector); static void printText(QPainter *painter, const QString &text, const QSize &position, bool absoluteCoords = true, float rotation = 0.0f, float scale = 1.0f); static QImage printTextToImage(const QFont &font, |