summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2013-11-15 12:48:13 +0200
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2013-11-20 09:34:06 +0200
commit51d4a9fcba6089ba433ae126f554b50979220d07 (patch)
tree5ffdabb461efc3989224226b600a649d395ef80a /examples
parent96995bda0da7ecf99d2ac4a4e417545c3506bf02 (diff)
Multi series selection part 1: bars
Task-number: QTRD-2556 Change-Id: I1f537f0b4c299028d4415f074d5eac6552bb3b9b Reviewed-by: Pasi Keränen <pasi.keranen@digia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/bars/graphmodifier.cpp27
-rw-r--r--examples/bars/main.cpp11
-rw-r--r--examples/itemmodel/main.cpp4
-rw-r--r--examples/qmlbars/doc/src/qmlbars.qdoc1
-rw-r--r--examples/qmlbars/qml/qmlbars/data.qml4
-rw-r--r--examples/qmlbars/qml/qmlbars/main.qml92
6 files changed, 79 insertions, 60 deletions
diff --git a/examples/bars/graphmodifier.cpp b/examples/bars/graphmodifier.cpp
index efd6aa6d..132ba4d6 100644
--- a/examples/bars/graphmodifier.cpp
+++ b/examples/bars/graphmodifier.cpp
@@ -76,9 +76,9 @@ GraphModifier::GraphModifier(Q3DBars *bargraph)
//! [3]
QBar3DSeries *series = new QBar3DSeries(m_primaryData);
- series->setItemLabelFormat(QStringLiteral("@valueTitle for @colLabel @rowLabel: @valueLabel"));
+ series->setItemLabelFormat(QStringLiteral("Oulu - @colLabel @rowLabel: @valueLabel"));
QBar3DSeries *series2 = new QBar3DSeries(m_secondaryData);
- series2->setItemLabelFormat(QStringLiteral("@valueTitle for @colLabel @rowLabel: @valueLabel"));
+ series2->setItemLabelFormat(QStringLiteral("Helsinki - @colLabel @rowLabel: @valueLabel"));
series2->setVisible(false);
//! [4]
@@ -109,7 +109,7 @@ void GraphModifier::resetTemperatureData()
{
//! [5]
// Set up data
- static const qreal temp[7][12] = {
+ static const qreal tempOulu[7][12] = {
{-6.7, -11.7, -9.7, 3.3, 9.2, 14.0, 16.3, 17.8, 10.2, 2.1, -2.6, -0.3}, // 2006
{-6.8, -13.3, 0.2, 1.5, 7.9, 13.4, 16.1, 15.5, 8.2, 5.4, -2.6, -0.8}, // 2007
{-4.2, -4.0, -4.6, 1.9, 7.3, 12.5, 15.0, 12.8, 7.6, 5.1, -0.9, -1.3}, // 2008
@@ -118,14 +118,15 @@ void GraphModifier::resetTemperatureData()
{-9.0, -15.2, -3.8, 2.6, 8.3, 15.9, 18.6, 14.9, 11.1, 5.3, 1.8, -0.2}, // 2011
{-8.7, -11.3, -2.3, 0.4, 7.5, 12.2, 16.4, 14.1, 9.2, 3.1, 0.3, -12.1} // 2012
};
- static const qreal temp2[7][12] = {
- {-8.7, -11.3, -2.3, 0.4, 7.5, 12.2, 16.4, 14.1, 9.2, 3.1, 0.3, -12.1}, // 2006
- {-7.8, -8.8, -4.2, 0.7, 9.3, 13.2, 15.8, 15.5, 11.2, 0.6, 0.7, -8.4}, // 2007
- {-6.8, -13.3, 0.2, 1.5, 7.9, 13.4, 16.1, 15.5, 8.2, 5.4, -2.6, -0.8}, // 2008
- {-6.7, -11.7, -9.7, 3.3, 9.2, 14.0, 16.3, 17.8, 10.2, 2.1, -2.6, -0.3}, // 2009
- {-4.2, -4.0, -4.6, 1.9, 7.3, 12.5, 15.0, 12.8, 7.6, 5.1, -0.9, -1.3}, // 2010
- {-14.4, -12.1, -7.0, 2.3, 11.0, 12.6, 18.8, 13.8, 9.4, 3.9, -5.6, -13.0}, // 2011
- {-9.0, -15.2, -3.8, 2.6, 8.3, 15.9, 18.6, 14.9, 11.1, 5.3, 1.8, -0.2} // 2012
+
+ static const qreal tempHelsinki[7][12] = {
+ {-3.7, -7.8, -5.4, 3.4, 10.7, 15.4, 18.6, 18.7, 14.3, 8.5, 2.9, 4.1}, // 2006
+ {-1.2, -7.5, 3.1, 5.5, 10.3, 15.9, 17.4, 17.9, 11.2, 7.3, 1.1, 0.5}, // 2007
+ {-0.6, 1.2, 0.2, 6.3, 10.2, 13.8, 18.1, 15.1, 10.1, 9.4, 2.5, 0.4}, // 2008
+ {-2.9, -3.5, -0.9, 4.7, 10.9, 14.0, 17.4, 16.8, 13.2, 4.1, 2.6, -2.3}, // 2009
+ {-10.2, -8.0, -1.9, 6.6, 11.3, 14.5, 21.0, 18.8, 12.6, 6.1, -0.5, -7.3}, // 2010
+ {-4.4, -9.1, -2.0, 5.5, 9.9, 15.6, 20.8, 17.8, 13.4, 8.9, 3.6, 1.5}, // 2011
+ {-3.5, -3.2, -0.7, 4.0, 11.1, 13.4, 17.3, 15.8, 13.1, 6.4, 4.1, -5.1} // 2012
};
// Create data arrays
@@ -141,8 +142,8 @@ void GraphModifier::resetTemperatureData()
dataRow2 = new QBarDataRow(m_months.size());
for (int month = 0; month < m_months.size(); month++) {
// Add data to the row
- (*dataRow)[month].setValue(temp[year][month]);
- (*dataRow2)[month].setValue(temp2[year][month]);
+ (*dataRow)[month].setValue(tempOulu[year][month]);
+ (*dataRow2)[month].setValue(tempHelsinki[year][month]);
}
// Add the row to the set
dataSet->append(dataRow);
diff --git a/examples/bars/main.cpp b/examples/bars/main.cpp
index ecd5d353..3bac58b2 100644
--- a/examples/bars/main.cpp
+++ b/examples/bars/main.cpp
@@ -52,7 +52,7 @@ int main(int argc, char **argv)
hLayout->addLayout(vLayout);
//! [1]
- widget->setWindowTitle(QStringLiteral("Average temperatures in Oulu, Finland (2006-2012)"));
+ widget->setWindowTitle(QStringLiteral("Average temperatures in Oulu and Helsinki, Finland (2006-2012)"));
QComboBox *themeList = new QComboBox(widget);
themeList->addItem(QStringLiteral("Qt"));
@@ -108,6 +108,15 @@ int main(int argc, char **argv)
int(QDataVis::SelectionSlice | QDataVis::SelectionColumn));
selectionModeList->addItem(QStringLiteral("Slice into Column and Item"),
int(QDataVis::SelectionSlice | QDataVis::SelectionItemAndColumn));
+ selectionModeList->addItem(QStringLiteral("Multi: Bar, Row, Col"),
+ int(QDataVis::SelectionItemRowAndColumn
+ | QDataVis::SelectionMultiSeries));
+ selectionModeList->addItem(QStringLiteral("Multi, Slice: Row, Item"),
+ int(QDataVis::SelectionSlice | QDataVis::SelectionItemAndRow
+ | QDataVis::SelectionMultiSeries));
+ selectionModeList->addItem(QStringLiteral("Multi, Slice: Col, Item"),
+ int(QDataVis::SelectionSlice | QDataVis::SelectionItemAndColumn
+ | QDataVis::SelectionMultiSeries));
selectionModeList->setCurrentIndex(1);
QCheckBox *backgroundCheckBox = new QCheckBox(widget);
diff --git a/examples/itemmodel/main.cpp b/examples/itemmodel/main.cpp
index 90bac03b..3325d6a2 100644
--- a/examples/itemmodel/main.cpp
+++ b/examples/itemmodel/main.cpp
@@ -223,7 +223,7 @@ void GraphDataGenerator::selectedFromTable(int currentRow, int currentColumn,
{
Q_UNUSED(previousRow)
Q_UNUSED(previousColumn)
- m_graph->setSelectedBar(QPoint(currentRow, currentColumn));
+ m_graph->seriesList().at(0)->setSelectedBar(QPoint(currentRow, currentColumn));
}
//! [14]
@@ -275,7 +275,7 @@ int main(int argc, char **argv)
//! [3]
GraphDataGenerator generator(graph, tableWidget);
- QObject::connect(graph, &Q3DBars::selectedBarChanged, &generator,
+ QObject::connect(series, &QBar3DSeries::selectedBarChanged, &generator,
&GraphDataGenerator::selectFromTable);
QObject::connect(tableWidget, &QTableWidget::currentCellChanged, &generator,
&GraphDataGenerator::selectedFromTable);
diff --git a/examples/qmlbars/doc/src/qmlbars.qdoc b/examples/qmlbars/doc/src/qmlbars.qdoc
index 9f51f89e..79b6c4fd 100644
--- a/examples/qmlbars/doc/src/qmlbars.qdoc
+++ b/examples/qmlbars/doc/src/qmlbars.qdoc
@@ -27,6 +27,7 @@
\image qmlbars-example.png
+ TODO: **This example is no longer about remapping, as multiple series are used instead**
The interesting thing about this example is remapping the data, so we concentrate on that
and skip explaining the basic Bars3D functionality - for more detailed QML example documentation,
see \l{Qt Quick 2 Scatter Example}.
diff --git a/examples/qmlbars/qml/qmlbars/data.qml b/examples/qmlbars/qml/qmlbars/data.qml
index 64df4c6a..12ba171c 100644
--- a/examples/qmlbars/qml/qmlbars/data.qml
+++ b/examples/qmlbars/qml/qmlbars/data.qml
@@ -29,7 +29,7 @@ Item {
id: valueMapping
rowRole: "year"
columnRole: "month"
- valueRole: "expenses"
+ valueRole: "income"
}
//! [1]
@@ -37,7 +37,7 @@ Item {
id: secondaryMapping
rowRole: "year"
columnRole: "month"
- valueRole: "income"
+ valueRole: "expenses"
}
//! [0]
diff --git a/examples/qmlbars/qml/qmlbars/main.qml b/examples/qmlbars/qml/qmlbars/main.qml
index 9432d44b..e48de35b 100644
--- a/examples/qmlbars/qml/qmlbars/main.qml
+++ b/examples/qmlbars/qml/qmlbars/main.qml
@@ -35,6 +35,36 @@ Item {
id: graphAxes
}
+ property Bar3DSeries selectedSeries
+ selectedSeries: barSeries
+
+ function handleSelectionChange(series, position) {
+ if (position.x !== -1) {
+ selectedSeries = series
+ }
+ // Set tableView current row to selected bar
+ var rowRole = series.dataProxy.rowLabels[position.x];
+ var colRole = series.dataProxy.columnLabels[position.y];
+ var currentRow = tableView.currentRow
+ if (currentRow === -1 || rowRole !== graphData.model.get(currentRow).year
+ || colRole !== graphData.model.get(currentRow).month) {
+ var totalRows = tableView.rowCount;
+ for (var i = 0; i < totalRows; i++) {
+ var currentRowRole = graphData.model.get(i).year
+ var currentColRole = graphData.model.get(i).month
+ if (currentRowRole === rowRole && currentColRole === colRole) {
+ tableView.currentRow = i
+ // Workaround to 5.2 row selection issue
+ if (typeof tableView.selection != "undefined") {
+ tableView.selection.clear()
+ tableView.selection.select(i)
+ }
+ break
+ }
+ }
+ }
+ }
+
Item {
id: dataView
width: parent.width - tableView.width
@@ -50,85 +80,63 @@ Item {
font.pointSize: 35
theme: AbstractGraph3D.ThemeRetro
labelStyle: AbstractGraph3D.LabelStyleFromTheme
- barThickness: 0.5
+ barThickness: 0.7
barSpacing: Qt.size(0.5, 0.5)
barSpacingRelative: false
scene.activeCamera.cameraPreset: AbstractGraph3D.CameraPresetIsometricLeftHigh
columnAxis: graphAxes.column
- valueAxis: graphAxes.expenses
+ valueAxis: graphAxes.income
Bar3DSeries {
id: barSeries
- itemLabelFormat: "@valueTitle for @colLabel, @rowLabel: @valueLabel"
+ itemLabelFormat: "Income for @colLabel, @rowLabel: @valueLabel"
ItemModelBarDataProxy {
id: modelProxy
activeMapping: graphData.mapping
itemModel: graphData.model
}
+
+ onSelectedBarChanged: handleSelectionChange(barSeries, position)
}
Bar3DSeries {
id: secondarySeries
visible: false
- itemLabelFormat: "@valueTitle for @colLabel, @rowLabel: @valueLabel"
+ itemLabelFormat: "Expenses for @colLabel, @rowLabel: @valueLabel"
ItemModelBarDataProxy {
id: secondaryProxy
activeMapping: graphData.secondaryMapping
itemModel: graphData.model
}
- }
- onSelectedBarChanged: {
- // Set tableView current row to selected bar
- var rowRole = modelProxy.rowLabels[position.x];
- var colRole = modelProxy.columnLabels[position.y];
- var currentRow = tableView.currentRow
- if (currentRow === -1 || rowRole !== graphData.model.get(currentRow).year
- || colRole !== graphData.model.get(currentRow).month) {
- var totalRows = tableView.rowCount;
- for (var i = 0; i < totalRows; i++) {
- var currentRowRole = graphData.model.get(i).year
- var currentColRole = graphData.model.get(i).month
- if (currentRowRole === rowRole && currentColRole === colRole) {
- tableView.currentRow = i
- // Workaround to 5.2 row selection issue
- if (typeof tableView.selection != "undefined") {
- tableView.selection.clear()
- tableView.selection.select(i)
- }
- break
- }
- }
- }
+ onSelectedBarChanged: handleSelectionChange(secondarySeries, position)
}
}
}
Button {
- id: mappingToggle
+ id: seriesToggle
anchors.bottom: parent.bottom
width: tableView.width
height: 60
- text: "Show Income"
+ text: "Show Expenses"
//! [0]
onClicked: {
- if (graphData.mapping.valueRole === "expenses" && !secondarySeries.visible) {
- // Change mapping to change series data
- graphData.mapping.valueRole = "income"
+ if (!secondarySeries.visible) {
text = "Show Both"
- testGraph.valueAxis = graphAxes.income
- } else if (graphData.mapping.valueRole === "income"){
- // Show both data set in separate series
+ testGraph.valueAxis = graphAxes.expenses
+ barSeries.visible = false
secondarySeries.visible = true
- graphData.mapping.valueRole = "expenses"
- text = "Show Expenses"
+ } else if (!barSeries.visible){
+ barSeries.visible = true
+ text = "Show Income"
testGraph.valueAxis = graphAxes.income
} else {
secondarySeries.visible = false
- text = "Show Income"
- testGraph.valueAxis = graphAxes.expenses
+ text = "Show Expenses"
+ testGraph.valueAxis = graphAxes.income
}
}
//! [0]
@@ -136,7 +144,7 @@ Item {
Button {
id: shadowToggle
- anchors.bottom: mappingToggle.top
+ anchors.bottom: seriesToggle.top
width: tableView.width
height: 60
text: "Hide Shadows"
@@ -181,7 +189,7 @@ Item {
x: 0
y: 0
width: 298
- height: parent.height - mappingToggle.height - shadowToggle.height - dataToggle.height
+ height: parent.height - seriesToggle.height - shadowToggle.height - dataToggle.height
TableViewColumn{ role: "year" ; title: "Year" ; width: 80 }
TableViewColumn{ role: "month" ; title: "Month" ; width: 80 }
TableViewColumn{ role: "expenses" ; title: "Expenses" ; width: 60 }
@@ -192,7 +200,7 @@ Item {
onCurrentRowChanged: {
var rowIndex = modelProxy.activeMapping.rowCategoryIndex(graphData.model.get(currentRow).year)
var colIndex = modelProxy.activeMapping.columnCategoryIndex(graphData.model.get(currentRow).month)
- testGraph.selectedBar = Qt.point(rowIndex, colIndex)
+ mainview.selectedSeries.selectedBar = Qt.point(rowIndex, colIndex)
}
//! [2]
}