##// END OF EJS Templates
more coding style fixes for examples...
Jani Honkonen -
r2102:f689de612f59
parent child
Show More
@@ -544,7 +544,7 QMenu *Window::createMenu()
544 menu->addMenu(subMenu);
544 menu->addMenu(subMenu);
545 }
545 }
546
546
547 foreach(Chart *chart, subCategoryMap.values(subCategory)) {
547 foreach (Chart *chart, subCategoryMap.values(subCategory)) {
548 createMenuAction(subMenu, QIcon(), chart->name(),
548 createMenuAction(subMenu, QIcon(), chart->name(),
549 qVariantFromValue((void *) chart));
549 qVariantFromValue((void *) chart));
550 }
550 }
@@ -31,8 +31,8 int main(int argc, char *argv[])
31 QApplication a(argc, argv);
31 QApplication a(argc, argv);
32
32
33 //![1]
33 //![1]
34 QLineSeries* series0 = new QLineSeries();
34 QLineSeries *series0 = new QLineSeries();
35 QLineSeries* series1 = new QLineSeries();
35 QLineSeries *series1 = new QLineSeries();
36 //![1]
36 //![1]
37
37
38 //![2]
38 //![2]
@@ -43,7 +43,7 int main(int argc, char *argv[])
43 //![2]
43 //![2]
44
44
45 //![3]
45 //![3]
46 QAreaSeries* series = new QAreaSeries(series0, series1);
46 QAreaSeries *series = new QAreaSeries(series0, series1);
47 series->setName("Batman");
47 series->setName("Batman");
48 QPen pen(0x059605);
48 QPen pen(0x059605);
49 pen.setWidth(3);
49 pen.setWidth(3);
@@ -57,7 +57,7 int main(int argc, char *argv[])
57 //![3]
57 //![3]
58
58
59 //![4]
59 //![4]
60 QChart* chart = new QChart();
60 QChart *chart = new QChart();
61 chart->addSeries(series);
61 chart->addSeries(series);
62 chart->setTitle("Simple areachart example");
62 chart->setTitle("Simple areachart example");
63 chart->createDefaultAxes();
63 chart->createDefaultAxes();
@@ -66,7 +66,7 int main(int argc, char *argv[])
66 //![4]
66 //![4]
67
67
68 //![5]
68 //![5]
69 QChartView* chartView = new QChartView(chart);
69 QChartView *chartView = new QChartView(chart);
70 chartView->setRenderHint(QPainter::Antialiasing);
70 chartView->setRenderHint(QPainter::Antialiasing);
71 //![5]
71 //![5]
72
72
@@ -47,7 +47,7 int main(int argc, char *argv[])
47 //![1]
47 //![1]
48
48
49 //![2]
49 //![2]
50 QBarSeries* series = new QBarSeries();
50 QBarSeries *series = new QBarSeries();
51 series->append(set0);
51 series->append(set0);
52 series->append(set1);
52 series->append(set1);
53 series->append(set2);
53 series->append(set2);
@@ -57,7 +57,7 int main(int argc, char *argv[])
57 //![2]
57 //![2]
58
58
59 //![3]
59 //![3]
60 QChart* chart = new QChart();
60 QChart *chart = new QChart();
61 chart->addSeries(series);
61 chart->addSeries(series);
62 chart->setTitle("Simple barchart example");
62 chart->setTitle("Simple barchart example");
63 chart->setAnimationOptions(QChart::SeriesAnimations);
63 chart->setAnimationOptions(QChart::SeriesAnimations);
@@ -66,7 +66,7 int main(int argc, char *argv[])
66 //![4]
66 //![4]
67 QStringList categories;
67 QStringList categories;
68 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
68 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
69 QBarCategoryAxis* axis = new QBarCategoryAxis();
69 QBarCategoryAxis *axis = new QBarCategoryAxis();
70 axis->append(categories);
70 axis->append(categories);
71 chart->createDefaultAxes();
71 chart->createDefaultAxes();
72 chart->setAxisX(axis, series);
72 chart->setAxisX(axis, series);
@@ -78,7 +78,7 int main(int argc, char *argv[])
78 //![5]
78 //![5]
79
79
80 //![6]
80 //![6]
81 QChartView* chartView = new QChartView(chart);
81 QChartView *chartView = new QChartView(chart);
82 chartView->setRenderHint(QPainter::Antialiasing);
82 chartView->setRenderHint(QPainter::Antialiasing);
83 //![6]
83 //![6]
84
84
@@ -45,13 +45,13 CustomTableModel::CustomTableModel(QObject *parent) :
45 }
45 }
46 }
46 }
47
47
48 int CustomTableModel::rowCount(const QModelIndex & parent) const
48 int CustomTableModel::rowCount(const QModelIndex &parent) const
49 {
49 {
50 Q_UNUSED(parent)
50 Q_UNUSED(parent)
51 return m_data.count();
51 return m_data.count();
52 }
52 }
53
53
54 int CustomTableModel::columnCount(const QModelIndex & parent) const
54 int CustomTableModel::columnCount(const QModelIndex &parent) const
55 {
55 {
56 Q_UNUSED(parent)
56 Q_UNUSED(parent)
57 return m_columnCount;
57 return m_columnCount;
@@ -68,7 +68,7 QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation,
68 return QString("%1").arg(section + 1);
68 return QString("%1").arg(section + 1);
69 }
69 }
70
70
71 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
71 QVariant CustomTableModel::data(const QModelIndex &index, int role) const
72 {
72 {
73 if (role == Qt::DisplayRole) {
73 if (role == Qt::DisplayRole) {
74 return m_data[index.row()]->at(index.column());
74 return m_data[index.row()]->at(index.column());
@@ -86,7 +86,7 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
86 return QVariant();
86 return QVariant();
87 }
87 }
88
88
89 bool CustomTableModel::setData(const QModelIndex & index, const QVariant & value, int role)
89 bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
90 {
90 {
91 if (index.isValid() && role == Qt::EditRole) {
91 if (index.isValid() && role == Qt::EditRole) {
92 m_data[index.row()]->replace(index.column(), value.toDouble());
92 m_data[index.row()]->replace(index.column(), value.toDouble());
@@ -96,7 +96,7 bool CustomTableModel::setData(const QModelIndex & index, const QVariant & value
96 return false;
96 return false;
97 }
97 }
98
98
99 Qt::ItemFlags CustomTableModel::flags(const QModelIndex & index) const
99 Qt::ItemFlags CustomTableModel::flags(const QModelIndex &index) const
100 {
100 {
101 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
101 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
102 }
102 }
@@ -31,12 +31,12 class CustomTableModel : public QAbstractTableModel
31 public:
31 public:
32 explicit CustomTableModel(QObject *parent = 0);
32 explicit CustomTableModel(QObject *parent = 0);
33
33
34 int rowCount(const QModelIndex & parent = QModelIndex()) const;
34 int rowCount(const QModelIndex &parent = QModelIndex()) const;
35 int columnCount(const QModelIndex & parent = QModelIndex()) const;
35 int columnCount(const QModelIndex &parent = QModelIndex()) const;
36 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
36 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
37 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
37 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
38 bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
38 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
39 Qt::ItemFlags flags(const QModelIndex & index) const;
39 Qt::ItemFlags flags(const QModelIndex &index) const;
40
40
41 void addMapping(QString color, QRect area);
41 void addMapping(QString color, QRect area);
42 void clearMapping() { m_mapping.clear(); }
42 void clearMapping() { m_mapping.clear(); }
@@ -78,7 +78,7 TableWidget::TableWidget(QWidget *parent)
78 QString seriesColorHex = "#000000";
78 QString seriesColorHex = "#000000";
79
79
80 // get the color of the series and use it for showing the mapped area
80 // get the color of the series and use it for showing the mapped area
81 QList<QBarSet*> barsets = series->barSets();
81 QList<QBarSet *> barsets = series->barSets();
82 for (int i = 0; i < barsets.count(); i++) {
82 for (int i = 0; i < barsets.count(); i++) {
83 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
83 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
84 model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count()));
84 model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count()));
@@ -88,7 +88,7 TableWidget::TableWidget(QWidget *parent)
88 //! [6]
88 //! [6]
89 QStringList categories;
89 QStringList categories;
90 categories << "April" << "May" << "June" << "July" << "August";
90 categories << "April" << "May" << "June" << "July" << "August";
91 QBarCategoryAxis* axis = new QBarCategoryAxis();
91 QBarCategoryAxis *axis = new QBarCategoryAxis();
92 axis->append(categories);
92 axis->append(categories);
93 chart->createDefaultAxes();
93 chart->createDefaultAxes();
94 chart->setAxisX(axis, series);
94 chart->setAxisX(axis, series);
@@ -102,7 +102,7 TableWidget::TableWidget(QWidget *parent)
102
102
103 //! [8]
103 //! [8]
104 // create main layout
104 // create main layout
105 QGridLayout* mainLayout = new QGridLayout;
105 QGridLayout *mainLayout = new QGridLayout;
106 mainLayout->addWidget(tableView, 1, 0);
106 mainLayout->addWidget(tableView, 1, 0);
107 mainLayout->addWidget(chartView, 1, 1);
107 mainLayout->addWidget(chartView, 1, 1);
108 mainLayout->setColumnStretch(1, 1);
108 mainLayout->setColumnStretch(1, 1);
@@ -31,9 +31,9 int main(int argc, char *argv[])
31 QApplication a(argc, argv);
31 QApplication a(argc, argv);
32
32
33 //![1]
33 //![1]
34 QLineSeries* series = new QLineSeries();
34 QLineSeries *series = new QLineSeries();
35 *series << QPointF(0, 6) << QPointF(9, 4) << QPointF(15, 20) << QPointF(25, 12) << QPointF(29, 26);
35 *series << QPointF(0, 6) << QPointF(9, 4) << QPointF(15, 20) << QPointF(25, 12) << QPointF(29, 26);
36 QChart* chart = new QChart();
36 QChart *chart = new QChart();
37 chart->legend()->hide();
37 chart->legend()->hide();
38 chart->addSeries(series);
38 chart->addSeries(series);
39 //![1]
39 //![1]
@@ -62,8 +62,8 int main(int argc, char *argv[])
62 //![2]
62 //![2]
63
63
64 //![3]
64 //![3]
65 QCategoryAxis* axisX = new QCategoryAxis();
65 QCategoryAxis *axisX = new QCategoryAxis();
66 QCategoryAxis* axisY = new QCategoryAxis();
66 QCategoryAxis *axisY = new QCategoryAxis();
67
67
68 // Customize axis label font
68 // Customize axis label font
69 QFont labelsFont;
69 QFont labelsFont;
@@ -106,7 +106,7 int main(int argc, char *argv[])
106 //![4]
106 //![4]
107
107
108 //![5]
108 //![5]
109 QChartView* chartView = new QChartView(chart);
109 QChartView *chartView = new QChartView(chart);
110 chartView->setRenderHint(QPainter::Antialiasing);
110 chartView->setRenderHint(QPainter::Antialiasing);
111 //![5]
111 //![5]
112
112
@@ -36,7 +36,7 int main(int argc, char *argv[])
36 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
36 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
37
37
38 //![1]
38 //![1]
39 QLineSeries* series = new QLineSeries();
39 QLineSeries *series = new QLineSeries();
40 //![1]
40 //![1]
41
41
42 //![2]
42 //![2]
@@ -62,7 +62,7 int main(int argc, char *argv[])
62 //![2]
62 //![2]
63
63
64 //![3]
64 //![3]
65 QChart* chart = new QChart();
65 QChart *chart = new QChart();
66 chart->addSeries(series);
66 chart->addSeries(series);
67 chart->legend()->hide();
67 chart->legend()->hide();
68 chart->createDefaultAxes();
68 chart->createDefaultAxes();
@@ -77,7 +77,7 int main(int argc, char *argv[])
77 //![4]
77 //![4]
78
78
79 //![5]
79 //![5]
80 QChartView* chartView = new QChartView(chart);
80 QChartView *chartView = new QChartView(chart);
81 chartView->setRenderHint(QPainter::Antialiasing);
81 chartView->setRenderHint(QPainter::Antialiasing);
82 //![5]
82 //![5]
83
83
@@ -66,7 +66,7 int main(int argc, char *argv[])
66
66
67 //![3]
67 //![3]
68 QMainWindow window;
68 QMainWindow window;
69 QChartView* chartView = new QChartView(donutBreakdown);
69 QChartView *chartView = new QChartView(donutBreakdown);
70 chartView->setRenderHint(QPainter::Antialiasing);
70 chartView->setRenderHint(QPainter::Antialiasing);
71 window.setCentralWidget(chartView);
71 window.setCentralWidget(chartView);
72 window.resize(800, 600);
72 window.resize(800, 600);
@@ -42,7 +42,7 int main(int argc, char *argv[])
42 //![1]
42 //![1]
43
43
44 //![2]
44 //![2]
45 QChartView* chartView = new QChartView();
45 QChartView *chartView = new QChartView();
46 chartView->setRenderHint(QPainter::Antialiasing);
46 chartView->setRenderHint(QPainter::Antialiasing);
47 chartView->chart()->setTitle("Donut with a lemon glaze (100g)");
47 chartView->chart()->setTitle("Donut with a lemon glaze (100g)");
48 chartView->chart()->addSeries(series);
48 chartView->chart()->addSeries(series);
@@ -57,7 +57,7 int main(int argc, char *argv[])
57 //![2]
57 //![2]
58
58
59 //![3]
59 //![3]
60 QChart* chart = new QChart();
60 QChart *chart = new QChart();
61 chart->addSeries(series);
61 chart->addSeries(series);
62 chart->setTitle("Simple horizontal barchart example");
62 chart->setTitle("Simple horizontal barchart example");
63 chart->setAnimationOptions(QChart::SeriesAnimations);
63 chart->setAnimationOptions(QChart::SeriesAnimations);
@@ -66,7 +66,7 int main(int argc, char *argv[])
66 //![4]
66 //![4]
67 QStringList categories;
67 QStringList categories;
68 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
68 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
69 QBarCategoryAxis* axis = new QBarCategoryAxis();
69 QBarCategoryAxis *axis = new QBarCategoryAxis();
70 axis->append(categories);
70 axis->append(categories);
71 chart->createDefaultAxes();
71 chart->createDefaultAxes();
72 chart->setAxisY(axis, series);
72 chart->setAxisY(axis, series);
@@ -78,7 +78,7 int main(int argc, char *argv[])
78 //![5]
78 //![5]
79
79
80 //![6]
80 //![6]
81 QChartView* chartView = new QChartView(chart);
81 QChartView *chartView = new QChartView(chart);
82 chartView->setRenderHint(QPainter::Antialiasing);
82 chartView->setRenderHint(QPainter::Antialiasing);
83 //![6]
83 //![6]
84
84
@@ -58,7 +58,7 int main(int argc, char *argv[])
58 //![2]
58 //![2]
59
59
60 //![3]
60 //![3]
61 QChart* chart = new QChart();
61 QChart *chart = new QChart();
62 chart->addSeries(series);
62 chart->addSeries(series);
63 chart->setTitle("Simple horizontal percent barchart example");
63 chart->setTitle("Simple horizontal percent barchart example");
64 chart->setAnimationOptions(QChart::SeriesAnimations);
64 chart->setAnimationOptions(QChart::SeriesAnimations);
@@ -67,7 +67,7 int main(int argc, char *argv[])
67 //![4]
67 //![4]
68 QStringList categories;
68 QStringList categories;
69 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
69 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
70 QBarCategoryAxis* axis = new QBarCategoryAxis();
70 QBarCategoryAxis *axis = new QBarCategoryAxis();
71 axis->append(categories);
71 axis->append(categories);
72 chart->createDefaultAxes();
72 chart->createDefaultAxes();
73 chart->setAxisY(axis, series);
73 chart->setAxisY(axis, series);
@@ -79,7 +79,7 int main(int argc, char *argv[])
79 //![5]
79 //![5]
80
80
81 //![6]
81 //![6]
82 QChartView* chartView = new QChartView(chart);
82 QChartView *chartView = new QChartView(chart);
83 chartView->setRenderHint(QPainter::Antialiasing);
83 chartView->setRenderHint(QPainter::Antialiasing);
84 //![6]
84 //![6]
85
85
@@ -58,7 +58,7 int main(int argc, char *argv[])
58 //![2]
58 //![2]
59
59
60 //![3]
60 //![3]
61 QChart* chart = new QChart();
61 QChart *chart = new QChart();
62 chart->addSeries(series);
62 chart->addSeries(series);
63 chart->setTitle("Simple horizontal stacked barchart example");
63 chart->setTitle("Simple horizontal stacked barchart example");
64 chart->setAnimationOptions(QChart::SeriesAnimations);
64 chart->setAnimationOptions(QChart::SeriesAnimations);
@@ -67,7 +67,7 int main(int argc, char *argv[])
67 //![4]
67 //![4]
68 QStringList categories;
68 QStringList categories;
69 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
69 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
70 QBarCategoryAxis* axis = new QBarCategoryAxis();
70 QBarCategoryAxis *axis = new QBarCategoryAxis();
71 axis->append(categories);
71 axis->append(categories);
72 chart->createDefaultAxes();
72 chart->createDefaultAxes();
73 chart->setAxisY(axis, series);
73 chart->setAxisY(axis, series);
@@ -79,7 +79,7 int main(int argc, char *argv[])
79 //![5]
79 //![5]
80
80
81 //![6]
81 //![6]
82 QChartView* chartView = new QChartView(chart);
82 QChartView *chartView = new QChartView(chart);
83 chartView->setRenderHint(QPainter::Antialiasing);
83 chartView->setRenderHint(QPainter::Antialiasing);
84 //![6]
84 //![6]
85
85
@@ -69,7 +69,7 MainWidget::MainWidget(QWidget *parent) :
69 connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
69 connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
70 connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
70 connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout()));
71
71
72 QFormLayout* legendLayout = new QFormLayout();
72 QFormLayout *legendLayout = new QFormLayout();
73 legendLayout->addRow("HPos", m_legendPosX);
73 legendLayout->addRow("HPos", m_legendPosX);
74 legendLayout->addRow("VPos", m_legendPosY);
74 legendLayout->addRow("VPos", m_legendPosY);
75 legendLayout->addRow("Width", m_legendWidth);
75 legendLayout->addRow("Width", m_legendWidth);
@@ -88,7 +88,7 MainWidget::MainWidget(QWidget *parent) :
88 m_fontSize->setValue(m_chart->legend()->font().pointSizeF());
88 m_fontSize->setValue(m_chart->legend()->font().pointSizeF());
89 connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged()));
89 connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged()));
90
90
91 QFormLayout* fontLayout = new QFormLayout();
91 QFormLayout *fontLayout = new QFormLayout();
92 fontLayout->addRow("Legend font size", m_fontSize);
92 fontLayout->addRow("Legend font size", m_fontSize);
93
93
94 // Create layout for grid and detached legend
94 // Create layout for grid and detached legend
@@ -180,7 +180,7 void MainWidget::addBarset()
180
180
181 void MainWidget::removeBarset()
181 void MainWidget::removeBarset()
182 {
182 {
183 QList<QBarSet*> sets = m_series->barSets();
183 QList<QBarSet *> sets = m_series->barSets();
184 if (sets.count() > 0) {
184 if (sets.count() > 0) {
185 m_series->remove(sets.at(sets.count() - 1));
185 m_series->remove(sets.at(sets.count() - 1));
186 }
186 }
@@ -68,7 +68,7 private:
68 QDoubleSpinBox *m_fontSize;
68 QDoubleSpinBox *m_fontSize;
69
69
70 // For detached layout
70 // For detached layout
71 QGroupBox* m_legendSettings;
71 QGroupBox *m_legendSettings;
72 QDoubleSpinBox *m_legendPosX;
72 QDoubleSpinBox *m_legendPosX;
73 QDoubleSpinBox *m_legendPosY;
73 QDoubleSpinBox *m_legendPosY;
74 QDoubleSpinBox *m_legendWidth;
74 QDoubleSpinBox *m_legendWidth;
@@ -49,7 +49,7 int main(int argc, char *argv[])
49 //![1]
49 //![1]
50
50
51 //![2]
51 //![2]
52 QBarSeries* barseries = new QBarSeries();
52 QBarSeries *barseries = new QBarSeries();
53 barseries->append(set0);
53 barseries->append(set0);
54 barseries->append(set1);
54 barseries->append(set1);
55 barseries->append(set2);
55 barseries->append(set2);
@@ -58,7 +58,7 int main(int argc, char *argv[])
58 //![2]
58 //![2]
59
59
60 //![8]
60 //![8]
61 QLineSeries* lineseries = new QLineSeries();
61 QLineSeries *lineseries = new QLineSeries();
62
62
63 lineseries->append(QPoint(0, 4));
63 lineseries->append(QPoint(0, 4));
64 lineseries->append(QPoint(1, 15));
64 lineseries->append(QPoint(1, 15));
@@ -69,7 +69,7 int main(int argc, char *argv[])
69 //![8]
69 //![8]
70
70
71 //![3]
71 //![3]
72 QChart* chart = new QChart();
72 QChart *chart = new QChart();
73 chart->addSeries(barseries);
73 chart->addSeries(barseries);
74 chart->addSeries(lineseries);
74 chart->addSeries(lineseries);
75 chart->setTitle("Line and barchart example");
75 chart->setTitle("Line and barchart example");
@@ -78,13 +78,13 int main(int argc, char *argv[])
78 //![4]
78 //![4]
79 QStringList categories;
79 QStringList categories;
80 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
80 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
81 QBarCategoryAxis* axisX = new QBarCategoryAxis();
81 QBarCategoryAxis *axisX = new QBarCategoryAxis();
82 axisX->append(categories);
82 axisX->append(categories);
83 chart->setAxisX(axisX, lineseries);
83 chart->setAxisX(axisX, lineseries);
84 chart->setAxisX(axisX, barseries);
84 chart->setAxisX(axisX, barseries);
85 axisX->setRange(QString("Jan"), QString("Jun"));
85 axisX->setRange(QString("Jan"), QString("Jun"));
86
86
87 QValueAxis* axisY = new QValueAxis();
87 QValueAxis *axisY = new QValueAxis();
88 chart->setAxisY(axisY, lineseries);
88 chart->setAxisY(axisY, lineseries);
89 chart->setAxisY(axisY, barseries);
89 chart->setAxisY(axisY, barseries);
90 axisY->setRange(0, 20);
90 axisY->setRange(0, 20);
@@ -96,7 +96,7 int main(int argc, char *argv[])
96 //![5]
96 //![5]
97
97
98 //![6]
98 //![6]
99 QChartView* chartView = new QChartView(chart);
99 QChartView *chartView = new QChartView(chart);
100 chartView->setRenderHint(QPainter::Antialiasing);
100 chartView->setRenderHint(QPainter::Antialiasing);
101 //![6]
101 //![6]
102
102
@@ -30,7 +30,7 int main(int argc, char *argv[])
30 QApplication a(argc, argv);
30 QApplication a(argc, argv);
31
31
32 //![1]
32 //![1]
33 QLineSeries* series = new QLineSeries();
33 QLineSeries *series = new QLineSeries();
34 //![1]
34 //![1]
35
35
36 //![2]
36 //![2]
@@ -43,7 +43,7 int main(int argc, char *argv[])
43 //![2]
43 //![2]
44
44
45 //![3]
45 //![3]
46 QChart* chart = new QChart();
46 QChart *chart = new QChart();
47 chart->legend()->hide();
47 chart->legend()->hide();
48 chart->addSeries(series);
48 chart->addSeries(series);
49 chart->createDefaultAxes();
49 chart->createDefaultAxes();
@@ -51,7 +51,7 int main(int argc, char *argv[])
51 //![3]
51 //![3]
52
52
53 //![4]
53 //![4]
54 QChartView* chartView = new QChartView(chart);
54 QChartView *chartView = new QChartView(chart);
55 chartView->setRenderHint(QPainter::Antialiasing);
55 chartView->setRenderHint(QPainter::Antialiasing);
56 //![4]
56 //![4]
57
57
@@ -45,13 +45,13 CustomTableModel::CustomTableModel(QObject *parent) :
45 }
45 }
46 }
46 }
47
47
48 int CustomTableModel::rowCount(const QModelIndex & parent) const
48 int CustomTableModel::rowCount(const QModelIndex &parent) const
49 {
49 {
50 Q_UNUSED(parent)
50 Q_UNUSED(parent)
51 return m_data.count();
51 return m_data.count();
52 }
52 }
53
53
54 int CustomTableModel::columnCount(const QModelIndex & parent) const
54 int CustomTableModel::columnCount(const QModelIndex &parent) const
55 {
55 {
56 Q_UNUSED(parent)
56 Q_UNUSED(parent)
57 return m_columnCount;
57 return m_columnCount;
@@ -72,7 +72,7 QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation,
72 }
72 }
73 }
73 }
74
74
75 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
75 QVariant CustomTableModel::data(const QModelIndex &index, int role) const
76 {
76 {
77 if (role == Qt::DisplayRole) {
77 if (role == Qt::DisplayRole) {
78 return m_data[index.row()]->at(index.column());
78 return m_data[index.row()]->at(index.column());
@@ -89,7 +89,7 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
89 return QVariant();
89 return QVariant();
90 }
90 }
91
91
92 bool CustomTableModel::setData(const QModelIndex & index, const QVariant & value, int role)
92 bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
93 {
93 {
94 if (index.isValid() && role == Qt::EditRole) {
94 if (index.isValid() && role == Qt::EditRole) {
95 m_data[index.row()]->replace(index.column(), value.toDouble());
95 m_data[index.row()]->replace(index.column(), value.toDouble());
@@ -99,7 +99,7 bool CustomTableModel::setData(const QModelIndex & index, const QVariant & value
99 return false;
99 return false;
100 }
100 }
101
101
102 Qt::ItemFlags CustomTableModel::flags(const QModelIndex & index) const
102 Qt::ItemFlags CustomTableModel::flags(const QModelIndex &index) const
103 {
103 {
104 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
104 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
105 }
105 }
@@ -31,12 +31,12 class CustomTableModel : public QAbstractTableModel
31 public:
31 public:
32 explicit CustomTableModel(QObject *parent = 0);
32 explicit CustomTableModel(QObject *parent = 0);
33
33
34 int rowCount(const QModelIndex & parent = QModelIndex()) const;
34 int rowCount(const QModelIndex &parent = QModelIndex()) const;
35 int columnCount(const QModelIndex & parent = QModelIndex()) const;
35 int columnCount(const QModelIndex &parent = QModelIndex()) const;
36 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
36 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
37 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
37 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
38 bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
38 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
39 Qt::ItemFlags flags(const QModelIndex & index) const;
39 Qt::ItemFlags flags(const QModelIndex &index) const;
40
40
41 void addMapping(QString color, QRect area);
41 void addMapping(QString color, QRect area);
42 void clearMapping() { m_mapping.clear(); }
42 void clearMapping() { m_mapping.clear(); }
@@ -102,7 +102,7 TableWidget::TableWidget(QWidget *parent)
102
102
103 //! [9]
103 //! [9]
104 // create main layout
104 // create main layout
105 QGridLayout* mainLayout = new QGridLayout;
105 QGridLayout *mainLayout = new QGridLayout;
106 mainLayout->addWidget(tableView, 1, 0);
106 mainLayout->addWidget(tableView, 1, 0);
107 mainLayout->addWidget(chartView, 1, 1);
107 mainLayout->addWidget(chartView, 1, 1);
108 mainLayout->setColumnStretch(1, 1);
108 mainLayout->setColumnStretch(1, 1);
@@ -35,10 +35,10 int main(int argc, char *argv[])
35 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
35 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
36
36
37 //![1]
37 //![1]
38 QLineSeries* series;
38 QLineSeries *series;
39 QValueAxis *axisX;
39 QValueAxis *axisX;
40 QValueAxis *axisY;
40 QValueAxis *axisY;
41 QChart* chart = new QChart();
41 QChart *chart = new QChart();
42 for (int i = 0; i < 5; i++) {
42 for (int i = 0; i < 5; i++) {
43 series = new QLineSeries;
43 series = new QLineSeries;
44 for (int k(0); k < 8; k++)
44 for (int k(0); k < 8; k++)
@@ -68,7 +68,7 int main(int argc, char *argv[])
68 //![3]
68 //![3]
69
69
70 //![4]
70 //![4]
71 QChartView* chartView = new QChartView(chart);
71 QChartView *chartView = new QChartView(chart);
72 chartView->setRenderHint(QPainter::Antialiasing);
72 chartView->setRenderHint(QPainter::Antialiasing);
73 //![4]
73 //![4]
74
74
@@ -47,7 +47,7 int main(int argc, char *argv[])
47 //![1]
47 //![1]
48
48
49 //![2]
49 //![2]
50 QPercentBarSeries* series = new QPercentBarSeries();
50 QPercentBarSeries *series = new QPercentBarSeries();
51 series->append(set0);
51 series->append(set0);
52 series->append(set1);
52 series->append(set1);
53 series->append(set2);
53 series->append(set2);
@@ -56,7 +56,7 int main(int argc, char *argv[])
56 //![2]
56 //![2]
57
57
58 //![3]
58 //![3]
59 QChart* chart = new QChart();
59 QChart *chart = new QChart();
60 chart->addSeries(series);
60 chart->addSeries(series);
61 chart->setTitle("Simple percentbarchart example");
61 chart->setTitle("Simple percentbarchart example");
62 chart->setAnimationOptions(QChart::SeriesAnimations);
62 chart->setAnimationOptions(QChart::SeriesAnimations);
@@ -65,7 +65,7 int main(int argc, char *argv[])
65 //![4]
65 //![4]
66 QStringList categories;
66 QStringList categories;
67 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
67 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
68 QBarCategoryAxis* axis = new QBarCategoryAxis();
68 QBarCategoryAxis *axis = new QBarCategoryAxis();
69 axis->append(categories);
69 axis->append(categories);
70 chart->createDefaultAxes();
70 chart->createDefaultAxes();
71 chart->setAxisX(axis, series);
71 chart->setAxisX(axis, series);
@@ -77,7 +77,7 int main(int argc, char *argv[])
77 //![5]
77 //![5]
78
78
79 //![6]
79 //![6]
80 QChartView* chartView = new QChartView(chart);
80 QChartView *chartView = new QChartView(chart);
81 chartView->setRenderHint(QPainter::Antialiasing);
81 chartView->setRenderHint(QPainter::Antialiasing);
82 //![6]
82 //![6]
83
83
@@ -48,14 +48,14 int main(int argc, char *argv[])
48 //![2]
48 //![2]
49
49
50 //![3]
50 //![3]
51 QChart* chart = new QChart();
51 QChart *chart = new QChart();
52 chart->addSeries(series);
52 chart->addSeries(series);
53 chart->setTitle("Simple piechart example");
53 chart->setTitle("Simple piechart example");
54 chart->legend()->hide();
54 chart->legend()->hide();
55 //![3]
55 //![3]
56
56
57 //![4]
57 //![4]
58 QChartView* chartView = new QChartView(chart);
58 QChartView *chartView = new QChartView(chart);
59 chartView->setRenderHint(QPainter::Antialiasing);
59 chartView->setRenderHint(QPainter::Antialiasing);
60 //![4]
60 //![4]
61
61
@@ -34,7 +34,7 DrilldownChart::~DrilldownChart()
34
34
35 }
35 }
36
36
37 void DrilldownChart::changeSeries(QAbstractSeries* series)
37 void DrilldownChart::changeSeries(QAbstractSeries *series)
38 {
38 {
39 // NOTE: if the series is owned by the chart it will be deleted
39 // NOTE: if the series is owned by the chart it will be deleted
40 // here the "window" owns the series...
40 // here the "window" owns the series...
@@ -45,9 +45,9 void DrilldownChart::changeSeries(QAbstractSeries* series)
45 setTitle(series->name());
45 setTitle(series->name());
46 }
46 }
47
47
48 void DrilldownChart::handleSliceClicked(QPieSlice* slice)
48 void DrilldownChart::handleSliceClicked(QPieSlice *slice)
49 {
49 {
50 DrilldownSlice* drilldownSlice = static_cast<DrilldownSlice*>(slice);
50 DrilldownSlice *drilldownSlice = static_cast<DrilldownSlice *>(slice);
51 changeSeries(drilldownSlice->drilldownSeries());
51 changeSeries(drilldownSlice->drilldownSeries());
52 }
52 }
53
53
@@ -35,13 +35,13 class DrilldownChart : public QChart
35 public:
35 public:
36 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
36 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
37 ~DrilldownChart();
37 ~DrilldownChart();
38 void changeSeries(QAbstractSeries* series);
38 void changeSeries(QAbstractSeries *series);
39
39
40 public Q_SLOTS:
40 public Q_SLOTS:
41 void handleSliceClicked(QPieSlice* slice);
41 void handleSliceClicked(QPieSlice *slice);
42
42
43 private:
43 private:
44 QAbstractSeries* m_currentSeries;
44 QAbstractSeries *m_currentSeries;
45 };
45 };
46
46
47 #endif // DRILLDOWNCHART_H
47 #endif // DRILLDOWNCHART_H
@@ -22,7 +22,7
22
22
23 QTCOMMERCIALCHART_USE_NAMESPACE
23 QTCOMMERCIALCHART_USE_NAMESPACE
24
24
25 DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries* drilldownSeries)
25 DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries *drilldownSeries)
26 : m_drilldownSeries(drilldownSeries),
26 : m_drilldownSeries(drilldownSeries),
27 m_prefix(prefix)
27 m_prefix(prefix)
28 {
28 {
@@ -38,7 +38,7 DrilldownSlice::~DrilldownSlice()
38
38
39 }
39 }
40
40
41 QAbstractSeries* DrilldownSlice::drilldownSeries() const
41 QAbstractSeries *DrilldownSlice::drilldownSeries() const
42 {
42 {
43 return m_drilldownSeries;
43 return m_drilldownSeries;
44 }
44 }
@@ -33,16 +33,16 class DrilldownSlice : public QPieSlice
33 Q_OBJECT
33 Q_OBJECT
34
34
35 public:
35 public:
36 DrilldownSlice(qreal value, QString prefix, QAbstractSeries* drilldownSeries);
36 DrilldownSlice(qreal value, QString prefix, QAbstractSeries *drilldownSeries);
37 virtual ~DrilldownSlice();
37 virtual ~DrilldownSlice();
38 QAbstractSeries* drilldownSeries() const;
38 QAbstractSeries *drilldownSeries() const;
39
39
40 public Q_SLOTS:
40 public Q_SLOTS:
41 void updateLabel();
41 void updateLabel();
42 void showHighlight(bool show);
42 void showHighlight(bool show);
43
43
44 private:
44 private:
45 QAbstractSeries* m_drilldownSeries;
45 QAbstractSeries *m_drilldownSeries;
46 QString m_prefix;
46 QString m_prefix;
47 };
47 };
48
48
@@ -37,13 +37,13 int main(int argc, char *argv[])
37
37
38 QMainWindow window;
38 QMainWindow window;
39
39
40 DrilldownChart* chart = new DrilldownChart();
40 DrilldownChart *chart = new DrilldownChart();
41 chart->setTheme(QChart::ChartThemeLight);
41 chart->setTheme(QChart::ChartThemeLight);
42 chart->setAnimationOptions(QChart::AllAnimations);
42 chart->setAnimationOptions(QChart::AllAnimations);
43 chart->legend()->setVisible(true);
43 chart->legend()->setVisible(true);
44 chart->legend()->setAlignment(Qt::AlignRight);
44 chart->legend()->setAlignment(Qt::AlignRight);
45
45
46 QPieSeries* yearSeries = new QPieSeries(&window);
46 QPieSeries *yearSeries = new QPieSeries(&window);
47 yearSeries->setName("Sales by year - All");
47 yearSeries->setName("Sales by year - All");
48
48
49 QList<QString> months;
49 QList<QString> months;
@@ -52,22 +52,22 int main(int argc, char *argv[])
52 names << "Jane" << "John" << "Axel" << "Mary" << "Susan" << "Bob";
52 names << "Jane" << "John" << "Axel" << "Mary" << "Susan" << "Bob";
53
53
54 foreach (QString name, names) {
54 foreach (QString name, names) {
55 QPieSeries* series = new QPieSeries(&window);
55 QPieSeries *series = new QPieSeries(&window);
56 series->setName("Sales by month - " + name);
56 series->setName("Sales by month - " + name);
57
57
58 foreach (QString month, months)
58 foreach (QString month, months)
59 *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
59 *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
60
60
61 QObject::connect(series, SIGNAL(clicked(QPieSlice*)), chart, SLOT(handleSliceClicked(QPieSlice*)));
61 QObject::connect(series, SIGNAL(clicked(QPieSlice *)), chart, SLOT(handleSliceClicked(QPieSlice *)));
62
62
63 *yearSeries << new DrilldownSlice(series->sum(), name, series);
63 *yearSeries << new DrilldownSlice(series->sum(), name, series);
64 }
64 }
65
65
66 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*)), chart, SLOT(handleSliceClicked(QPieSlice*)));
66 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice *)), chart, SLOT(handleSliceClicked(QPieSlice *)));
67
67
68 chart->changeSeries(yearSeries);
68 chart->changeSeries(yearSeries);
69
69
70 QChartView* chartView = new QChartView(chart);
70 QChartView *chartView = new QChartView(chart);
71 chartView->setRenderHint(QPainter::Antialiasing);
71 chartView->setRenderHint(QPainter::Antialiasing);
72 window.setCentralWidget(chartView);
72 window.setCentralWidget(chartView);
73 window.resize(800, 500);
73 window.resize(800, 500);
@@ -25,7 +25,7
25 #include <QAreaSeries>
25 #include <QAreaSeries>
26 #include <QTime>
26 #include <QTime>
27
27
28 ChartView::ChartView(QChart* chart, QWidget* parent)
28 ChartView::ChartView(QChart *chart, QWidget *parent)
29 : QChartView(chart, parent),
29 : QChartView(chart, parent),
30 m_index(-1),
30 m_index(-1),
31 m_chart(chart)
31 m_chart(chart)
@@ -36,16 +36,16 ChartView::ChartView(QChart* chart, QWidget* parent)
36 m_timer.setInterval(3000);
36 m_timer.setInterval(3000);
37
37
38 //![1]
38 //![1]
39 QLineSeries* series0 = new QLineSeries();
39 QLineSeries *series0 = new QLineSeries();
40 series0->setName("line");
40 series0->setName("line");
41
41
42 QScatterSeries* series1 = new QScatterSeries();
42 QScatterSeries *series1 = new QScatterSeries();
43 series1->setName("scatter");
43 series1->setName("scatter");
44
44
45 QSplineSeries* series2 = new QSplineSeries();
45 QSplineSeries *series2 = new QSplineSeries();
46 series2->setName("spline");
46 series2->setName("spline");
47
47
48 QAreaSeries* series3 = new QAreaSeries(series0);
48 QAreaSeries *series3 = new QAreaSeries(series0);
49 series3->setName("area");
49 series3->setName("area");
50 //![1]
50 //![1]
51
51
@@ -31,7 +31,7 class ChartView: public QChartView
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 public:
33 public:
34 ChartView(QChart* chart, QWidget* parent = 0);
34 ChartView(QChart *chart, QWidget *parent = 0);
35 virtual ~ChartView();
35 virtual ~ChartView();
36
36
37 public slots:
37 public slots:
@@ -26,7 +26,7 int main(int argc, char *argv[])
26 {
26 {
27 QApplication a(argc, argv);
27 QApplication a(argc, argv);
28 QMainWindow window;
28 QMainWindow window;
29 QChart* chart = new QChart();
29 QChart *chart = new QChart();
30 ChartView chartView(chart, &window);
30 ChartView chartView(chart, &window);
31 chartView.setRenderHint(QPainter::Antialiasing);
31 chartView.setRenderHint(QPainter::Antialiasing);
32 chart->setAnimationOptions(QChart::SeriesAnimations);
32 chart->setAnimationOptions(QChart::SeriesAnimations);
@@ -29,7 +29,7 int main(int argc, char *argv[])
29 QApplication a(argc, argv);
29 QApplication a(argc, argv);
30
30
31 //![4]
31 //![4]
32 ChartView* chartView = new ChartView();
32 ChartView *chartView = new ChartView();
33 QMainWindow window;
33 QMainWindow window;
34 window.setCentralWidget(chartView);
34 window.setCentralWidget(chartView);
35 window.resize(400, 300);
35 window.resize(400, 300);
@@ -56,7 +56,7 ChartView::~ChartView()
56 {
56 {
57 }
57 }
58
58
59 void ChartView::handleClickedPoint(const QPointF& point)
59 void ChartView::handleClickedPoint(const QPointF &point)
60 {
60 {
61 QPointF clickedPoint = point;
61 QPointF clickedPoint = point;
62 // Find the closest point from series 1
62 // Find the closest point from series 1
@@ -36,7 +36,7 public:
36 ~ChartView();
36 ~ChartView();
37
37
38 private Q_SLOTS:
38 private Q_SLOTS:
39 void handleClickedPoint(const QPointF& point);
39 void handleClickedPoint(const QPointF &point);
40
40
41 private:
41 private:
42 QScatterSeries *m_scatter;
42 QScatterSeries *m_scatter;
@@ -41,11 +41,11 Chart::~Chart()
41 bool Chart::sceneEvent(QEvent *event)
41 bool Chart::sceneEvent(QEvent *event)
42 {
42 {
43 if (event->type() == QEvent::Gesture)
43 if (event->type() == QEvent::Gesture)
44 return gestureEvent(static_cast<QGestureEvent*>(event));
44 return gestureEvent(static_cast<QGestureEvent *>(event));
45 return QChart::event(event);
45 return QChart::event(event);
46 }
46 }
47
47
48 bool Chart::gestureEvent(QGestureEvent* event)
48 bool Chart::gestureEvent(QGestureEvent *event)
49 {
49 {
50 if (QGesture *gesture = event->gesture(Qt::PanGesture)) {
50 if (QGesture *gesture = event->gesture(Qt::PanGesture)) {
51 QPanGesture *pan = static_cast<QPanGesture *>(gesture);
51 QPanGesture *pan = static_cast<QPanGesture *>(gesture);
@@ -39,10 +39,7 protected:
39 bool sceneEvent(QEvent *event);
39 bool sceneEvent(QEvent *event);
40
40
41 private:
41 private:
42 bool gestureEvent(QGestureEvent* event);
42 bool gestureEvent(QGestureEvent *event);
43
44 private:
45
46 };
43 };
47
44
48 #endif // CHART_H
45 #endif // CHART_H
@@ -35,7 +35,7 int main(int argc, char *argv[])
35 {
35 {
36 QApplication a(argc, argv);
36 QApplication a(argc, argv);
37
37
38 QLineSeries* series = new QLineSeries();
38 QLineSeries *series = new QLineSeries();
39 for (int i = 0; i < 500; i++) {
39 for (int i = 0; i < 500; i++) {
40 QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
40 QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
41 p.ry() += qrand() % 20;
41 p.ry() += qrand() % 20;
@@ -55,14 +55,14 int main(int argc, char *argv[])
55 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
55 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
56
56
57 //QHorizontalBarSeries* series2 = new QHorizontalBarSeries();
57 //QHorizontalBarSeries* series2 = new QHorizontalBarSeries();
58 QBarSeries* series2 = new QBarSeries();
58 QBarSeries *series2 = new QBarSeries();
59 series2->append(set0);
59 series2->append(set0);
60 series2->append(set1);
60 series2->append(set1);
61 series2->append(set2);
61 series2->append(set2);
62 series2->append(set3);
62 series2->append(set3);
63 series2->append(set4);
63 series2->append(set4);
64
64
65 Chart* chart = new Chart();
65 Chart *chart = new Chart();
66 // chart->addSeries(series);
66 // chart->addSeries(series);
67 chart->addSeries(series2);
67 chart->addSeries(series2);
68 chart->setTitle("Scroll in/out example");
68 chart->setTitle("Scroll in/out example");
@@ -71,11 +71,11 int main(int argc, char *argv[])
71
71
72 QStringList categories;
72 QStringList categories;
73 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
73 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
74 QBarCategoryAxis* axis = new QBarCategoryAxis();
74 QBarCategoryAxis *axis = new QBarCategoryAxis();
75 axis->append(categories);
75 axis->append(categories);
76 chart->setAxisX(axis, series2);
76 chart->setAxisX(axis, series2);
77
77
78 ChartView* chartView = new ChartView(chart);
78 ChartView *chartView = new ChartView(chart);
79 chartView->setRenderHint(QPainter::Antialiasing);
79 chartView->setRenderHint(QPainter::Antialiasing);
80
80
81 QMainWindow window;
81 QMainWindow window;
@@ -30,7 +30,7 int main(int argc, char *argv[])
30 QApplication a(argc, argv);
30 QApplication a(argc, argv);
31
31
32 //![1]
32 //![1]
33 QSplineSeries* series = new QSplineSeries();
33 QSplineSeries *series = new QSplineSeries();
34 series->setName("spline");
34 series->setName("spline");
35 //![1]
35 //![1]
36
36
@@ -44,7 +44,7 int main(int argc, char *argv[])
44 //![2]
44 //![2]
45
45
46 //![3]
46 //![3]
47 QChart* chart = new QChart();
47 QChart *chart = new QChart();
48 chart->legend()->hide();
48 chart->legend()->hide();
49 chart->addSeries(series);
49 chart->addSeries(series);
50 chart->setTitle("Simple spline chart example");
50 chart->setTitle("Simple spline chart example");
@@ -53,7 +53,7 int main(int argc, char *argv[])
53 //![3]
53 //![3]
54
54
55 //![4]
55 //![4]
56 QChartView* chartView = new QChartView(chart);
56 QChartView *chartView = new QChartView(chart);
57 chartView->setRenderHint(QPainter::Antialiasing);
57 chartView->setRenderHint(QPainter::Antialiasing);
58 //![4]
58 //![4]
59
59
@@ -47,7 +47,7 int main(int argc, char *argv[])
47 //![1]
47 //![1]
48
48
49 //![2]
49 //![2]
50 QStackedBarSeries* series = new QStackedBarSeries();
50 QStackedBarSeries *series = new QStackedBarSeries();
51 series->append(set0);
51 series->append(set0);
52 series->append(set1);
52 series->append(set1);
53 series->append(set2);
53 series->append(set2);
@@ -56,7 +56,7 int main(int argc, char *argv[])
56 //![2]
56 //![2]
57
57
58 //![3]
58 //![3]
59 QChart* chart = new QChart();
59 QChart *chart = new QChart();
60 chart->addSeries(series);
60 chart->addSeries(series);
61 chart->setTitle("Simple stackedbarchart example");
61 chart->setTitle("Simple stackedbarchart example");
62 chart->setAnimationOptions(QChart::SeriesAnimations);
62 chart->setAnimationOptions(QChart::SeriesAnimations);
@@ -65,7 +65,7 int main(int argc, char *argv[])
65 //![4]
65 //![4]
66 QStringList categories;
66 QStringList categories;
67 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
67 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
68 QBarCategoryAxis* axis = new QBarCategoryAxis();
68 QBarCategoryAxis *axis = new QBarCategoryAxis();
69 axis->append(categories);
69 axis->append(categories);
70 chart->createDefaultAxes();
70 chart->createDefaultAxes();
71 chart->setAxisX(axis, series);
71 chart->setAxisX(axis, series);
@@ -77,7 +77,7 int main(int argc, char *argv[])
77 //![5]
77 //![5]
78
78
79 //![6]
79 //![6]
80 QChartView* chartView = new QChartView(chart);
80 QChartView *chartView = new QChartView(chart);
81 chartView->setRenderHint(QPainter::Antialiasing);
81 chartView->setRenderHint(QPainter::Antialiasing);
82 //![6]
82 //![6]
83
83
@@ -38,7 +38,7 void DrilldownChart::changeSeries(DrilldownBarSeries *series)
38 m_currentSeries = series;
38 m_currentSeries = series;
39
39
40 // Reset axis
40 // Reset axis
41 QBarCategoryAxis* axis = new QBarCategoryAxis();
41 QBarCategoryAxis *axis = new QBarCategoryAxis();
42 axis->append(m_currentSeries->categories());
42 axis->append(m_currentSeries->categories());
43
43
44 addSeries(series);
44 addSeries(series);
@@ -52,7 +52,7 void DrilldownChart::changeSeries(DrilldownBarSeries *series)
52 void DrilldownChart::handleClicked(int index, QBarSet *barset)
52 void DrilldownChart::handleClicked(int index, QBarSet *barset)
53 {
53 {
54 Q_UNUSED(barset)
54 Q_UNUSED(barset)
55 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*>(sender());
55 DrilldownBarSeries *series = static_cast<DrilldownBarSeries *>(sender());
56 changeSeries(series->drilldownSeries(index));
56 changeSeries(series->drilldownSeries(index));
57 }
57 }
58
58
@@ -39,7 +39,7 public Q_SLOTS:
39 void handleClicked(int index, QBarSet *barset);
39 void handleClicked(int index, QBarSet *barset);
40
40
41 private:
41 private:
42 DrilldownBarSeries* m_currentSeries;
42 DrilldownBarSeries *m_currentSeries;
43 };
43 };
44 //! [1]
44 //! [1]
45
45
@@ -28,12 +28,12 DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent)
28 m_categories = categories;
28 m_categories = categories;
29 }
29 }
30
30
31 void DrilldownBarSeries::mapDrilldownSeries(int index, DrilldownBarSeries* drilldownSeries)
31 void DrilldownBarSeries::mapDrilldownSeries(int index, DrilldownBarSeries *drilldownSeries)
32 {
32 {
33 m_DrilldownSeries[index] = drilldownSeries;
33 m_DrilldownSeries[index] = drilldownSeries;
34 }
34 }
35
35
36 DrilldownBarSeries* DrilldownBarSeries::drilldownSeries(int index)
36 DrilldownBarSeries *DrilldownBarSeries::drilldownSeries(int index)
37 {
37 {
38 return m_DrilldownSeries[index];
38 return m_DrilldownSeries[index];
39 }
39 }
@@ -33,14 +33,14 class DrilldownBarSeries : public QStackedBarSeries
33 public:
33 public:
34 DrilldownBarSeries(QStringList categories, QObject *parent = 0);
34 DrilldownBarSeries(QStringList categories, QObject *parent = 0);
35
35
36 void mapDrilldownSeries(int index, DrilldownBarSeries* drilldownSeries);
36 void mapDrilldownSeries(int index, DrilldownBarSeries *drilldownSeries);
37
37
38 DrilldownBarSeries* drilldownSeries(int index);
38 DrilldownBarSeries *drilldownSeries(int index);
39
39
40 QStringList categories();
40 QStringList categories();
41
41
42 private:
42 private:
43 QMap<int, DrilldownBarSeries*> m_DrilldownSeries;
43 QMap<int, DrilldownBarSeries *> m_DrilldownSeries;
44 QStringList m_categories;
44 QStringList m_categories;
45 };
45 };
46 //! [1]
46 //! [1]
@@ -34,7 +34,7 int main(int argc, char *argv[])
34 QMainWindow window;
34 QMainWindow window;
35
35
36 //! [1]
36 //! [1]
37 DrilldownChart* drilldownChart = new DrilldownChart();
37 DrilldownChart *drilldownChart = new DrilldownChart();
38 drilldownChart->setTheme(QChart::ChartThemeBlueIcy);
38 drilldownChart->setTheme(QChart::ChartThemeBlueIcy);
39 drilldownChart->setAnimationOptions(QChart::SeriesAnimations);
39 drilldownChart->setAnimationOptions(QChart::SeriesAnimations);
40 //! [1]
40 //! [1]
@@ -51,14 +51,14 int main(int argc, char *argv[])
51
51
52 //! [3]
52 //! [3]
53 // Create drilldown structure
53 // Create drilldown structure
54 DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart);
54 DrilldownBarSeries *seasonSeries = new DrilldownBarSeries(months, drilldownChart);
55 seasonSeries->setName("Crop by month - Season");
55 seasonSeries->setName("Crop by month - Season");
56
56
57 // Each month in season series has drilldown series for weekly data
57 // Each month in season series has drilldown series for weekly data
58 for (int month = 0; month < months.count(); month++) {
58 for (int month = 0; month < months.count(); month++) {
59
59
60 // Create drilldown series for every week
60 // Create drilldown series for every week
61 DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
61 DrilldownBarSeries *weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
62 seasonSeries->mapDrilldownSeries(month, weeklySeries);
62 seasonSeries->mapDrilldownSeries(month, weeklySeries);
63
63
64 // Drilling down from weekly data brings us back to season data.
64 // Drilling down from weekly data brings us back to season data.
@@ -68,19 +68,19 int main(int argc, char *argv[])
68 }
68 }
69
69
70 // Use clicked signal to implement drilldown
70 // Use clicked signal to implement drilldown
71 QObject::connect(weeklySeries, SIGNAL(clicked(int, QBarSet*)), drilldownChart, SLOT(handleClicked(int, QBarSet*)));
71 QObject::connect(weeklySeries, SIGNAL(clicked(int, QBarSet *)), drilldownChart, SLOT(handleClicked(int, QBarSet *)));
72 }
72 }
73
73
74 // Enable drilldown from season series using clicked signal
74 // Enable drilldown from season series using clicked signal
75 QObject::connect(seasonSeries, SIGNAL(clicked(int, QBarSet*)), drilldownChart, SLOT(handleClicked(int, QBarSet*)));
75 QObject::connect(seasonSeries, SIGNAL(clicked(int, QBarSet *)), drilldownChart, SLOT(handleClicked(int, QBarSet *)));
76 //! [3]
76 //! [3]
77
77
78 //! [4]
78 //! [4]
79 // Fill monthly and weekly series with data
79 // Fill monthly and weekly series with data
80 foreach (QString plant, plants) {
80 foreach (QString plant, plants) {
81 QBarSet* monthlyCrop = new QBarSet(plant);
81 QBarSet *monthlyCrop = new QBarSet(plant);
82 for (int month = 0; month < months.count(); month++) {
82 for (int month = 0; month < months.count(); month++) {
83 QBarSet* weeklyCrop = new QBarSet(plant);
83 QBarSet *weeklyCrop = new QBarSet(plant);
84 for (int week = 0; week < weeks.count(); week++)
84 for (int week = 0; week < weeks.count(); week++)
85 *weeklyCrop << (qrand() % 20);
85 *weeklyCrop << (qrand() % 20);
86 // Get the drilldown series from season series and add crop to it.
86 // Get the drilldown series from season series and add crop to it.
@@ -48,7 +48,7 int main(int argc, char *argv[])
48 //![2]
48 //![2]
49
49
50 //![3]
50 //![3]
51 QChart* chart = new QChart();
51 QChart *chart = new QChart();
52 chart->addSeries(series);
52 chart->addSeries(series);
53 chart->setTitle("Temperature records in celcius");
53 chart->setTitle("Temperature records in celcius");
54 chart->setAnimationOptions(QChart::SeriesAnimations);
54 chart->setAnimationOptions(QChart::SeriesAnimations);
@@ -58,7 +58,7 int main(int argc, char *argv[])
58 QStringList categories;
58 QStringList categories;
59 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
59 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
60
60
61 QBarCategoryAxis* axis = new QBarCategoryAxis();
61 QBarCategoryAxis *axis = new QBarCategoryAxis();
62 axis->append(categories);
62 axis->append(categories);
63 chart->createDefaultAxes();
63 chart->createDefaultAxes();
64 chart->setAxisX(axis, series);
64 chart->setAxisX(axis, series);
@@ -71,7 +71,7 int main(int argc, char *argv[])
71 //![5]
71 //![5]
72
72
73 //![6]
73 //![6]
74 QChartView* chartView = new QChartView(chart);
74 QChartView *chartView = new QChartView(chart);
75 chartView->setRenderHint(QPainter::Antialiasing);
75 chartView->setRenderHint(QPainter::Antialiasing);
76 //![6]
76 //![6]
77
77
@@ -41,11 +41,11 Chart::~Chart()
41 bool Chart::sceneEvent(QEvent *event)
41 bool Chart::sceneEvent(QEvent *event)
42 {
42 {
43 if (event->type() == QEvent::Gesture)
43 if (event->type() == QEvent::Gesture)
44 return gestureEvent(static_cast<QGestureEvent*>(event));
44 return gestureEvent(static_cast<QGestureEvent *>(event));
45 return QChart::event(event);
45 return QChart::event(event);
46 }
46 }
47
47
48 bool Chart::gestureEvent(QGestureEvent* event)
48 bool Chart::gestureEvent(QGestureEvent *event)
49 {
49 {
50 if (QGesture *gesture = event->gesture(Qt::PanGesture)) {
50 if (QGesture *gesture = event->gesture(Qt::PanGesture)) {
51 QPanGesture *pan = static_cast<QPanGesture *>(gesture);
51 QPanGesture *pan = static_cast<QPanGesture *>(gesture);
@@ -39,7 +39,7 protected:
39 bool sceneEvent(QEvent *event);
39 bool sceneEvent(QEvent *event);
40
40
41 private:
41 private:
42 bool gestureEvent(QGestureEvent* event);
42 bool gestureEvent(QGestureEvent *event);
43
43
44 private:
44 private:
45
45
@@ -32,7 +32,7 int main(int argc, char *argv[])
32 QApplication a(argc, argv);
32 QApplication a(argc, argv);
33
33
34 //![1]
34 //![1]
35 QLineSeries* series = new QLineSeries();
35 QLineSeries *series = new QLineSeries();
36 for (int i = 0; i < 500; i++) {
36 for (int i = 0; i < 500; i++) {
37 QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
37 QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
38 p.ry() += qrand() % 20;
38 p.ry() += qrand() % 20;
@@ -40,14 +40,14 int main(int argc, char *argv[])
40 }
40 }
41 //![1]
41 //![1]
42
42
43 Chart* chart = new Chart();
43 Chart *chart = new Chart();
44 chart->addSeries(series);
44 chart->addSeries(series);
45 chart->setTitle("Zoom in/out example");
45 chart->setTitle("Zoom in/out example");
46 chart->setAnimationOptions(QChart::SeriesAnimations);
46 chart->setAnimationOptions(QChart::SeriesAnimations);
47 chart->legend()->hide();
47 chart->legend()->hide();
48 chart->createDefaultAxes();
48 chart->createDefaultAxes();
49
49
50 ChartView* chartView = new ChartView(chart);
50 ChartView *chartView = new ChartView(chart);
51 chartView->setRenderHint(QPainter::Antialiasing);
51 chartView->setRenderHint(QPainter::Antialiasing);
52
52
53 QMainWindow window;
53 QMainWindow window;
General Comments 0
You need to be logged in to leave comments. Login now