summaryrefslogtreecommitdiffstats
path: root/tests/barstest
diff options
context:
space:
mode:
Diffstat (limited to 'tests/barstest')
-rw-r--r--tests/barstest/barstest.pro4
-rw-r--r--tests/barstest/chart.cpp499
-rw-r--r--tests/barstest/chart.h43
-rw-r--r--tests/barstest/custominputhandler.cpp54
-rw-r--r--tests/barstest/custominputhandler.h36
-rw-r--r--tests/barstest/main.cpp40
6 files changed, 599 insertions, 77 deletions
diff --git a/tests/barstest/barstest.pro b/tests/barstest/barstest.pro
index 55fbefbd..108f8aa7 100644
--- a/tests/barstest/barstest.pro
+++ b/tests/barstest/barstest.pro
@@ -2,8 +2,8 @@
error( "Couldn't find the tests.pri file!" )
}
-SOURCES += main.cpp chart.cpp
-HEADERS += chart.h
+SOURCES += main.cpp chart.cpp custominputhandler.cpp
+HEADERS += chart.h custominputhandler.h
QT += widgets
diff --git a/tests/barstest/chart.cpp b/tests/barstest/chart.cpp
index 8bef7479..8ab619ec 100644
--- a/tests/barstest/chart.cpp
+++ b/tests/barstest/chart.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc
+** Copyright (C) 2014 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
@@ -17,15 +17,17 @@
****************************************************************************/
#include "chart.h"
-#include <QtDataVisualization/q3dcategoryaxis.h>
-#include <QtDataVisualization/q3dvalueaxis.h>
+#include "custominputhandler.h"
+#include <QtDataVisualization/qcategory3daxis.h>
+#include <QtDataVisualization/qvalue3daxis.h>
#include <QtDataVisualization/qbardataproxy.h>
#include <QtDataVisualization/q3dscene.h>
#include <QtDataVisualization/q3dcamera.h>
#include <QtDataVisualization/q3dtheme.h>
+#include <QtDataVisualization/q3dinputhandler.h>
#include <QTime>
-QT_DATAVISUALIZATION_USE_NAMESPACE
+using namespace QtDataVisualization;
const QString celsiusString = QString(QChar(0xB0)) + "C";
@@ -45,13 +47,14 @@ GraphModifier::GraphModifier(Q3DBars *barchart, QColorDialog *colorDialog)
m_minval(-16.0f),
m_maxval(20.0f),
m_selectedBar(-1, -1),
- m_autoAdjustingAxis(new Q3DValueAxis),
- m_fixedRangeAxis(new Q3DValueAxis),
- m_temperatureAxis(new Q3DValueAxis),
- m_yearAxis(new Q3DCategoryAxis),
- m_monthAxis(new Q3DCategoryAxis),
- m_genericRowAxis(new Q3DCategoryAxis),
- m_genericColumnAxis(new Q3DCategoryAxis),
+ m_selectedSeries(0),
+ m_autoAdjustingAxis(new QValue3DAxis),
+ m_fixedRangeAxis(new QValue3DAxis),
+ m_temperatureAxis(new QValue3DAxis),
+ m_yearAxis(new QCategory3DAxis),
+ m_monthAxis(new QCategory3DAxis),
+ m_genericRowAxis(new QCategory3DAxis),
+ m_genericColumnAxis(new QCategory3DAxis),
m_temperatureData(new QBar3DSeries),
m_temperatureData2(new QBar3DSeries),
m_genericData(new QBar3DSeries),
@@ -63,8 +66,20 @@ 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),
+ m_builtinTheme(new Q3DTheme(Q3DTheme::ThemeStoneMoss)),
+ m_customInputHandler(new CustomInputHandler)
{
+ m_temperatureData->setObjectName("m_temperatureData");
+ m_temperatureData2->setObjectName("m_temperatureData2");
+ m_genericData->setObjectName("m_genericData");
+ m_dummyData->setObjectName("m_dummyData");
+ m_dummyData2->setObjectName("m_dummyData2");
+ m_dummyData3->setObjectName("m_dummyData3");
+ m_dummyData4->setObjectName("m_dummyData4");
+ m_dummyData5->setObjectName("m_dummyData5");
+
// Generate generic labels
QStringList genericColumnLabels;
for (int i = 0; i < 400; i++) {
@@ -116,12 +131,28 @@ 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->setShadowQuality(QDataVis::ShadowQualitySoftMedium);
+ m_graph->setActiveTheme(m_builtinTheme);
+ m_graph->setShadowQuality(QAbstract3DGraph::ShadowQualitySoftMedium);
+
+ m_temperatureData->setName("Oulu");
+ m_temperatureData2->setName("Helsinki");
+ m_genericData->setName("Generic series");
+ m_dummyData->setName("Dummy 1");
+ m_dummyData2->setName("Dummy 2");
+ m_dummyData3->setName("Dummy 3");
+ m_dummyData4->setName("Dummy 4");
+ m_dummyData5->setName("Dummy 5");
+
+ m_temperatureData->setItemLabelFormat(QStringLiteral("@seriesName: @valueTitle for @colLabel @rowLabel: @valueLabel"));
+ m_temperatureData2->setItemLabelFormat(QStringLiteral("@seriesName: @valueTitle for @colLabel @rowLabel: @valueLabel"));
+ m_genericData->setItemLabelFormat(QStringLiteral("@seriesName: @valueTitle for (@rowIdx, @colIdx): @valueLabel"));
+
+ m_dummyData->setItemLabelFormat(QStringLiteral("@seriesName: @valueLabel"));
+ m_dummyData2->setItemLabelFormat(QStringLiteral("@seriesName: @valueLabel"));
+ m_dummyData3->setItemLabelFormat(QStringLiteral("@seriesName: @valueLabel"));
+ m_dummyData4->setItemLabelFormat(QStringLiteral("@seriesName: @valueLabel"));
+ m_dummyData5->setItemLabelFormat(QStringLiteral("@seriesName: @valueLabel"));
- m_temperatureData->setItemLabelFormat(QStringLiteral("1: @valueTitle for @colLabel @rowLabel: @valueLabel"));
- m_temperatureData2->setItemLabelFormat(QStringLiteral("2: @valueTitle for @colLabel @rowLabel: @valueLabel"));
- m_genericData->setItemLabelFormat(QStringLiteral("3: @valueTitle for (@rowIdx, @colIdx): @valueLabel"));
m_genericData->dataProxy()->setColumnLabels(genericColumnLabels);
m_temperatureData->setBaseColor(Qt::red);
@@ -166,7 +197,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();
@@ -182,9 +213,26 @@ GraphModifier::GraphModifier(Q3DBars *barchart, QColorDialog *colorDialog)
QObject::connect(m_genericData, &QBar3DSeries::selectedBarChanged, this,
&GraphModifier::handleSelectionChange);
+ QObject::connect(m_graph, &Q3DBars::rowAxisChanged, this,
+ &GraphModifier::handleRowAxisChanged);
+ QObject::connect(m_graph, &Q3DBars::columnAxisChanged, this,
+ &GraphModifier::handleColumnAxisChanged);
+ QObject::connect(m_graph, &Q3DBars::valueAxisChanged, this,
+ &GraphModifier::handleValueAxisChanged);
+ QObject::connect(m_graph, &Q3DBars::primarySeriesChanged, this,
+ &GraphModifier::handlePrimarySeriesChanged);
+
+ QObject::connect(&m_insertRemoveTimer, &QTimer::timeout, this,
+ &GraphModifier::insertRemoveTimerTimeout);
+
m_graph->addSeries(m_temperatureData);
m_graph->addSeries(m_temperatureData2);
+ QObject::connect(&m_selectionTimer, &QTimer::timeout, this,
+ &GraphModifier::triggerSelection);
+ QObject::connect(&m_rotationTimer, &QTimer::timeout, this,
+ &GraphModifier::triggerRotation);
+
resetTemperatureData();
}
@@ -507,7 +555,7 @@ void GraphModifier::removeRows()
// TODO Needs to be changed to account for data window offset once it is implemented.
int row = m_selectedBar.x();
if (row >= 0) {
- int startRow = qMax(row - 2, 0);
+ int startRow = qMax(row - 3, 0);
m_genericData->dataProxy()->removeRows(startRow, 3);
}
}
@@ -576,7 +624,10 @@ void GraphModifier::changeTheme()
{
static int theme = Q3DTheme::ThemeQt;
- m_graph->setTheme(new Q3DTheme((Q3DTheme::Theme)theme));
+ Q3DTheme *currentTheme = m_graph->activeTheme();
+ m_builtinTheme->setType(Q3DTheme::Theme(theme));
+ if (currentTheme == m_ownTheme)
+ m_graph->setActiveTheme(m_builtinTheme);
switch (theme) {
case Q3DTheme::ThemeQt:
@@ -614,35 +665,35 @@ 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()
{
static int selectionMode = m_graph->selectionMode();
- if (++selectionMode > (QDataVis::SelectionItemAndColumn | QDataVis::SelectionSlice | QDataVis::SelectionMultiSeries))
- selectionMode = QDataVis::SelectionNone;
+ if (++selectionMode > (QAbstract3DGraph::SelectionItemAndColumn | QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionMultiSeries))
+ selectionMode = QAbstract3DGraph::SelectionNone;
- m_graph->setSelectionMode((QDataVis::SelectionFlag)selectionMode);
+ m_graph->setSelectionMode((QAbstract3DGraph::SelectionFlag)selectionMode);
}
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)
+void GraphModifier::shadowQualityUpdatedByVisual(QAbstract3DGraph::ShadowQuality sq)
{
int quality = int(sq);
// Updates the UI component to show correct shadow quality
@@ -654,11 +705,17 @@ void GraphModifier::handleSelectionChange(const QPoint &position)
m_selectedBar = position;
int index = 0;
foreach (QBar3DSeries *series, m_graph->seriesList()) {
- if (series == sender())
+ if (series == sender()) {
+ if (series->selectedBar() != QBar3DSeries::invalidSelectionPosition())
+ m_selectedSeries = series;
break;
+ }
index++;
}
+ if (m_selectedSeries->selectedBar() == QBar3DSeries::invalidSelectionPosition())
+ m_selectedSeries = 0;
+
qDebug() << "Selected bar position:" << position << "series:" << index;
}
@@ -676,10 +733,29 @@ void GraphModifier::setUseNullInputHandler(bool useNull)
m_graph->setActiveInputHandler(m_defaultInputHandler);
}
+void GraphModifier::handleRowAxisChanged(QCategory3DAxis *axis)
+{
+ qDebug() << __FUNCTION__ << axis << axis->orientation() << (axis == m_graph->rowAxis());
+}
+
+void GraphModifier::handleColumnAxisChanged(QCategory3DAxis *axis)
+{
+ qDebug() << __FUNCTION__ << axis << axis->orientation() << (axis == m_graph->columnAxis());
+}
+
+void GraphModifier::handleValueAxisChanged(QValue3DAxis *axis)
+{
+ qDebug() << __FUNCTION__ << axis << axis->orientation() << (axis == m_graph->valueAxis());
+}
+
+void GraphModifier::handlePrimarySeriesChanged(QBar3DSeries *series)
+{
+ qDebug() << __FUNCTION__ << series;
+}
void GraphModifier::changeShadowQuality(int quality)
{
- QDataVis::ShadowQuality sq = QDataVis::ShadowQuality(quality);
+ QAbstract3DGraph::ShadowQuality sq = QAbstract3DGraph::ShadowQuality(quality);
m_graph->setShadowQuality(sq);
emit shadowQualityChanged(quality);
}
@@ -688,7 +764,7 @@ void GraphModifier::showFiveSeries()
{
releaseProxies();
releaseAxes();
- m_graph->setSelectionMode(QDataVis::SelectionItemRowAndColumn | QDataVis::SelectionMultiSeries);
+ m_graph->setSelectionMode(QAbstract3DGraph::SelectionItemRowAndColumn | QAbstract3DGraph::SelectionMultiSeries);
m_dummyData->dataProxy()->resetArray(makeDummyData(), QStringList(), QStringList());
m_dummyData2->dataProxy()->resetArray(makeDummyData(), QStringList(), QStringList());
@@ -735,14 +811,305 @@ QBarDataArray *GraphModifier::makeDummyData()
return dataSet;
}
+// Executes one step of the primary series test
+void GraphModifier::primarySeriesTest()
+{
+ static int nextStep = 0;
+
+ QStringList testLabels;
+ QStringList testLabels2;
+ QStringList testLabels3;
+ QStringList testLabels5;
+ testLabels << "1" << "2" << "3" << "4";
+ testLabels2 << "11" << "22" << "33" << "44";
+ testLabels3 << "111" << "222" << "333" << "444";
+ testLabels5 << "11111" << "22222" << "33333" << "44444";
+
+ switch (nextStep++) {
+ case 0: {
+ qDebug() << "Step 0 - Init:";
+ m_graph->addSeries(m_dummyData); // Add one series to enforce release in releaseProxies()
+ releaseProxies();
+ releaseAxes();
+ m_dummyData->dataProxy()->resetArray(makeDummyData(),
+ testLabels,
+ QStringList() << "A" << "B" << "C" << "D");
+ m_dummyData2->dataProxy()->resetArray(makeDummyData(),
+ testLabels2,
+ QStringList() << "AA" << "BB" << "CC" << "DD");
+ m_dummyData3->dataProxy()->resetArray(makeDummyData(),
+ testLabels3,
+ QStringList() << "AAA" << "BBB" << "CCC" << "DDD");
+ m_dummyData4->dataProxy()->resetArray(makeDummyData(),
+ QStringList() << "1111" << "2222" << "3333" << "4444",
+ QStringList() << "AAAA" << "BBBB" << "CCCC" << "DDDD");
+ m_dummyData5->dataProxy()->resetArray(makeDummyData(),
+ testLabels5,
+ QStringList() << "AAAAA" << "BBBBB" << "CCCCC" << "DDDDD");
+
+ m_graph->addSeries(m_dummyData);
+ m_graph->addSeries(m_dummyData2);
+ m_graph->addSeries(m_dummyData3);
+
+ m_dummyData->setBaseColor(Qt::black);
+ m_dummyData2->setBaseColor(Qt::white);
+ m_dummyData3->setBaseColor(Qt::red);
+ m_dummyData4->setBaseColor(Qt::blue);
+ m_dummyData5->setBaseColor(Qt::green);
+
+ if (m_graph->primarySeries() == m_dummyData)
+ if (m_graph->rowAxis()->labels() == testLabels)
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Row labels incorrect: " << m_graph->rowAxis()->labels();
+ else
+ qDebug() << "--> FAIL!!! Primary should be m_dummyData, actual: " << m_graph->primarySeries();
+ break;
+ }
+ case 1: {
+ qDebug() << "Step 1 - Set another series as primary:";
+ m_graph->setPrimarySeries(m_dummyData3);
+ if (m_graph->primarySeries() == m_dummyData3) {
+ if (m_graph->rowAxis()->labels() == testLabels3)
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Row labels incorrect: " << m_graph->rowAxis()->labels();
+ } else {
+ qDebug() << "--> FAIL!!! Primary should be m_dummyData3, actual: " << m_graph->primarySeries();
+ }
+ break;
+ }
+ case 2: {
+ qDebug() << "Step 2 - Add new series:";
+ m_graph->addSeries(m_dummyData4);
+ if (m_graph->primarySeries() == m_dummyData3)
+ if (m_graph->rowAxis()->labels() == testLabels3)
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Row labels incorrect: " << m_graph->rowAxis()->labels();
+ else
+ qDebug() << "--> FAIL!!! Primary should be m_dummyData3, actual: " << m_graph->primarySeries();
+ break;
+ }
+ case 3: {
+ qDebug() << "Step 3 - Reset primary series:";
+ m_graph->setPrimarySeries(0);
+ if (m_graph->primarySeries() == m_dummyData)
+ if (m_graph->rowAxis()->labels() == testLabels)
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Row labels incorrect: " << m_graph->rowAxis()->labels();
+ else
+ qDebug() << "--> FAIL!!! Primary should be m_dummyData, actual: " << m_graph->primarySeries();
+ break;
+ }
+ case 4: {
+ qDebug() << "Step 4 - Set new series at primary:";
+ m_graph->setPrimarySeries(m_dummyData5);
+ if (m_graph->primarySeries() == m_dummyData5)
+ if (m_graph->rowAxis()->labels() == testLabels5)
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Row labels incorrect: " << m_graph->rowAxis()->labels();
+ else
+ qDebug() << "--> FAIL!!! Primary should be m_dummyData5, actual: " << m_graph->primarySeries();
+ break;
+ }
+ case 5: {
+ qDebug() << "Step 5 - Remove nonexistent series:";
+ m_graph->removeSeries(0);
+ if (m_graph->primarySeries() == m_dummyData5)
+ if (m_graph->rowAxis()->labels() == testLabels5)
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Row labels incorrect: " << m_graph->rowAxis()->labels();
+ else
+ qDebug() << "--> FAIL!!! Primary should be m_dummyData5, actual: " << m_graph->primarySeries();
+ break;
+ }
+ case 6: {
+ qDebug() << "Step 6 - Remove non-primary series:";
+ m_graph->removeSeries(m_dummyData);
+ if (m_graph->primarySeries() == m_dummyData5)
+ if (m_graph->rowAxis()->labels() == testLabels5)
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Row labels incorrect: " << m_graph->rowAxis()->labels();
+ else
+ qDebug() << "--> FAIL!!! Primary should be m_dummyData5, actual: " << m_graph->primarySeries();
+ break;
+ }
+ case 7: {
+ qDebug() << "Step 7 - Remove primary series:";
+ m_graph->removeSeries(m_dummyData5);
+ if (m_graph->primarySeries() == m_dummyData2) // first series removed, second should be first now
+ if (m_graph->rowAxis()->labels() == testLabels2)
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Row labels incorrect: " << m_graph->rowAxis()->labels();
+ else
+ qDebug() << "--> FAIL!!! Primary should be m_dummyData3, actual: " << m_graph->primarySeries();
+ break;
+ }
+ case 8: {
+ qDebug() << "Step 8 - move a series (m_dummyData2) forward to a different position";
+ m_graph->insertSeries(3, m_dummyData2);
+ if (m_graph->primarySeries() == m_dummyData2)
+ if (m_graph->seriesList().at(2) == m_dummyData2) // moving series forward, index decrements
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Moved to incorrect index, index 2 has:" << m_graph->seriesList().at(2);
+ else
+ qDebug() << "--> FAIL!!! Primary should be m_dummyData3, actual: " << m_graph->primarySeries();
+ break;
+ }
+ case 9: {
+ qDebug() << "Step 9 - move a series (m_dummyData4) backward to a different position";
+ m_graph->insertSeries(0, m_dummyData4);
+ if (m_graph->primarySeries() == m_dummyData2)
+ if (m_graph->seriesList().at(0) == m_dummyData4)
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Moved to incorrect index, index 0 has:" << m_graph->seriesList().at(0);
+ else
+ qDebug() << "--> FAIL!!! Primary should be m_dummyData3, actual: " << m_graph->primarySeries();
+ break;
+ }
+ case 10: {
+ qDebug() << "Step 10 - Insert a series (m_dummyData) series to position 2";
+ m_graph->insertSeries(2, m_dummyData);
+ if (m_graph->primarySeries() == m_dummyData2)
+ if (m_graph->seriesList().at(2) == m_dummyData)
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Moved to incorrect index, index 2 has:" << m_graph->seriesList().at(2);
+ else
+ qDebug() << "--> FAIL!!! Primary should be m_dummyData3, actual: " << m_graph->primarySeries();
+ break;
+ }
+ case 11: {
+ qDebug() << "Step 11 - Remove everything";
+ m_graph->removeSeries(m_dummyData);
+ m_graph->removeSeries(m_dummyData2);
+ m_graph->removeSeries(m_dummyData3);
+ m_graph->removeSeries(m_dummyData4);
+ m_graph->removeSeries(m_dummyData5);
+ if (m_graph->primarySeries() == 0)
+ if (m_graph->rowAxis()->labels() == QStringList())
+ qDebug() << "--> SUCCESS";
+ else
+ qDebug() << "--> FAIL!!! Row labels incorrect: " << m_graph->rowAxis()->labels();
+ else
+ qDebug() << "--> FAIL!!! Primary should be null, actual: " << m_graph->primarySeries();
+ break;
+ }
+ default:
+ qDebug() << "-- Restarting test sequence --";
+ nextStep = 0;
+ break;
+ }
+
+
+}
+
+void GraphModifier::insertRemoveTestToggle()
+{
+ if (m_insertRemoveTimer.isActive()) {
+ m_insertRemoveTimer.stop();
+ m_selectionTimer.stop();
+ m_graph->removeSeries(m_dummyData);
+ m_graph->removeSeries(m_dummyData2);
+ releaseProxies();
+ releaseAxes();
+ m_graph->setActiveInputHandler(m_defaultInputHandler);
+ } else {
+ releaseProxies();
+ releaseAxes();
+ m_graph->rowAxis()->setRange(0, 32);
+ m_graph->columnAxis()->setRange(0, 10);
+ m_graph->setActiveInputHandler(m_customInputHandler);
+ m_graph->addSeries(m_dummyData);
+ m_graph->addSeries(m_dummyData2);
+ m_insertRemoveStep = 0;
+ m_insertRemoveTimer.start(100);
+ m_selectionTimer.start(10);
+ }
+}
+
+void GraphModifier::toggleRotation()
+{
+ if (m_rotationTimer.isActive())
+ m_rotationTimer.stop();
+ else
+ m_rotationTimer.start(20);
+}
+
+void GraphModifier::insertRemoveTimerTimeout()
+{
+ if (m_insertRemoveStep < 32) {
+ for (int k = 0; k < 1; k++) {
+ QBarDataRow *dataRow = new QBarDataRow(10);
+ for (float i = 0; i < 10; i++)
+ (*dataRow)[i].setValue(((i + 1) / 10.0f) * (float)(rand() % 100));
+
+ QString label = QStringLiteral("Insert %1").arg(insertCounter++);
+ m_dummyData->dataProxy()->insertRow(0, dataRow, label);
+ }
+ } else {
+ for (int k = 0; k < 1; k++)
+ m_dummyData->dataProxy()->removeRows(0, 1);
+ }
+
+ if (m_insertRemoveStep < 16 || (m_insertRemoveStep > 31 && m_insertRemoveStep < 48)) {
+ for (int k = 0; k < 2; k++) {
+ QBarDataRow *dataRow = new QBarDataRow(10);
+ for (float i = 0; i < 10; i++)
+ (*dataRow)[i].setValue(((i + 1) / 10.0f) * (float)(rand() % 100));
+
+ QString label = QStringLiteral("Insert %1").arg(insertCounter++);
+ m_dummyData2->dataProxy()->insertRow(0, dataRow, label);
+ }
+ } else {
+ for (int k = 0; k < 2; k++)
+ m_dummyData2->dataProxy()->removeRows(0, 1);
+ }
+
+ if (m_insertRemoveStep++ > 63)
+ m_insertRemoveStep = 0;
+}
+
+void GraphModifier::triggerSelection()
+{
+ m_graph->scene()->setSelectionQueryPosition(m_customInputHandler->inputPosition());
+}
+
+void GraphModifier::triggerRotation()
+{
+ if (m_selectedSeries) {
+ QPoint selectedBar = m_selectedSeries->selectedBar();
+ if (selectedBar != QBar3DSeries::invalidSelectionPosition()) {
+ QBarDataItem item(*(m_selectedSeries->dataProxy()->itemAt(selectedBar.x(), selectedBar.y())));
+ item.setRotation(item.rotation() + 1.0f);
+ m_selectedSeries->dataProxy()->setItem(selectedBar.x(), selectedBar.y(), item);
+ }
+ } else {
+ // Rotate the first series instead
+ static float seriesAngle = 0.0f;
+ if (m_graph->seriesList().size()) {
+ QQuaternion rotation = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, seriesAngle++);
+ m_graph->seriesList().at(0)->setMeshRotation(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::rotateX(int rotation)
@@ -811,38 +1178,41 @@ 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)));
+ }
+
+ m_graph->setActiveTheme(m_ownTheme);
m_colorDialog->open();
}
@@ -852,7 +1222,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 +1253,14 @@ 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);
+}
+
+void GraphModifier::toggleMultiseriesScaling()
+{
+ m_graph->setMultiSeriesUniform(!m_graph->isMultiSeriesUniform());
}
diff --git a/tests/barstest/chart.h b/tests/barstest/chart.h
index 96038b9f..5758262c 100644
--- a/tests/barstest/chart.h
+++ b/tests/barstest/chart.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc
+** Copyright (C) 2014 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
@@ -22,11 +22,13 @@
#include <QtDataVisualization/q3dbars.h>
#include <QtDataVisualization/qabstract3dinputhandler.h>
#include <QtDataVisualization/qbar3dseries.h>
+#include <QtDataVisualization/q3dtheme.h>
#include <QFont>
#include <QDebug>
#include <QStringList>
#include <QPointer>
#include <QColorDialog>
+#include <QTimer>
using namespace QtDataVisualization;
@@ -80,15 +82,28 @@ public:
void changeColorStyle();
void showFiveSeries();
QBarDataArray *makeDummyData();
+ void primarySeriesTest();
+ void insertRemoveTestToggle();
+ void toggleRotation();
public slots:
void flipViews();
void setGradient();
+ void toggleMultiseriesScaling();
void changeShadowQuality(int quality);
- void shadowQualityUpdatedByVisual(QDataVis::ShadowQuality shadowQuality);
+ void shadowQualityUpdatedByVisual(QAbstract3DGraph::ShadowQuality shadowQuality);
void handleSelectionChange(const QPoint &position);
void setUseNullInputHandler(bool useNull);
+ void handleRowAxisChanged(QCategory3DAxis *axis);
+ void handleColumnAxisChanged(QCategory3DAxis *axis);
+ void handleValueAxisChanged(QValue3DAxis *axis);
+ void handlePrimarySeriesChanged(QBar3DSeries *series);
+
+ void insertRemoveTimerTimeout();
+ void triggerSelection();
+ void triggerRotation();
+
signals:
void shadowQualityChanged(int quality);
@@ -110,13 +125,14 @@ private:
QStringList m_months;
QStringList m_years;
QPoint m_selectedBar;
- Q3DValueAxis *m_autoAdjustingAxis;
- Q3DValueAxis *m_fixedRangeAxis;
- Q3DValueAxis *m_temperatureAxis;
- Q3DCategoryAxis *m_yearAxis;
- Q3DCategoryAxis *m_monthAxis;
- Q3DCategoryAxis *m_genericRowAxis;
- Q3DCategoryAxis *m_genericColumnAxis;
+ QBar3DSeries *m_selectedSeries;
+ QValue3DAxis *m_autoAdjustingAxis;
+ QValue3DAxis *m_fixedRangeAxis;
+ QValue3DAxis *m_temperatureAxis;
+ QCategory3DAxis *m_yearAxis;
+ QCategory3DAxis *m_monthAxis;
+ QCategory3DAxis *m_genericRowAxis;
+ QCategory3DAxis *m_genericColumnAxis;
QBar3DSeries *m_temperatureData;
QBar3DSeries *m_temperatureData2;
QBar3DSeries *m_genericData;
@@ -125,10 +141,17 @@ private:
QBar3DSeries *m_dummyData3;
QBar3DSeries *m_dummyData4;
QBar3DSeries *m_dummyData5;
- Q3DValueAxis *m_currentAxis;
+ QValue3DAxis *m_currentAxis;
bool m_negativeValuesOn;
bool m_useNullInputHandler;
QAbstract3DInputHandler *m_defaultInputHandler;
+ Q3DTheme *m_ownTheme;
+ Q3DTheme *m_builtinTheme;
+ QTimer m_insertRemoveTimer;
+ int m_insertRemoveStep;
+ QAbstract3DInputHandler *m_customInputHandler;
+ QTimer m_selectionTimer;
+ QTimer m_rotationTimer;
};
#endif
diff --git a/tests/barstest/custominputhandler.cpp b/tests/barstest/custominputhandler.cpp
new file mode 100644
index 00000000..a5734e16
--- /dev/null
+++ b/tests/barstest/custominputhandler.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#include "custominputhandler.h"
+
+#include <QtDataVisualization/Q3DCamera>
+
+CustomInputHandler::CustomInputHandler(QObject *parent) :
+ QAbstract3DInputHandler(parent)
+{
+}
+
+//! [0]
+void CustomInputHandler::mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos)
+{
+ Q_UNUSED(event)
+ setInputPosition(mousePos);
+}
+//! [0]
+
+//! [1]
+void CustomInputHandler::wheelEvent(QWheelEvent *event)
+{
+ // Adjust zoom level based on what zoom range we're in.
+ int zoomLevel = scene()->activeCamera()->zoomLevel();
+ if (zoomLevel > 100)
+ zoomLevel += event->angleDelta().y() / 12;
+ else if (zoomLevel > 50)
+ zoomLevel += event->angleDelta().y() / 60;
+ else
+ zoomLevel += event->angleDelta().y() / 120;
+ if (zoomLevel > 500)
+ zoomLevel = 500;
+ else if (zoomLevel < 10)
+ zoomLevel = 10;
+
+ scene()->activeCamera()->setZoomLevel(zoomLevel);
+}
+//! [1]
diff --git a/tests/barstest/custominputhandler.h b/tests/barstest/custominputhandler.h
new file mode 100644
index 00000000..60c88ef7
--- /dev/null
+++ b/tests/barstest/custominputhandler.h
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#ifndef CUSTOMINPUTHANDLER_H
+#define CUSTOMINPUTHANDLER_H
+
+#include <QtDataVisualization/QAbstract3DInputHandler>
+
+using namespace QtDataVisualization;
+
+class CustomInputHandler : public QAbstract3DInputHandler
+{
+ Q_OBJECT
+public:
+ explicit CustomInputHandler(QObject *parent = 0);
+
+ virtual void mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos);
+ virtual void wheelEvent(QWheelEvent *event);
+};
+
+#endif
diff --git a/tests/barstest/main.cpp b/tests/barstest/main.cpp
index e18aaed1..8189f917 100644
--- a/tests/barstest/main.cpp
+++ b/tests/barstest/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc
+** Copyright (C) 2014 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
@@ -42,7 +42,14 @@ int main(int argc, char **argv)
QVBoxLayout *vLayout = new QVBoxLayout();
QVBoxLayout *vLayout2 = new QVBoxLayout();
- Q3DBars *widgetchart = new Q3DBars();
+ // For testing custom surface format
+ QSurfaceFormat surfaceFormat;
+ surfaceFormat.setDepthBufferSize(24);
+#if !defined(QT_OPENGL_ES_2)
+ surfaceFormat.setSamples(8);
+#endif
+
+ Q3DBars *widgetchart = new Q3DBars(&surfaceFormat);
QSize screenSize = widgetchart->screen()->size();
QWidget *container = QWidget::createWindowContainer(widgetchart);
@@ -90,7 +97,7 @@ int main(int argc, char **argv)
removeRowButton->setEnabled(false);
QPushButton *removeRowsButton = new QPushButton(widget);
- removeRowsButton->setText(QStringLiteral("Remove three rows from selected"));
+ removeRowsButton->setText(QStringLiteral("Remove three rows before selected"));
removeRowsButton->setEnabled(false);
QPushButton *massiveArrayButton = new QPushButton(widget);
@@ -103,6 +110,9 @@ int main(int argc, char **argv)
QPushButton *labelButton = new QPushButton(widget);
labelButton->setText(QStringLiteral("Change label style"));
+ QPushButton *multiScaleButton = new QPushButton(widget);
+ multiScaleButton->setText(QStringLiteral("Change multiseries scaling"));
+
QPushButton *styleButton = new QPushButton(widget);
styleButton->setText(QStringLiteral("Change bar style"));
@@ -119,6 +129,10 @@ int main(int argc, char **argv)
swapAxisButton->setText(QStringLiteral("Swap value axis"));
swapAxisButton->setEnabled(false);
+ QPushButton *insertRemoveTestButton = new QPushButton(widget);
+ insertRemoveTestButton->setText(QStringLiteral("Toggle insert/remove cycle"));
+ insertRemoveTestButton->setEnabled(true);
+
QPushButton *releaseAxesButton = new QPushButton(widget);
releaseAxesButton->setText(QStringLiteral("Release all axes"));
releaseAxesButton->setEnabled(true);
@@ -143,6 +157,14 @@ int main(int argc, char **argv)
ownThemeButton->setText(QStringLiteral("Use own theme"));
ownThemeButton->setEnabled(true);
+ QPushButton *primarySeriesTestsButton = new QPushButton(widget);
+ primarySeriesTestsButton->setText(QStringLiteral("Test primary series"));
+ primarySeriesTestsButton->setEnabled(true);
+
+ QPushButton *toggleRotationButton = new QPushButton(widget);
+ toggleRotationButton->setText(QStringLiteral("Toggle rotation"));
+ toggleRotationButton->setEnabled(true);
+
QColorDialog *colorDialog = new QColorDialog(widget);
QLinearGradient grBtoY(0, 0, 100, 0);
@@ -277,16 +299,20 @@ int main(int argc, char **argv)
vLayout->addWidget(showFiveSeriesButton, 0, Qt::AlignTop);
vLayout->addWidget(themeButton, 0, Qt::AlignTop);
vLayout->addWidget(labelButton, 0, Qt::AlignTop);
+ vLayout->addWidget(multiScaleButton, 0, Qt::AlignTop);
vLayout->addWidget(styleButton, 0, Qt::AlignTop);
vLayout->addWidget(cameraButton, 0, Qt::AlignTop);
vLayout->addWidget(selectionButton, 0, Qt::AlignTop);
vLayout->addWidget(setSelectedBarButton, 0, Qt::AlignTop);
vLayout->addWidget(swapAxisButton, 0, Qt::AlignTop);
+ vLayout->addWidget(insertRemoveTestButton, 0, Qt::AlignTop);
vLayout->addWidget(releaseAxesButton, 0, Qt::AlignTop);
vLayout->addWidget(releaseProxiesButton, 1, Qt::AlignTop);
vLayout->addWidget(flipViewsButton, 0, Qt::AlignTop);
vLayout->addWidget(changeColorStyleButton, 0, Qt::AlignTop);
vLayout->addWidget(ownThemeButton, 0, Qt::AlignTop);
+ vLayout->addWidget(primarySeriesTestsButton, 0, Qt::AlignTop);
+ vLayout->addWidget(toggleRotationButton, 0, Qt::AlignTop);
vLayout->addWidget(gradientBtoYPB, 1, Qt::AlignTop);
vLayout2->addWidget(staticCheckBox, 0, Qt::AlignTop);
@@ -350,6 +376,8 @@ int main(int argc, char **argv)
QObject::connect(fontSizeSlider, &QSlider::valueChanged, modifier,
&GraphModifier::changeFontSize);
+ QObject::connect(multiScaleButton, &QPushButton::clicked, modifier,
+ &GraphModifier::toggleMultiseriesScaling);
QObject::connect(styleButton, &QPushButton::clicked, modifier, &GraphModifier::changeStyle);
QObject::connect(cameraButton, &QPushButton::clicked, modifier,
&GraphModifier::changePresetCamera);
@@ -373,6 +401,8 @@ int main(int argc, char **argv)
&GraphModifier::selectBar);
QObject::connect(swapAxisButton, &QPushButton::clicked, modifier,
&GraphModifier::swapAxis);
+ QObject::connect(insertRemoveTestButton, &QPushButton::clicked, modifier,
+ &GraphModifier::insertRemoveTestToggle);
QObject::connect(releaseAxesButton, &QPushButton::clicked, modifier,
&GraphModifier::releaseAxes);
QObject::connect(releaseProxiesButton, &QPushButton::clicked, modifier,
@@ -384,6 +414,10 @@ int main(int argc, char **argv)
&GraphModifier::changeColorStyle);
QObject::connect(ownThemeButton, &QPushButton::clicked, modifier,
&GraphModifier::useOwnTheme);
+ QObject::connect(primarySeriesTestsButton, &QPushButton::clicked, modifier,
+ &GraphModifier::primarySeriesTest);
+ QObject::connect(toggleRotationButton, &QPushButton::clicked, modifier,
+ &GraphModifier::toggleRotation);
QObject::connect(colorDialog, &QColorDialog::currentColorChanged, modifier,
&GraphModifier::changeBaseColor);
QObject::connect(gradientBtoYPB, &QPushButton::clicked, modifier,