MCPcopy Create free account
hub / github.com/KDAB/KDChart / addRows

Function addRows

tests/DelayedData/main.cpp:20–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18#include <QtGui>
19
20class ChartWidget : public QWidget
21{
22 Q_OBJECT
23public:
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
70private 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 }

Callers

nothing calls this directly

Calls 5

insertRowsMethod · 0.80
rowCountMethod · 0.45
columnCountMethod · 0.45
setDataMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected