##// END OF EJS Templates
modeldata example documented with explanations....
Marek Rosa -
r935:f71e86066044
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -1,247 +1,243
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "widget.h"
21 #include "widget.h"
22
22
23 #include <QChart>
23 #include <QChart>
24 #include <QScatterSeries>
24 #include <QScatterSeries>
25 #include <QChartAxis>
25 #include <QChartAxis>
26 #include <QBarSet>
26 #include <QBarSet>
27 #include <QBarSeries>
27 #include <QBarSeries>
28 #include <QLegend>
28
29
29 #include <QGridLayout>
30 #include <QGridLayout>
30 #include <QPushButton>
31 #include <QPushButton>
31 #include <QLabel>
32 #include <QLabel>
32 #include <QListWidget>
33 #include <QListWidget>
33 #include <QPrinter>
34 #include <QPrinter>
34 #include <QPrintDialog>
35 #include <QPrintDialog>
35 #include <QRadioButton>
36 #include <QRadioButton>
36 #include <QStringList>
37 #include <QStringList>
37 #include <QSqlQuery>
38 #include <QSqlQuery>
38
39
39 QTCOMMERCIALCHART_USE_NAMESPACE
40 QTCOMMERCIALCHART_USE_NAMESPACE
40
41
41 Widget::Widget(QWidget *parent)
42 Widget::Widget(QWidget *parent)
42 : QWidget(parent)
43 : QWidget(parent)
43 {
44 {
44 setGeometry(100, 100, 1000, 600);
45 setGeometry(100, 100, 1000, 600);
45
46
46 // right panel layout
47 // right panel layout
47 barChartRadioButton = new QRadioButton(tr("Bar chart"));
48 barChartRadioButton = new QRadioButton(tr("Bar chart"));
48 barChartRadioButton->setChecked(true);
49 barChartRadioButton->setChecked(true);
49 scatterChartRadioButton = new QRadioButton(tr("Scatter chart"));
50 scatterChartRadioButton = new QRadioButton(tr("Scatter chart"));
50 scatterChartRadioButton->setChecked(false);
51 scatterChartRadioButton->setChecked(false);
51 countrieslist = new QListWidget;
52 countrieslist = new QListWidget;
52 countrieslist->setSelectionMode(QAbstractItemView::MultiSelection);
53 countrieslist->setSelectionMode(QAbstractItemView::MultiSelection);
53
54
54 //list of years widget
55 //list of years widget
55 yearslist = new QListWidget;
56 yearslist = new QListWidget;
56 yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
57 yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
57 for (int i = 1990; i < 2011; i++)
58 for (int i = 1990; i < 2011; i++)
58 yearslist->addItem(QString("%1").arg(i));
59 yearslist->addItem(QString("%1").arg(i));
59
60
60 QPushButton* refreshButton = new QPushButton(tr("Refresh"));
61 QPushButton* refreshButton = new QPushButton(tr("Refresh"));
61 connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart()));
62 connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart()));
62
63
63 QPushButton* printButton = new QPushButton(tr("Print chart"));
64 QPushButton* printButton = new QPushButton(tr("Print to pdf"));
64 connect(printButton, SIGNAL(clicked()), this, SLOT(printChart()));
65 connect(printButton, SIGNAL(clicked()), this, SLOT(printChart()));
65
66
66 QVBoxLayout* rightPanelLayout = new QVBoxLayout;
67 QVBoxLayout* rightPanelLayout = new QVBoxLayout;
67 rightPanelLayout->addWidget(barChartRadioButton);
68 rightPanelLayout->addWidget(barChartRadioButton);
68 rightPanelLayout->addWidget(scatterChartRadioButton);
69 rightPanelLayout->addWidget(scatterChartRadioButton);
69 rightPanelLayout->addWidget(countrieslist);
70 rightPanelLayout->addWidget(countrieslist);
70 rightPanelLayout->addWidget(yearslist);
71 rightPanelLayout->addWidget(yearslist);
71 rightPanelLayout->addWidget(refreshButton);
72 rightPanelLayout->addWidget(refreshButton);
72 rightPanelLayout->addWidget(printButton);
73 rightPanelLayout->addWidget(printButton);
73 rightPanelLayout->setStretch(0, 1);
74 rightPanelLayout->setStretch(0, 1);
74 rightPanelLayout->setStretch(1, 0);
75 rightPanelLayout->setStretch(1, 0);
75
76
76 QChart *chart = new QChart();
77 QChart *chart = new QChart();
77 chart->setTitle("GDP by country");
78 chart->setTitle("GDP by country");
79 chart->legend()->setVisible(true);
78
80
79 // main layout
81 // main layout
80 chartView = new QChartView(chart);
82 chartView = new QChartView(chart);
81 QGridLayout* mainLayout = new QGridLayout;
83 QGridLayout* mainLayout = new QGridLayout;
82 mainLayout->addWidget(chartView, 0, 0);
84 mainLayout->addWidget(chartView, 0, 0);
83 mainLayout->addLayout(rightPanelLayout, 0, 1);
85 mainLayout->addLayout(rightPanelLayout, 0, 1);
84 mainLayout->setColumnStretch(0,1);
86 mainLayout->setColumnStretch(0,1);
85 setLayout(mainLayout);
87 setLayout(mainLayout);
86
88
87 // connect to the database
89 // connect to the database
88 db = QSqlDatabase::addDatabase("QSQLITE");
90 db = QSqlDatabase::addDatabase("QSQLITE");
89 db.setDatabaseName("gdpData");
91 db.setDatabaseName("gdpData");
90 if(!db.open())
92 if(!db.open())
91 {
93 {
92 qDebug() << "could not open database. SQLite db file missing (?)";
94 qDebug() << "could not open database. SQLite db file missing (?)";
93 return;
95 return;
94 }
96 }
95
97
96 // get the list of all countires and regions.
98 // get the list of all countires and regions.
97 QSqlQuery query;
99 QSqlQuery query;
98 query.exec("SELECT DISTINCT country FROM gdp2");
100 query.exec("SELECT DISTINCT country FROM gdp2");
99
101
100 // add the countries to the country filter
102 // add the countries to the country filter
101 while (query.next()) {
103 while (query.next()) {
102 countrieslist->addItem(query.value(0).toString());
104 countrieslist->addItem(query.value(0).toString());
103 }
105 }
104
105 // hide axis X labels
106 //QChartAxis* axis = chartArea->axisX();
107 // axis->
108 // axis->setLabelsVisible(false);
109 // newAxis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide);
110
111 }
106 }
112
107
113 Widget::~Widget()
108 Widget::~Widget()
114 {
109 {
115 //
110 //
116 db.close();
111 db.close();
117 }
112 }
118
113
119 /*!
114 /*!
120 refreshes the chart
115 refreshes the chart
121 */
116 */
122 void Widget::refreshChart()
117 void Widget::refreshChart()
123 {
118 {
124 chartView->chart()->removeAllSeries();
119 chartView->chart()->removeAllSeries();
125
120
126 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
121 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
127 QStringList selectedCountriesStrings;
122 QStringList selectedCountriesStrings;
128 QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems();
123 QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems();
129 for (int i = 0; i < selectedCountriesItems.size(); i++)
124 for (int i = 0; i < selectedCountriesItems.size(); i++)
130 selectedCountriesStrings.append(selectedCountriesItems[i]->text());
125 selectedCountriesStrings.append(selectedCountriesItems[i]->text());
131 selectedCountriesStrings.sort();
126 selectedCountriesStrings.sort();
132
127
133 QSqlQuery query;
128 QSqlQuery query;
134 // selected years items list is not sorted. copy the values to QList<int> and sort them.
129 // selected years items list is not sorted. copy the values to QList<int> and sort them.
135 QList<int> selectedYearsInts;
130 QList<int> selectedYearsInts;
136 QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems();
131 QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems();
137 for (int i = 0; i < selectedYearsItems.size(); i++)
132 for (int i = 0; i < selectedYearsItems.size(); i++)
138 selectedYearsInts.append(selectedYearsItems[i]->text().toInt());
133 selectedYearsInts.append(selectedYearsItems[i]->text().toInt());
139 qSort(selectedYearsInts.begin(), selectedYearsInts.end(), qGreater<int>());
134 qSort(selectedYearsInts.begin(), selectedYearsInts.end());
140
135
141 if (barChartRadioButton->isChecked())
136 if (barChartRadioButton->isChecked())
142 {
137 {
143 // use the sorted selected coutries list to initialize BarCategory
138 // use the sorted selected coutries list to initialize BarCategory
144 QStringList category;
139 QStringList category;
145 for (int i = 0; i < selectedCountriesStrings.size(); i++)
140 for (int i = 0; i < selectedCountriesStrings.size(); i++)
146 category << selectedCountriesStrings[i];
141 category << selectedCountriesStrings[i];
147 QBarSeries* series0 = new QBarSeries(category);
142 QBarSeries* series0 = new QBarSeries(category);
148 series0 = new QBarSeries(category);
143 series0 = new QBarSeries(category);
149
144
150 // prepare the selected counries SQL query
145 // prepare the selected counries SQL query
151 QString countriesQuery = "country IN (";
146 QString countriesQuery = "country IN (";
152 for (int i = 0; i < selectedCountriesStrings.size(); i++)
147 for (int i = 0; i < selectedCountriesStrings.size(); i++)
153 {
148 {
154 countriesQuery.append("'" + selectedCountriesStrings[i] + "'");
149 countriesQuery.append("'" + selectedCountriesStrings[i] + "'");
155 if ( i < selectedCountriesStrings.size() - 1)
150 if ( i < selectedCountriesStrings.size() - 1)
156 countriesQuery.append(",");
151 countriesQuery.append(",");
157 else
152 else
158 countriesQuery.append(")");
153 countriesQuery.append(")");
159 }
154 }
160
155
161 // perform a query for each selected year
156 // perform a query for each selected year
162 for (int i = 0; i < selectedYearsInts.size(); i++)
157 for (int i = 0; i < selectedYearsInts.size(); i++)
163 {
158 {
164 query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery);
159 query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery);
165 QBarSet* barSet = new QBarSet("Barset" + QString::number(i));
160 QBarSet* barSet = new QBarSet(QString::number(selectedYearsInts[i]));
166
161
167 // while (query.next()) {
162 // while (query.next()) {
168 // qDebug() << query.value(0).toString() << " : " << query.value(1).toString();
163 // qDebug() << query.value(0).toString() << " : " << query.value(1).toString();
169 // }
164 // }
170 query.first();
165 query.first();
171
166
172 // the data for some of the coutries for some years might be missing.
167 // the data for some of the coutries for some years might be missing.
173 // QBarChart needs bars to have same size
168 // QBarChart needs bars to have same size
174 for (int k = 0; k < selectedCountriesStrings.size(); k++)
169 for (int k = 0; k < selectedCountriesStrings.size(); k++)
175 {
170 {
176 if (selectedCountriesStrings[k] == query.value(0).toString())
171 if (selectedCountriesStrings[k] == query.value(0).toString())
177 {
172 {
178 *barSet << query.value(1).toReal();
173 *barSet << query.value(1).toReal();
179 qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]);
174 qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]);
180 query.next();
175 query.next();
181 }
176 }
182 else
177 else
183 {
178 {
184 // data missing, put 0
179 // data missing, put 0
185 *barSet << 0.0f;
180 *barSet << 0.0f;
186 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]);
181 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]);
187 }
182 }
188 }
183 }
189 series0->appendBarSet(barSet);
184 series0->appendBarSet(barSet);
190 }
185 }
191 // add the serie to the chart
186 // add the serie to the chart
192 chartView->chart()->addSeries(series0);
187 chartView->chart()->addSeries(series0);
193 }
188 }
194 else if (scatterChartRadioButton->isChecked())
189 else if (scatterChartRadioButton->isChecked())
195 {
190 {
196 QString yearsQuery = "year IN (";
191 QString yearsQuery = "year IN (";
197 for (int i = 0; i < selectedYearsInts.size(); i++)
192 for (int i = 0; i < selectedYearsInts.size(); i++)
198 {
193 {
199 yearsQuery.append("'" + QString("%1").arg(selectedYearsInts[i]) + "'");
194 yearsQuery.append("'" + QString("%1").arg(selectedYearsInts[i]) + "'");
200 if ( i < selectedYearsInts.size() - 1)
195 if ( i < selectedYearsInts.size() - 1)
201 yearsQuery.append(",");
196 yearsQuery.append(",");
202 else
197 else
203 yearsQuery.append(")");
198 yearsQuery.append(")");
204 }
199 }
205
200
206 // perform a query for each selected country
201 // perform a query for each selected country
207 for (int i = 0; i < selectedCountriesStrings.size(); i++)
202 for (int i = 0; i < selectedCountriesStrings.size(); i++)
208 {
203 {
209 query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery);
204 query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery);
210 query.first();
205 query.first();
211
206
212 QScatterSeries* series = new QScatterSeries;
207 QScatterSeries* series = new QScatterSeries;
208 series->setName(selectedCountriesStrings[i]);
213 // the data for some of the coutries for some years might be missing.
209 // the data for some of the coutries for some years might be missing.
214 for (int k = 0; k < selectedYearsInts.size(); k++)
210 for (int k = 0; k < selectedYearsInts.size(); k++)
215 {
211 {
216 if (selectedYearsInts[k] == query.value(0).toInt())
212 if (selectedYearsInts[k] == query.value(0).toInt())
217 {
213 {
218 *series << QPointF(query.value(0).toInt() , query.value(1).toReal());
214 *series << QPointF(query.value(0).toInt() , query.value(1).toReal());
219 qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[k]);
215 qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[k]);
220 query.next();
216 query.next();
221 }
217 }
222 else
218 else
223 {
219 {
224 // data missing, put 0
220 // data missing, put 0
225 *series << QPointF(selectedYearsInts[k] , 0.0f);
221 *series << QPointF(selectedYearsInts[k] , 0.0f);
226 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt();
222 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt();
227 }
223 }
228 }
224 }
229 // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1);
225 // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1);
230 chartView->chart()->addSeries(series);
226 chartView->chart()->addSeries(series);
231 }
227 }
232 chartView->chart()->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] - 1, selectedYearsInts[0] + 1);
228 chartView->chart()->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] - 1, selectedYearsInts[0] + 1);
233 }
229 }
234 }
230 }
235
231
236 void Widget::printChart()
232 void Widget::printChart()
237 {
233 {
238 QPrinter printer;
234 QPrinter printer;
239 // QPrinter printer(QPrinter::HighResolution);
235 // QPrinter printer(QPrinter::HighResolution);
240 printer.setOutputFormat(QPrinter::PdfFormat);
236 printer.setOutputFormat(QPrinter::PdfFormat);
241 printer.setOrientation(QPrinter::Landscape);
237 printer.setOrientation(QPrinter::Landscape);
242 printer.setOutputFileName("print.pdf");
238 printer.setOutputFileName("print.pdf");
243
239
244 QPainter painter;
240 QPainter painter;
245 painter.begin(&printer);
241 painter.begin(&printer);
246 chartView->render(&painter);
242 chartView->render(&painter);
247 }
243 }
@@ -1,7 +1,56
1 /*!
1 /*!
2 \example examples/modeldata
2 \example examples/modeldata
3 \title Model data example
3 \title Model data example
4 \subtitle
4 \subtitle
5
5
6 This example shows how to use QAbstractItemModel derived model as the data for the series.
6 This example shows how to use QAbstractItemModel derived model as the data for the series.
7
8 \image modeldata.png
9
10 Let's start by creating an instance of CustomTableModel class.
11 CustomTableModel class is derived from QAbstractTableModel and it was created for the purpose of this example.
12 The constructor of this class populates the internal data store of the model with the data that is good for our chart example.
13
14 \snippet ../examples/modeldata/tablewidget.cpp 1
15
16 We now have a model with data that we would like to display both on the chart and in a QTableView.
17 First, we create QTableView and tell it use the model as a data source.
18
19 \snippet ../examples/modeldata/tablewidget.cpp 2
20
21 Now we need QChart instance to display the same data on the chart.
22 We also enable animations. It makes it easier to see how modifying the model's data affect the chart.
23
24 \snippet ../examples/modeldata/tablewidget.cpp 3
25
26 Then let's create two QLineSeries and tell them to use the data from the model.
27 First line of the code below creates new line series. Line number two sets the model as the data source for the series.
28 Third line specifies that x coordinates are taken from the model's column(Qt::Vertical) with index 0 and the y coordinates are taken from the model's column with index 1.
29 Finally the series is added to the chart.
30
31 \snippet ../examples/modeldata/tablewidget.cpp 4
32
33 To show in QTableView which data coresponds with which series this example uses table coloring.
34 When series is added to the chart it is assigned a color beased on the currently selected theme.
35 Code below extracts that color from the series and uses it to create colored QTableView.
36 Coloring of the view is not a part of the QChart functionality.
37
38 \snippet ../examples/modeldata/tablewidget.cpp 5
39
40 The same operations are done with second series. Notice that for this series different columns of the same model are mapped.
41
42 \snippet ../examples/modeldata/tablewidget.cpp 6
43
44 \snippet ../examples/modeldata/tablewidget.cpp 7
45
46 To avoid setting up the QGraphicsScene we use QChartView class that does it for us. QChart object pointer is used as a parameter of the QChartView constructor.
47 To make the render look nicer Antialiasing is turned on and the minimum size of the chart is set.
48
49 \snippet ../examples/modeldata/tablewidget.cpp 8
50
51 Finally we place both widgets in a layout and use the layout as the application layout.
52
53 \snippet ../examples/modeldata/tablewidget.cpp 9
54
55 Application is ready. Try modifying the data in the table view and see how it affects the chart.
7 */
56 */
@@ -1,82 +1,101
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "tablewidget.h"
21 #include "tablewidget.h"
22 #include "customtablemodel.h"
22 #include "customtablemodel.h"
23 #include <QGridLayout>
23 #include <QGridLayout>
24 #include <QTableView>
24 #include <QTableView>
25 #include <QChart>
25 #include <QChart>
26 #include <QChartView>
26 #include <QChartView>
27 #include <QLineSeries>
27 #include <QLineSeries>
28
28
29 QTCOMMERCIALCHART_USE_NAMESPACE
29 QTCOMMERCIALCHART_USE_NAMESPACE
30
30
31 TableWidget::TableWidget(QWidget *parent)
31 TableWidget::TableWidget(QWidget *parent)
32 : QWidget(parent)
32 : QWidget(parent)
33 {
33 {
34 // create simple model for storing data
34 // create simple model for storing data
35 // user's table data model
35 // user's table data model
36 //! [1]
36 CustomTableModel *model = new CustomTableModel;
37 CustomTableModel *model = new CustomTableModel;
38 //! [1]
37
39
40 //! [2]
38 // create table view and add model to it
41 // create table view and add model to it
39 QTableView *tableView = new QTableView;
42 QTableView *tableView = new QTableView;
40 tableView->setModel(model);
43 tableView->setModel(model);
44 //! [2]
41 tableView->setColumnWidth(0, 56);
45 tableView->setColumnWidth(0, 56);
42 tableView->setColumnWidth(1, 56);
46 tableView->setColumnWidth(1, 56);
43 tableView->setColumnWidth(2, 56);
47 tableView->setColumnWidth(2, 56);
44 tableView->setColumnWidth(3, 56);
48 tableView->setColumnWidth(3, 56);
45
49
46 QChart *m_chart = new QChart;
50 //! [3]
47 m_chart->setAnimationOptions(QChart::AllAnimations);
51 QChart *chart = new QChart;
48 QChartView *m_chartView = new QChartView(m_chart);
52 chart->setAnimationOptions(QChart::AllAnimations);
49 m_chartView->setRenderHint(QPainter::Antialiasing);
53 //! [3]
50 m_chartView->setMinimumSize(640, 480);
51
54
55 // series 1
56 //! [4]
57 QLineSeries *series = new QLineSeries;
58 series->setModel(model);
59 series->setModelMapping(0, 1, Qt::Vertical);
60 chart->addSeries(series);
61 //! [4]
62
63 //! [5]
52 // for storing color hex from the series
64 // for storing color hex from the series
53 QString seriesColorHex = "#000000";
65 QString seriesColorHex = "#000000";
54
66
55 // series 1
56 QLineSeries *m_series = new QLineSeries;
57 m_series->setModel(model);
58 m_series->setModelMapping(0, 1, Qt::Vertical);
59 m_chart->addSeries(m_series);
60
61 // get the color of the series and use it for showing the mapped area
67 // get the color of the series and use it for showing the mapped area
62 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
68 seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
63 model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount()));
69 model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount()));
70 //! [5]
64
71
65 // series 2
72 // series 2
66 m_series = new QLineSeries;
73 //! [6]
67 m_series->setModel(model);
74 series = new QLineSeries;
68 m_series->setModelMapping(2,3, Qt::Vertical);
75 series->setModel(model);
69 m_chart->addSeries(m_series);
76 series->setModelMapping(2,3, Qt::Vertical);
77 chart->addSeries(series);
78 //! [6]
70
79
80 //! [7]
71 // get the color of the series and use it for showing the mapped area
81 // get the color of the series and use it for showing the mapped area
72 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
82 seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
73 model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount()));
83 model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount()));
84 //! [7]
85
86 //! [8]
87 QChartView *chartView = new QChartView(chart);
88 chartView->setRenderHint(QPainter::Antialiasing);
89 chartView->setMinimumSize(640, 480);
90 //! [8]
74
91
92 //! [9]
75 // create main layout
93 // create main layout
76 QGridLayout* mainLayout = new QGridLayout;
94 QGridLayout* mainLayout = new QGridLayout;
77 mainLayout->addWidget(tableView, 1, 0);
95 mainLayout->addWidget(tableView, 1, 0);
78 mainLayout->addWidget(m_chartView, 1, 1);
96 mainLayout->addWidget(chartView, 1, 1);
79 mainLayout->setColumnStretch(1, 1);
97 mainLayout->setColumnStretch(1, 1);
80 mainLayout->setColumnStretch(0, 0);
98 mainLayout->setColumnStretch(0, 0);
81 setLayout(mainLayout);
99 setLayout(mainLayout);
100 //! [9]
82 }
101 }
@@ -1,421 +1,419
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qchartaxis.h"
21 #include "qchartaxis.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QChartAxis
26 \class QChartAxis
27 \brief The QChartAxis class is used for manipulating chart's axis
27 \brief The QChartAxis class is used for manipulating chart's axis
28 and for adding optional axes to the chart.
28 and for adding optional axes to the chart.
29 \mainclass
29 \mainclass
30
30
31 There is only one x Axis, however there can be multiple y axes.
31 There is only one x Axis, however there can be multiple y axes.
32 Each chart series can be bound to exactly one Y axis and the share common X axis.
32 Each chart series can be bound to exactly one Y axis and the share common X axis.
33 Axis can be setup to show axis line with ticks, gird lines and shades.
33 Axis can be setup to show axis line with ticks, gird lines and shades.
34
34
35 */
35 */
36
36
37 /*!
37 /*!
38 \fn bool QChartAxis::isAxisVisible() const
38 \fn bool QChartAxis::isAxisVisible() const
39 \brief Returns if axis is visible
39 \brief Returns if axis is visible
40 \sa setAxisVisible()
40 \sa setAxisVisible()
41 */
41 */
42
42
43 /*!
43 /*!
44 \fn QPen QChartAxis::axisPen() const
44 \fn QPen QChartAxis::axisPen() const
45 \brief Returns pen used to draw axis and ticks.
45 \brief Returns pen used to draw axis and ticks.
46 \sa setAxisPen()
46 \sa setAxisPen()
47 */
47 */
48
48
49
49
50 /*!
50 /*!
51 \fn bool QChartAxis::isGridLineVisible() const
51 \fn bool QChartAxis::isGridLineVisible() const
52 \brief Returns if grid is visible
52 \brief Returns if grid is visible
53 \sa setGridLineVisible()
53 \sa setGridLineVisible()
54 */
54 */
55
55
56 /*!
56 /*!
57 \fn QPen QChartAxis::gridLinePen() const
57 \fn QPen QChartAxis::gridLinePen() const
58 \brief Returns pen used to draw grid.
58 \brief Returns pen used to draw grid.
59 \sa setGridLinePen()
59 \sa setGridLinePen()
60 */
60 */
61
61
62 /*!
62 /*!
63 \fn bool QChartAxis::labelsVisible() const
63 \fn bool QChartAxis::labelsVisible() const
64 \brief Returns if grid is visible
64 \brief Returns if grid is visible
65 \sa setLabelsVisible()
65 \sa setLabelsVisible()
66 */
66 */
67
67
68 /*!
68 /*!
69 \fn QPen QChartAxis::labelsPen() const
69 \fn QPen QChartAxis::labelsPen() const
70 \brief Returns the pen used to labels.
70 \brief Returns the pen used to labels.
71 \sa setLabelsPen()
71 \sa setLabelsPen()
72 */
72 */
73
73
74 /*!
74 /*!
75 \fn QBrush QChartAxis::labelsBrush() const
75 \fn QBrush QChartAxis::labelsBrush() const
76 \brief Returns brush used to draw labels.
76 \brief Returns brush used to draw labels.
77 \sa setLabelsBrush()
77 \sa setLabelsBrush()
78 */
78 */
79
79
80 /*!
80 /*!
81 \fn QFont QChartAxis::labelsFont() const
81 \fn QFont QChartAxis::labelsFont() const
82 \brief Returns font used to draw labels.
82 \brief Returns font used to draw labels.
83 \sa setLabelsFont()
83 \sa setLabelsFont()
84 */
84 */
85
85
86 /*!
86 /*!
87 \fn QFont QChartAxis::labelsAngle() const
87 \fn QFont QChartAxis::labelsAngle() const
88 \brief Returns angle used to draw labels.
88 \brief Returns angle used to draw labels.
89 \sa setLabelsAngle()
89 \sa setLabelsAngle()
90 */
90 */
91
91
92 /*!
92 /*!
93 \fn bool QChartAxis::shadesVisible() const
93 \fn bool QChartAxis::shadesVisible() const
94 \brief Returns if shades are visible.
94 \brief Returns if shades are visible.
95 \sa setShadesVisible()
95 \sa setShadesVisible()
96 */
96 */
97
97
98 /*!
98 /*!
99 \fn qreal QChartAxis::shadesOpacity() const
99 \fn qreal QChartAxis::shadesOpacity() const
100 \brief Returns opacity of shades.
100 \brief Returns opacity of shades.
101 */
101 */
102
102
103 /*!
103 /*!
104 \fn QPen QChartAxis::shadesPen() const
104 \fn QPen QChartAxis::shadesPen() const
105 \brief Returns pen used to draw shades.
105 \brief Returns pen used to draw shades.
106 \sa setShadesPen()
106 \sa setShadesPen()
107 */
107 */
108
108
109 /*!
109 /*!
110 \fn QBrush QChartAxis::shadesBrush() const
110 \fn QBrush QChartAxis::shadesBrush() const
111 \brief Returns brush used to draw shades.
111 \brief Returns brush used to draw shades.
112 \sa setShadesBrush()
112 \sa setShadesBrush()
113 */
113 */
114
114
115 /*!
115 /*!
116 \fn qreal QChartAxis::min() const
116 \fn qreal QChartAxis::min() const
117 \brief Returns minimum value on the axis.
117 \brief Returns minimum value on the axis.
118 \sa setMin()
118 \sa setMin()
119 */
119 */
120
120
121 /*!
121 /*!
122 \fn qreal QChartAxis::max() const
122 \fn qreal QChartAxis::max() const
123 \brief Returns maximim value on the axis.
123 \brief Returns maximim value on the axis.
124 \sa setMax()
124 \sa setMax()
125 */
125 */
126
126
127 /*!
127 /*!
128 \fn void QChartAxis::minChanged(qreal min)
128 \fn void QChartAxis::minChanged(qreal min)
129 \brief Axis emits signal when \a min of axis has changed.
129 \brief Axis emits signal when \a min of axis has changed.
130 */
130 */
131
131
132 /*!
132 /*!
133 \fn void QChartAxis::maxChanged(qreal max)
133 \fn void QChartAxis::maxChanged(qreal max)
134 \brief Axis emits signal when \a max of axis has changed.
134 \brief Axis emits signal when \a max of axis has changed.
135 */
135 */
136
136
137 /*!
137 /*!
138 \fn void QChartAxis::rangeChanged(qreal min, qreal max)
138 \fn void QChartAxis::rangeChanged(qreal min, qreal max)
139 \brief Axis emits signal when \a min or \a max of axis has changed.
139 \brief Axis emits signal when \a min or \a max of axis has changed.
140 */
140 */
141
141
142 /*!
142 /*!
143 \fn int QChartAxis::ticksCount() const
143 \fn int QChartAxis::ticksCount() const
144 \brief Return number of ticks on the axis
144 \brief Return number of ticks on the axis
145 \sa setTicksCount()
145 \sa setTicksCount()
146 */
146 */
147
147
148 /*!
148 /*!
149 \fn void QChartAxis::updated()
149 \fn void QChartAxis::updated()
150 \brief \internal
150 \brief \internal
151 */
151 */
152
152
153 /*!
153 /*!
154 \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max)
155 \brief \internal \a min \a max
156 */
157
158 /*!
159 Constructs new axis object which is a child of \a parent. Ownership is taken by
154 Constructs new axis object which is a child of \a parent. Ownership is taken by
160 QChatView or QChart when axis added.
155 QChatView or QChart when axis added.
161 */
156 */
162
157
163 QChartAxis::QChartAxis(QObject *parent) : QObject(parent),
158 QChartAxis::QChartAxis(QObject *parent) : QObject(parent),
164 m_axisVisible(true),
159 m_axisVisible(true),
165 m_gridLineVisible(true),
160 m_gridLineVisible(true),
166 m_labelsVisible(true),
161 m_labelsVisible(true),
167 m_labelsAngle(0),
162 m_labelsAngle(0),
168 m_shadesVisible(false),
163 m_shadesVisible(false),
169 m_shadesOpacity(1.0),
164 m_shadesOpacity(1.0),
170 m_min(0),
165 m_min(0),
171 m_max(0),
166 m_max(0),
172 m_ticksCount(5),
167 m_ticksCount(5),
173 m_niceNumbers(false)
168 m_niceNumbers(false)
174 {
169 {
175
170
176 }
171 }
177
172
178 /*!
173 /*!
179 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
174 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
180 */
175 */
181
176
182 QChartAxis::~QChartAxis()
177 QChartAxis::~QChartAxis()
183 {
178 {
184 }
179 }
185
180
186 /*!
181 /*!
187 Sets \a pen used to draw axis line and ticks.
182 Sets \a pen used to draw axis line and ticks.
188 */
183 */
189 void QChartAxis::setAxisPen(const QPen &pen)
184 void QChartAxis::setAxisPen(const QPen &pen)
190 {
185 {
191 if (pen != m_axisPen) {
186 if (pen != m_axisPen) {
192 m_axisPen = pen;
187 m_axisPen = pen;
193 emit updated();
188 emit updated();
194 }
189 }
195 }
190 }
196
191
197 /*!
192 /*!
198 Sets if axis and ticks are \a visible.
193 Sets if axis and ticks are \a visible.
199 */
194 */
200 void QChartAxis::setAxisVisible(bool visible)
195 void QChartAxis::setAxisVisible(bool visible)
201 {
196 {
202 if (m_axisVisible != visible) {
197 if (m_axisVisible != visible) {
203 m_axisVisible = visible;
198 m_axisVisible = visible;
204 emit updated();
199 emit updated();
205 }
200 }
206 }
201 }
207
202
208 /*!
203 /*!
209 Sets if grid line is \a visible.
204 Sets if grid line is \a visible.
210 */
205 */
211 void QChartAxis::setGridLineVisible(bool visible)
206 void QChartAxis::setGridLineVisible(bool visible)
212 {
207 {
213 if (m_gridLineVisible != visible) {
208 if (m_gridLineVisible != visible) {
214 m_gridLineVisible = visible;
209 m_gridLineVisible = visible;
215 emit updated();
210 emit updated();
216 }
211 }
217 }
212 }
218
213
219 /*!
214 /*!
220 Sets \a pen used to draw grid line.
215 Sets \a pen used to draw grid line.
221 */
216 */
222 void QChartAxis::setGridLinePen(const QPen &pen)
217 void QChartAxis::setGridLinePen(const QPen &pen)
223 {
218 {
224 if (m_gridLinePen != pen) {
219 if (m_gridLinePen != pen) {
225 m_gridLinePen = pen;
220 m_gridLinePen = pen;
226 emit updated();
221 emit updated();
227 }
222 }
228 }
223 }
229
224
230 /*!
225 /*!
231 Sets if axis' labels are \a visible.
226 Sets if axis' labels are \a visible.
232 */
227 */
233 void QChartAxis::setLabelsVisible(bool visible)
228 void QChartAxis::setLabelsVisible(bool visible)
234 {
229 {
235 if (m_labelsVisible != visible) {
230 if (m_labelsVisible != visible) {
236 m_labelsVisible = visible;
231 m_labelsVisible = visible;
237 emit updated();
232 emit updated();
238 }
233 }
239 }
234 }
240
235
241 /*!
236 /*!
242 Sets \a pen used to draw labels.
237 Sets \a pen used to draw labels.
243 */
238 */
244 void QChartAxis::setLabelsPen(const QPen &pen)
239 void QChartAxis::setLabelsPen(const QPen &pen)
245 {
240 {
246 if (m_labelsPen != pen) {
241 if (m_labelsPen != pen) {
247 m_labelsPen = pen;
242 m_labelsPen = pen;
248 emit updated();
243 emit updated();
249 }
244 }
250 }
245 }
251
246
252 /*!
247 /*!
253 Sets \a brush used to draw labels.
248 Sets \a brush used to draw labels.
254 */
249 */
255 void QChartAxis::setLabelsBrush(const QBrush &brush)
250 void QChartAxis::setLabelsBrush(const QBrush &brush)
256 {
251 {
257 if (m_labelsBrush != brush) {
252 if (m_labelsBrush != brush) {
258 m_labelsBrush = brush;
253 m_labelsBrush = brush;
259 emit updated();
254 emit updated();
260 }
255 }
261 }
256 }
262
257
263 /*!
258 /*!
264 Sets \a font used to draw labels.
259 Sets \a font used to draw labels.
265 */
260 */
266 void QChartAxis::setLabelsFont(const QFont &font)
261 void QChartAxis::setLabelsFont(const QFont &font)
267 {
262 {
268 if (m_labelsFont != font) {
263 if (m_labelsFont != font) {
269 m_labelsFont = font;
264 m_labelsFont = font;
270 emit updated();
265 emit updated();
271 }
266 }
272 }
267 }
273
268
274 /*!
269 /*!
275 Sets \a angle for all the labels on given axis.
270 Sets \a angle for all the labels on given axis.
276 */
271 */
277 void QChartAxis::setLabelsAngle(int angle)
272 void QChartAxis::setLabelsAngle(int angle)
278 {
273 {
279 if (m_labelsAngle != angle) {
274 if (m_labelsAngle != angle) {
280 m_labelsAngle = angle;
275 m_labelsAngle = angle;
281 emit updated();
276 emit updated();
282 }
277 }
283 }
278 }
284
279
285 /*!
280 /*!
286 Sets if shades are \a visible.
281 Sets if shades are \a visible.
287 */
282 */
288 void QChartAxis::setShadesVisible(bool visible)
283 void QChartAxis::setShadesVisible(bool visible)
289 {
284 {
290 if (m_shadesVisible != visible) {
285 if (m_shadesVisible != visible) {
291 m_shadesVisible = visible;
286 m_shadesVisible = visible;
292 emit updated();
287 emit updated();
293 }
288 }
294 }
289 }
295
290
296 /*!
291 /*!
297 Sets \a pen used to draw shades.
292 Sets \a pen used to draw shades.
298 */
293 */
299 void QChartAxis::setShadesPen(const QPen &pen)
294 void QChartAxis::setShadesPen(const QPen &pen)
300 {
295 {
301 if (m_shadesPen != pen) {
296 if (m_shadesPen != pen) {
302 m_shadesPen = pen;
297 m_shadesPen = pen;
303 emit updated();
298 emit updated();
304 }
299 }
305 }
300 }
306
301
307 /*!
302 /*!
308 Sets \a brush used to draw shades.
303 Sets \a brush used to draw shades.
309 */
304 */
310 void QChartAxis::setShadesBrush(const QBrush &brush)
305 void QChartAxis::setShadesBrush(const QBrush &brush)
311 {
306 {
312 if (m_shadesBrush != brush) {
307 if (m_shadesBrush != brush) {
313 m_shadesBrush = brush;
308 m_shadesBrush = brush;
314 emit updated();
309 emit updated();
315 }
310 }
316 }
311 }
317
312
318 /*!
313 /*!
319 Sets \a opacity of the shades.
314 Sets \a opacity of the shades.
320 */
315 */
321 void QChartAxis::setShadesOpacity(qreal opacity)
316 void QChartAxis::setShadesOpacity(qreal opacity)
322 {
317 {
323 if (m_shadesOpacity != opacity) {
318 if (m_shadesOpacity != opacity) {
324 m_shadesOpacity=opacity;
319 m_shadesOpacity=opacity;
325 emit updated();
320 emit updated();
326 }
321 }
327 }
322 }
328
323
329 /*!
324 /*!
330 Sets \a min value on the axis.
325 Sets \a min value on the axis.
331 */
326 */
332 void QChartAxis::setMin(qreal min)
327 void QChartAxis::setMin(qreal min)
333 {
328 {
334 setRange(min,m_max);
329 setRange(min,m_max);
335 }
330 }
336
331
337 /*!
332 /*!
338 Sets \a max value on the axis.
333 Sets \a max value on the axis.
339 */
334 */
340 void QChartAxis::setMax(qreal max)
335 void QChartAxis::setMax(qreal max)
341 {
336 {
342 setRange(m_min,max);
337 setRange(m_min,max);
343 }
338 }
344
339
345 /*!
340 /*!
346 Sets range from \a min to \a max on the axis.
341 Sets range from \a min to \a max on the axis.
347 */
342 */
348 void QChartAxis::setRange(qreal min, qreal max)
343 void QChartAxis::setRange(qreal min, qreal max)
349 {
344 {
350 bool changed = false;
345 bool changed = false;
351 if (!qFuzzyIsNull(m_min - min)) {
346 if (!qFuzzyIsNull(m_min - min)) {
352 m_min = min;
347 m_min = min;
353 changed = true;
348 changed = true;
354 emit minChanged(min);
349 emit minChanged(min);
355 }
350 }
356
351
357 if (!qFuzzyIsNull(m_max - max)) {
352 if (!qFuzzyIsNull(m_max - max)) {
358 m_max = max;
353 m_max = max;
359 changed = true;
354 changed = true;
360 emit maxChanged(max);
355 emit maxChanged(max);
361 }
356 }
362
357
363 if (changed) {
358 if (changed) {
364 emit rangeChanged(m_min,m_max);
359 emit rangeChanged(m_min,m_max);
365 emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers);
360 emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers);
366 }
361 }
367 }
362 }
368
363
369 /*!
364 /*!
370 Sets \a count for ticks on the axis.
365 Sets \a count for ticks on the axis.
371 */
366 */
372 void QChartAxis::setTicksCount(int count)
367 void QChartAxis::setTicksCount(int count)
373 {
368 {
374 if (m_ticksCount != count) {
369 if (m_ticksCount != count) {
375 m_ticksCount = count;
370 m_ticksCount = count;
376 emit ticksCountChanged(count);
371 emit ticksCountChanged(count);
377 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
372 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
378 }
373 }
379 }
374 }
380
375
381 /*!
376 /*!
382 Sets axis, shades, labels and grid lines to be visible.
377 Sets axis, shades, labels and grid lines to be visible.
383 */
378 */
384 void QChartAxis::show()
379 void QChartAxis::show()
385 {
380 {
386 m_axisVisible=true;
381 m_axisVisible=true;
387 m_gridLineVisible=true;
382 m_gridLineVisible=true;
388 m_labelsVisible=true;
383 m_labelsVisible=true;
389 m_shadesVisible=true;
384 m_shadesVisible=true;
390 emit updated();
385 emit updated();
391 }
386 }
392
387
393 /*!
388 /*!
394 Sets axis, shades, labels and grid lines to not be visible.
389 Sets axis, shades, labels and grid lines to not be visible.
395 */
390 */
396 void QChartAxis::hide()
391 void QChartAxis::hide()
397 {
392 {
398 m_axisVisible = false;
393 m_axisVisible = false;
399 m_gridLineVisible = false;
394 m_gridLineVisible = false;
400 m_labelsVisible = false;
395 m_labelsVisible = false;
401 m_shadesVisible = false;
396 m_shadesVisible = false;
402 emit updated();
397 emit updated();
403 }
398 }
404
399
400 /*!
401 \internal
402 */
405 void QChartAxis::handleAxisRangeChanged(qreal min, qreal max,int count)
403 void QChartAxis::handleAxisRangeChanged(qreal min, qreal max,int count)
406 {
404 {
407 setRange(min,max);
405 setRange(min,max);
408 setTicksCount(count);
406 setTicksCount(count);
409 }
407 }
410
408
411 void QChartAxis::setNiceNumbers(bool enabled)
409 void QChartAxis::setNiceNumbers(bool enabled)
412 {
410 {
413 if (m_niceNumbers != enabled){
411 if (m_niceNumbers != enabled){
414 m_niceNumbers = enabled;
412 m_niceNumbers = enabled;
415 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
413 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
416 }
414 }
417 }
415 }
418
416
419 #include "moc_qchartaxis.cpp"
417 #include "moc_qchartaxis.cpp"
420
418
421 QTCOMMERCIALCHART_END_NAMESPACE
419 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,250 +1,250
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qchartview.h"
21 #include "qchartview.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "qchartview_p.h"
23 #include "qchartview_p.h"
24 #include <QGraphicsScene>
24 #include <QGraphicsScene>
25 #include <QRubberBand>
25 #include <QRubberBand>
26
26
27
27
28 /*!
28 /*!
29 \enum QChartView::RubberBandPolicy
29 \enum QChartView::RubberBand
30
30
31 This enum describes the different types of rubber bands that can be used for zoom rect selection
31 This enum describes the different types of rubber bands that can be used for zoom rect selection
32
32
33 \value NoRubberBand
33 \value NoRubberBand
34 \value VerticalRubberBand
34 \value VerticalRubberBand
35 \value HorizonalRubberBand
35 \value HorizonalRubberBand
36 \value RectangleRubberBand
36 \value RectangleRubberBand
37 */
37 */
38
38
39 /*!
39 /*!
40 \class QChartView
40 \class QChartView
41 \brief Standalone charting widget.
41 \brief Standalone charting widget.
42
42
43 QChartView is a standalone widget that can display charts. It does not require separate
43 QChartView is a standalone widget that can display charts. It does not require separate
44 QGraphicsScene to work. It manages the graphical representation of different types of
44 QGraphicsScene to work. It manages the graphical representation of different types of
45 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
45 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
46 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
46 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
47
47
48 \sa QChart
48 \sa QChart
49 */
49 */
50
50
51 QTCOMMERCIALCHART_BEGIN_NAMESPACE
51 QTCOMMERCIALCHART_BEGIN_NAMESPACE
52
52
53 /*!
53 /*!
54 Constructs a chartView object which is a child of a\a parent.
54 Constructs a chartView object which is a child of a\a parent.
55 */
55 */
56 QChartView::QChartView(QChart *chart,QWidget *parent) :
56 QChartView::QChartView(QChart *chart,QWidget *parent) :
57 QGraphicsView(parent),
57 QGraphicsView(parent),
58 d_ptr(new QChartViewPrivate())
58 d_ptr(new QChartViewPrivate())
59 {
59 {
60 Q_ASSERT(chart);
60 Q_ASSERT(chart);
61 d_ptr->m_scene = new QGraphicsScene(this);
61 d_ptr->m_scene = new QGraphicsScene(this);
62 d_ptr->m_chart = chart;
62 d_ptr->m_chart = chart;
63 setFrameShape(QFrame::NoFrame);
63 setFrameShape(QFrame::NoFrame);
64 setBackgroundRole(QPalette::Window);
64 setBackgroundRole(QPalette::Window);
65 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
65 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
66 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
66 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
67 setScene(d_ptr->m_scene);
67 setScene(d_ptr->m_scene);
68 d_ptr->m_scene->addItem(chart);
68 d_ptr->m_scene->addItem(chart);
69 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
69 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
70 }
70 }
71
71
72
72
73 /*!
73 /*!
74 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
74 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
75 */
75 */
76 QChartView::~QChartView()
76 QChartView::~QChartView()
77 {
77 {
78 }
78 }
79
79
80 /*!
80 /*!
81 Returns the pointer to the associated chart
81 Returns the pointer to the associated chart
82 */
82 */
83 QChart* QChartView::chart() const
83 QChart* QChartView::chart() const
84 {
84 {
85 return d_ptr->m_chart;
85 return d_ptr->m_chart;
86 }
86 }
87
87
88 /*!
88 /*!
89 Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed.
89 Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed.
90 */
90 */
91 void QChartView::setRubberBand(const RubberBands& rubberBand)
91 void QChartView::setRubberBand(const RubberBands& rubberBand)
92 {
92 {
93 d_ptr->m_rubberBandFlags=rubberBand;
93 d_ptr->m_rubberBandFlags=rubberBand;
94
94
95 if (!d_ptr->m_rubberBandFlags) {
95 if (!d_ptr->m_rubberBandFlags) {
96 delete d_ptr->m_rubberBand;
96 delete d_ptr->m_rubberBand;
97 d_ptr->m_rubberBand=0;
97 d_ptr->m_rubberBand=0;
98 return;
98 return;
99 }
99 }
100
100
101 if (!d_ptr->m_rubberBand) {
101 if (!d_ptr->m_rubberBand) {
102 d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
102 d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
103 d_ptr->m_rubberBand->setEnabled(true);
103 d_ptr->m_rubberBand->setEnabled(true);
104 }
104 }
105 }
105 }
106
106
107 /*!
107 /*!
108 Returns the RubberBandPolicy that is currently being used by the widget.
108 Returns the RubberBandPolicy that is currently being used by the widget.
109 */
109 */
110 QChartView::RubberBands QChartView::rubberBand() const
110 QChartView::RubberBands QChartView::rubberBand() const
111 {
111 {
112 return d_ptr->m_rubberBandFlags;
112 return d_ptr->m_rubberBandFlags;
113 }
113 }
114
114
115 /*!
115 /*!
116 If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
116 If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
117 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
117 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
118 */
118 */
119 void QChartView::mousePressEvent(QMouseEvent *event)
119 void QChartView::mousePressEvent(QMouseEvent *event)
120 {
120 {
121 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
121 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
122
122
123 int padding = d_ptr->m_chart->margins().top();
123 int padding = d_ptr->m_chart->margins().top();
124 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
124 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
125
125
126 if (rect.contains(event->pos())) {
126 if (rect.contains(event->pos())) {
127 d_ptr->m_rubberBandOrigin = event->pos();
127 d_ptr->m_rubberBandOrigin = event->pos();
128 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
128 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
129 d_ptr->m_rubberBand->show();
129 d_ptr->m_rubberBand->show();
130 event->accept();
130 event->accept();
131 }
131 }
132 }
132 }
133 else {
133 else {
134 QGraphicsView::mousePressEvent(event);
134 QGraphicsView::mousePressEvent(event);
135 }
135 }
136 }
136 }
137
137
138 /*!
138 /*!
139 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
139 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
140 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
140 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
141 */
141 */
142 void QChartView::mouseMoveEvent(QMouseEvent *event)
142 void QChartView::mouseMoveEvent(QMouseEvent *event)
143 {
143 {
144 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
144 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
145 QRectF margins = d_ptr->m_chart->margins();
145 QRectF margins = d_ptr->m_chart->margins();
146 QRectF geometry = d_ptr->m_chart->geometry();
146 QRectF geometry = d_ptr->m_chart->geometry();
147 QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom());
147 QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom());
148 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
148 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
149 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
149 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
150 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
150 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
151 d_ptr->m_rubberBandOrigin.setY(rect.top());
151 d_ptr->m_rubberBandOrigin.setY(rect.top());
152 height = rect.height();
152 height = rect.height();
153 }
153 }
154 if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) {
154 if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) {
155 d_ptr->m_rubberBandOrigin.setX(rect.left());
155 d_ptr->m_rubberBandOrigin.setX(rect.left());
156 width= rect.width();
156 width= rect.width();
157 }
157 }
158 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized());
158 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized());
159 }
159 }
160 else {
160 else {
161 QGraphicsView::mouseMoveEvent(event);
161 QGraphicsView::mouseMoveEvent(event);
162 }
162 }
163 }
163 }
164
164
165 /*!
165 /*!
166 If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
166 If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
167 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
167 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
168 */
168 */
169 void QChartView::mouseReleaseEvent(QMouseEvent *event)
169 void QChartView::mouseReleaseEvent(QMouseEvent *event)
170 {
170 {
171 if(d_ptr->m_rubberBand) {
171 if(d_ptr->m_rubberBand) {
172 if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) {
172 if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) {
173 d_ptr->m_rubberBand->hide();
173 d_ptr->m_rubberBand->hide();
174 QRect rect = d_ptr->m_rubberBand->geometry();
174 QRect rect = d_ptr->m_rubberBand->geometry();
175 d_ptr->m_chart->zoomIn(rect);
175 d_ptr->m_chart->zoomIn(rect);
176 event->accept();
176 event->accept();
177 }
177 }
178
178
179 if(event->button()==Qt::RightButton){
179 if(event->button()==Qt::RightButton){
180 d_ptr->m_chart->zoomOut();
180 d_ptr->m_chart->zoomOut();
181 event->accept();
181 event->accept();
182 }
182 }
183 }
183 }
184 else {
184 else {
185 QGraphicsView::mouseReleaseEvent(event);
185 QGraphicsView::mouseReleaseEvent(event);
186 }
186 }
187 }
187 }
188
188
189 /*!
189 /*!
190 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
190 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
191 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
191 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
192 */
192 */
193 void QChartView::keyPressEvent(QKeyEvent *event)
193 void QChartView::keyPressEvent(QKeyEvent *event)
194 {
194 {
195 switch (event->key()) {
195 switch (event->key()) {
196 case Qt::Key_Plus:
196 case Qt::Key_Plus:
197 d_ptr->m_chart->zoomIn();
197 d_ptr->m_chart->zoomIn();
198 break;
198 break;
199 case Qt::Key_Minus:
199 case Qt::Key_Minus:
200 d_ptr->m_chart->zoomOut();
200 d_ptr->m_chart->zoomOut();
201 break;
201 break;
202 case Qt::Key_Left:
202 case Qt::Key_Left:
203 d_ptr->m_chart->scrollLeft();
203 d_ptr->m_chart->scrollLeft();
204 break;
204 break;
205 case Qt::Key_Right:
205 case Qt::Key_Right:
206 d_ptr->m_chart->scrollRight();
206 d_ptr->m_chart->scrollRight();
207 break;
207 break;
208 case Qt::Key_Up:
208 case Qt::Key_Up:
209 d_ptr->m_chart->scrollUp();
209 d_ptr->m_chart->scrollUp();
210 break;
210 break;
211 case Qt::Key_Down:
211 case Qt::Key_Down:
212 d_ptr->m_chart->scrollDown();
212 d_ptr->m_chart->scrollDown();
213 break;
213 break;
214 default:
214 default:
215 QGraphicsView::keyPressEvent(event);
215 QGraphicsView::keyPressEvent(event);
216 break;
216 break;
217 }
217 }
218 }
218 }
219
219
220 /*!
220 /*!
221 Resizes and updates the chart area using the \a event data
221 Resizes and updates the chart area using the \a event data
222 */
222 */
223 void QChartView::resizeEvent(QResizeEvent *event)
223 void QChartView::resizeEvent(QResizeEvent *event)
224 {
224 {
225 QGraphicsView::resizeEvent(event);
225 QGraphicsView::resizeEvent(event);
226 d_ptr->m_chart->resize(size());
226 d_ptr->m_chart->resize(size());
227 setMinimumSize(d_ptr->m_chart->minimumSize().toSize());
227 setMinimumSize(d_ptr->m_chart->minimumSize().toSize());
228 setSceneRect(d_ptr->m_chart->geometry());
228 setSceneRect(d_ptr->m_chart->geometry());
229 }
229 }
230
230
231 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
231 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
232
232
233 QChartViewPrivate::QChartViewPrivate():
233 QChartViewPrivate::QChartViewPrivate():
234 m_scene(0),
234 m_scene(0),
235 m_chart(0),
235 m_chart(0),
236 m_presenter(0),
236 m_presenter(0),
237 m_rubberBand(0),
237 m_rubberBand(0),
238 m_rubberBandFlags(QChartView::NoRubberBand)
238 m_rubberBandFlags(QChartView::NoRubberBand)
239 {
239 {
240
240
241 }
241 }
242
242
243 QChartViewPrivate::~QChartViewPrivate()
243 QChartViewPrivate::~QChartViewPrivate()
244 {
244 {
245
245
246 }
246 }
247
247
248 #include "moc_qchartview.cpp"
248 #include "moc_qchartview.cpp"
249
249
250 QTCOMMERCIALCHART_END_NAMESPACE
250 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,97 +1,97
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qseries.h"
21 #include "qseries.h"
22
22
23 /*!
23 /*!
24 \class QSeries
24 \class QSeries
25 \brief Base class for all QtCommercial Chart series.
25 \brief Base class for all QtCommercial Chart series.
26 \mainclass
26 \mainclass
27
27
28 Usually you use the series type specific inherited classes instead of the base class.
28 Usually you use the series type specific inherited classes instead of the base class.
29 \sa QScatterSeries
29 \sa QScatterSeries
30 */
30 */
31
31
32 /*!
32 /*!
33 \enum QSeries::QSeriesType
33 \enum QSeries::QSeriesType
34
34
35 The type of the series object.
35 The type of the series object.
36
36
37 \value SeriesTypeLine
37 \value SeriesTypeLine
38 \value SeriesTypeArea
38 \value SeriesTypeArea
39 \value SeriesTypeBar
39 \value SeriesTypeBar
40 \value SeriesTypeStackedBar
40 \value SeriesTypeStackedBar
41 \value SeriesTypePercentBar
41 \value SeriesTypePercentBar
42 \value SeriesTypePie
42 \value SeriesTypePie
43 \value SeriesTypeScatter
43 \value SeriesTypeScatter
44 \value SeriesTypeSpline
44 \value SeriesTypeSpline
45 */
45 */
46
46
47 /*!
47 /*!
48 \fn QSeries::QSeries(QObject *parent)
48 \fn QSeries::QSeries(QObject *parent)
49 \brief Constructs ChartSeries object with \a parent.
49 \brief Constructs ChartSeries object with \a parent.
50 */
50 */
51
51
52 /*!
52 /*!
53 \fn QSeries::~QSeries()
53 \fn QSeries::~QSeries()
54 \brief Virtual destructor for the chart series.
54 \brief Virtual destructor for the chart series.
55 */
55 */
56
56
57 /*!
57 /*!
58 \fn QSeriesType QSeries::type() const
58 \fn QSeriesType QSeries::type() const
59 \brief The type of the series.
59 \brief The type of the series.
60 */
60 */
61
61
62 /*!
62 /*!
63 \fn bool QSeries::setModel(QAbstractItemModel *model)
63 \fn bool QSeries::setModel(QAbstractItemModel *model)
64 \brief Use the \a model to provide data for the series. The model overrides possible user data
64 \brief Use the \a model to provide data for the series. The model overrides possible user data
65 set with QChartSeries type specific data setters. For example if you call both
65 set with QChartSeries type specific data setters. For example if you call both
66 QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is
66 QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is
67 used by the series. Returns true if the model is valid for the series.
67 used by the series. Returns true if the model is valid for the series.
68 */
68 */
69
69
70 /*!
70 /*!
71 \fn QAbstractItemModel* QSeries::model() const
71 \fn QAbstractItemModel* QSeries::model() const
72 \brief Returns the pointer to the model that is used as the series data source
72 \brief Returns the pointer to the model that is used as the series data source
73 */
73 */
74
74
75 /*!
75 /*!
76 \property QString QSeries::name
76 \property QSeries::name
77 \brief name of the series property
77 \brief name of the series property
78 */
78 */
79
79
80 /*!
80 /*!
81 \fn void QSeries::setName(QString name)
81 \fn void QSeries::setName(QString name)
82 \brief Sets a \a name for the series.
82 \brief Sets a \a name for the series.
83
83
84 The name of a series is shown in the legend for QXYSeries.
84 The name of a series is shown in the legend for QXYSeries.
85 \sa QChart::setTitle()
85 \sa QChart::setTitle()
86 \sa QPieSlice::setLabel()
86 \sa QPieSlice::setLabel()
87 \sa QBarSet::setName()
87 \sa QBarSet::setName()
88 */
88 */
89
89
90 /*!
90 /*!
91 \fn QString QSeries::name() const
91 \fn QString QSeries::name() const
92 \brief Returns the name of the series.
92 \brief Returns the name of the series.
93 \sa setName()
93 \sa setName()
94 */
94 */
95
95
96 QTCOMMERCIALCHART_USE_NAMESPACE
96 QTCOMMERCIALCHART_USE_NAMESPACE
97 #include "moc_qseries.cpp"
97 #include "moc_qseries.cpp"
@@ -1,72 +1,71
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QSERIES_H
21 #ifndef QSERIES_H
22 #define QSERIES_H
22 #define QSERIES_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QObject>
25 #include <QObject>
26 //#include <QAbstractItemModel>
27 #include <QPen>
26 #include <QPen>
28
27
29 class QAbstractItemModel;
28 class QAbstractItemModel;
30
29
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
31
33 class QTCOMMERCIALCHART_EXPORT QSeries : public QObject
32 class QTCOMMERCIALCHART_EXPORT QSeries : public QObject
34 {
33 {
35 Q_OBJECT
34 Q_OBJECT
36 Q_PROPERTY(QString name READ name WRITE setName)
35 Q_PROPERTY(QString name READ name WRITE setName)
37
36
38 public:
37 public:
39 enum QSeriesType {
38 enum QSeriesType {
40 SeriesTypeLine,
39 SeriesTypeLine,
41 SeriesTypeArea,
40 SeriesTypeArea,
42 SeriesTypeBar,
41 SeriesTypeBar,
43 SeriesTypeStackedBar,
42 SeriesTypeStackedBar,
44 SeriesTypePercentBar,
43 SeriesTypePercentBar,
45 SeriesTypePie,
44 SeriesTypePie,
46 SeriesTypeScatter,
45 SeriesTypeScatter,
47 SeriesTypeSpline
46 SeriesTypeSpline
48 };
47 };
49
48
50 protected:
49 protected:
51 QSeries(QObject *parent = 0) : QObject(parent) {m_model = 0;}
50 QSeries(QObject *parent = 0) : QObject(parent) {m_model = 0;}
52
51
53 public:
52 public:
54 virtual ~QSeries() {}
53 virtual ~QSeries() {}
55 virtual QSeriesType type() const = 0;
54 virtual QSeriesType type() const = 0;
56 // TODO
55 // TODO
57 virtual bool setModel(QAbstractItemModel* /*model*/) { return false; }
56 virtual bool setModel(QAbstractItemModel* /*model*/) { return false; }
58 QAbstractItemModel* model() const { return m_model; }
57 QAbstractItemModel* model() const { return m_model; }
59
58
60 void setName(QString name) { m_name = name; }
59 void setName(QString name) { m_name = name; }
61 QString name() const { return m_name; }
60 QString name() const { return m_name; }
62
61
63 protected:
62 protected:
64 QAbstractItemModel* m_model;
63 QAbstractItemModel* m_model;
65
64
66 private:
65 private:
67 QString m_name;
66 QString m_name;
68 };
67 };
69
68
70 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
71
70
72 #endif
71 #endif
General Comments 0
You need to be logged in to leave comments. Login now