summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-11-28 13:58:02 +0200
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-11-28 14:02:07 +0200
commit5c4592ea5bb3a4c98a5fe1846c8b3082bd33e678 (patch)
tree0f3e4094c0443c7a93821a9f87dcdbc4393277ac
parenta7e8a3279547dbea4b5343f44f3b7563c0212f1e (diff)
Theme sync
Task-number: QTRD-2538 Change-Id: I12dfb562dc59ae1df3b5127f0f675a3796ba3f00 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
-rw-r--r--examples/bars/graphmodifier.cpp5
-rw-r--r--examples/bars/graphmodifier.h4
-rw-r--r--examples/bars/main.cpp10
-rw-r--r--examples/scatter/main.cpp8
-rw-r--r--examples/scatter/scatterdatamodifier.cpp3
-rw-r--r--examples/scatter/scatterdatamodifier.h3
-rw-r--r--src/datavisualization/engine/abstract3dcontroller.cpp91
-rw-r--r--src/datavisualization/engine/abstract3dcontroller_p.h11
-rw-r--r--src/datavisualization/engine/abstract3drenderer.cpp49
-rw-r--r--src/datavisualization/engine/abstract3drenderer_p.h8
-rw-r--r--src/datavisualization/engine/bars3drenderer.cpp18
-rw-r--r--src/datavisualization/engine/bars3drenderer_p.h2
-rw-r--r--src/datavisualization/engine/drawer.cpp12
-rw-r--r--src/datavisualization/engine/drawer_p.h2
-rw-r--r--src/datavisualization/engine/scatter3drenderer.cpp12
-rw-r--r--src/datavisualization/engine/scatter3drenderer_p.h2
-rw-r--r--src/datavisualization/engine/surface3drenderer.cpp6
-rw-r--r--src/datavisualization/theme/q3dtheme.cpp177
-rw-r--r--src/datavisualization/theme/q3dtheme.h3
-rw-r--r--src/datavisualization/theme/q3dtheme_p.h6
-rw-r--r--src/datavisualization/theme/thememanager.cpp36
21 files changed, 244 insertions, 224 deletions
diff --git a/examples/bars/graphmodifier.cpp b/examples/bars/graphmodifier.cpp
index a27782c5..6a35b1b1 100644
--- a/examples/bars/graphmodifier.cpp
+++ b/examples/bars/graphmodifier.cpp
@@ -176,6 +176,10 @@ void GraphModifier::changePresetCamera()
void GraphModifier::changeTheme(int theme)
{
m_graph->setTheme(new Q3DTheme(QDataVis::Theme(theme)));
+ emit backgroundEnabledChanged(m_graph->theme()->isBackgroundEnabled());
+ emit gridEnabledChanged(m_graph->theme()->isGridEnabled());
+ emit fontChanged(m_graph->theme()->font());
+ emit fontSizeChanged(m_graph->theme()->font().pointSize());
}
void GraphModifier::changeLabelBackground()
@@ -195,7 +199,6 @@ void GraphModifier::changeSelectionMode(int selectionMode)
void GraphModifier::changeFont(const QFont &font)
{
QFont newFont = font;
- newFont.setPointSize(m_fontSize);
m_graph->theme()->setFont(newFont);
}
diff --git a/examples/bars/graphmodifier.h b/examples/bars/graphmodifier.h
index b48451cd..6887a54b 100644
--- a/examples/bars/graphmodifier.h
+++ b/examples/bars/graphmodifier.h
@@ -58,6 +58,10 @@ public slots:
signals:
void shadowQualityChanged(int quality);
+ void backgroundEnabledChanged(bool enabled);
+ void gridEnabledChanged(bool enabled);
+ void fontChanged(QFont font);
+ void fontSizeChanged(int size);
private:
Q3DBars *m_graph;
diff --git a/examples/bars/main.cpp b/examples/bars/main.cpp
index 7a74473b..7cf4381d 100644
--- a/examples/bars/main.cpp
+++ b/examples/bars/main.cpp
@@ -214,6 +214,11 @@ int main(int argc, char **argv)
QObject::connect(seriesCheckBox, &QCheckBox::stateChanged, modifier,
&GraphModifier::setSeriesVisibility);
+ QObject::connect(modifier, &GraphModifier::backgroundEnabledChanged,
+ backgroundCheckBox, &QCheckBox::setChecked);
+ QObject::connect(modifier, &GraphModifier::gridEnabledChanged,
+ gridCheckBox, &QCheckBox::setChecked);
+
QObject::connect(barStyleList, SIGNAL(currentIndexChanged(int)), modifier,
SLOT(changeStyle(int)));
@@ -236,6 +241,11 @@ int main(int argc, char **argv)
QObject::connect(fontList, &QFontComboBox::currentFontChanged, modifier,
&GraphModifier::changeFont);
+ QObject::connect(modifier, &GraphModifier::fontSizeChanged, fontSizeSlider,
+ &QSlider::setValue);
+ QObject::connect(modifier, &GraphModifier::fontChanged, fontList,
+ &QFontComboBox::setCurrentFont);
+
//! [3]
widget->show();
modifier->start();
diff --git a/examples/scatter/main.cpp b/examples/scatter/main.cpp
index c652361b..40027a40 100644
--- a/examples/scatter/main.cpp
+++ b/examples/scatter/main.cpp
@@ -136,6 +136,11 @@ int main(int argc, char **argv)
QObject::connect(smoothCheckBox, &QCheckBox::stateChanged, modifier,
&ScatterDataModifier::setSmoothDots);
+ QObject::connect(modifier, &ScatterDataModifier::backgroundEnabledChanged,
+ backgroundCheckBox, &QCheckBox::setChecked);
+ QObject::connect(modifier, &ScatterDataModifier::gridEnabledChanged,
+ gridCheckBox, &QCheckBox::setChecked);
+
QObject::connect(barStyleList, SIGNAL(currentIndexChanged(int)), modifier,
SLOT(changeStyle(int)));
@@ -152,6 +157,9 @@ int main(int argc, char **argv)
QObject::connect(fontList, &QFontComboBox::currentFontChanged, modifier,
&ScatterDataModifier::changeFont);
+
+ QObject::connect(modifier, &ScatterDataModifier::fontChanged, fontList,
+ &QFontComboBox::setCurrentFont);
//! [6]
//! [3]
diff --git a/examples/scatter/scatterdatamodifier.cpp b/examples/scatter/scatterdatamodifier.cpp
index 5a46b0ec..fea50992 100644
--- a/examples/scatter/scatterdatamodifier.cpp
+++ b/examples/scatter/scatterdatamodifier.cpp
@@ -130,6 +130,9 @@ void ScatterDataModifier::setSmoothDots(int smooth)
void ScatterDataModifier::changeTheme(int theme)
{
m_graph->setTheme(new Q3DTheme(QDataVis::Theme(theme)));
+ emit backgroundEnabledChanged(m_graph->theme()->isBackgroundEnabled());
+ emit gridEnabledChanged(m_graph->theme()->isGridEnabled());
+ emit fontChanged(m_graph->theme()->font());
}
void ScatterDataModifier::changePresetCamera()
diff --git a/examples/scatter/scatterdatamodifier.h b/examples/scatter/scatterdatamodifier.h
index 5cc9348b..43c58fd9 100644
--- a/examples/scatter/scatterdatamodifier.h
+++ b/examples/scatter/scatterdatamodifier.h
@@ -49,7 +49,10 @@ public slots:
void shadowQualityUpdatedByVisual(QDataVis::ShadowQuality shadowQuality);
signals:
+ void backgroundEnabledChanged(bool enabled);
+ void gridEnabledChanged(bool enabled);
void shadowQualityChanged(int quality);
+ void fontChanged(QFont font);
private:
QVector3D randVector();
diff --git a/src/datavisualization/engine/abstract3dcontroller.cpp b/src/datavisualization/engine/abstract3dcontroller.cpp
index d06a2609..302b74ad 100644
--- a/src/datavisualization/engine/abstract3dcontroller.cpp
+++ b/src/datavisualization/engine/abstract3dcontroller.cpp
@@ -141,13 +141,9 @@ void Abstract3DController::synchDataToRenderer()
m_renderer->updateScene(m_scene);
- // TODO: Renderer doesn't need to know the theme, so remove this bit entirely (QTRD-2538)
- if (m_changeTracker.themeChanged) {
- m_renderer->updateTheme(m_themeManager->theme());
- m_changeTracker.themeChanged = false;
- }
+ m_renderer->updateTheme(m_themeManager->theme());
- // TODO: Move to a sync function to clean this up a bit (make a separate task)
+ // 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;
@@ -183,26 +179,6 @@ void Abstract3DController::synchDataToRenderer()
m_changeTracker.multiHighlightGradientChanged = false;
}
- if (m_changeTracker.fontChanged) {
- m_renderer->updateFont(m_font);
- m_changeTracker.fontChanged = false;
- }
-
- if (m_changeTracker.labelBackgroundEnabledChanged) {
- m_renderer->updateLabelBackgroundEnabled(m_labelBackground);
- m_changeTracker.labelBackgroundEnabledChanged = false;
- }
-
- if (m_changeTracker.gridEnabledChanged) {
- m_renderer->updateGridEnabled(m_isGridEnabled);
- m_changeTracker.gridEnabledChanged = false;
- }
-
- if (m_changeTracker.backgroundEnabledChanged) {
- m_renderer->updateBackgroundEnabled(m_isBackgroundEnabled);
- m_changeTracker.backgroundEnabledChanged = false;
- }
-
if (m_changeTracker.shadowQualityChanged) {
m_renderer->updateShadowQuality(m_shadowQuality);
m_changeTracker.shadowQualityChanged = false;
@@ -805,13 +781,8 @@ void Abstract3DController::setTheme(Q3DTheme *theme)
if (theme != m_themeManager->theme()) {
m_themeManager->setTheme(theme);
m_changeTracker.themeChanged = true;
- // TODO: set all colors/styles here (QTRD-2538)
+ // TODO: Rethink this once color api has been moved to series (QTRD-2200/2557)
setColorStyle(theme->colorStyle());
- // Set all other theme properties
- setBackgroundEnabled(theme->isBackgroundEnabled());
- setFont(theme->font());
- setGridEnabled(theme->isGridEnabled());
- setLabelBackgroundEnabled(theme->isLabelBackgroundEnabled());
emit themeChanged(theme);
}
}
@@ -821,20 +792,6 @@ Q3DTheme *Abstract3DController::theme() const
return m_themeManager->theme();
}
-void Abstract3DController::setFont(const QFont &font)
-{
- if (font != m_font) {
- m_font = font;
- m_changeTracker.fontChanged = true;
- emitNeedRender();
- }
-}
-
-QFont Abstract3DController::font() const
-{
- return m_font;
-}
-
void Abstract3DController::setSelectionMode(QDataVis::SelectionFlags mode)
{
if (mode != m_selectionMode) {
@@ -865,48 +822,6 @@ QDataVis::ShadowQuality Abstract3DController::shadowQuality() const
return m_shadowQuality;
}
-void Abstract3DController::setLabelBackgroundEnabled(bool enable)
-{
- if (enable != m_labelBackground) {
- m_labelBackground = enable;
- m_changeTracker.labelBackgroundEnabledChanged = true;
- emitNeedRender();
- }
-}
-
-bool Abstract3DController::isLabelBackgroundEnabled() const
-{
- return m_labelBackground;
-}
-
-void Abstract3DController::setBackgroundEnabled(bool enable)
-{
- if (enable != m_isBackgroundEnabled) {
- m_isBackgroundEnabled = enable;
- m_changeTracker.backgroundEnabledChanged = true;
- emitNeedRender();
- }
-}
-
-bool Abstract3DController::backgroundEnabled() const
-{
- return m_isBackgroundEnabled;
-}
-
-void Abstract3DController::setGridEnabled(bool enable)
-{
- if (enable != m_isGridEnabled) {
- m_isGridEnabled = enable;
- m_changeTracker.gridEnabledChanged = true;
- emitNeedRender();
- }
-}
-
-bool Abstract3DController::gridEnabled() const
-{
- return m_isGridEnabled;
-}
-
bool Abstract3DController::isSlicingActive() const
{
return m_scene->isSlicingActive();
diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h
index 0180623c..556d1ea5 100644
--- a/src/datavisualization/engine/abstract3dcontroller_p.h
+++ b/src/datavisualization/engine/abstract3dcontroller_p.h
@@ -256,7 +256,8 @@ public:
virtual void setTheme(Q3DTheme *theme);
virtual Q3DTheme *theme() const;
- // Properties from theme
+ // Properties from color api
+ // TODO: Rethink these after color api has been moveed to series (QTRD-2200/2557)
virtual void setColorStyle(QDataVis::ColorStyle style);
virtual QDataVis::ColorStyle colorStyle() const;
virtual void setBaseColor(const QColor &color);
@@ -271,14 +272,6 @@ public:
virtual QColor multiHighlightColor() const;
virtual void setMultiHighlightGradient(const QLinearGradient &gradient);
virtual QLinearGradient multiHighlightGradient() const;
- virtual void setFont(const QFont &font);
- virtual QFont font() const;
- virtual void setLabelBackgroundEnabled(bool enable);
- virtual bool isLabelBackgroundEnabled() const;
- virtual void setBackgroundEnabled(bool enable);
- virtual bool backgroundEnabled() const;
- virtual void setGridEnabled(bool enable);
- virtual bool gridEnabled() const;
virtual void setSelectionMode(QDataVis::SelectionFlags mode);
virtual QDataVis::SelectionFlags selectionMode() const;
diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp
index 118f7b13..50e56ce5 100644
--- a/src/datavisualization/engine/abstract3drenderer.cpp
+++ b/src/datavisualization/engine/abstract3drenderer.cpp
@@ -24,6 +24,7 @@
#include "q3dcamera_p.h"
#include "q3dlight_p.h"
#include "qabstract3dseries_p.h"
+#include "q3dtheme_p.h"
Q_DECLARE_METATYPE(QtDataVisualization::QDataVis::ShadowQuality)
@@ -32,16 +33,12 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
Abstract3DRenderer::Abstract3DRenderer(Abstract3DController *controller)
: QObject(0),
m_hasNegativeValues(false),
- m_cachedTheme(),
- m_cachedFont(QFont(QStringLiteral("Arial"))),
- m_cachedLabelBackground(false),
- m_drawer(new Drawer(m_cachedTheme, m_cachedFont, m_cachedLabelBackground)),
+ m_cachedTheme(new Q3DTheme()),
+ m_drawer(new Drawer(m_cachedTheme)),
m_cachedBoundingRect(QRect(0, 0, 0, 0)),
m_cachedShadowQuality(QDataVis::ShadowQualityMedium),
m_autoScaleAdjustment(1.0f),
m_cachedSelectionMode(QDataVis::SelectionNone),
- m_cachedIsGridEnabled(false),
- m_cachedIsBackgroundEnabled(false),
m_cachedColorStyle(QDataVis::ColorStyleUniform),
m_objectGradientTexture(0),
m_singleHighlightGradientTexture(0),
@@ -166,12 +163,15 @@ void Abstract3DRenderer::updatePosition(const QRect &boundingRect)
void Abstract3DRenderer::updateTheme(Q3DTheme *theme)
{
- m_cachedTheme = theme;
+ // Synchronize the controller theme with renderer
+ bool changed = theme->d_ptr->sync(*m_cachedTheme->d_ptr);
- m_drawer->setTheme(m_cachedTheme);
-
- // Re-initialize shaders
- reInitShaders();
+ if (changed) {
+ // Update drawer if sync changed something
+ m_drawer->setTheme(m_cachedTheme);
+ // Re-initialize shaders
+ reInitShaders();
+ }
}
void Abstract3DRenderer::updateScene(Q3DScene *scene)
@@ -196,10 +196,8 @@ void Abstract3DRenderer::updateScene(Q3DScene *scene)
}
}
- // Synchronize the controller scene to that of the renderer, and vice versa.
- // Controller scene had priority if both have changed same values.
+ // Synchronize the controller scene with renderer
scene->d_ptr->sync(*m_cachedScene->d_ptr);
- m_cachedScene->d_ptr->sync(*scene->d_ptr);
}
void Abstract3DRenderer::reInitShaders()
@@ -252,19 +250,6 @@ void Abstract3DRenderer::handleShadowQualityChange()
#endif
}
-void Abstract3DRenderer::updateFont(const QFont &font)
-{
- m_cachedFont = font;
- m_drawer->setFont(font);
-}
-
-void Abstract3DRenderer::updateLabelBackgroundEnabled(bool enabled)
-{
- qDebug() << __FUNCTION__ << enabled;
- m_cachedLabelBackground = enabled;
- m_drawer->setLabelBackground(enabled);
-}
-
void Abstract3DRenderer::updateMeshFileName(const QString &objFileName)
{
if (objFileName != m_cachedObjFile) {
@@ -279,16 +264,6 @@ void Abstract3DRenderer::updateSelectionMode(QDataVis::SelectionFlags mode)
m_selectionDirty = true;
}
-void Abstract3DRenderer::updateGridEnabled(bool enable)
-{
- m_cachedIsGridEnabled = enable;
-}
-
-void Abstract3DRenderer::updateBackgroundEnabled(bool enable)
-{
- m_cachedIsBackgroundEnabled = enable;
-}
-
void Abstract3DRenderer::handleResize()
{
if (m_cachedBoundingRect.width() == 0 || m_cachedBoundingRect.height() == 0)
diff --git a/src/datavisualization/engine/abstract3drenderer_p.h b/src/datavisualization/engine/abstract3drenderer_p.h
index ea659524..6582fbc3 100644
--- a/src/datavisualization/engine/abstract3drenderer_p.h
+++ b/src/datavisualization/engine/abstract3drenderer_p.h
@@ -61,8 +61,6 @@ protected:
bool m_hasNegativeValues;
Q3DTheme *m_cachedTheme;
- QFont m_cachedFont;
- bool m_cachedLabelBackground;
Drawer *m_drawer;
QRect m_cachedBoundingRect;
QDataVis::ShadowQuality m_cachedShadowQuality;
@@ -70,8 +68,6 @@ protected:
QString m_cachedObjFile;
QDataVis::SelectionFlags m_cachedSelectionMode;
- bool m_cachedIsGridEnabled;
- bool m_cachedIsBackgroundEnabled;
QDataVis::ColorStyle m_cachedColorStyle;
QColor m_cachedObjectColor;
@@ -116,11 +112,7 @@ public:
virtual void updatePosition(const QRect &boundingRect);
virtual void updateTheme(Q3DTheme *theme);
- virtual void updateFont(const QFont &font);
- virtual void updateLabelBackgroundEnabled(bool enabled);
virtual void updateSelectionMode(QDataVis::SelectionFlags newMode);
- virtual void updateGridEnabled(bool enable);
- virtual void updateBackgroundEnabled(bool enable);
virtual void updateMeshFileName(const QString &objFileName);
virtual void updateScene(Q3DScene *scene);
virtual void updateTextures() = 0;
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp
index 29215eb0..142640b3 100644
--- a/src/datavisualization/engine/bars3drenderer.cpp
+++ b/src/datavisualization/engine/bars3drenderer.cpp
@@ -339,7 +339,7 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel,
bool itemMode = m_cachedSelectionMode.testFlag(QDataVis::SelectionItem);
// Draw grid lines
- if (m_cachedIsGridEnabled) {
+ if (m_cachedTheme->isGridEnabled()) {
glDisable(GL_DEPTH_TEST);
ShaderHelper *lineShader = m_backgroundShader;
// Bind line shader
@@ -1205,7 +1205,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
GLfloat rowScaleFactor = m_rowWidth / m_scaleFactor;
GLfloat columnScaleFactor = m_columnDepth / m_scaleFactor;
- if (m_cachedIsBackgroundEnabled && m_backgroundObj) {
+ if (m_cachedTheme->isBackgroundEnabled() && m_backgroundObj) {
QMatrix4x4 modelMatrix;
QMatrix4x4 MVPMatrix;
QMatrix4x4 itModelMatrix;
@@ -1311,7 +1311,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
glDisable(GL_TEXTURE_2D);
// Draw grid lines
- if (m_cachedIsGridEnabled && m_heightNormalizer) {
+ if (m_cachedTheme->isGridEnabled() && m_heightNormalizer) {
ShaderHelper *lineShader = m_backgroundShader;
QQuaternion lineRotation = QQuaternion();
@@ -1829,12 +1829,14 @@ void Bars3DRenderer::updateAxisRange(Q3DAbstractAxis::AxisOrientation orientatio
}
}
-void Bars3DRenderer::updateBackgroundEnabled(bool enable)
+void Bars3DRenderer::updateTheme(Q3DTheme *theme)
{
- if (enable != m_cachedIsBackgroundEnabled) {
- Abstract3DRenderer::updateBackgroundEnabled(enable);
+ bool wasEnabled = m_cachedTheme->isBackgroundEnabled();
+
+ Abstract3DRenderer::updateTheme(theme);
+
+ if (theme->isBackgroundEnabled() != wasEnabled)
loadMeshFile(); // Load changed bar type
- }
}
void Bars3DRenderer::updateSelectedBar(const QPoint &position, const QBar3DSeries *series)
@@ -1921,7 +1923,7 @@ void Bars3DRenderer::loadMeshFile()
if (m_barObj)
delete m_barObj;
// If background is disabled, load full version of bar mesh
- if (!m_cachedIsBackgroundEnabled)
+ if (!m_cachedTheme->isBackgroundEnabled())
objectFileName.append(QStringLiteral("Full"));
m_barObj = new ObjectHelper(objectFileName);
m_barObj->load();
diff --git a/src/datavisualization/engine/bars3drenderer_p.h b/src/datavisualization/engine/bars3drenderer_p.h
index fa2e1268..f3e9103b 100644
--- a/src/datavisualization/engine/bars3drenderer_p.h
+++ b/src/datavisualization/engine/bars3drenderer_p.h
@@ -129,7 +129,6 @@ public slots:
const QSizeF &spacing = QSizeF(1.0, 1.0),
bool relative = true);
void updateSlicingActive(bool isSlicing);
- void updateBackgroundEnabled(bool enable);
void updateSelectedBar(const QPoint &position, const QBar3DSeries *series);
// Overloaded from abstract renderer
@@ -142,6 +141,7 @@ private:
virtual void initShaders(const QString &vertexShader, const QString &fragmentShader);
virtual void updateShadowQuality(QDataVis::ShadowQuality quality);
virtual void updateTextures();
+ virtual void updateTheme(Q3DTheme *theme);
void drawSlicedScene(const LabelItem &xLabel, const LabelItem &yLabel, const LabelItem &zLabel);
void drawScene(GLuint defaultFboHandle);
diff --git a/src/datavisualization/engine/drawer.cpp b/src/datavisualization/engine/drawer.cpp
index 4cb5511a..87f64e4f 100644
--- a/src/datavisualization/engine/drawer.cpp
+++ b/src/datavisualization/engine/drawer.cpp
@@ -44,10 +44,10 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
// Vertex array buffer for point
const GLfloat point_data[] = {0.0f, 0.0f, 0.0f};
-Drawer::Drawer(Q3DTheme *theme, const QFont &font, bool labelBackground)
+Drawer::Drawer(Q3DTheme *theme)
: m_theme(theme),
- m_font(font),
- m_labelBackground(labelBackground),
+ m_font(theme->font()),
+ m_labelBackground(theme->isLabelBackgroundEnabled()),
m_textureHelper(0),
m_pointbuffer(0)
{
@@ -70,6 +70,8 @@ void Drawer::initializeOpenGL()
void Drawer::setTheme(Q3DTheme *theme)
{
m_theme = theme;
+ m_font = m_theme->font();
+ m_labelBackground = m_theme->isLabelBackgroundEnabled();
emit drawerChanged();
}
@@ -80,6 +82,8 @@ Q3DTheme *Drawer::theme() const
void Drawer::setFont(const QFont &font)
{
+ // We need to be able to override theme's font for drawer
+ // TODO: (or do we?)
m_font = font;
emit drawerChanged();
}
@@ -91,6 +95,8 @@ QFont Drawer::font() const
void Drawer::setLabelBackground(bool enabled)
{
+ // We need to be able to override theme's label background for drawer
+ // TODO: (or do we?)
m_labelBackground = enabled;
emit drawerChanged();
}
diff --git a/src/datavisualization/engine/drawer_p.h b/src/datavisualization/engine/drawer_p.h
index c3f92380..8bc62209 100644
--- a/src/datavisualization/engine/drawer_p.h
+++ b/src/datavisualization/engine/drawer_p.h
@@ -63,7 +63,7 @@ public:
};
public:
- explicit Drawer(Q3DTheme *theme, const QFont &font, bool labelBackground);
+ explicit Drawer(Q3DTheme *theme);
~Drawer();
void initializeOpenGL();
diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp
index 73864643..24e33ba6 100644
--- a/src/datavisualization/engine/scatter3drenderer.cpp
+++ b/src/datavisualization/engine/scatter3drenderer.cpp
@@ -679,7 +679,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
glCullFace(GL_BACK);
// Draw background
- if (m_cachedIsBackgroundEnabled && m_backgroundObj) {
+ if (m_cachedTheme->isBackgroundEnabled() && m_backgroundObj) {
QMatrix4x4 modelMatrix;
QMatrix4x4 MVPMatrix;
QMatrix4x4 itModelMatrix;
@@ -760,7 +760,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
axisCacheMax = &m_axisCacheX;
#endif
- if (m_cachedIsGridEnabled && m_heightNormalizer) {
+ if (m_cachedTheme->isGridEnabled() && m_heightNormalizer) {
ShaderHelper *lineShader = m_backgroundShader;
// Bind line shader
@@ -1455,14 +1455,6 @@ void Scatter3DRenderer::handleResize()
Abstract3DRenderer::handleResize();
}
-void Scatter3DRenderer::updateBackgroundEnabled(bool enable)
-{
- if (enable != m_cachedIsBackgroundEnabled) {
- Abstract3DRenderer::updateBackgroundEnabled(enable);
- loadMeshFile(); // Load changed dot type
- }
-}
-
void Scatter3DRenderer::updateShadowQuality(QDataVis::ShadowQuality quality)
{
m_cachedShadowQuality = quality;
diff --git a/src/datavisualization/engine/scatter3drenderer_p.h b/src/datavisualization/engine/scatter3drenderer_p.h
index 31ed08a9..6a0bbbec 100644
--- a/src/datavisualization/engine/scatter3drenderer_p.h
+++ b/src/datavisualization/engine/scatter3drenderer_p.h
@@ -137,8 +137,6 @@ private:
friend class ScatterRenderItem;
public slots:
- void updateBackgroundEnabled(bool enable);
-
// Overloaded from abstract renderer
virtual void updateAxisRange(Q3DAbstractAxis::AxisOrientation orientation, float min, float max);
diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp
index 4c1de83f..df4a12f0 100644
--- a/src/datavisualization/engine/surface3drenderer.cpp
+++ b/src/datavisualization/engine/surface3drenderer.cpp
@@ -591,7 +591,7 @@ void Surface3DRenderer::drawSlicedScene()
glDisable(GL_TEXTURE_2D);
// Grid lines
- if (m_cachedIsGridEnabled && m_heightNormalizer) {
+ if (m_cachedTheme->isGridEnabled() && m_heightNormalizer) {
ShaderHelper *lineShader = m_backgroundShader;
// Bind line shader
lineShader->bind();
@@ -1050,7 +1050,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
glCullFace(GL_BACK);
// Draw background
- if (m_cachedIsBackgroundEnabled && m_backgroundObj) {
+ if (m_cachedTheme->isBackgroundEnabled() && m_backgroundObj) {
QMatrix4x4 modelMatrix;
QMatrix4x4 MVPMatrix;
QMatrix4x4 itModelMatrix;
@@ -1119,7 +1119,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
QVector3D gridLineScaleZ(gridLineWidth, gridLineWidth, m_scaleZWithBackground);
QVector3D gridLineScaleY(gridLineWidth, backgroundMargin, gridLineWidth);
- if (m_cachedIsGridEnabled && m_heightNormalizer) {
+ if (m_cachedTheme->isGridEnabled() && m_heightNormalizer) {
ShaderHelper *lineShader = m_backgroundShader;
// Bind line shader
diff --git a/src/datavisualization/theme/q3dtheme.cpp b/src/datavisualization/theme/q3dtheme.cpp
index dccaee91..21c21c98 100644
--- a/src/datavisualization/theme/q3dtheme.cpp
+++ b/src/datavisualization/theme/q3dtheme.cpp
@@ -45,6 +45,7 @@ Q3DTheme::~Q3DTheme()
}
+// TODO: Add needRenders if necessary after color api has been added to series (QTRD-2200/2557)
// TODO: Basecolors as a list, containing one for each series?
void Q3DTheme::setBaseColor(const QColor &color)
{
@@ -66,6 +67,7 @@ void Q3DTheme::setBackgroundColor(const QColor &color)
d_ptr->m_dirtyBits.backgroundColorDirty = true;
d_ptr->m_backgroundColor = color;
emit backgroundColorChanged(color);
+ emit needRender();
}
}
@@ -80,6 +82,7 @@ void Q3DTheme::setWindowColor(const QColor &color)
d_ptr->m_dirtyBits.windowColorDirty = true;
d_ptr->m_windowColor = color;
emit windowColorChanged(color);
+ emit needRender();
}
}
@@ -94,6 +97,7 @@ void Q3DTheme::setTextColor(const QColor &color)
d_ptr->m_dirtyBits.textColorDirty = true;
d_ptr->m_textColor = color;
emit textColorChanged(color);
+ emit needRender();
}
}
@@ -108,6 +112,7 @@ void Q3DTheme::setTextBackgroundColor(const QColor &color)
d_ptr->m_dirtyBits.textBackgroundColorDirty = true;
d_ptr->m_textBackgroundColor = color;
emit textBackgroundColorChanged(color);
+ emit needRender();
}
}
@@ -122,6 +127,7 @@ void Q3DTheme::setGridLineColor(const QColor &color)
d_ptr->m_dirtyBits.gridLineColorDirty = true;
d_ptr->m_gridLineColor = color;
emit gridLineColorChanged(color);
+ emit needRender();
}
}
@@ -164,6 +170,7 @@ void Q3DTheme::setLightColor(const QColor &color)
d_ptr->m_dirtyBits.lightColorDirty = true;
d_ptr->m_lightColor = color;
emit lightColorChanged(color);
+ emit needRender();
}
}
@@ -221,6 +228,7 @@ void Q3DTheme::setLightStrength(float strength)
d_ptr->m_dirtyBits.lightStrengthDirty = true;
d_ptr->m_lightStrength = strength;
emit lightStrengthChanged(strength);
+ emit needRender();
}
}
@@ -235,6 +243,7 @@ void Q3DTheme::setAmbientLightStrength(float strength)
d_ptr->m_dirtyBits.ambientLightStrengthDirty = true;
d_ptr->m_ambientLightStrength = strength;
emit ambientLightStrengthChanged(strength);
+ emit needRender();
}
}
@@ -249,6 +258,7 @@ void Q3DTheme::setHighlightLightStrength(float strength)
d_ptr->m_dirtyBits.highlightLightStrengthDirty = true;
d_ptr->m_highlightLightStrength = strength;
emit highlightLightStrengthChanged(strength);
+ emit needRender();
}
}
@@ -263,6 +273,7 @@ void Q3DTheme::setLabelBorderEnabled(bool enabled)
d_ptr->m_dirtyBits.labelBorderEnabledDirty = true;
d_ptr->m_labelBorders = enabled;
emit labelBorderEnabledChanged(enabled);
+ emit needRender();
}
}
@@ -277,6 +288,7 @@ void Q3DTheme::setFont(const QFont &font)
d_ptr->m_dirtyBits.fontDirty = true;
d_ptr->m_font = font;
emit fontChanged(font);
+ emit needRender();
}
}
@@ -291,6 +303,7 @@ void Q3DTheme::setBackgroundEnabled(bool enabled)
d_ptr->m_dirtyBits.backgroundEnabledDirty = true;
d_ptr->m_backgoundEnabled = enabled;
emit backgroundEnabledChanged(enabled);
+ emit needRender();
}
}
@@ -305,6 +318,7 @@ void Q3DTheme::setGridEnabled(bool enabled)
d_ptr->m_dirtyBits.gridEnabledDirty = true;
d_ptr->m_gridEnabled = enabled;
emit gridEnabledChanged(enabled);
+ emit needRender();
}
}
@@ -319,6 +333,7 @@ void Q3DTheme::setLabelBackgroundEnabled(bool enabled)
d_ptr->m_dirtyBits.labelBackgroundEnabledDirty = true;
d_ptr->m_labelBackground = enabled;
emit labelBackgroundEnabledChanged(enabled);
+ emit needRender();
}
}
@@ -344,6 +359,7 @@ QDataVis::ColorStyle Q3DTheme::colorStyle() const
void Q3DTheme::setType(QDataVis::Theme themeType)
{
if (d_ptr->m_themeId != themeType) {
+ d_ptr->m_dirtyBits.themeIdDirty = true;
d_ptr->m_themeId = themeType;
emit typeChanged(themeType);
}
@@ -382,7 +398,7 @@ Q3DThemePrivate::Q3DThemePrivate(Q3DTheme *q, QDataVis::Theme theme_id)
m_highlightLightStrength(0.75f),
m_labelBorders(true),
m_colorStyle(QDataVis::ColorStyleUniform),
- m_font(QFont(QStringLiteral("Arial"))),
+ m_font(QFont()),
m_backgoundEnabled(true),
m_gridEnabled(true),
m_labelBackground(true),
@@ -396,27 +412,144 @@ Q3DThemePrivate::~Q3DThemePrivate()
void Q3DThemePrivate::resetDirtyBits()
{
- m_dirtyBits.ambientLightStrengthDirty = false;
- m_dirtyBits.backgroundColorDirty = false;
- m_dirtyBits.backgroundEnabledDirty = false;
- m_dirtyBits.baseColorDirty = false;
- m_dirtyBits.baseGradientDirty = false;
- m_dirtyBits.colorStyleDirty = false;
- m_dirtyBits.fontDirty = false;
- m_dirtyBits.gridEnabledDirty = false;
- m_dirtyBits.gridLineColorDirty = false;
- m_dirtyBits.highlightLightStrengthDirty = false;
- m_dirtyBits.labelBackgroundEnabledDirty = false;
- m_dirtyBits.labelBorderEnabledDirty = false;
- m_dirtyBits.lightColorDirty = false;
- m_dirtyBits.lightStrengthDirty = false;
- m_dirtyBits.multiHighlightColorDirty = false;
- m_dirtyBits.multiHighlightGradientDirty = false;
- m_dirtyBits.singleHighlightColorDirty = false;
- m_dirtyBits.singleHighlightGradientDirty = false;
- m_dirtyBits.textBackgroundColorDirty = false;
- m_dirtyBits.textColorDirty = false;
- m_dirtyBits.windowColorDirty = false;
+ m_dirtyBits.ambientLightStrengthDirty = true;
+ m_dirtyBits.backgroundColorDirty = true;
+ m_dirtyBits.backgroundEnabledDirty = true;
+ m_dirtyBits.baseColorDirty = true;
+ m_dirtyBits.baseGradientDirty = true;
+ m_dirtyBits.colorStyleDirty = true;
+ m_dirtyBits.fontDirty = true;
+ m_dirtyBits.gridEnabledDirty = true;
+ m_dirtyBits.gridLineColorDirty = true;
+ m_dirtyBits.highlightLightStrengthDirty = true;
+ m_dirtyBits.labelBackgroundEnabledDirty = true;
+ m_dirtyBits.labelBorderEnabledDirty = true;
+ m_dirtyBits.lightColorDirty = true;
+ m_dirtyBits.lightStrengthDirty = true;
+ m_dirtyBits.multiHighlightColorDirty = true;
+ m_dirtyBits.multiHighlightGradientDirty = true;
+ m_dirtyBits.singleHighlightColorDirty = true;
+ m_dirtyBits.singleHighlightGradientDirty = true;
+ m_dirtyBits.textBackgroundColorDirty = true;
+ m_dirtyBits.textColorDirty = true;
+ m_dirtyBits.themeIdDirty = true;
+ m_dirtyBits.windowColorDirty = true;
+}
+
+bool Q3DThemePrivate::sync(Q3DThemePrivate &other)
+{
+ bool changed = false;
+ if (m_dirtyBits.ambientLightStrengthDirty) {
+ other.q_ptr->setAmbientLightStrength(m_ambientLightStrength);
+ m_dirtyBits.ambientLightStrengthDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.backgroundColorDirty) {
+ other.q_ptr->setBackgroundColor(m_backgroundColor);
+ m_dirtyBits.backgroundColorDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.backgroundEnabledDirty) {
+ other.q_ptr->setBackgroundEnabled(m_backgoundEnabled);
+ m_dirtyBits.backgroundEnabledDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.baseColorDirty) {
+ other.q_ptr->setBaseColor(m_baseColor);
+ m_dirtyBits.baseColorDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.baseGradientDirty) {
+ other.q_ptr->setBaseGradient(m_baseGradient);
+ m_dirtyBits.baseGradientDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.colorStyleDirty) {
+ other.q_ptr->setColorStyle(m_colorStyle);
+ m_dirtyBits.colorStyleDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.fontDirty) {
+ other.q_ptr->setFont(m_font);
+ m_dirtyBits.fontDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.gridEnabledDirty) {
+ other.q_ptr->setGridEnabled(m_gridEnabled);
+ m_dirtyBits.gridEnabledDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.gridLineColorDirty) {
+ other.q_ptr->setGridLineColor(m_gridLineColor);
+ m_dirtyBits.gridLineColorDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.highlightLightStrengthDirty) {
+ other.q_ptr->setHighlightLightStrength(m_highlightLightStrength);
+ m_dirtyBits.highlightLightStrengthDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.labelBackgroundEnabledDirty) {
+ other.q_ptr->setLabelBackgroundEnabled(m_labelBackground);
+ m_dirtyBits.labelBackgroundEnabledDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.labelBorderEnabledDirty) {
+ other.q_ptr->setLabelBorderEnabled(m_labelBorders);
+ m_dirtyBits.labelBorderEnabledDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.lightColorDirty) {
+ other.q_ptr->setLightColor(m_lightColor);
+ m_dirtyBits.lightColorDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.lightStrengthDirty) {
+ other.q_ptr->setLightStrength(m_lightStrength);
+ m_dirtyBits.lightStrengthDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.multiHighlightColorDirty) {
+ other.q_ptr->setMultiHighlightColor(m_multiHighlightColor);
+ m_dirtyBits.multiHighlightColorDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.multiHighlightGradientDirty) {
+ other.q_ptr->setMultiHighlightGradient(m_multiHighlightGradient);
+ m_dirtyBits.multiHighlightGradientDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.singleHighlightColorDirty) {
+ other.q_ptr->setSingleHighlightColor(m_singleHighlightColor);
+ m_dirtyBits.singleHighlightColorDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.singleHighlightGradientDirty) {
+ other.q_ptr->setSingleHighlightGradient(m_singleHighlightGradient);
+ m_dirtyBits.singleHighlightGradientDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.textBackgroundColorDirty) {
+ other.q_ptr->setTextBackgroundColor(m_textBackgroundColor);
+ m_dirtyBits.textBackgroundColorDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.textColorDirty) {
+ other.q_ptr->setTextColor(m_textColor);
+ m_dirtyBits.textColorDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.themeIdDirty) {
+ other.m_themeId = m_themeId; // Set directly to avoid a call to ThemeManager's useTheme()
+ m_dirtyBits.themeIdDirty = false;
+ changed = true;
+ }
+ if (m_dirtyBits.windowColorDirty) {
+ other.q_ptr->setWindowColor(m_windowColor);
+ m_dirtyBits.windowColorDirty = false;
+ changed = true;
+ }
+ return changed;
}
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualization/theme/q3dtheme.h b/src/datavisualization/theme/q3dtheme.h
index 43e9fd70..db044826 100644
--- a/src/datavisualization/theme/q3dtheme.h
+++ b/src/datavisualization/theme/q3dtheme.h
@@ -150,6 +150,8 @@ signals:
void labelBackgroundEnabledChanged(bool enabled);
void colorStyleChanged(QDataVis::ColorStyle style);
+ void needRender();
+
protected:
explicit Q3DTheme(Q3DThemePrivate *d,
QDataVis::Theme themeType,
@@ -157,6 +159,7 @@ protected:
QScopedPointer<Q3DThemePrivate> d_ptr;
friend class ThemeManager;
+ friend class Abstract3DRenderer;
private:
Q_DISABLE_COPY(Q3DTheme)
diff --git a/src/datavisualization/theme/q3dtheme_p.h b/src/datavisualization/theme/q3dtheme_p.h
index 08efa61e..9107095c 100644
--- a/src/datavisualization/theme/q3dtheme_p.h
+++ b/src/datavisualization/theme/q3dtheme_p.h
@@ -56,6 +56,7 @@ struct Q3DThemeDirtyBitField {
bool backgroundEnabledDirty : 1;
bool gridEnabledDirty : 1;
bool labelBackgroundEnabledDirty : 1;
+ bool themeIdDirty : 1;
Q3DThemeDirtyBitField()
: baseColorDirty(false),
@@ -78,7 +79,8 @@ struct Q3DThemeDirtyBitField {
fontDirty(false),
backgroundEnabledDirty(false),
gridEnabledDirty(false),
- labelBackgroundEnabledDirty(false)
+ labelBackgroundEnabledDirty(false),
+ themeIdDirty(false)
{
}
};
@@ -93,6 +95,8 @@ public:
void resetDirtyBits();
+ bool sync(Q3DThemePrivate &other);
+
public:
QDataVis::Theme m_themeId;
diff --git a/src/datavisualization/theme/thememanager.cpp b/src/datavisualization/theme/thememanager.cpp
index 36a879bf..d552287b 100644
--- a/src/datavisualization/theme/thememanager.cpp
+++ b/src/datavisualization/theme/thememanager.cpp
@@ -49,6 +49,7 @@ void ThemeManager::setTheme(Q3DTheme *theme)
if (type != QDataVis::ThemeUserDefined) {
useTheme(type);
+ // Reset all bits to dirty for sync
m_theme->d_ptr->resetDirtyBits();
}
@@ -64,48 +65,23 @@ 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);
connect(m_theme.data(), &Q3DTheme::baseColorChanged,
m_controller, &Abstract3DController::setBaseColor);
-// connect(m_theme.data(), &Q3DTheme::backgroundColorChanged,
-// m_controller, &Abstract3DController::setBackgroundColor);
-// connect(m_theme.data(), &Q3DTheme::windowColorChanged,
-// m_controller, &Abstract3DController::setWindowColor);
-// connect(m_theme.data(), &Q3DTheme::textColorChanged,
-// m_controller, &Abstract3DController::setTextColor);
-// connect(m_theme.data(), &Q3DTheme::textBackgroundColorChanged,
-// m_controller, &Abstract3DController::setTextBackgroundColor);
-// connect(m_theme.data(), &Q3DTheme::gridLineColorChanged,
-// m_controller, &Abstract3DController::setGridLineColor);
connect(m_theme.data(), &Q3DTheme::singleHighlightColorChanged,
m_controller, &Abstract3DController::setSingleHighlightColor);
connect(m_theme.data(), &Q3DTheme::multiHighlightColorChanged,
m_controller, &Abstract3DController::setMultiHighlightColor);
-// connect(m_theme.data(), &Q3DTheme::lightColorChanged,
-// m_controller, &Abstract3DController::setLightColor);
connect(m_theme.data(), &Q3DTheme::baseGradientChanged,
m_controller, &Abstract3DController::setBaseGradient);
connect(m_theme.data(), &Q3DTheme::singleHighlightGradientChanged,
m_controller, &Abstract3DController::setSingleHighlightGradient);
connect(m_theme.data(), &Q3DTheme::multiHighlightGradientChanged,
m_controller, &Abstract3DController::setMultiHighlightGradient);
-// connect(m_theme.data(), &Q3DTheme::lightStrengthChanged,
-// m_controller, &Abstract3DController::setLightStrength);
-// connect(m_theme.data(), &Q3DTheme::ambientLightStrengthChanged,
-// m_controller, &Abstract3DController::setAmbientLightStrength);
-// connect(m_theme.data(), &Q3DTheme::highlightLightStrengthChanged,
-// m_controller, &Abstract3DController::setHighlightLightStrength);
-// connect(m_theme.data(), &Q3DTheme::labelBorderEnabledChanged,
-// m_controller, &Abstract3DController::setLabelBorderEnabled);
- connect(m_theme.data(), &Q3DTheme::fontChanged,
- m_controller, &Abstract3DController::setFont);
- connect(m_theme.data(), &Q3DTheme::backgroundEnabledChanged,
- m_controller, &Abstract3DController::setBackgroundEnabled);
- connect(m_theme.data(), &Q3DTheme::gridEnabledChanged,
- m_controller, &Abstract3DController::setGridEnabled);
- connect(m_theme.data(), &Q3DTheme::labelBackgroundEnabledChanged,
- m_controller, &Abstract3DController::setLabelBackgroundEnabled);
- connect(m_theme.data(), &Q3DTheme::colorStyleChanged,
- m_controller, &Abstract3DController::setColorStyle);
+
+ connect(m_theme.data(), &Q3DTheme::needRender, m_controller, &Abstract3DController::needRender);
connect(m_theme.data(), &Q3DTheme::typeChanged, this, &ThemeManager::useTheme);
}