diff --git a/example/gdpbarchart/gdpbarchart.pro b/example/gdpbarchart/gdpbarchart.pro index b31d903..10aa172 100644 --- a/example/gdpbarchart/gdpbarchart.pro +++ b/example/gdpbarchart/gdpbarchart.pro @@ -22,10 +22,10 @@ SOURCES += main.cpp\ HEADERS += widget.h -COPY_DATABASE_COMMAND = "cp gdpData $$CHART_BUILD_BIN_DIR/gdpData" +COPY_DATABASE_COMMAND = $$QMAKE_COPY gdpData $$CHART_BUILD_BIN_DIR/gdpData win32 { - COPY_DATABASE_COMMAND = $$replace(COPY_DATABASE_COMMAND, /,\\) + COPY_DATABASE_COMMAND = $$replace(COPY_DATABASE_COMMAND, "/","\\") } QMAKE_POST_LINK = $$COPY_DATABASE_COMMAND diff --git a/example/gdpbarchart/widget.cpp b/example/gdpbarchart/widget.cpp index 19c1c05..1cd0280 100644 --- a/example/gdpbarchart/widget.cpp +++ b/example/gdpbarchart/widget.cpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -36,10 +38,14 @@ Widget::Widget(QWidget *parent) QPushButton* refreshButton = new QPushButton(tr("Refresh")); connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); + QPushButton* printButton = new QPushButton(tr("Print chart")); + connect(printButton, SIGNAL(clicked()), this, SLOT(printChart())); + QVBoxLayout* rightPanelLayout = new QVBoxLayout; rightPanelLayout->addWidget(countrieslist); rightPanelLayout->addWidget(yearslist); rightPanelLayout->addWidget(refreshButton); + rightPanelLayout->addWidget(printButton); rightPanelLayout->setStretch(0, 1); rightPanelLayout->setStretch(1, 0); @@ -73,7 +79,7 @@ Widget::Widget(QWidget *parent) // hide axis X labels QChartAxis* axis = chartArea->axisX(); axis->setLabelsVisible(false); -// newAxis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); + // newAxis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); } @@ -88,7 +94,7 @@ Widget::~Widget() */ void Widget::refreshChart() { -// chartArea-> + // chartArea-> // selected countries items list is not sorted. copy the values to QStringlist and sort them. QStringList selectedCountriesStrings; QList selectedCountriesItems = countrieslist->selectedItems(); @@ -126,9 +132,9 @@ void Widget::refreshChart() { query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); QBarSet* barSet = new QBarSet; -// while (query.next()) { -// qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); -// } + // while (query.next()) { + // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); + // } query.first(); // the data for some of the coutries for some years might be missing. @@ -154,3 +160,16 @@ void Widget::refreshChart() // add the serie to the chart chartArea->addSeries(series0); } + +void Widget::printChart() +{ + QPrinter printer; +// QPrinter printer(QPrinter::HighResolution); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOrientation(QPrinter::Landscape); + printer.setOutputFileName("print.pdf"); + + QPainter painter; + painter.begin(&printer); + chartArea->render(&painter); +} diff --git a/example/gdpbarchart/widget.h b/example/gdpbarchart/widget.h index fe2b1f1..205d216 100644 --- a/example/gdpbarchart/widget.h +++ b/example/gdpbarchart/widget.h @@ -19,6 +19,7 @@ public: public slots: void refreshChart(); + void printChart(); private: QChartView* chartArea;