diff --git a/charts.pro b/charts.pro index e19590a..ea9ae0c 100644 --- a/charts.pro +++ b/charts.pro @@ -3,7 +3,7 @@ } TEMPLATE = subdirs -SUBDIRS += src examples test qmlplugin +SUBDIRS += src examples demos test qmlplugin integrated_build:{ message('Configured for integrated build') diff --git a/demos/chartthemes/chartthemes.pro b/demos/chartthemes/chartthemes.pro new file mode 100644 index 0000000..24a33ef --- /dev/null +++ b/demos/chartthemes/chartthemes.pro @@ -0,0 +1,7 @@ +!include( ../demos.pri ) { + error( "Couldn't find the examples.pri file!" ) +} +TARGET = chartthemes +SOURCES += main.cpp + + diff --git a/demos/chartthemes/main.cpp b/demos/chartthemes/main.cpp new file mode 100644 index 0000000..b9019eb --- /dev/null +++ b/demos/chartthemes/main.cpp @@ -0,0 +1,180 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QTCOMMERCIALCHART_USE_NAMESPACE + +typedef QPair Data; +typedef QList DataList; +typedef QList DataTable; + + +class MainWidget : public QWidget +{ + Q_OBJECT + +public: + explicit MainWidget(QWidget* parent = 0) + :QWidget(parent) + { + // set seed for random stuff + qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); + + // generate random data + int listCount = 3; + int valueMax = 100; + int valueCount = 50; + for (int i=0; iaddItem("Default", QChart::ChartThemeDefault); + m_themeComboBox->addItem("Vanilla", QChart::ChartThemeVanilla); + m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy); + m_themeComboBox->addItem("Grayscale", QChart::ChartThemeGrayscale); + m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific); + connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateTheme())); + baseLayout->addWidget(new QLabel("Theme:"), 0, 0); + baseLayout->addWidget(m_themeComboBox, 0, 1); + + // area chart + QChartView *chart = new QChartView(); + chart->setChartTitle("Area chart"); + chart->setRenderHint(QPainter::Antialiasing); + baseLayout->addWidget(chart, 1, 0); + { + QLineSeries *series1 = new QLineSeries(chart); + foreach (Data data, m_dataTable.first()) + series1->add(data.first); + QLineSeries *series2 = new QLineSeries(chart); + foreach (Data data, m_dataTable.last()) + series2->add(data.first); + QAreaSeries *series = new QAreaSeries(series1, series2); + chart->addSeries(series); + } + m_charts << chart; + + // bar chart + chart = new QChartView(); + chart->setChartTitle("bar chart"); + chart->setRenderHint(QPainter::Antialiasing); + baseLayout->addWidget(chart, 1, 1); + m_charts << chart; + + // line chart + chart = new QChartView(); + chart->setChartTitle("line chart"); + chart->setRenderHint(QPainter::Antialiasing); + baseLayout->addWidget(chart, 1, 2); + foreach (DataList list, m_dataTable) { + QLineSeries *series = new QLineSeries(chart); + foreach (Data data, list) + series->add(data.first); + chart->addSeries(series); + } + m_charts << chart; + + // pie chart + chart = new QChartView(); + chart->setChartTitle("pie chart"); + chart->setRenderHint(QPainter::Antialiasing); + baseLayout->addWidget(chart, 2, 0); + + qreal pieSize = 1.0 / m_dataTable.count(); + for (int i=0; iadd(data.first.x(), data.second); + qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); + series->setPieSize(pieSize); + series->setPiePosition(hPos, 0.5); + chart->addSeries(series); + } + m_charts << chart; + + // spine chart + chart = new QChartView(); + chart->setChartTitle("spline chart"); + chart->setRenderHint(QPainter::Antialiasing); + baseLayout->addWidget(chart, 2, 1); + foreach (DataList list, m_dataTable) { + QSplineSeries *series = new QSplineSeries(chart); + foreach (Data data, list) + series->add(data.first); + chart->addSeries(series); + } + m_charts << chart; + + // scatter chart + chart = new QChartView(); + chart->setChartTitle("scatter chart"); + chart->setRenderHint(QPainter::Antialiasing); + baseLayout->addWidget(chart, 2, 2); + foreach (DataList list, m_dataTable) { + QScatterSeries *series = new QScatterSeries(chart); + foreach (Data data, list) + series->add(data.first); + chart->addSeries(series); + } + m_charts << chart; + + setLayout(baseLayout); + } + +public Q_SLOTS: + + void updateTheme() + { + QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); + foreach (QChartView *chart, m_charts) + chart->setChartTheme(theme); + } + +private: + QList m_charts; + QComboBox *m_themeComboBox; + DataTable m_dataTable; +}; + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QMainWindow window; + + MainWidget* widget = new MainWidget(); + + window.setCentralWidget(widget); + window.resize(900, 600); + window.show(); + + return a.exec(); +} + +#include "main.moc" diff --git a/demos/demos.pri b/demos/demos.pri new file mode 100644 index 0000000..53fbe14 --- /dev/null +++ b/demos/demos.pri @@ -0,0 +1,16 @@ +!include( ../common.pri ) { + error( "Couldn't find the common.pri file!" ) +} + +!include( ../integrated.pri ) { + error( "Couldn't find the integrated.pri file !") +} + +DESTDIR = $$CHART_BUILD_BIN_DIR +OBJECTS_DIR = $$CHART_BUILD_DIR/bin/$$TARGET +MOC_DIR = $$CHART_BUILD_DIR/bin/$$TARGET +UI_DIR = $$CHART_BUILD_DIR/bin/$$TARGET +RCC_DIR = $$CHART_BUILD_DIR/bin/$$TARGET + +TEMPLATE = app +QT += core gui \ No newline at end of file diff --git a/demos/demos.pro b/demos/demos.pro new file mode 100644 index 0000000..d9c428d --- /dev/null +++ b/demos/demos.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS += chartthemes \ + piechartcustomization \ No newline at end of file diff --git a/examples/piechartcustomization/main.cpp b/demos/piechartcustomization/main.cpp similarity index 100% rename from examples/piechartcustomization/main.cpp rename to demos/piechartcustomization/main.cpp diff --git a/examples/piechartcustomization/piechartcustomization.pro b/demos/piechartcustomization/piechartcustomization.pro similarity index 80% rename from examples/piechartcustomization/piechartcustomization.pro rename to demos/piechartcustomization/piechartcustomization.pro index 55eecaa..352af7e 100644 --- a/examples/piechartcustomization/piechartcustomization.pro +++ b/demos/piechartcustomization/piechartcustomization.pro @@ -1,4 +1,4 @@ -!include( ../examples.pri ) { +!include( ../demos.pri ) { error( "Couldn't find the examples.pri file!" ) } TARGET = piechartcustomization diff --git a/examples/examples.pro b/examples/examples.pro index df79d39..93d795f 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -7,7 +7,6 @@ SUBDIRS += linechart \ percentbarchart \ scatterchart \ piechart \ - piechartcustomization \ piechartdrilldown \ dynamiclinechart \ axischart \