From ab751f5c733f3ce4e83923a554897d8a58e2072f 2012-03-28 12:55:32 From: Michal Klocek Date: 2012-03-28 12:55:32 Subject: [PATCH] Combines color,axis,custom into one example --- diff --git a/examples/axischart/axischart.pro b/examples/axischart/axischart.pro deleted file mode 100644 index b13f301..0000000 --- a/examples/axischart/axischart.pro +++ /dev/null @@ -1,8 +0,0 @@ -!include( ../examples.pri ) { - error( "Couldn't find the examples.pri file!" ) -} -TARGET = axischart -SOURCES = main.cpp - - - diff --git a/examples/axischart/main.cpp b/examples/axischart/main.cpp deleted file mode 100644 index 804f48f..0000000 --- a/examples/axischart/main.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -QTCOMMERCIALCHART_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - QMainWindow window; - - QLineSeries* series0 = new QLineSeries(); - QPen blue(Qt::blue); - blue.setWidth(3); - series0->setPen(blue); - - *series0 << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5); - - QChartView* chartView = new QChartView(&window); - - chartView->setRenderHint(QPainter::Antialiasing); - chartView->setChartTitle("Simple axis example"); - chartView->addSeries(series0); - - QLinearGradient backgroundGradient; - backgroundGradient.setColorAt(0.0, Qt::white); - backgroundGradient.setColorAt(1.0, Qt::white); - backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); - chartView->setChartBackgroundBrush(backgroundGradient); - - QChartAxis* axisX = chartView->axisX(); - axisX->setRange(0,10); - axisX->setTicksCount(4); - axisX->setGridLineVisible(true); - axisX->setShadesVisible(false); - - QChartAxis* axisY = chartView->axisY(); - axisY->setRange(0,10); - axisY->setLabelsAngle(45); - axisY->setTicksCount(4); - axisY->setShadesPen(Qt::NoPen); - axisY->setShadesOpacity(0.5); - axisY->setShadesBrush(Qt::blue); - axisY->setGridLineVisible(false); - axisY->setShadesVisible(true); - - QChartAxisCategories* categoriesX = axisX->categories(); - categoriesX->insert(1,"low"); - categoriesX->insert(5,"optimal"); - categoriesX->insert(10,"high"); - - QChartAxisCategories* categoriesY = axisY->categories(); - categoriesY->insert(1,"slow"); - categoriesY->insert(5,"med"); - categoriesY->insert(10,"fast"); - - window.setCentralWidget(chartView); - window.resize(400, 300); - window.show(); - - return a.exec(); -} diff --git a/examples/colorlinechart/colorlinechart.pro b/examples/customchart/customchart.pro similarity index 80% rename from examples/colorlinechart/colorlinechart.pro rename to examples/customchart/customchart.pro index 18415c8..6e40273 100644 --- a/examples/colorlinechart/colorlinechart.pro +++ b/examples/customchart/customchart.pro @@ -2,7 +2,7 @@ error( "Couldn't find the examples.pri file!" ) } -TARGET = colorlinechart +TARGET = customechart SOURCES += main.cpp diff --git a/examples/colorlinechart/main.cpp b/examples/customchart/main.cpp similarity index 77% rename from examples/colorlinechart/main.cpp rename to examples/customchart/main.cpp index 0aa695a..bd14bef 100644 --- a/examples/colorlinechart/main.cpp +++ b/examples/customchart/main.cpp @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) //![1] QLineSeries* series = new QLineSeries(); - QPen blue(Qt::blue); + QPen blue(Qt::yellow); blue.setWidth(3); series->setPen(blue); //![1] @@ -62,34 +62,63 @@ int main(int argc, char *argv[]) //![3] QChart* chart = new QChart(); chart->addSeries(series); - chart->setTitle("Custom colors example"); + chart->setTitle("Simple customchart example"); //![3] //![4] QFont font; font.setPixelSize(18); chart->setTitleFont(font); - chart->setTitleBrush(Qt::red); + chart->setTitleBrush(Qt::yellow); QLinearGradient backgroundGradient; - backgroundGradient.setColorAt(0.0, Qt::lightGray); - backgroundGradient.setColorAt(1.0, Qt::white); + backgroundGradient.setStart(QPointF(0,0)); + backgroundGradient.setFinalStop(QPointF(0,1)); + backgroundGradient.setColorAt(0.0, 0x3cc63c); + backgroundGradient.setColorAt(1.0, 0x26f626); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); chart->setBackgroundBrush(backgroundGradient); - - QPen black(Qt::black); - chart->axisX()->setGridLinePen(black); - chart->axisX()->setAxisPen(black); - chart->axisY()->setGridLinePen(black); - chart->axisY()->setAxisPen(black); //![4] //![5] + QPen black(Qt::black); + QChartAxis* axisX = chart->axisX(); + QChartAxis* axisY = chart->axisY(); + + axisX->setAxisPen(black); + axisY->setAxisPen(black); + axisX->setGridLineVisible(false); + axisY->setGridLineVisible(false); + + axisY->setShadesPen(Qt::NoPen); + axisY->setShadesOpacity(0.5); + axisY->setShadesBrush(Qt::white); + axisY->setShadesVisible(true); +//![5] +//![6] + QChartAxisCategories* categoriesX = chart->axisX()->categories(); + categoriesX->insert(1,"low"); + categoriesX->insert(5,"optimal"); + categoriesX->insert(10,"high"); + + QChartAxisCategories* categoriesY = chart->axisY()->categories(); + categoriesY->insert(1,"slow"); + categoriesY->insert(5,"med"); + categoriesY->insert(10,"fast"); +//![6] +//![7] + axisX->setRange(0,10); + axisX->setTicksCount(4); + axisY->setRange(0,10); + axisY->setTicksCount(4); +//![7] +//![8] QChartView* chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); -//![5] +//![8] +//![9] QMainWindow window; window.setCentralWidget(chartView); window.resize(400, 300); window.show(); -//![5] +//![9] return a.exec(); } diff --git a/examples/customcolors/customcolors.pro b/examples/customcolors/customcolors.pro deleted file mode 100644 index 19154ee..0000000 --- a/examples/customcolors/customcolors.pro +++ /dev/null @@ -1,11 +0,0 @@ -!include( ../examples.pri ) { - error( "Couldn't find the examples.pri file!" ) -} - -TARGET = customcolors -TEMPLATE = app - -SOURCES += main.cpp\ - mainwindow.cpp - -HEADERS += mainwindow.h diff --git a/examples/customcolors/main.cpp b/examples/customcolors/main.cpp deleted file mode 100644 index 9ae175b..0000000 --- a/examples/customcolors/main.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include "mainwindow.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; - w.show(); - - return a.exec(); -} diff --git a/examples/customcolors/mainwindow.cpp b/examples/customcolors/mainwindow.cpp deleted file mode 100644 index 3955597..0000000 --- a/examples/customcolors/mainwindow.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "mainwindow.h" -#include -#include -#include -#include -#include -#include -#include - -QTCOMMERCIALCHART_USE_NAMESPACE - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) -{ - // Here's the set of company's colors used throughout the example - m_companyColor1 = "#b90020"; - m_companyColor2 = "#6d0013"; - m_companyColor3 = "#f5d5d5"; - m_companyColor4 = "#fcfcfc"; - - resize(400, 300); - setWindowFlags(Qt::FramelessWindowHint); - - // Create chart view - //! [4] - m_chartView = new QChartView(this); - m_chartView->setChartTheme(QChart::ChartThemeHighContrast); - //! [4] - setCentralWidget(m_chartView); - m_chartView->setChartTitle("Custom colors example"); - m_chartView->setRenderHint(QPainter::Antialiasing); - - // Create line series - m_line = new QLineSeries(); - m_line->add(0.0, 1.1); - m_line->add(1.0, 2.3); - m_line->add(2.0, 2.1); - m_line->add(3.0, 3.3); - m_chartView->addSeries(m_line); - - // Create scatter series with the same data - m_scatter = new QScatterSeries(); - m_scatter->add(m_line->data()); - m_chartView->addSeries(m_scatter); - - // Create pie series with different data - m_pie = new QPieSeries(); - m_pie->add(1.1, "1"); - m_pie->add(2.1, "2"); - m_pie->add(3.0, "3"); - m_pie->setPiePosition(0.7, 0.7); - m_pie->setPieSize(0.5); - m_chartView->addSeries(m_pie); - - connect(&m_timer, SIGNAL(timeout()), this, SLOT(customize())); - m_timer.setInterval(1500); - m_timer.setSingleShot(false); - m_timer.start(); -} - -MainWindow::~MainWindow() -{ -} - -void MainWindow::customize() -{ - //! [1] - // Use a gradient from "color 3" to "color 4" for chart background - QLinearGradient chartGradient(0, 0, 0, 300); - chartGradient.setColorAt(0.0, m_companyColor3); - chartGradient.setColorAt(0.5, m_companyColor4); - chartGradient.setColorAt(1.0, m_companyColor3); - m_chartView->setChartBackgroundBrush(chartGradient); - m_chartView->setBackgroundBrush(m_companyColor4); - m_chartView->setChartTitleBrush(m_companyColor1); - //! [1] - - //! [2] - QPen color1Pen(m_companyColor1, 4.0); - m_chartView->axisX()->setAxisPen(color1Pen); - m_chartView->axisY()->setAxisPen(color1Pen); - //! [2] - - //! [3] - // Customize pen of the line series - m_line->setPen(color1Pen); - - // Customize pen and brush for the scatter - m_scatter->setPen(color1Pen); - m_scatter->setBrush(m_companyColor3); - - // Customize pen and brush for the pie - for (int i(0); i < m_pie->slices().count(); i++) { - Qt::BrushStyle style = static_cast(i + 1); - m_pie->slices().at(i)->setBrush(QBrush(m_companyColor2, style)); - m_pie->slices().at(i)->setPen(color1Pen); - } - //! [3] - - // Calculate new colors to be used on the next update for the series - m_companyColor1.setRed((m_companyColor1.red() + 25) % 255); - m_companyColor1.setGreen((m_companyColor1.green() + 25) % 255); - m_companyColor1.setBlue((m_companyColor1.blue() + 25) % 255); - m_companyColor2.setRed((m_companyColor2.red() + 25) % 255); - m_companyColor2.setGreen((m_companyColor2.green() + 25) % 255); - m_companyColor2.setBlue((m_companyColor2.blue() + 25) % 255); -} diff --git a/examples/customcolors/mainwindow.h b/examples/customcolors/mainwindow.h deleted file mode 100644 index 394ba97..0000000 --- a/examples/customcolors/mainwindow.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include -#include - -QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QChartView; -class QLineSeries; -class QScatterSeries; -class QPieSeries; -QTCOMMERCIALCHART_END_NAMESPACE - -QTCOMMERCIALCHART_USE_NAMESPACE - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(QWidget *parent = 0); - ~MainWindow(); - -private Q_SLOTS: - void customize(); - -private: - QColor m_companyColor1; - QColor m_companyColor2; - QColor m_companyColor3; - QColor m_companyColor4; - QChartView *m_chartView; - QLineSeries *m_line; - QScatterSeries *m_scatter; - QPieSeries *m_pie; - QTimer m_timer; -}; - -#endif // MAINWINDOW_H diff --git a/examples/examples.pro b/examples/examples.pro index cc22fa3..9906c48 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,11 +1,9 @@ TEMPLATE = subdirs SUBDIRS += \ areachart \ - #axischart \ barchart \ #chartview \ - colorlinechart \ - #customcolors \ + customchart \ #dynamiclinechart \ #ekgchart \ #gdpbarchart \