| 18 | #include <QtGui> |
| 19 | |
| 20 | class ChartWidget : public QWidget |
| 21 | { |
| 22 | Q_OBJECT |
| 23 | public: |
| 24 | explicit ChartWidget(QWidget *parent = 0) |
| 25 | : QWidget(parent) |
| 26 | { |
| 27 | m_model.insertRows(0, 0, QModelIndex()); |
| 28 | auto *diagram = new KDChart::BarDiagram; |
| 29 | diagram->setModel(&m_model); |
| 30 | |
| 31 | auto *legend = new KDChart::Legend(diagram, diagram); |
| 32 | m_chart.addLegend(legend); |
| 33 | |
| 34 | // The code below doesn't work, but it would |
| 35 | // be nice if it did: |
| 36 | #if 0 |
| 37 | KDChart::Legend* legend = new KDChart::Legend; |
| 38 | legend->addDiagram(diagram1); |
| 39 | legend->addDiagram(diagram2); |
| 40 | ... |
| 41 | m_chart.addLegend(legend); |
| 42 | #endif |
| 43 | |
| 44 | auto *abcissa = new KDChart::CartesianAxis(diagram); |
| 45 | abcissa->setPosition(KDChart::CartesianAxis::Bottom); |
| 46 | auto *ordinate = new KDChart::CartesianAxis(diagram); |
| 47 | ordinate->setPosition(KDChart::CartesianAxis::Left); |
| 48 | diagram->addAxis(abcissa); |
| 49 | diagram->addAxis(ordinate); |
| 50 | |
| 51 | // NOTE: If this is done before adding axes, |
| 52 | // the axes don't show up at all |
| 53 | m_chart.coordinatePlane()->replaceDiagram(diagram); |
| 54 | |
| 55 | m_rowbutton.setText(tr("Add rows")); |
| 56 | m_colbutton.setText(tr("Add columns")); |
| 57 | connect(&m_rowbutton, SIGNAL(clicked()), |
| 58 | this, SLOT(addRows())); |
| 59 | connect(&m_colbutton, SIGNAL(clicked()), |
| 60 | this, SLOT(addCols())); |
| 61 | |
| 62 | auto *l = new QVBoxLayout(this); |
| 63 | l->addWidget(&m_chart); |
| 64 | l->addWidget(&m_rowbutton); |
| 65 | l->addWidget(&m_colbutton); |
| 66 | |
| 67 | setLayout(l); |
| 68 | } |
| 69 | |
| 70 | private slots: |
| 71 | |
| 72 | void addRows() |
| 73 | { |
| 74 | m_model.insertRows(m_model.rowCount(), 1); |
| 75 | for (int i = 0; i < m_model.columnCount(); ++i) { |
| 76 | m_model.setData(m_model.index(m_model.rowCount() - 1, i), i); |
| 77 | } |
nothing calls this directly
no test coverage detected