File indexing completed on 2024-05-12 04:20:13

0001 /**
0002  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include <QStandardItemModel>
0010 #include <QTimer>
0011 #include <KChartChart>
0012 #include <KChartBarDiagram>
0013 
0014 #include <QApplication>
0015 
0016 
0017 class ChartWidget : public QWidget {
0018   Q_OBJECT
0019 public:
0020   explicit ChartWidget(QWidget* parent = nullptr)
0021     : QWidget(parent)
0022   {
0023 
0024     m_model.insertRows( 0, 2, QModelIndex() );
0025     m_model.insertColumns(  0,  3,  QModelIndex() );
0026     for (int row = 0; row < 3; ++row) {
0027             for (int column = 0; column < 3; ++column) {
0028                 QModelIndex index = m_model.index(row, column, QModelIndex());
0029                 m_model.setData(index, QVariant(row+1 * column) );
0030             }
0031     }
0032 
0033     KChart::BarDiagram* diagram = new KChart::BarDiagram;
0034     diagram->setModel(&m_model);
0035 
0036     m_chart.coordinatePlane()->replaceDiagram(diagram);
0037 
0038     QVBoxLayout* l = new QVBoxLayout(this);
0039     l->addWidget(&m_chart);
0040     setLayout(l);
0041     m_timer = new QTimer(this);
0042     connect( m_timer, SIGNAL(timeout()),
0043              this, SLOT(slotTimeout()) );
0044     m_timer->start( 200 );
0045   }
0046 
0047 private Q_SLOTS:
0048       void slotTimeout() {
0049           QModelIndex index = m_model.index( 0, 1, QModelIndex());
0050           qreal value = ( m_model.data( index ).toInt() % 24 ) +1;
0051           m_model.setData( index, value );
0052       }
0053 
0054 private:
0055   KChart::Chart m_chart;
0056   QStandardItemModel m_model;
0057   QTimer *m_timer;
0058 };
0059 
0060 int main( int argc, char** argv ) {
0061     QApplication app( argc, argv );
0062 
0063     ChartWidget w;
0064     w.show();
0065 
0066     return app.exec();
0067 }
0068 
0069 #include "main.moc"