summaryrefslogtreecommitdiffstats
path: root/tests
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 /tests
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 'tests')
-rw-r--r--tests/barstest/chart.cpp92
-rw-r--r--tests/barstest/chart.h1
-rw-r--r--tests/multigraphs/data.cpp26
-rw-r--r--tests/scattertest/scatterchart.cpp23
-rw-r--r--tests/spectrum/spectrumapp/main.cpp2
-rw-r--r--tests/surfacetest/graphmodifier.cpp9
-rw-r--r--tests/surfacetest/main.cpp2
7 files changed, 92 insertions, 63 deletions
diff --git a/tests/barstest/chart.cpp b/tests/barstest/chart.cpp
index 8bef7479..5c36607e 100644
--- a/tests/barstest/chart.cpp
+++ b/tests/barstest/chart.cpp
@@ -63,7 +63,8 @@ GraphModifier::GraphModifier(Q3DBars *barchart, QColorDialog *colorDialog)
m_currentAxis(m_fixedRangeAxis),
m_negativeValuesOn(false),
m_useNullInputHandler(false),
- m_defaultInputHandler(0)
+ m_defaultInputHandler(0),
+ m_ownTheme(0)
{
// Generate generic labels
QStringList genericColumnLabels;
@@ -116,7 +117,7 @@ GraphModifier::GraphModifier(Q3DBars *barchart, QColorDialog *colorDialog)
m_graph->addAxis(m_genericRowAxis);
m_graph->addAxis(m_genericColumnAxis);
- m_graph->setTheme(new Q3DTheme(Q3DTheme::ThemeStoneMoss));
+ m_graph->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeStoneMoss));
m_graph->setShadowQuality(QDataVis::ShadowQualitySoftMedium);
m_temperatureData->setItemLabelFormat(QStringLiteral("1: @valueTitle for @colLabel @rowLabel: @valueLabel"));
@@ -166,7 +167,7 @@ GraphModifier::GraphModifier(Q3DBars *barchart, QColorDialog *colorDialog)
m_temperatureData->setSingleHighlightGradient(singleHighlightGradient);
m_temperatureData->setMultiHighlightGradient(multiHighlightGradient);
- m_graph->theme()->setFont(QFont("Times Roman", 20));
+ m_graph->activeTheme()->setFont(QFont("Times Roman", 20));
// Release and store the default input handler.
m_defaultInputHandler = m_graph->activeInputHandler();
@@ -576,7 +577,12 @@ void GraphModifier::changeTheme()
{
static int theme = Q3DTheme::ThemeQt;
- m_graph->setTheme(new Q3DTheme((Q3DTheme::Theme)theme));
+ Q3DTheme *currentTheme = m_graph->activeTheme();
+ if (currentTheme != m_ownTheme) {
+ m_graph->releaseTheme(currentTheme);
+ delete currentTheme;
+ }
+ m_graph->setActiveTheme(new Q3DTheme((Q3DTheme::Theme)theme));
switch (theme) {
case Q3DTheme::ThemeQt:
@@ -614,7 +620,7 @@ void GraphModifier::changeTheme()
void GraphModifier::changeLabelStyle()
{
- m_graph->theme()->setLabelBackgroundEnabled(!m_graph->theme()->isLabelBackgroundEnabled());
+ m_graph->activeTheme()->setLabelBackgroundEnabled(!m_graph->activeTheme()->isLabelBackgroundEnabled());
}
void GraphModifier::changeSelectionMode()
@@ -631,15 +637,15 @@ void GraphModifier::changeFont(const QFont &font)
{
QFont newFont = font;
newFont.setPointSize(m_fontSize);
- 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)
@@ -737,12 +743,12 @@ QBarDataArray *GraphModifier::makeDummyData()
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::rotateX(int rotation)
@@ -811,38 +817,46 @@ void GraphModifier::setMaxY(int max)
void GraphModifier::changeColorStyle()
{
- int style = m_graph->theme()->colorStyle();
+ int style = m_graph->activeTheme()->colorStyle();
if (++style > Q3DTheme::ColorStyleRangeGradient)
style = Q3DTheme::ColorStyleUniform;
- m_graph->theme()->setColorStyle(Q3DTheme::ColorStyle(style));
+ m_graph->activeTheme()->setColorStyle(Q3DTheme::ColorStyle(style));
}
void GraphModifier::useOwnTheme()
{
- Q3DTheme *theme = new Q3DTheme();
- theme->setBackgroundEnabled(true);
- theme->setGridEnabled(true);
- theme->setAmbientLightStrength(0.3f);
- theme->setBackgroundColor(QColor(QRgb(0x99ca53)));
- QList<QColor> colors;
- colors.append(QColor(QRgb(0x209fdf)));
- theme->setBaseColors(colors);
- theme->setColorStyle(Q3DTheme::ColorStyleUniform);
- theme->setGridLineColor(QColor(QRgb(0x99ca53)));
- theme->setHighlightLightStrength(7.0f);
- theme->setLabelBackgroundEnabled(true);
- theme->setLabelBorderEnabled(true);
- theme->setLightColor(Qt::white);
- theme->setLightStrength(6.0f);
- theme->setMultiHighlightColor(QColor(QRgb(0x6d5fd5)));
- theme->setSingleHighlightColor(QColor(QRgb(0xf6a625)));
- theme->setLabelBackgroundColor(QColor(0xf6, 0xa6, 0x25, 0xa0));
- theme->setLabelTextColor(QColor(QRgb(0x404044)));
- theme->setWindowColor(QColor(QRgb(0xffffff)));
-
- m_graph->setTheme(theme);
+ // Own theme is persistent, any changes to it via UI will be remembered
+ if (!m_ownTheme) {
+ m_ownTheme = new Q3DTheme();
+ m_ownTheme->setBackgroundEnabled(true);
+ m_ownTheme->setGridEnabled(true);
+ m_ownTheme->setAmbientLightStrength(0.3f);
+ m_ownTheme->setBackgroundColor(QColor(QRgb(0x99ca53)));
+ QList<QColor> colors;
+ colors.append(QColor(QRgb(0x209fdf)));
+ m_ownTheme->setBaseColors(colors);
+ m_ownTheme->setColorStyle(Q3DTheme::ColorStyleUniform);
+ m_ownTheme->setGridLineColor(QColor(QRgb(0x99ca53)));
+ m_ownTheme->setHighlightLightStrength(7.0f);
+ m_ownTheme->setLabelBackgroundEnabled(true);
+ m_ownTheme->setLabelBorderEnabled(true);
+ m_ownTheme->setLightColor(Qt::white);
+ m_ownTheme->setLightStrength(6.0f);
+ m_ownTheme->setMultiHighlightColor(QColor(QRgb(0x6d5fd5)));
+ m_ownTheme->setSingleHighlightColor(QColor(QRgb(0xf6a625)));
+ m_ownTheme->setLabelBackgroundColor(QColor(0xf6, 0xa6, 0x25, 0xa0));
+ m_ownTheme->setLabelTextColor(QColor(QRgb(0x404044)));
+ m_ownTheme->setWindowColor(QColor(QRgb(0xffffff)));
+ }
+
+ Q3DTheme *currentTheme = m_graph->activeTheme();
+ if (currentTheme != m_ownTheme) {
+ m_graph->releaseTheme(currentTheme);
+ delete currentTheme;
+ }
+ m_graph->setActiveTheme(m_ownTheme);
m_colorDialog->open();
}
@@ -852,7 +866,7 @@ void GraphModifier::changeBaseColor(const QColor &color)
qDebug() << "base color changed to" << color;
QList<QColor> colors;
colors.append(color);
- m_graph->theme()->setBaseColors(colors);
+ m_graph->activeTheme()->setBaseColors(colors);
}
void GraphModifier::setGradient()
@@ -883,9 +897,9 @@ void GraphModifier::setGradient()
QList<QLinearGradient> barGradients;
barGradients.append(barGradient);
- m_graph->theme()->setBaseGradients(barGradients);
- m_graph->theme()->setSingleHighlightGradient(singleHighlightGradient);
- m_graph->theme()->setMultiHighlightGradient(multiHighlightGradient);
+ m_graph->activeTheme()->setBaseGradients(barGradients);
+ m_graph->activeTheme()->setSingleHighlightGradient(singleHighlightGradient);
+ m_graph->activeTheme()->setMultiHighlightGradient(multiHighlightGradient);
- m_graph->theme()->setColorStyle(Q3DTheme::ColorStyleObjectGradient);
+ m_graph->activeTheme()->setColorStyle(Q3DTheme::ColorStyleObjectGradient);
}
diff --git a/tests/barstest/chart.h b/tests/barstest/chart.h
index 96038b9f..3948ca8f 100644
--- a/tests/barstest/chart.h
+++ b/tests/barstest/chart.h
@@ -129,6 +129,7 @@ private:
bool m_negativeValuesOn;
bool m_useNullInputHandler;
QAbstract3DInputHandler *m_defaultInputHandler;
+ Q3DTheme *m_ownTheme;
};
#endif
diff --git a/tests/multigraphs/data.cpp b/tests/multigraphs/data.cpp
index 99354caf..177d86b7 100644
--- a/tests/multigraphs/data.cpp
+++ b/tests/multigraphs/data.cpp
@@ -45,15 +45,15 @@ Data::Data(Q3DSurface *surface, Q3DScatter *scatter, Q3DBars *bars,
m_started(false)
{
// Initialize surface
- m_surface->setTheme(new Q3DTheme(Q3DTheme::ThemeIsabelle));
+ m_surface->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeIsabelle));
QLinearGradient gradient;
gradient.setColorAt(0.0, Qt::black);
gradient.setColorAt(0.33, Qt::blue);
gradient.setColorAt(0.67, Qt::red);
gradient.setColorAt(1.0, Qt::yellow);
m_surface->setSelectionMode(QDataVis::SelectionNone);
- m_surface->theme()->setGridEnabled(false);
- m_surface->theme()->setBackgroundEnabled(false);
+ m_surface->activeTheme()->setGridEnabled(false);
+ m_surface->activeTheme()->setBackgroundEnabled(false);
m_surface->scene()->activeCamera()->setCameraPosition(0.0, 90.0, 150);
QSurface3DSeries *series1 = new QSurface3DSeries(new QHeightMapSurfaceDataProxy());
series1->setFlatShadingEnabled(true);
@@ -63,9 +63,9 @@ Data::Data(Q3DSurface *surface, Q3DScatter *scatter, Q3DBars *bars,
m_surface->addSeries(series1);
// Initialize scatter
- m_scatter->setTheme(new Q3DTheme(Q3DTheme::ThemeStoneMoss));
+ m_scatter->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeStoneMoss));
m_scatter->setSelectionMode(QDataVis::SelectionNone);
- m_scatter->theme()->setGridEnabled(false);
+ m_scatter->activeTheme()->setGridEnabled(false);
m_scatter->setShadowQuality(QDataVis::ShadowQualitySoftLow);
m_scatter->scene()->activeCamera()->setCameraPosition(0.0, 85.0, 150);
QScatter3DSeries *series2 = new QScatter3DSeries;
@@ -73,9 +73,9 @@ Data::Data(Q3DSurface *surface, Q3DScatter *scatter, Q3DBars *bars,
m_scatter->addSeries(series2);
// Initialize bars
- m_bars->setTheme(new Q3DTheme(Q3DTheme::ThemeQt));
+ m_bars->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeQt));
m_bars->setSelectionMode(QDataVis::SelectionItemAndRow | QDataVis::SelectionSlice);
- m_bars->theme()->setGridEnabled(false);
+ m_bars->activeTheme()->setGridEnabled(false);
m_bars->setShadowQuality(QDataVis::ShadowQualityLow);
m_bars->setBarSpacing(QSizeF(0.0, 0.0));
m_bars->scene()->activeCamera()->setCameraPosition(0.0, 75.0, 150);
@@ -185,24 +185,32 @@ void Data::scrollDown()
void Data::useGradientOne()
{
- m_surface->setTheme(new Q3DTheme(Q3DTheme::ThemeIsabelle));
+ Q3DTheme *currentTheme = m_surface->activeTheme();
+ m_surface->releaseTheme(currentTheme);
+ delete currentTheme;
+ m_surface->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeIsabelle));
QLinearGradient gradient;
gradient.setColorAt(0.0, Qt::black);
gradient.setColorAt(0.33, Qt::blue);
gradient.setColorAt(0.67, Qt::red);
gradient.setColorAt(1.0, Qt::yellow);
m_surface->seriesList().at(0)->setBaseGradient(gradient);
+ m_surface->seriesList().at(0)->setColorStyle(Q3DTheme::ColorStyleRangeGradient);
m_statusArea->append(QStringLiteral("<b>Colors:</b> Thermal image imitation"));
}
void Data::useGradientTwo()
{
- m_surface->setTheme(new Q3DTheme(Q3DTheme::ThemeQt));
+ Q3DTheme *currentTheme = m_surface->activeTheme();
+ m_surface->releaseTheme(currentTheme);
+ delete currentTheme;
+ m_surface->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeQt));
QLinearGradient gradient;
gradient.setColorAt(0.0, Qt::white);
gradient.setColorAt(0.8, Qt::red);
gradient.setColorAt(1.0, Qt::green);
m_surface->seriesList().at(0)->setBaseGradient(gradient);
+ m_surface->seriesList().at(0)->setColorStyle(Q3DTheme::ColorStyleRangeGradient);
m_statusArea->append(QStringLiteral("<b>Colors:</b> Highlight foreground"));
}
diff --git a/tests/scattertest/scatterchart.cpp b/tests/scattertest/scatterchart.cpp
index b1df526a..10f48465 100644
--- a/tests/scattertest/scatterchart.cpp
+++ b/tests/scattertest/scatterchart.cpp
@@ -37,10 +37,10 @@ ScatterDataModifier::ScatterDataModifier(Q3DScatter *scatter)
m_selectedItem(-1),
m_targetSeries(0)
{
- m_chart->setTheme(new Q3DTheme(Q3DTheme::ThemeStoneMoss));
- QFont font = m_chart->theme()->font();
+ m_chart->setActiveTheme(new Q3DTheme(Q3DTheme::ThemeStoneMoss));
+ QFont font = m_chart->activeTheme()->font();
font.setPointSize(m_fontSize);
- m_chart->theme()->setFont(font);
+ m_chart->activeTheme()->setFont(font);
m_chart->setShadowQuality(QDataVis::ShadowQualityNone);
m_chart->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPresetFront);
m_chart->setAxisX(new Q3DValueAxis);
@@ -161,7 +161,10 @@ void ScatterDataModifier::changeTheme()
{
static int theme = Q3DTheme::ThemeQt;
- m_chart->setTheme(new Q3DTheme(Q3DTheme::Theme(theme)));
+ Q3DTheme *currentTheme = m_chart->activeTheme();
+ m_chart->releaseTheme(currentTheme);
+ delete currentTheme;
+ m_chart->setActiveTheme(new Q3DTheme(Q3DTheme::Theme(theme)));
if (++theme > Q3DTheme::ThemeIsabelle)
theme = Q3DTheme::ThemeQt;
@@ -169,22 +172,22 @@ void ScatterDataModifier::changeTheme()
void ScatterDataModifier::changeLabelStyle()
{
- m_chart->theme()->setLabelBackgroundEnabled(!m_chart->theme()->isLabelBackgroundEnabled());
+ m_chart->activeTheme()->setLabelBackgroundEnabled(!m_chart->activeTheme()->isLabelBackgroundEnabled());
}
void ScatterDataModifier::changeFont(const QFont &font)
{
QFont newFont = font;
newFont.setPointSizeF(m_fontSize);
- m_chart->theme()->setFont(newFont);
+ m_chart->activeTheme()->setFont(newFont);
}
void ScatterDataModifier::changeFontSize(int fontSize)
{
m_fontSize = fontSize;
- QFont font = m_chart->theme()->font();
+ QFont font = m_chart->activeTheme()->font();
font.setPointSize(m_fontSize);
- m_chart->theme()->setFont(font);
+ m_chart->activeTheme()->setFont(font);
}
void ScatterDataModifier::changePointSize(int pointSize)
@@ -470,12 +473,12 @@ void ScatterDataModifier::changeShadowQuality(int quality)
void ScatterDataModifier::setBackgroundEnabled(int enabled)
{
- m_chart->theme()->setBackgroundEnabled((bool)enabled);
+ m_chart->activeTheme()->setBackgroundEnabled((bool)enabled);
}
void ScatterDataModifier::setGridEnabled(int enabled)
{
- m_chart->theme()->setGridEnabled((bool)enabled);
+ m_chart->activeTheme()->setGridEnabled((bool)enabled);
}
QVector3D ScatterDataModifier::randVector()
diff --git a/tests/spectrum/spectrumapp/main.cpp b/tests/spectrum/spectrumapp/main.cpp
index 311de719..92965c1c 100644
--- a/tests/spectrum/spectrumapp/main.cpp
+++ b/tests/spectrum/spectrumapp/main.cpp
@@ -74,7 +74,7 @@ MainApp::MainApp(Q3DBars *window)
m_chart->rowAxis()->setMax(SpectrumNumBands * 2);
m_chart->columnAxis()->setMax(SpectrumNumBands - 1);
// Disable grid
- m_chart->theme()->setGridEnabled(false);
+ m_chart->activeTheme()->setGridEnabled(false);
// Disable auto-scaling of height by defining explicit range
m_chart->valueAxis()->setRange(0.0f, 1.0f);
// Disable shadows
diff --git a/tests/surfacetest/graphmodifier.cpp b/tests/surfacetest/graphmodifier.cpp
index 3474b67f..749b1c69 100644
--- a/tests/surfacetest/graphmodifier.cpp
+++ b/tests/surfacetest/graphmodifier.cpp
@@ -338,12 +338,12 @@ void GraphModifier::changeFont(const QFont &font)
{
QFont newFont = font;
newFont.setPointSizeF(m_fontSize);
- m_graph->theme()->setFont(newFont);
+ m_graph->activeTheme()->setFont(newFont);
}
void GraphModifier::changeStyle()
{
- m_graph->theme()->setLabelBackgroundEnabled(!m_graph->theme()->isLabelBackgroundEnabled());
+ m_graph->activeTheme()->setLabelBackgroundEnabled(!m_graph->activeTheme()->isLabelBackgroundEnabled());
}
void GraphModifier::selectButtonClicked()
@@ -363,7 +363,10 @@ void GraphModifier::selectedPointChanged(const QPoint &point)
void GraphModifier::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)));
}
diff --git a/tests/surfacetest/main.cpp b/tests/surfacetest/main.cpp
index c25c5b89..5a26c7ce 100644
--- a/tests/surfacetest/main.cpp
+++ b/tests/surfacetest/main.cpp
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
QSize screenSize = surfaceGraph->screen()->size();
// Set to default, should be same as the initial on themeList
- surfaceGraph->setTheme(new Q3DTheme(Q3DTheme::Theme(initialTheme)));
+ surfaceGraph->setActiveTheme(new Q3DTheme(Q3DTheme::Theme(initialTheme)));
QWidget *container = QWidget::createWindowContainer(surfaceGraph);
container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 2));