summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2013-12-20 10:56:59 +0200
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-01-07 08:10:13 +0200
commitaa842c39480aa5b95f704c97b8b3acc821144883 (patch)
tree8a1e90e1fe1d6d85054286e655cb2e1722d758eb /examples
parent91a94a743b4cfd30ef77aa73837050d44620469b (diff)
Fix theme ownership
Theme ownership now uses similar model as axis and inputhandler ownership: Graph can own multiple themes, but only one is active at the time. Task-number: QTRD-2623 Change-Id: I7134384df6f8cc465cc28fbebb454b7d2e254f83 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/audiolevels/audiolevels.cpp10
-rw-r--r--examples/bars/graphmodifier.cpp32
-rw-r--r--examples/custominput/scatterdatamodifier.cpp2
-rw-r--r--examples/customproxy/rainfallgraph.cpp4
-rw-r--r--examples/itemmodel/main.cpp4
-rw-r--r--examples/qmlscatter/doc/src/qmlscatter.qdoc6
-rw-r--r--examples/qmlscatter/qml/qmlscatter/main.qml30
-rw-r--r--examples/scatter/scatterdatamodifier.cpp26
-rw-r--r--examples/surface/doc/src/surface.qdoc2
-rw-r--r--examples/surface/surfacegraph.cpp5
10 files changed, 71 insertions, 50 deletions
diff --git a/examples/audiolevels/audiolevels.cpp b/examples/audiolevels/audiolevels.cpp
index 3677c1f1..259274d9 100644
--- a/examples/audiolevels/audiolevels.cpp
+++ b/examples/audiolevels/audiolevels.cpp
@@ -46,12 +46,12 @@ AudioLevels::AudioLevels(Q3DBars *graph, QObject *parent)
m_graph->setShadowQuality(QDataVis::ShadowQualityNone);
m_graph->setSelectionMode(QDataVis::SelectionNone);
m_graph->scene()->activeCamera()->setCameraPosition(-25.0f, 10.0f, 190.0f);
- m_graph->setTheme(new Q3DTheme(Q3DTheme::ThemeIsabelle));
- m_graph->theme()->setGridEnabled(true);
- m_graph->theme()->setBackgroundEnabled(false);
- QFont font = m_graph->theme()->font();
+ m_graph->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeIsabelle));
+ m_graph->activeTheme()->setGridEnabled(true);
+ m_graph->activeTheme()->setBackgroundEnabled(false);
+ QFont font = m_graph->activeTheme()->font();
font.setPointSize(10);
- m_graph->theme()->setFont(font);
+ m_graph->activeTheme()->setFont(font);
QBar3DSeries *series = new QBar3DSeries;
series->setMesh(QAbstract3DSeries::MeshBar);
m_graph->addSeries(series);
diff --git a/examples/bars/graphmodifier.cpp b/examples/bars/graphmodifier.cpp
index 13e4d3e7..09fec65d 100644
--- a/examples/bars/graphmodifier.cpp
+++ b/examples/bars/graphmodifier.cpp
@@ -54,9 +54,9 @@ GraphModifier::GraphModifier(Q3DBars *bargraph)
{
//! [2]
m_graph->setShadowQuality(QDataVis::ShadowQualitySoftMedium);
- m_graph->theme()->setBackgroundEnabled(false);
- m_graph->theme()->setFont(QFont("Times New Roman", m_fontSize));
- m_graph->theme()->setLabelBackgroundEnabled(true);
+ m_graph->activeTheme()->setBackgroundEnabled(false);
+ m_graph->activeTheme()->setFont(QFont("Times New Roman", m_fontSize));
+ m_graph->activeTheme()->setLabelBackgroundEnabled(true);
//! [2]
m_months << "January" << "February" << "March" << "April" << "May" << "June" << "July" << "August" << "September" << "October" << "November" << "December";
@@ -185,16 +185,20 @@ void GraphModifier::changePresetCamera()
void GraphModifier::changeTheme(int theme)
{
- m_graph->setTheme(new Q3DTheme(Q3DTheme::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());
+ Q3DTheme *currentTheme = m_graph->activeTheme();
+ m_graph->releaseTheme(currentTheme);
+ delete currentTheme;
+ currentTheme = new Q3DTheme(Q3DTheme::Theme(theme));
+ m_graph->setActiveTheme(currentTheme);
+ emit backgroundEnabledChanged(currentTheme->isBackgroundEnabled());
+ emit gridEnabledChanged(currentTheme->isGridEnabled());
+ emit fontChanged(currentTheme->font());
+ emit fontSizeChanged(currentTheme->font().pointSize());
}
void GraphModifier::changeLabelBackground()
{
- m_graph->theme()->setLabelBackgroundEnabled(!m_graph->theme()->isLabelBackgroundEnabled());
+ m_graph->activeTheme()->setLabelBackgroundEnabled(!m_graph->activeTheme()->isLabelBackgroundEnabled());
}
void GraphModifier::changeSelectionMode(int selectionMode)
@@ -209,15 +213,15 @@ void GraphModifier::changeSelectionMode(int selectionMode)
void GraphModifier::changeFont(const QFont &font)
{
QFont newFont = font;
- m_graph->theme()->setFont(newFont);
+ m_graph->activeTheme()->setFont(newFont);
}
void GraphModifier::changeFontSize(int fontsize)
{
m_fontSize = fontsize;
- QFont font = m_graph->theme()->font();
+ QFont font = m_graph->activeTheme()->font();
font.setPointSize(m_fontSize);
- m_graph->theme()->setFont(font);
+ m_graph->activeTheme()->setFont(font);
}
void GraphModifier::shadowQualityUpdatedByVisual(QDataVis::ShadowQuality sq)
@@ -250,12 +254,12 @@ void GraphModifier::rotateY(int rotation)
void GraphModifier::setBackgroundEnabled(int enabled)
{
- m_graph->theme()->setBackgroundEnabled(bool(enabled));
+ m_graph->activeTheme()->setBackgroundEnabled(bool(enabled));
}
void GraphModifier::setGridEnabled(int enabled)
{
- m_graph->theme()->setGridEnabled(bool(enabled));
+ m_graph->activeTheme()->setGridEnabled(bool(enabled));
}
void GraphModifier::setSmoothBars(int smooth)
diff --git a/examples/custominput/scatterdatamodifier.cpp b/examples/custominput/scatterdatamodifier.cpp
index aabb1b3a..aeef4c98 100644
--- a/examples/custominput/scatterdatamodifier.cpp
+++ b/examples/custominput/scatterdatamodifier.cpp
@@ -32,7 +32,7 @@ ScatterDataModifier::ScatterDataModifier(Q3DScatter *scatter)
: m_graph(scatter),
m_inputHandler(new CustomInputHandler())
{
- m_graph->setTheme(new Q3DTheme(Q3DTheme::ThemeDigia));
+ m_graph->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeDigia));
m_graph->setShadowQuality(QDataVis::ShadowQualityMedium);
m_graph->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPresetFront);
diff --git a/examples/customproxy/rainfallgraph.cpp b/examples/customproxy/rainfallgraph.cpp
index ad45d016..57e1d0ea 100644
--- a/examples/customproxy/rainfallgraph.cpp
+++ b/examples/customproxy/rainfallgraph.cpp
@@ -72,10 +72,10 @@ RainfallGraph::RainfallGraph(Q3DBars *rainfall)
m_graph->setSelectionMode(QDataVis::SelectionItemAndColumn | QDataVis::SelectionSlice);
// Set theme
- m_graph->setTheme(new Q3DTheme(Q3DTheme::ThemeArmyBlue));
+ m_graph->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeArmyBlue));
// Set font to theme
- m_graph->theme()->setFont(QFont("Century Gothic", 30));
+ m_graph->activeTheme()->setFont(QFont("Century Gothic", 30));
// Set camera position and zoom
m_graph->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPresetIsometricRightHigh);
diff --git a/examples/itemmodel/main.cpp b/examples/itemmodel/main.cpp
index 46aa8bb8..015470d1 100644
--- a/examples/itemmodel/main.cpp
+++ b/examples/itemmodel/main.cpp
@@ -107,10 +107,10 @@ GraphDataGenerator::GraphDataGenerator(Q3DBars *bargraph, QTableWidget *tableWid
//! [7]
// Set theme
- m_graph->setTheme(new Q3DTheme(Q3DTheme::ThemeDigia));
+ m_graph->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeDigia));
// Set font
- m_graph->theme()->setFont(QFont("Impact", 20));
+ m_graph->activeTheme()->setFont(QFont("Impact", 20));
// Set preset camera position
m_graph->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPresetFront);
diff --git a/examples/qmlscatter/doc/src/qmlscatter.qdoc b/examples/qmlscatter/doc/src/qmlscatter.qdoc
index 0a758751..19559f4c 100644
--- a/examples/qmlscatter/doc/src/qmlscatter.qdoc
+++ b/examples/qmlscatter/doc/src/qmlscatter.qdoc
@@ -112,9 +112,13 @@
\snippet ../examples/qmlscatter/qml/qmlscatter/main.qml 3
- We added a built-in Theme3D and changed the font in it. We also changed the shadow quality.
+ We added a customized theme and changed the shadow quality.
We're happy with the other visual properties, so we won't change them.
+ The custom theme is based on a predefined theme, but we change the font in it:
+
+ \snippet ../examples/qmlscatter/qml/qmlscatter/main.qml 13
+
Then it's time to start feeding the graph some data.
\section1 Adding data to the graph
diff --git a/examples/qmlscatter/qml/qmlscatter/main.qml b/examples/qmlscatter/qml/qmlscatter/main.qml
index e0a7f26b..50164c50 100644
--- a/examples/qmlscatter/qml/qmlscatter/main.qml
+++ b/examples/qmlscatter/qml/qmlscatter/main.qml
@@ -33,6 +33,21 @@ Item {
id: seriesData
}
//! [4]
+
+ //! [13]
+ Theme3D {
+ id: themeIsabelle
+ type: Theme3D.ThemeIsabelle
+ font.family: "Lucida Handwriting"
+ font.pointSize: 40
+ }
+ //! [13]
+
+ Theme3D {
+ id : themeArmyBlue
+ type: Theme3D.ThemeArmyBlue
+ }
+
//! [8]
//! [9]
Item {
@@ -50,11 +65,7 @@ Item {
height: dataView.height
//! [2]
//! [3]
- theme: Theme3D {
- type: Theme3D.ThemeIsabelle
- font.family: "Lucida Handwriting"
- font.pointSize: 40
- }
+ theme: themeIsabelle
shadowQuality: AbstractGraph3D.ShadowQualitySoftLow
//! [3]
//! [6]
@@ -179,14 +190,9 @@ Item {
text: "Change Theme"
onClicked: {
if (scatterGraph.theme.type === Theme3D.ThemeArmyBlue) {
- // Ownership of the theme is transferred and old theme is destroyed when setting
- // a new one, so we need to create them dynamically
- scatterGraph.theme = Qt.createQmlObject('import QtDataVisualization 1.0;
- Theme3D {type: Theme3D.ThemeIsabelle; font.family: "Lucida Handwriting";
- font.pointSize: 40}', parent);
+ scatterGraph.theme = themeIsabelle
} else {
- scatterGraph.theme = Qt.createQmlObject('import QtDataVisualization 1.0;
- Theme3D {type: Theme3D.ThemeArmyBlue}', parent);
+ scatterGraph.theme = themeArmyBlue
}
}
}
diff --git a/examples/scatter/scatterdatamodifier.cpp b/examples/scatter/scatterdatamodifier.cpp
index 6cdb1458..964da977 100644
--- a/examples/scatter/scatterdatamodifier.cpp
+++ b/examples/scatter/scatterdatamodifier.cpp
@@ -39,10 +39,10 @@ ScatterDataModifier::ScatterDataModifier(Q3DScatter *scatter)
m_smooth(true)
{
//! [0]
- m_graph->setTheme(new Q3DTheme(Q3DTheme::ThemeEbony));
- QFont font = m_graph->theme()->font();
+ m_graph->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeEbony));
+ QFont font = m_graph->activeTheme()->font();
font.setPointSize(m_fontSize);
- m_graph->theme()->setFont(font);
+ m_graph->activeTheme()->setFont(font);
m_graph->setShadowQuality(QDataVis::ShadowQualitySoftLow);
m_graph->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPresetFront);
//! [0]
@@ -131,10 +131,14 @@ void ScatterDataModifier::setSmoothDots(int smooth)
void ScatterDataModifier::changeTheme(int theme)
{
- m_graph->setTheme(new Q3DTheme(Q3DTheme::Theme(theme)));
- emit backgroundEnabledChanged(m_graph->theme()->isBackgroundEnabled());
- emit gridEnabledChanged(m_graph->theme()->isGridEnabled());
- emit fontChanged(m_graph->theme()->font());
+ Q3DTheme *currentTheme = m_graph->activeTheme();
+ m_graph->releaseTheme(currentTheme);
+ delete currentTheme;
+ currentTheme = new Q3DTheme(Q3DTheme::Theme(theme));
+ m_graph->setActiveTheme(currentTheme);
+ emit backgroundEnabledChanged(currentTheme->isBackgroundEnabled());
+ emit gridEnabledChanged(currentTheme->isGridEnabled());
+ emit fontChanged(currentTheme->font());
}
void ScatterDataModifier::changePresetCamera()
@@ -149,14 +153,14 @@ void ScatterDataModifier::changePresetCamera()
void ScatterDataModifier::changeLabelStyle()
{
- m_graph->theme()->setLabelBackgroundEnabled(!m_graph->theme()->isLabelBackgroundEnabled());
+ m_graph->activeTheme()->setLabelBackgroundEnabled(!m_graph->activeTheme()->isLabelBackgroundEnabled());
}
void ScatterDataModifier::changeFont(const QFont &font)
{
QFont newFont = font;
newFont.setPointSizeF(m_fontSize);
- m_graph->theme()->setFont(newFont);
+ m_graph->activeTheme()->setFont(newFont);
}
void ScatterDataModifier::shadowQualityUpdatedByVisual(QDataVis::ShadowQuality sq)
@@ -173,12 +177,12 @@ void ScatterDataModifier::changeShadowQuality(int quality)
void ScatterDataModifier::setBackgroundEnabled(int enabled)
{
- m_graph->theme()->setBackgroundEnabled((bool)enabled);
+ m_graph->activeTheme()->setBackgroundEnabled((bool)enabled);
}
void ScatterDataModifier::setGridEnabled(int enabled)
{
- m_graph->theme()->setGridEnabled((bool)enabled);
+ m_graph->activeTheme()->setGridEnabled((bool)enabled);
}
//! [8]
diff --git a/examples/surface/doc/src/surface.qdoc b/examples/surface/doc/src/surface.qdoc
index 6f49a3dc..dd334d01 100644
--- a/examples/surface/doc/src/surface.qdoc
+++ b/examples/surface/doc/src/surface.qdoc
@@ -124,7 +124,7 @@
Q3DSurface supports all the themes Qt Data Visualization has. The example has a pull
down menu for selecting the theme. The following method is connected to the
- menu to activate the selected theme.
+ menu to activate the selected theme. The old theme is released and deleted:
\snippet ../examples/surface/surfacegraph.cpp 6
diff --git a/examples/surface/surfacegraph.cpp b/examples/surface/surfacegraph.cpp
index 7ebb6b72..3770906e 100644
--- a/examples/surface/surfacegraph.cpp
+++ b/examples/surface/surfacegraph.cpp
@@ -229,7 +229,10 @@ void SurfaceGraph::setAxisZRange(float min, float max)
//! [6]
void SurfaceGraph::changeTheme(int theme)
{
- m_graph->setTheme(new Q3DTheme(Q3DTheme::Theme(theme)));
+ Q3DTheme *currentTheme = m_graph->activeTheme();
+ m_graph->releaseTheme(currentTheme);
+ delete currentTheme;
+ m_graph->setActiveTheme(new Q3DTheme(Q3DTheme::Theme(theme)));
}
//! [6]