File indexing completed on 2024-05-12 15:53:55
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 "ModelParamVsParam.h" 0021 0022 0023 ModelParamVsParam::ModelParamVsParam( 0024 QObject *p_parent) 0025 : 0026 QStandardItemModel(p_parent) 0027 { 0028 connect(&m_timer, SIGNAL(timeout()), SLOT(timeout())); 0029 //m_timer.setSingleShot(true); 0030 m_timer.setInterval(2000); 0031 } // ModelParamVsParam::ModelParamVsParam() 0032 0033 0034 void ModelParamVsParam::setTimeout( 0035 int p_timeout) 0036 { 0037 m_timer.setInterval(p_timeout * 1000); 0038 } // ModelParamVsParam::setTimeout() 0039 0040 0041 void ModelParamVsParam::startSampling() 0042 { 0043 m_timer.start(); 0044 } // ModelParamVsParam::startSampling() 0045 0046 0047 void ModelParamVsParam::stopSampling() 0048 { 0049 m_timer.stop(); 0050 } // ModelParamVsParam::stopSampling() 0051 0052 0053 void ModelParamVsParam::populate( 0054 int p_nrOfParameters, 0055 int p_nrOfSamples) 0056 { 0057 m_timer.stop(); 0058 0059 setColumnCount(p_nrOfParameters); 0060 setRowCount(p_nrOfSamples); 0061 timeout(); 0062 0063 m_timer.start(); 0064 } // ModelParamVsParam::populate() 0065 0066 0067 void ModelParamVsParam::timeout() 0068 { 0069 blockSignals(true); 0070 0071 for (int r = 0; r < rowCount(); r++) 0072 for (int c = 0; c < columnCount(); c++) 0073 { 0074 // First column values in range 0..10, second column in range 10..20 etc. 0075 qreal offset(c * 10); 0076 qreal value(offset + (10.0 * rand()) / RAND_MAX); 0077 setData(index(r, c), value); 0078 } 0079 0080 blockSignals(false); 0081 0082 QModelIndex topLeft(index(0, 0)); 0083 QModelIndex bottomRight(index(rowCount() - 1, columnCount() - 1)); 0084 Q_EMIT dataChanged(topLeft, bottomRight); 0085 } // ModelParamVsParam::timeout()