##// END OF EJS Templates
Added chart printing to pdf
Marek Rosa -
r244:615e346403e5
parent child
Show More
@@ -22,10 +22,10 SOURCES += main.cpp\
22
22
23 HEADERS += widget.h
23 HEADERS += widget.h
24
24
25 COPY_DATABASE_COMMAND = "cp gdpData $$CHART_BUILD_BIN_DIR/gdpData"
25 COPY_DATABASE_COMMAND = $$QMAKE_COPY gdpData $$CHART_BUILD_BIN_DIR/gdpData
26
26
27 win32 {
27 win32 {
28 COPY_DATABASE_COMMAND = $$replace(COPY_DATABASE_COMMAND, /,\\)
28 COPY_DATABASE_COMMAND = $$replace(COPY_DATABASE_COMMAND, "/","\\")
29 }
29 }
30
30
31 QMAKE_POST_LINK = $$COPY_DATABASE_COMMAND
31 QMAKE_POST_LINK = $$COPY_DATABASE_COMMAND
@@ -16,6 +16,8
16 #include <qbarcategory.h>
16 #include <qbarcategory.h>
17 #include <qbarset.h>
17 #include <qbarset.h>
18 #include <QListWidget>
18 #include <QListWidget>
19 #include <QPrinter>
20 #include <QPrintDialog>
19
21
20 QTCOMMERCIALCHART_USE_NAMESPACE
22 QTCOMMERCIALCHART_USE_NAMESPACE
21
23
@@ -36,10 +38,14 Widget::Widget(QWidget *parent)
36 QPushButton* refreshButton = new QPushButton(tr("Refresh"));
38 QPushButton* refreshButton = new QPushButton(tr("Refresh"));
37 connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart()));
39 connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart()));
38
40
41 QPushButton* printButton = new QPushButton(tr("Print chart"));
42 connect(printButton, SIGNAL(clicked()), this, SLOT(printChart()));
43
39 QVBoxLayout* rightPanelLayout = new QVBoxLayout;
44 QVBoxLayout* rightPanelLayout = new QVBoxLayout;
40 rightPanelLayout->addWidget(countrieslist);
45 rightPanelLayout->addWidget(countrieslist);
41 rightPanelLayout->addWidget(yearslist);
46 rightPanelLayout->addWidget(yearslist);
42 rightPanelLayout->addWidget(refreshButton);
47 rightPanelLayout->addWidget(refreshButton);
48 rightPanelLayout->addWidget(printButton);
43 rightPanelLayout->setStretch(0, 1);
49 rightPanelLayout->setStretch(0, 1);
44 rightPanelLayout->setStretch(1, 0);
50 rightPanelLayout->setStretch(1, 0);
45
51
@@ -73,7 +79,7 Widget::Widget(QWidget *parent)
73 // hide axis X labels
79 // hide axis X labels
74 QChartAxis* axis = chartArea->axisX();
80 QChartAxis* axis = chartArea->axisX();
75 axis->setLabelsVisible(false);
81 axis->setLabelsVisible(false);
76 // newAxis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide);
82 // newAxis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide);
77
83
78 }
84 }
79
85
@@ -88,7 +94,7 Widget::~Widget()
88 */
94 */
89 void Widget::refreshChart()
95 void Widget::refreshChart()
90 {
96 {
91 // chartArea->
97 // chartArea->
92 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
98 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
93 QStringList selectedCountriesStrings;
99 QStringList selectedCountriesStrings;
94 QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems();
100 QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems();
@@ -126,9 +132,9 void Widget::refreshChart()
126 {
132 {
127 query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery);
133 query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery);
128 QBarSet* barSet = new QBarSet;
134 QBarSet* barSet = new QBarSet;
129 // while (query.next()) {
135 // while (query.next()) {
130 // qDebug() << query.value(0).toString() << " : " << query.value(1).toString();
136 // qDebug() << query.value(0).toString() << " : " << query.value(1).toString();
131 // }
137 // }
132 query.first();
138 query.first();
133
139
134 // the data for some of the coutries for some years might be missing.
140 // the data for some of the coutries for some years might be missing.
@@ -154,3 +160,16 void Widget::refreshChart()
154 // add the serie to the chart
160 // add the serie to the chart
155 chartArea->addSeries(series0);
161 chartArea->addSeries(series0);
156 }
162 }
163
164 void Widget::printChart()
165 {
166 QPrinter printer;
167 // QPrinter printer(QPrinter::HighResolution);
168 printer.setOutputFormat(QPrinter::PdfFormat);
169 printer.setOrientation(QPrinter::Landscape);
170 printer.setOutputFileName("print.pdf");
171
172 QPainter painter;
173 painter.begin(&printer);
174 chartArea->render(&painter);
175 }
@@ -19,6 +19,7 public:
19
19
20 public slots:
20 public slots:
21 void refreshChart();
21 void refreshChart();
22 void printChart();
22
23
23 private:
24 private:
24 QChartView* chartArea;
25 QChartView* chartArea;
General Comments 0
You need to be logged in to leave comments. Login now