##// 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 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 27 win32 {
28 COPY_DATABASE_COMMAND = $$replace(COPY_DATABASE_COMMAND, /,\\)
28 COPY_DATABASE_COMMAND = $$replace(COPY_DATABASE_COMMAND, "/","\\")
29 29 }
30 30
31 31 QMAKE_POST_LINK = $$COPY_DATABASE_COMMAND
@@ -16,6 +16,8
16 16 #include <qbarcategory.h>
17 17 #include <qbarset.h>
18 18 #include <QListWidget>
19 #include <QPrinter>
20 #include <QPrintDialog>
19 21
20 22 QTCOMMERCIALCHART_USE_NAMESPACE
21 23
@@ -36,10 +38,14 Widget::Widget(QWidget *parent)
36 38 QPushButton* refreshButton = new QPushButton(tr("Refresh"));
37 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 44 QVBoxLayout* rightPanelLayout = new QVBoxLayout;
40 45 rightPanelLayout->addWidget(countrieslist);
41 46 rightPanelLayout->addWidget(yearslist);
42 47 rightPanelLayout->addWidget(refreshButton);
48 rightPanelLayout->addWidget(printButton);
43 49 rightPanelLayout->setStretch(0, 1);
44 50 rightPanelLayout->setStretch(1, 0);
45 51
@@ -73,7 +79,7 Widget::Widget(QWidget *parent)
73 79 // hide axis X labels
74 80 QChartAxis* axis = chartArea->axisX();
75 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 95 void Widget::refreshChart()
90 96 {
91 // chartArea->
97 // chartArea->
92 98 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
93 99 QStringList selectedCountriesStrings;
94 100 QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems();
@@ -126,9 +132,9 void Widget::refreshChart()
126 132 {
127 133 query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery);
128 134 QBarSet* barSet = new QBarSet;
129 // while (query.next()) {
130 // qDebug() << query.value(0).toString() << " : " << query.value(1).toString();
131 // }
135 // while (query.next()) {
136 // qDebug() << query.value(0).toString() << " : " << query.value(1).toString();
137 // }
132 138 query.first();
133 139
134 140 // the data for some of the coutries for some years might be missing.
@@ -154,3 +160,16 void Widget::refreshChart()
154 160 // add the serie to the chart
155 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 20 public slots:
21 21 void refreshChart();
22 void printChart();
22 23
23 24 private:
24 25 QChartView* chartArea;
General Comments 0
You need to be logged in to leave comments. Login now