@@ -1,44 +1,44 | |||||
1 | #include($QTDIR/compat.qdocconf) |
|
1 | #include($QTDIR/compat.qdocconf) | |
2 | #include($QTDIR/qt-html-templates.qdocconf) |
|
2 | #include($QTDIR/qt-html-templates.qdocconf) | |
3 | #include(C:/Qt/QtCommercialSdk/src/qt/480/tools/qdoc3/doc/files/qt.qdocconf) |
|
3 | #include(C:/Qt/QtCommercialSdk/src/qt/480/tools/qdoc3/doc/files/qt.qdocconf) | |
4 |
|
4 | |||
5 | project = QtCommercialCharts |
|
5 | project = QtCommercialCharts | |
6 | description = Library for creating charts |
|
6 | description = Library for creating charts | |
7 |
|
7 | |||
8 | sourcedirs = ../src \ |
|
8 | sourcedirs = ../src \ | |
9 | ../example |
|
9 | ../example | |
10 | headerdirs = ../src \ |
|
10 | headerdirs = ../src \ | |
11 | ../example |
|
11 | ../example | |
12 | exampledirs = ../src \ |
|
12 | exampledirs = ../src \ | |
13 | ../example |
|
13 | ../example | |
14 |
|
14 | |||
15 | HTML.templatedir = . |
|
15 | HTML.templatedir = . | |
16 | HTML.stylesheets = style/offline.css |
|
16 | HTML.stylesheets = style/offline.css | |
17 | HTML.headerstyles = \ |
|
17 | HTML.headerstyles = \ | |
18 | " <link rel=\"stylesheet\" type=\"text/css\" href=\"style/offline.css\" />\n" |
|
18 | " <link rel=\"stylesheet\" type=\"text/css\" href=\"style/offline.css\" />\n" | |
19 |
sources.fileextensions = |
|
19 | sources.fileextensions = *.cpp *.qdoc *.mm *.qml | |
20 |
headers.fileextensions = |
|
20 | headers.fileextensions = *.h *.ch *.h++ *.hh *.hpp *.hxx | |
21 |
examples.fileextensions = |
|
21 | examples.fileextensions = *.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml | |
22 |
examples.imageextensions = |
|
22 | examples.imageextensions = *.png *.jpeg *.jpg *.gif *.mng | |
23 | imagedirs = ./images |
|
23 | imagedirs = ./images | |
24 | outputdir = ./html |
|
24 | outputdir = ./html | |
25 |
|
25 | |||
26 | Cpp.ignoretokens = QTCOMMERCIALCHART_EXPORT \ |
|
26 | Cpp.ignoretokens = QTCOMMERCIALCHART_EXPORT \ | |
27 | QTCOMMERCIALCHART_END_NAMESPACE \ |
|
27 | QTCOMMERCIALCHART_END_NAMESPACE \ | |
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 | Cpp.ignoredirectives = Q_DECLARE_HANDLE \ |
|
29 | Cpp.ignoredirectives = Q_DECLARE_HANDLE \ | |
30 | Q_DECLARE_INTERFACE \ |
|
30 | Q_DECLARE_INTERFACE \ | |
31 | Q_DECLARE_METATYPE \ |
|
31 | Q_DECLARE_METATYPE \ | |
32 | Q_DECLARE_OPERATORS_FOR_FLAGS \ |
|
32 | Q_DECLARE_OPERATORS_FOR_FLAGS \ | |
33 | Q_DECLARE_PRIVATE \ |
|
33 | Q_DECLARE_PRIVATE \ | |
34 | Q_DECLARE_PUBLIC \ |
|
34 | Q_DECLARE_PUBLIC \ | |
35 | Q_DECLARE_SHARED \ |
|
35 | Q_DECLARE_SHARED \ | |
36 | Q_DECLARE_TR_FUNCTIONS \ |
|
36 | Q_DECLARE_TR_FUNCTIONS \ | |
37 | Q_DECLARE_TYPEINFO \ |
|
37 | Q_DECLARE_TYPEINFO \ | |
38 | Q_DISABLE_COPY \ |
|
38 | Q_DISABLE_COPY \ | |
39 | QT_FORWARD_DECLARE_CLASS \ |
|
39 | QT_FORWARD_DECLARE_CLASS \ | |
40 | Q_DUMMY_COMPARISON_OPERATOR \ |
|
40 | Q_DUMMY_COMPARISON_OPERATOR \ | |
41 | Q_ENUMS \ |
|
41 | Q_ENUMS \ | |
42 | Q_FLAGS \ |
|
42 | Q_FLAGS \ | |
43 | Q_INTERFACES \ |
|
43 | Q_INTERFACES \ | |
44 | __attribute__ No newline at end of file |
|
44 | __attribute__ |
@@ -1,175 +1,176 | |||||
1 | /*! |
|
1 | /*! | |
2 | \class Widget |
|
2 | \class Widget | |
3 | \brief Ui for the application. |
|
3 | \brief Ui for the application. | |
|
4 | \internal | |||
4 | */ |
|
5 | */ | |
5 |
|
6 | |||
6 | #include "widget.h" |
|
7 | #include "widget.h" | |
7 | #include <QGridLayout> |
|
8 | #include <QGridLayout> | |
8 | #include <QPushButton> |
|
9 | #include <QPushButton> | |
9 | #include <QLabel> |
|
10 | #include <QLabel> | |
10 |
|
11 | |||
11 | #include <QSqlQuery> |
|
12 | #include <QSqlQuery> | |
12 | #include <qscatterseries.h> |
|
13 | #include <qscatterseries.h> | |
13 | #include <qchartview.h> |
|
14 | #include <qchartview.h> | |
14 | #include <qchartaxis.h> |
|
15 | #include <qchartaxis.h> | |
15 | #include <qbarchartseries.h> |
|
16 | #include <qbarchartseries.h> | |
16 | #include <qbarcategory.h> |
|
17 | #include <qbarcategory.h> | |
17 | #include <qbarset.h> |
|
18 | #include <qbarset.h> | |
18 | #include <QListWidget> |
|
19 | #include <QListWidget> | |
19 | #include <QPrinter> |
|
20 | #include <QPrinter> | |
20 | #include <QPrintDialog> |
|
21 | #include <QPrintDialog> | |
21 |
|
22 | |||
22 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
23 | QTCOMMERCIALCHART_USE_NAMESPACE | |
23 |
|
24 | |||
24 | Widget::Widget(QWidget *parent) |
|
25 | Widget::Widget(QWidget *parent) | |
25 | : QWidget(parent) |
|
26 | : QWidget(parent) | |
26 | { |
|
27 | { | |
27 | setGeometry(100, 100, 1000, 600); |
|
28 | setGeometry(100, 100, 1000, 600); | |
28 |
|
29 | |||
29 | // right panel layout |
|
30 | // right panel layout | |
30 | countrieslist = new QListWidget; |
|
31 | countrieslist = new QListWidget; | |
31 | countrieslist->setSelectionMode(QAbstractItemView::MultiSelection); |
|
32 | countrieslist->setSelectionMode(QAbstractItemView::MultiSelection); | |
32 |
|
33 | |||
33 | yearslist = new QListWidget; |
|
34 | yearslist = new QListWidget; | |
34 | yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
35 | yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
35 | for (int i = 1990; i < 2011; i++) |
|
36 | for (int i = 1990; i < 2011; i++) | |
36 | yearslist->addItem(QString("%1").arg(i)); |
|
37 | yearslist->addItem(QString("%1").arg(i)); | |
37 |
|
38 | |||
38 | QPushButton* refreshButton = new QPushButton(tr("Refresh")); |
|
39 | QPushButton* refreshButton = new QPushButton(tr("Refresh")); | |
39 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); |
|
40 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); | |
40 |
|
41 | |||
41 | QPushButton* printButton = new QPushButton(tr("Print chart")); |
|
42 | QPushButton* printButton = new QPushButton(tr("Print chart")); | |
42 | connect(printButton, SIGNAL(clicked()), this, SLOT(printChart())); |
|
43 | connect(printButton, SIGNAL(clicked()), this, SLOT(printChart())); | |
43 |
|
44 | |||
44 | QVBoxLayout* rightPanelLayout = new QVBoxLayout; |
|
45 | QVBoxLayout* rightPanelLayout = new QVBoxLayout; | |
45 | rightPanelLayout->addWidget(countrieslist); |
|
46 | rightPanelLayout->addWidget(countrieslist); | |
46 | rightPanelLayout->addWidget(yearslist); |
|
47 | rightPanelLayout->addWidget(yearslist); | |
47 | rightPanelLayout->addWidget(refreshButton); |
|
48 | rightPanelLayout->addWidget(refreshButton); | |
48 | rightPanelLayout->addWidget(printButton); |
|
49 | rightPanelLayout->addWidget(printButton); | |
49 | rightPanelLayout->setStretch(0, 1); |
|
50 | rightPanelLayout->setStretch(0, 1); | |
50 | rightPanelLayout->setStretch(1, 0); |
|
51 | rightPanelLayout->setStretch(1, 0); | |
51 |
|
52 | |||
52 | // main layout |
|
53 | // main layout | |
53 | chartArea = new QChartView(this); |
|
54 | chartArea = new QChartView(this); | |
54 | chartArea->setChartTitle("GDP by country"); |
|
55 | chartArea->setChartTitle("GDP by country"); | |
55 | QGridLayout* mainLayout = new QGridLayout; |
|
56 | QGridLayout* mainLayout = new QGridLayout; | |
56 | mainLayout->addWidget(chartArea, 0, 0); |
|
57 | mainLayout->addWidget(chartArea, 0, 0); | |
57 | mainLayout->addLayout(rightPanelLayout, 0, 1); |
|
58 | mainLayout->addLayout(rightPanelLayout, 0, 1); | |
58 | mainLayout->setColumnStretch(0,1); |
|
59 | mainLayout->setColumnStretch(0,1); | |
59 | setLayout(mainLayout); |
|
60 | setLayout(mainLayout); | |
60 |
|
61 | |||
61 | // connect to the database |
|
62 | // connect to the database | |
62 | db = QSqlDatabase::addDatabase("QSQLITE"); |
|
63 | db = QSqlDatabase::addDatabase("QSQLITE"); | |
63 | db.setDatabaseName("gdpData"); |
|
64 | db.setDatabaseName("gdpData"); | |
64 | if(!db.open()) |
|
65 | if(!db.open()) | |
65 | { |
|
66 | { | |
66 | qDebug() << "could not open database. SQLite db file missing (?)"; |
|
67 | qDebug() << "could not open database. SQLite db file missing (?)"; | |
67 | return; |
|
68 | return; | |
68 | } |
|
69 | } | |
69 |
|
70 | |||
70 | // get the list of all countires and regions. |
|
71 | // get the list of all countires and regions. | |
71 | QSqlQuery query; |
|
72 | QSqlQuery query; | |
72 | query.exec("SELECT DISTINCT country FROM gdp2"); |
|
73 | query.exec("SELECT DISTINCT country FROM gdp2"); | |
73 |
|
74 | |||
74 | // add the countries to the country filter |
|
75 | // add the countries to the country filter | |
75 | while (query.next()) { |
|
76 | while (query.next()) { | |
76 | countrieslist->addItem(query.value(0).toString()); |
|
77 | countrieslist->addItem(query.value(0).toString()); | |
77 | } |
|
78 | } | |
78 |
|
79 | |||
79 | // hide axis X labels |
|
80 | // hide axis X labels | |
80 | QChartAxis* axis = chartArea->axisX(); |
|
81 | QChartAxis* axis = chartArea->axisX(); | |
81 | axis->setLabelsVisible(false); |
|
82 | axis->setLabelsVisible(false); | |
82 | // newAxis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); |
|
83 | // newAxis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); | |
83 |
|
84 | |||
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | Widget::~Widget() |
|
87 | Widget::~Widget() | |
87 | { |
|
88 | { | |
88 | // |
|
89 | // | |
89 | db.close(); |
|
90 | db.close(); | |
90 | } |
|
91 | } | |
91 |
|
92 | |||
92 | /*! |
|
93 | /*! | |
93 | refreshes the chart |
|
94 | refreshes the chart | |
94 | */ |
|
95 | */ | |
95 | void Widget::refreshChart() |
|
96 | void Widget::refreshChart() | |
96 | { |
|
97 | { | |
97 | // chartArea-> |
|
98 | // chartArea-> | |
98 | // selected countries items list is not sorted. copy the values to QStringlist and sort them. |
|
99 | // selected countries items list is not sorted. copy the values to QStringlist and sort them. | |
99 | QStringList selectedCountriesStrings; |
|
100 | QStringList selectedCountriesStrings; | |
100 | QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems(); |
|
101 | QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems(); | |
101 | for (int i = 0; i < selectedCountriesItems.size(); i++) |
|
102 | for (int i = 0; i < selectedCountriesItems.size(); i++) | |
102 | selectedCountriesStrings.append(selectedCountriesItems[i]->text()); |
|
103 | selectedCountriesStrings.append(selectedCountriesItems[i]->text()); | |
103 | selectedCountriesStrings.sort(); |
|
104 | selectedCountriesStrings.sort(); | |
104 |
|
105 | |||
105 | // use the sorted selected coutries list to initialize BarCategory |
|
106 | // use the sorted selected coutries list to initialize BarCategory | |
106 | QBarCategory* category = new QBarCategory; |
|
107 | QBarCategory* category = new QBarCategory; | |
107 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
108 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
108 | *category << selectedCountriesStrings[i]; |
|
109 | *category << selectedCountriesStrings[i]; | |
109 | QBarChartSeries* series0 = new QBarChartSeries(category); |
|
110 | QBarChartSeries* series0 = new QBarChartSeries(category); | |
110 |
|
111 | |||
111 | // prepare the selected counries SQL query |
|
112 | // prepare the selected counries SQL query | |
112 | QString countriesQuery = "country IN ("; |
|
113 | QString countriesQuery = "country IN ("; | |
113 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
114 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
114 | { |
|
115 | { | |
115 | countriesQuery.append("'" + selectedCountriesStrings[i] + "'"); |
|
116 | countriesQuery.append("'" + selectedCountriesStrings[i] + "'"); | |
116 | if ( i < selectedCountriesStrings.size() - 1) |
|
117 | if ( i < selectedCountriesStrings.size() - 1) | |
117 | countriesQuery.append(","); |
|
118 | countriesQuery.append(","); | |
118 | else |
|
119 | else | |
119 | countriesQuery.append(")"); |
|
120 | countriesQuery.append(")"); | |
120 | } |
|
121 | } | |
121 |
|
122 | |||
122 | QSqlQuery query; |
|
123 | QSqlQuery query; | |
123 | // selected years items list is not sorted. copy the values to QList<Integer> and sort them. |
|
124 | // selected years items list is not sorted. copy the values to QList<Integer> and sort them. | |
124 | QList<int> selectedYearsInts; |
|
125 | QList<int> selectedYearsInts; | |
125 | QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems(); |
|
126 | QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems(); | |
126 | for (int i = 0; i < selectedYearsItems.size(); i++) |
|
127 | for (int i = 0; i < selectedYearsItems.size(); i++) | |
127 | selectedYearsInts.append(selectedYearsItems[i]->text().toInt()); |
|
128 | selectedYearsInts.append(selectedYearsItems[i]->text().toInt()); | |
128 | qSort(selectedYearsInts); |
|
129 | qSort(selectedYearsInts); | |
129 |
|
130 | |||
130 | // perform a query for each selected year |
|
131 | // perform a query for each selected year | |
131 | for (int i = 0; i < selectedYearsInts.size(); i++) |
|
132 | for (int i = 0; i < selectedYearsInts.size(); i++) | |
132 | { |
|
133 | { | |
133 | query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); |
|
134 | query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); | |
134 | QBarSet* barSet = new QBarSet; |
|
135 | QBarSet* barSet = new QBarSet; | |
135 | // while (query.next()) { |
|
136 | // while (query.next()) { | |
136 | // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); |
|
137 | // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); | |
137 | // } |
|
138 | // } | |
138 | query.first(); |
|
139 | query.first(); | |
139 |
|
140 | |||
140 | // the data for some of the coutries for some years might be missing. |
|
141 | // the data for some of the coutries for some years might be missing. | |
141 | // QBarChart needs bars to have same size |
|
142 | // QBarChart needs bars to have same size | |
142 | for (int k = 0; k < selectedCountriesStrings.size(); k++) |
|
143 | for (int k = 0; k < selectedCountriesStrings.size(); k++) | |
143 | { |
|
144 | { | |
144 | if (selectedCountriesStrings[k] == query.value(0).toString()) |
|
145 | if (selectedCountriesStrings[k] == query.value(0).toString()) | |
145 | { |
|
146 | { | |
146 | *barSet << query.value(1).toReal(); |
|
147 | *barSet << query.value(1).toReal(); | |
147 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
148 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]); | |
148 | query.next(); |
|
149 | query.next(); | |
149 | } |
|
150 | } | |
150 | else |
|
151 | else | |
151 | { |
|
152 | { | |
152 | // data missing, put 0 |
|
153 | // data missing, put 0 | |
153 | *barSet << 0.0f; |
|
154 | *barSet << 0.0f; | |
154 | qDebug() << "Putting 0 for Bosnia" << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
155 | qDebug() << "Putting 0 for Bosnia" << " : " << QString("%1").arg(selectedYearsInts[i]); | |
155 | } |
|
156 | } | |
156 | } |
|
157 | } | |
157 | series0->addBarSet(barSet); |
|
158 | series0->addBarSet(barSet); | |
158 | } |
|
159 | } | |
159 |
|
160 | |||
160 | // add the serie to the chart |
|
161 | // add the serie to the chart | |
161 | chartArea->addSeries(series0); |
|
162 | chartArea->addSeries(series0); | |
162 | } |
|
163 | } | |
163 |
|
164 | |||
164 | void Widget::printChart() |
|
165 | void Widget::printChart() | |
165 | { |
|
166 | { | |
166 | QPrinter printer; |
|
167 | QPrinter printer; | |
167 | // QPrinter printer(QPrinter::HighResolution); |
|
168 | // QPrinter printer(QPrinter::HighResolution); | |
168 | printer.setOutputFormat(QPrinter::PdfFormat); |
|
169 | printer.setOutputFormat(QPrinter::PdfFormat); | |
169 | printer.setOrientation(QPrinter::Landscape); |
|
170 | printer.setOrientation(QPrinter::Landscape); | |
170 | printer.setOutputFileName("print.pdf"); |
|
171 | printer.setOutputFileName("print.pdf"); | |
171 |
|
172 | |||
172 | QPainter painter; |
|
173 | QPainter painter; | |
173 | painter.begin(&printer); |
|
174 | painter.begin(&printer); | |
174 | chartArea->render(&painter); |
|
175 | chartArea->render(&painter); | |
175 | } |
|
176 | } |
@@ -1,161 +1,184 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QGraphicsSceneResizeEvent> |
|
6 | #include <QGraphicsSceneResizeEvent> | |
7 | #include <QDebug> |
|
7 | #include <QDebug> | |
8 |
|
8 | |||
|
9 | /*! | |||
|
10 | \class QChart | |||
|
11 | \brief QtCommercial chart API. | |||
|
12 | ||||
|
13 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |||
|
14 | representation of different types of QChartSeries and other chart related objects like | |||
|
15 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |||
|
16 | convenience class QChartView instead of QChart. | |||
|
17 | */ | |||
|
18 | ||||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
20 | |||
|
21 | /*! | |||
|
22 | Constructs a chart object which is a child of parent. | |||
|
23 | */ | |||
11 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
24 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
12 | m_backgroundItem(0), |
|
25 | m_backgroundItem(0), | |
13 | m_titleItem(0), |
|
26 | m_titleItem(0), | |
14 | m_dataset(new ChartDataSet(this)), |
|
27 | m_dataset(new ChartDataSet(this)), | |
15 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
28 | m_presenter(new ChartPresenter(this,m_dataset)) | |
16 | { |
|
29 | { | |
17 | } |
|
30 | } | |
18 |
|
31 | |||
19 | QChart::~QChart() {} |
|
32 | /*! | |
|
33 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |||
|
34 | */ | |||
|
35 | QChart::~QChart() | |||
|
36 | { | |||
|
37 | } | |||
20 |
|
38 | |||
21 | void QChart::addSeries(QChartSeries* series,QChartAxis* axisY) |
|
39 | /*! | |
|
40 | Adds the series and optional y axis onto the chart and takes the ownership of the objects. | |||
|
41 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |||
|
42 | the y axis). | |||
|
43 | */ | |||
|
44 | void QChart::addSeries(QChartSeries* series, QChartAxis* axisY) | |||
22 | { |
|
45 | { | |
23 | m_dataset->addSeries(series,axisY); |
|
46 | m_dataset->addSeries(series, axisY); | |
24 | } |
|
47 | } | |
25 |
|
48 | |||
26 | void QChart::removeSeries(QChartSeries* series) |
|
49 | void QChart::removeSeries(QChartSeries* series) | |
27 | { |
|
50 | { | |
28 | m_dataset->removeSeries(series); |
|
51 | m_dataset->removeSeries(series); | |
29 | } |
|
52 | } | |
30 |
|
53 | |||
31 | void QChart::removeAllSeries() |
|
54 | void QChart::removeAllSeries() | |
32 | { |
|
55 | { | |
33 | m_dataset->removeAllSeries(); |
|
56 | m_dataset->removeAllSeries(); | |
34 | } |
|
57 | } | |
35 |
|
58 | |||
36 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
59 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
37 | { |
|
60 | { | |
38 | createChartBackgroundItem(); |
|
61 | createChartBackgroundItem(); | |
39 | m_backgroundItem->setBrush(brush); |
|
62 | m_backgroundItem->setBrush(brush); | |
40 | m_backgroundItem->update(); |
|
63 | m_backgroundItem->update(); | |
41 | } |
|
64 | } | |
42 |
|
65 | |||
43 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
66 | void QChart::setChartBackgroundPen(const QPen& pen) | |
44 | { |
|
67 | { | |
45 | createChartBackgroundItem(); |
|
68 | createChartBackgroundItem(); | |
46 | m_backgroundItem->setPen(pen); |
|
69 | m_backgroundItem->setPen(pen); | |
47 | m_backgroundItem->update(); |
|
70 | m_backgroundItem->update(); | |
48 | } |
|
71 | } | |
49 |
|
72 | |||
50 | void QChart::setChartTitle(const QString& title) |
|
73 | void QChart::setChartTitle(const QString& title) | |
51 | { |
|
74 | { | |
52 | createChartTitleItem(); |
|
75 | createChartTitleItem(); | |
53 | m_titleItem->setPlainText(title); |
|
76 | m_titleItem->setPlainText(title); | |
54 | } |
|
77 | } | |
55 |
|
78 | |||
56 | void QChart::setChartTitleFont(const QFont& font) |
|
79 | void QChart::setChartTitleFont(const QFont& font) | |
57 | { |
|
80 | { | |
58 | createChartTitleItem(); |
|
81 | createChartTitleItem(); | |
59 | m_titleItem->setFont(font); |
|
82 | m_titleItem->setFont(font); | |
60 | } |
|
83 | } | |
61 |
|
84 | |||
62 | void QChart::createChartBackgroundItem() |
|
85 | void QChart::createChartBackgroundItem() | |
63 | { |
|
86 | { | |
64 | if(!m_backgroundItem) { |
|
87 | if(!m_backgroundItem) { | |
65 | m_backgroundItem = new QGraphicsRectItem(this); |
|
88 | m_backgroundItem = new QGraphicsRectItem(this); | |
66 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
89 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
67 | } |
|
90 | } | |
68 | } |
|
91 | } | |
69 |
|
92 | |||
70 | void QChart::createChartTitleItem() |
|
93 | void QChart::createChartTitleItem() | |
71 | { |
|
94 | { | |
72 | if(!m_titleItem) { |
|
95 | if(!m_titleItem) { | |
73 | m_titleItem = new QGraphicsTextItem(this); |
|
96 | m_titleItem = new QGraphicsTextItem(this); | |
74 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
97 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
75 | } |
|
98 | } | |
76 | } |
|
99 | } | |
77 |
|
100 | |||
78 | int QChart::margin() const |
|
101 | int QChart::margin() const | |
79 | { |
|
102 | { | |
80 | return m_presenter->margin(); |
|
103 | return m_presenter->margin(); | |
81 | } |
|
104 | } | |
82 |
|
105 | |||
83 | void QChart::setMargin(int margin) |
|
106 | void QChart::setMargin(int margin) | |
84 | { |
|
107 | { | |
85 | m_presenter->setMargin(margin); |
|
108 | m_presenter->setMargin(margin); | |
86 | } |
|
109 | } | |
87 |
|
110 | |||
88 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
111 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
89 | { |
|
112 | { | |
90 | m_presenter->setChartTheme(theme); |
|
113 | m_presenter->setChartTheme(theme); | |
91 | } |
|
114 | } | |
92 |
|
115 | |||
93 | QChart::ChartTheme QChart::chartTheme() const |
|
116 | QChart::ChartTheme QChart::chartTheme() const | |
94 | { |
|
117 | { | |
95 | return m_presenter->chartTheme(); |
|
118 | return m_presenter->chartTheme(); | |
96 | } |
|
119 | } | |
97 |
|
120 | |||
98 | void QChart::zoomIn() |
|
121 | void QChart::zoomIn() | |
99 | { |
|
122 | { | |
100 | if (!m_dataset->nextDomain()) { |
|
123 | if (!m_dataset->nextDomain()) { | |
101 | QRectF rect = m_presenter->geometry(); |
|
124 | QRectF rect = m_presenter->geometry(); | |
102 | rect.setWidth(rect.width()/2); |
|
125 | rect.setWidth(rect.width()/2); | |
103 | rect.setHeight(rect.height()/2); |
|
126 | rect.setHeight(rect.height()/2); | |
104 | rect.moveCenter(m_presenter->geometry().center()); |
|
127 | rect.moveCenter(m_presenter->geometry().center()); | |
105 | zoomIn(rect); |
|
128 | zoomIn(rect); | |
106 | } |
|
129 | } | |
107 | } |
|
130 | } | |
108 |
|
131 | |||
109 | void QChart::zoomIn(const QRectF& rect) |
|
132 | void QChart::zoomIn(const QRectF& rect) | |
110 | { |
|
133 | { | |
111 | if(!rect.isValid()) return; |
|
134 | if(!rect.isValid()) return; | |
112 | QRectF r = rect.normalized(); |
|
135 | QRectF r = rect.normalized(); | |
113 | int margin = m_presenter->margin(); |
|
136 | int margin = m_presenter->margin(); | |
114 | r.translate(-margin, -margin); |
|
137 | r.translate(-margin, -margin); | |
115 | m_dataset->addDomain(r,m_presenter->geometry()); |
|
138 | m_dataset->addDomain(r,m_presenter->geometry()); | |
116 | } |
|
139 | } | |
117 |
|
140 | |||
118 | void QChart::zoomOut() |
|
141 | void QChart::zoomOut() | |
119 | { |
|
142 | { | |
120 | m_dataset->previousDomain(); |
|
143 | m_dataset->previousDomain(); | |
121 | } |
|
144 | } | |
122 |
|
145 | |||
123 | void QChart::zoomReset() |
|
146 | void QChart::zoomReset() | |
124 | { |
|
147 | { | |
125 | m_dataset->clearDomains(); |
|
148 | m_dataset->clearDomains(); | |
126 | } |
|
149 | } | |
127 |
|
150 | |||
128 | QChartAxis* QChart::axisX() const |
|
151 | QChartAxis* QChart::axisX() const | |
129 | { |
|
152 | { | |
130 | return m_dataset->axisX(); |
|
153 | return m_dataset->axisX(); | |
131 | } |
|
154 | } | |
132 |
|
155 | |||
133 | QChartAxis* QChart::axisY() const |
|
156 | QChartAxis* QChart::axisY() const | |
134 | { |
|
157 | { | |
135 | return m_dataset->axisY(); |
|
158 | return m_dataset->axisY(); | |
136 | } |
|
159 | } | |
137 |
|
160 | |||
138 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
161 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
139 | { |
|
162 | { | |
140 |
|
163 | |||
141 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
164 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
142 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
165 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
143 |
|
166 | |||
144 | // recalculate title position |
|
167 | // recalculate title position | |
145 | if (m_titleItem) { |
|
168 | if (m_titleItem) { | |
146 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
169 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
147 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
170 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
148 | } |
|
171 | } | |
149 |
|
172 | |||
150 | //recalculate background gradient |
|
173 | //recalculate background gradient | |
151 | if (m_backgroundItem) { |
|
174 | if (m_backgroundItem) { | |
152 | m_backgroundItem->setRect(rect); |
|
175 | m_backgroundItem->setRect(rect); | |
153 | } |
|
176 | } | |
154 |
|
177 | |||
155 | QGraphicsWidget::resizeEvent(event); |
|
178 | QGraphicsWidget::resizeEvent(event); | |
156 | update(); |
|
179 | update(); | |
157 | } |
|
180 | } | |
158 |
|
181 | |||
159 | #include "moc_qchart.cpp" |
|
182 | #include "moc_qchart.cpp" | |
160 |
|
183 | |||
161 | QTCOMMERCIALCHART_END_NAMESPACE |
|
184 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,85 +1,82 | |||||
1 | #ifndef CHART_H |
|
1 | #ifndef QCHART_H | |
2 | #define CHART_H |
|
2 | #define QCHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartseries.h> |
|
5 | #include <qchartseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QChartSeries; |
|
15 | class QChartSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarPresenter; |
|
17 | class BarPresenter; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 |
|
23 | |||
24 | /*! |
|
|||
25 | * TODO: define the responsibilities |
|
|||
26 | */ |
|
|||
27 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
24 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
28 | { |
|
25 | { | |
29 | Q_OBJECT |
|
26 | Q_OBJECT | |
30 | public: |
|
27 | public: | |
31 | enum ChartTheme { |
|
28 | enum ChartTheme { | |
32 | /*! The default theme follows the GUI style of the Operating System */ |
|
29 | /*! The default theme follows the GUI style of the Operating System */ | |
33 | ChartThemeDefault, |
|
30 | ChartThemeDefault, | |
34 | ChartThemeVanilla, |
|
31 | ChartThemeVanilla, | |
35 | ChartThemeIcy, |
|
32 | ChartThemeIcy, | |
36 | ChartThemeGrayscale, |
|
33 | ChartThemeGrayscale, | |
37 |
ChartThemeScientific |
|
34 | ChartThemeScientific | |
38 | //ChartThemeUnnamed1 |
|
35 | //ChartThemeUnnamed1 | |
39 | }; |
|
36 | }; | |
40 |
|
37 | |||
41 | public: |
|
38 | public: | |
42 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
39 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
43 | ~QChart(); |
|
40 | ~QChart(); | |
44 |
|
41 | |||
45 |
void addSeries(QChartSeries* series,QChartAxis* axisY=0); |
|
42 | void addSeries(QChartSeries* series, QChartAxis* axisY = 0); | |
46 | void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached |
|
43 | void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached | |
47 | void removeAllSeries(); // deletes series and axis |
|
44 | void removeAllSeries(); // deletes series and axis | |
48 |
|
45 | |||
49 | void setMargin(int margin); |
|
46 | void setMargin(int margin); | |
50 | int margin() const; |
|
47 | int margin() const; | |
51 | void setChartTheme(QChart::ChartTheme theme); |
|
48 | void setChartTheme(QChart::ChartTheme theme); | |
52 | QChart::ChartTheme chartTheme() const; |
|
49 | QChart::ChartTheme chartTheme() const; | |
53 |
|
50 | |||
54 | void setChartTitle(const QString& title); |
|
51 | void setChartTitle(const QString& title); | |
55 | void setChartTitleFont(const QFont& font); |
|
52 | void setChartTitleFont(const QFont& font); | |
56 | void setChartBackgroundBrush(const QBrush& brush); |
|
53 | void setChartBackgroundBrush(const QBrush& brush); | |
57 | void setChartBackgroundPen(const QPen& pen); |
|
54 | void setChartBackgroundPen(const QPen& pen); | |
58 |
|
55 | |||
59 | void zoomIn(); |
|
56 | void zoomIn(); | |
60 | void zoomIn(const QRectF& rect); |
|
57 | void zoomIn(const QRectF& rect); | |
61 | void zoomOut(); |
|
58 | void zoomOut(); | |
62 | void zoomReset(); |
|
59 | void zoomReset(); | |
63 |
|
60 | |||
64 | QChartAxis* axisX() const; |
|
61 | QChartAxis* axisX() const; | |
65 | QChartAxis* axisY() const; |
|
62 | QChartAxis* axisY() const; | |
66 |
|
63 | |||
67 | protected: |
|
64 | protected: | |
68 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
65 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
69 |
|
66 | |||
70 | private: |
|
67 | private: | |
71 | inline void createChartBackgroundItem(); |
|
68 | inline void createChartBackgroundItem(); | |
72 | inline void createChartTitleItem(); |
|
69 | inline void createChartTitleItem(); | |
73 |
|
70 | |||
74 | private: |
|
71 | private: | |
75 | Q_DISABLE_COPY(QChart) |
|
72 | Q_DISABLE_COPY(QChart) | |
76 | QGraphicsRectItem* m_backgroundItem; |
|
73 | QGraphicsRectItem* m_backgroundItem; | |
77 | QGraphicsTextItem* m_titleItem; |
|
74 | QGraphicsTextItem* m_titleItem; | |
78 | QRectF m_rect; |
|
75 | QRectF m_rect; | |
79 | ChartDataSet *m_dataset; |
|
76 | ChartDataSet *m_dataset; | |
80 | ChartPresenter *m_presenter; |
|
77 | ChartPresenter *m_presenter; | |
81 | }; |
|
78 | }; | |
82 |
|
79 | |||
83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
80 | QTCOMMERCIALCHART_END_NAMESPACE | |
84 |
|
81 | |||
85 | #endif |
|
82 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now