| 25 | using namespace KDChart; |
| 26 | |
| 27 | class ChartWidget : public QWidget |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | public: |
| 31 | explicit ChartWidget(QWidget *parent = nullptr) |
| 32 | : QWidget(parent) |
| 33 | { |
| 34 | m_model.insertRows(0, 6, QModelIndex()); |
| 35 | m_model.insertColumns(0, 4, QModelIndex()); |
| 36 | for (int row = 0; row < 6; ++row) { |
| 37 | for (int column = 0; column < 4; ++column) { |
| 38 | QModelIndex index = m_model.index(row, column, QModelIndex()); |
| 39 | m_model.setData(index, QVariant(row * 0.5 + column)); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | auto *diagram = new LineDiagram; |
| 44 | diagram->setModel(&m_model); |
| 45 | |
| 46 | auto *xAxis = new CartesianAxis(diagram); |
| 47 | auto *yAxis = new CartesianAxis(diagram); |
| 48 | xAxis->setPosition(KDChart::CartesianAxis::Bottom); |
| 49 | yAxis->setPosition(KDChart::CartesianAxis::Left); |
| 50 | diagram->addAxis(xAxis); |
| 51 | diagram->addAxis(yAxis); |
| 52 | |
| 53 | m_chart.coordinatePlane()->replaceDiagram(diagram); |
| 54 | |
| 55 | /* Header */ |
| 56 | |
| 57 | // Add at one Header and set it up |
| 58 | auto *header = new HeaderFooter(&m_chart); |
| 59 | header->setPosition(Position::North); |
| 60 | header->setText("A Line Chart with Grid Configured"); |
| 61 | m_chart.addHeaderFooter(header); |
| 62 | |
| 63 | // Configure the Header text attributes |
| 64 | TextAttributes hta; |
| 65 | hta.setPen(QPen(Qt::red)); |
| 66 | |
| 67 | // let the header resize itself |
| 68 | // together with the widget. |
| 69 | // so-called relative size |
| 70 | Measure m(35.0); |
| 71 | m.setRelativeMode(header->autoReferenceArea(), |
| 72 | KDChartEnums::MeasureOrientationMinimum); |
| 73 | hta.setFontSize(m); |
| 74 | // min font size |
| 75 | m.setValue(3.0); |
| 76 | m.setCalculationMode(KDChartEnums::MeasureCalculationModeAbsolute); |
| 77 | hta.setMinimalFontSize(m); |
| 78 | header->setTextAttributes(hta); |
| 79 | |
| 80 | // Configure the Header's Background |
| 81 | BackgroundAttributes hba; |
| 82 | hba.setBrush(Qt::white); |
| 83 | hba.setVisible(true); |
| 84 | header->setBackgroundAttributes(hba); |
nothing calls this directly
no test coverage detected