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

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