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

Method MainWindow

examples/ModelView/HidingData/mainwindow.cpp:25–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23using namespace KDChart;
24
25MainWindow::MainWindow(QWidget *parent)
26 : QWidget(parent)
27{
28 setupUi(this);
29
30 auto *chartLayout = new QHBoxLayout(chartFrame);
31 m_chart = new Chart();
32 m_chart->setGlobalLeading(20, 20, 20, 20);
33 chartLayout->addWidget(m_chart);
34
35 // Initialize the model, and fill it with data
36 const int rowCount = 8;
37 const int columnCount = 3;
38 m_model = new QStandardItemModel(rowCount, columnCount, this);
39 m_model->setHeaderData(0, Qt::Horizontal, tr("Product A"));
40 m_model->setHeaderData(1, Qt::Horizontal, tr("Product B"));
41 m_model->setHeaderData(2, Qt::Horizontal, tr("Product C"));
42 openFile(":/Charts/qtdata.cht");
43
44 // Set up the diagram
45 m_lines = new LineDiagram();
46 // Register the data model at the diagram
47 m_lines->setModel(m_model);
48 // Add axes to the diagram
49 auto *xAxis = new CartesianAxis(m_lines);
50 auto *yAxis = new CartesianAxis(m_lines);
51 xAxis->setPosition(KDChart::CartesianAxis::Bottom);
52 yAxis->setPosition(KDChart::CartesianAxis::Left);
53 m_lines->addAxis(xAxis);
54 m_lines->addAxis(yAxis);
55 // Make the lines thicker
56 for (int iColumn = 0; iColumn < columnCount; ++iColumn) {
57 QPen linePen(m_lines->pen(iColumn));
58 linePen.setWidth(3);
59 m_lines->setPen(iColumn, linePen);
60 }
61 // Register the diagram at the coordinate plane
62 m_chart->coordinatePlane()->replaceDiagram(m_lines);
63
64 // Add a legend
65 auto *legend = new Legend(m_lines, m_chart);
66 legend->setPosition(Position::South);
67 legend->setAlignment(Qt::AlignCenter);
68 legend->setShowLines(true);
69 legend->setTitleText("");
70 legend->setOrientation(Qt::Horizontal);
71 legend->addDiagram(m_lines);
72 m_chart->addLegend(legend);
73}
74
75void MainWindow::on_showDataset1CB_toggled(bool checked)
76{

Callers

nothing calls this directly

Calls 15

setHeaderDataMethod · 0.80
setShowLinesMethod · 0.80
setGlobalLeadingMethod · 0.45
setModelMethod · 0.45
setPositionMethod · 0.45
addAxisMethod · 0.45
penMethod · 0.45
setPenMethod · 0.45
replaceDiagramMethod · 0.45
coordinatePlaneMethod · 0.45
setAlignmentMethod · 0.45
setTitleTextMethod · 0.45

Tested by

no test coverage detected