##// END OF EJS Templates
Fix setting custom color to pie. Now the pie knows if the color is set by the user.
Fix setting custom color to pie. Now the pie knows if the color is set by the user.

File last commit:

r661:4756f59398b8
r691:02b456949de5
Show More
main.cpp
247 lines | 8.6 KiB | text/x-c | CppLexer
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508 #include <QtGui/QApplication>
#include <QMainWindow>
#include <qchartglobal.h>
#include <qchartview.h>
#include <qpieseries.h>
#include <qpieslice.h>
Tero Ahola
Bar series to use theme base colors. Pie brush minor fix....
r661 #include <qbarseries.h>
Tero Ahola
Now using percent bar series in theme demo
r521 #include <qpercentbarseries.h>
Tero Ahola
Bar series to use theme base colors. Pie brush minor fix....
r661 #include <qstackedbarseries.h>
Tero Ahola
Fixed initial bounding rect issue with bar series
r518 #include <qbarset.h>
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508 #include <QGridLayout>
#include <QFormLayout>
#include <QComboBox>
#include <QSpinBox>
#include <QCheckBox>
#include <QGroupBox>
#include <QLabel>
#include <QTime>
#include <qlineseries.h>
#include <qsplineseries.h>
#include <qscatterseries.h>
#include <qareaseries.h>
QTCOMMERCIALCHART_USE_NAMESPACE
typedef QPair<QPointF, QString> Data;
typedef QList<Data> DataList;
typedef QList<DataList> 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;
Tero Ahola
Less test data in chartthemes demo
r583 int valueCount = 11;
Tero Ahola
Chartthemes example to use increasing x values
r515 for (int i(0); i < listCount; i++) {
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508 DataList dataList;
Tero Ahola
Chartthemes example to use increasing x values
r515 for (int j(0); j < valueCount; j++) {
QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax);
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508 QString label = QString::number(i) + ":" + QString::number(j);
dataList << Data(value, label);
}
m_dataTable << dataList;
}
// create layout
QGridLayout* baseLayout = new QGridLayout();
Jani Honkonen
Add animated&antialiasing checkboxes to chartthemes demo
r636 // settings layout
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508 m_themeComboBox = new QComboBox();
m_themeComboBox->addItem("Default", QChart::ChartThemeDefault);
Tero Ahola
Three more themes
r651 m_themeComboBox->addItem("Light", QChart::ChartThemeLight);
m_themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
m_themeComboBox->addItem("Dark", QChart::ChartThemeDark);
m_themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
m_themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508 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()));
Jani Honkonen
Add animated&antialiasing checkboxes to chartthemes demo
r636 QCheckBox *antialiasCheckBox = new QCheckBox("Anti aliasing");
connect(antialiasCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateAntialiasing(bool)));
QCheckBox *animatedCheckBox = new QCheckBox("Animated");
connect(animatedCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateAnimations(bool)));
QHBoxLayout *settingsLayout = new QHBoxLayout();
settingsLayout->addWidget(new QLabel("Theme:"));
settingsLayout->addWidget(m_themeComboBox);
settingsLayout->addWidget(antialiasCheckBox);
settingsLayout->addWidget(animatedCheckBox);
settingsLayout->addStretch();
baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508
// area chart
QChartView *chart = new QChartView();
chart->setChartTitle("Area chart");
baseLayout->addWidget(chart, 1, 0);
{
Tero Ahola
Area chart of theme example to use zero lower series
r539 for (int i(0); i < m_dataTable.count(); i++) {
QLineSeries *series1 = new QLineSeries(chart);
QLineSeries *series2 = new QLineSeries(chart);
foreach (Data data, m_dataTable[i]) {
series1->add(data.first);
series2->add(QPointF(data.first.x(), 0.0));
}
QAreaSeries *area = new QAreaSeries(series1, series2);
chart->addSeries(area);
}
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508 }
m_charts << chart;
// bar chart
chart = new QChartView();
chart->setChartTitle("bar chart");
baseLayout->addWidget(chart, 1, 1);
Tero Ahola
Fixed initial bounding rect issue with bar series
r518 {
QStringList categories;
// TODO: categories
for (int i(0); i < valueCount; i++)
categories << QString::number(i);
Tero Ahola
Bar series to use theme base colors. Pie brush minor fix....
r661 // QBarSeries* series = new QBarSeries(categories, chart);
// QPercentBarSeries* series = new QPercentBarSeries(categories, chart);
QStackedBarSeries* series = new QStackedBarSeries(categories, chart);
Tero Ahola
Fixed initial bounding rect issue with bar series
r518 for (int i(0); i < m_dataTable.count(); i++) {
QBarSet *set = new QBarSet("Set" + QString::number(i));
foreach (Data data, m_dataTable[i])
*set << data.first.y();
series->addBarSet(set);
}
chart->addSeries(series);
}
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508 m_charts << chart;
// line chart
chart = new QChartView();
chart->setChartTitle("line chart");
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");
baseLayout->addWidget(chart, 2, 0);
qreal pieSize = 1.0 / m_dataTable.count();
for (int i=0; i<m_dataTable.count(); i++) {
QPieSeries *series = new QPieSeries(chart);
foreach (Data data, m_dataTable[i])
Tero Ahola
Chartthemes example to use increasing x values
r515 series->add(data.first.y(), data.second);
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508 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");
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");
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);
Tero Ahola
Fonts and background of the themes...
r614
QPalette pal = window()->palette();
Tero Ahola
Three more themes
r651 if (theme == QChart::ChartThemeLight) {
pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
pal.setColor(QPalette::WindowText, QRgb(0x404044));
} else if (theme == QChart::ChartThemeDark) {
Tero Ahola
Fonts and background of the themes...
r614 pal.setColor(QPalette::Window, QRgb(0x121218));
pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
Tero Ahola
Three more themes
r651 } else if (theme == QChart::ChartThemeBlueCerulean) {
pal.setColor(QPalette::Window, QRgb(0x40434a));
pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
} else if (theme == QChart::ChartThemeBrownSand) {
pal.setColor(QPalette::Window, QRgb(0x9e8965));
pal.setColor(QPalette::WindowText, QRgb(0x404044));
} else if (theme == QChart::ChartThemeBlueNcs) {
pal.setColor(QPalette::Window, QRgb(0x018bba));
pal.setColor(QPalette::WindowText, QRgb(0x404044));
Tero Ahola
Fonts and background of the themes...
r614 } else {
pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
pal.setColor(QPalette::WindowText, QRgb(0x404044));
}
window()->setPalette(pal);
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508 }
Jani Honkonen
Add animated&antialiasing checkboxes to chartthemes demo
r636 void updateAntialiasing(bool enabled)
{
foreach (QChartView *chart, m_charts)
chart->setRenderHint(QPainter::Antialiasing, enabled);
}
void updateAnimations(bool animated)
{
QChart::AnimationOptions options = QChart::NoAnimation;
if (animated)
options = QChart::AllAnimations;
foreach (QChartView *chart, m_charts)
chart->setAnimationOptions(options);
}
Jani Honkonen
Adding demos folder. Move piechartcustomization to it. Add chartthemes demo (incomplete).
r508 private:
QList<QChartView*> 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"