From 17fb42f3ff672f5215931e6553d2701dcd4ebfa5 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 13 Jan 2014 12:48:28 +0200 Subject: Same mesh used for all series in bar example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I19e118f44b2fc232c57aaf19d5d4125fc1d5bba6 Reviewed-by: Tomi Korpipää --- examples/bars/doc/src/bars.qdoc | 6 ++--- examples/bars/graphmodifier.cpp | 49 ++++++++++++++++++----------------------- examples/bars/graphmodifier.h | 7 +++--- 3 files changed, 28 insertions(+), 34 deletions(-) (limited to 'examples') diff --git a/examples/bars/doc/src/bars.qdoc b/examples/bars/doc/src/bars.qdoc index 79cfb270..4144ca7c 100644 --- a/examples/bars/doc/src/bars.qdoc +++ b/examples/bars/doc/src/bars.qdoc @@ -75,7 +75,7 @@ Let's take a closer look at parts of the code. - First we're creating the axes and the proxy into member variables to support changing them + First we're creating the axes and the series into member variables to support changing them easily later on, if we want to: \snippet ../examples/bars/graphmodifier.cpp 1 @@ -88,8 +88,8 @@ \snippet ../examples/bars/graphmodifier.cpp 3 - Next we create two series for the graph, giving each one a data proxy. Here we also initialize - some of the visual properties of the series. Note that the second series is initially not visible: + Next we initialize the visual properties of the series. + Note that the second series is initially not visible: \snippet ../examples/bars/graphmodifier.cpp 8 diff --git a/examples/bars/graphmodifier.cpp b/examples/bars/graphmodifier.cpp index dc1aa1cc..cd0ecd77 100644 --- a/examples/bars/graphmodifier.cpp +++ b/examples/bars/graphmodifier.cpp @@ -45,11 +45,10 @@ GraphModifier::GraphModifier(Q3DBars *bargraph) m_temperatureAxis(new QValue3DAxis), m_yearAxis(new QCategory3DAxis), m_monthAxis(new QCategory3DAxis), - m_primaryData(new QBarDataProxy), - m_secondaryData(new QBarDataProxy), + m_primarySeries(new QBar3DSeries), + m_secondarySeries(new QBar3DSeries), //! [1] - m_primaryStyle(QAbstract3DSeries::MeshBevelBar), - m_secondaryStyle(QAbstract3DSeries::MeshSphere), + m_barMesh(QAbstract3DSeries::MeshBevelBar), m_smooth(false) { //! [2] @@ -78,21 +77,19 @@ GraphModifier::GraphModifier(Q3DBars *bargraph) //! [3] //! [8] - QBar3DSeries *series = new QBar3DSeries(m_primaryData); - series->setItemLabelFormat(QStringLiteral("Oulu - @colLabel @rowLabel: @valueLabel")); - series->setMesh(QAbstract3DSeries::MeshBevelBar); - series->setMeshSmooth(false); - - QBar3DSeries *series2 = new QBar3DSeries(m_secondaryData); - series2->setItemLabelFormat(QStringLiteral("Helsinki - @colLabel @rowLabel: @valueLabel")); - series2->setMesh(QAbstract3DSeries::MeshSphere); - series2->setMeshSmooth(false); - series2->setVisible(false); + m_primarySeries->setItemLabelFormat(QStringLiteral("Oulu - @colLabel @rowLabel: @valueLabel")); + m_primarySeries->setMesh(QAbstract3DSeries::MeshBevelBar); + m_primarySeries->setMeshSmooth(false); + + m_secondarySeries->setItemLabelFormat(QStringLiteral("Helsinki - @colLabel @rowLabel: @valueLabel")); + m_secondarySeries->setMesh(QAbstract3DSeries::MeshBevelBar); + m_secondarySeries->setMeshSmooth(false); + m_secondarySeries->setVisible(false); //! [8] //! [4] - m_graph->addSeries(series); - m_graph->addSeries(series2); + m_graph->addSeries(m_primarySeries); + m_graph->addSeries(m_secondarySeries); //! [4] //! [6] @@ -155,9 +152,9 @@ void GraphModifier::resetTemperatureData() dataSet2->append(dataRow2); } - // Add data to the graph (the graph assumes ownership of it) - m_primaryData->resetArray(dataSet, m_years, m_months); - m_secondaryData->resetArray(dataSet2, m_years, m_months); + // Add data to the data proxy (the data proxy assumes ownership of it) + m_primarySeries->dataProxy()->resetArray(dataSet, m_years, m_months); + m_secondarySeries->dataProxy()->resetArray(dataSet2, m_years, m_months); //! [5] } @@ -165,9 +162,9 @@ void GraphModifier::changeStyle(int style) { QComboBox *comboBox = qobject_cast(sender()); if (comboBox) { - m_primaryStyle = QAbstract3DSeries::Mesh(comboBox->itemData(style).toInt()); - if (m_graph->seriesList().size()) - m_graph->seriesList().at(0)->setMesh(m_primaryStyle); + m_barMesh = QAbstract3DSeries::Mesh(comboBox->itemData(style).toInt()); + m_primarySeries->setMesh(m_barMesh); + m_secondarySeries->setMesh(m_barMesh); } } @@ -262,15 +259,13 @@ void GraphModifier::setGridEnabled(int enabled) void GraphModifier::setSmoothBars(int smooth) { m_smooth = bool(smooth); - if (m_graph->seriesList().size()) { - m_graph->seriesList().at(0)->setMeshSmooth(m_smooth); - m_graph->seriesList().at(1)->setMeshSmooth(m_smooth); - } + m_primarySeries->setMeshSmooth(m_smooth); + m_secondarySeries->setMeshSmooth(m_smooth); } void GraphModifier::setSeriesVisibility(int enabled) { - m_graph->seriesList().at(1)->setVisible(bool(enabled)); + m_secondarySeries->setVisible(bool(enabled)); if (enabled) { m_graph->setBarThickness(2.0f); m_graph->setBarSpacing(QSizeF(1.0, 3.0)); diff --git a/examples/bars/graphmodifier.h b/examples/bars/graphmodifier.h index ca56d754..f4b238b7 100644 --- a/examples/bars/graphmodifier.h +++ b/examples/bars/graphmodifier.h @@ -77,10 +77,9 @@ private: QValue3DAxis *m_temperatureAxis; QCategory3DAxis *m_yearAxis; QCategory3DAxis *m_monthAxis; - QBarDataProxy *m_primaryData; - QBarDataProxy *m_secondaryData; - QAbstract3DSeries::Mesh m_primaryStyle; - QAbstract3DSeries::Mesh m_secondaryStyle; + QBar3DSeries *m_primarySeries; + QBar3DSeries *m_secondarySeries; + QAbstract3DSeries::Mesh m_barMesh; bool m_smooth; }; -- cgit v1.2.3