Warning, file /graphics/kdiagram/examples/RealTime/main.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /** 0002 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include <QStandardItemModel> 0021 #include <QTimer> 0022 #include <KChartChart> 0023 #include <KChartBarDiagram> 0024 0025 #include <QApplication> 0026 0027 0028 class ChartWidget : public QWidget { 0029 Q_OBJECT 0030 public: 0031 explicit ChartWidget(QWidget* parent = nullptr) 0032 : QWidget(parent) 0033 { 0034 0035 m_model.insertRows( 0, 2, QModelIndex() ); 0036 m_model.insertColumns( 0, 3, QModelIndex() ); 0037 for (int row = 0; row < 3; ++row) { 0038 for (int column = 0; column < 3; ++column) { 0039 QModelIndex index = m_model.index(row, column, QModelIndex()); 0040 m_model.setData(index, QVariant(row+1 * column) ); 0041 } 0042 } 0043 0044 KChart::BarDiagram* diagram = new KChart::BarDiagram; 0045 diagram->setModel(&m_model); 0046 0047 m_chart.coordinatePlane()->replaceDiagram(diagram); 0048 0049 QVBoxLayout* l = new QVBoxLayout(this); 0050 l->addWidget(&m_chart); 0051 setLayout(l); 0052 m_timer = new QTimer(this); 0053 connect( m_timer, SIGNAL(timeout()), 0054 this, SLOT(slotTimeout()) ); 0055 m_timer->start( 200 ); 0056 } 0057 0058 private Q_SLOTS: 0059 void slotTimeout() { 0060 QModelIndex index = m_model.index( 0, 1, QModelIndex()); 0061 qreal value = ( m_model.data( index ).toInt() % 24 ) +1; 0062 m_model.setData( index, value ); 0063 } 0064 0065 private: 0066 KChart::Chart m_chart; 0067 QStandardItemModel m_model; 0068 QTimer *m_timer; 0069 }; 0070 0071 int main( int argc, char** argv ) { 0072 QApplication app( argc, argv ); 0073 0074 ChartWidget w; 0075 w.show(); 0076 0077 return app.exec(); 0078 } 0079 0080 #include "main.moc"