1 /**
2 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "ModelParamVsParam.h"
21
22
ModelParamVsParam(QObject * p_parent)23 ModelParamVsParam::ModelParamVsParam(
24 QObject *p_parent)
25 :
26 QStandardItemModel(p_parent)
27 {
28 connect(&m_timer, SIGNAL(timeout()), SLOT(timeout()));
29 //m_timer.setSingleShot(true);
30 m_timer.setInterval(2000);
31 } // ModelParamVsParam::ModelParamVsParam()
32
33
setTimeout(int p_timeout)34 void ModelParamVsParam::setTimeout(
35 int p_timeout)
36 {
37 m_timer.setInterval(p_timeout * 1000);
38 } // ModelParamVsParam::setTimeout()
39
40
startSampling()41 void ModelParamVsParam::startSampling()
42 {
43 m_timer.start();
44 } // ModelParamVsParam::startSampling()
45
46
stopSampling()47 void ModelParamVsParam::stopSampling()
48 {
49 m_timer.stop();
50 } // ModelParamVsParam::stopSampling()
51
52
populate(int p_nrOfParameters,int p_nrOfSamples)53 void ModelParamVsParam::populate(
54 int p_nrOfParameters,
55 int p_nrOfSamples)
56 {
57 m_timer.stop();
58
59 setColumnCount(p_nrOfParameters);
60 setRowCount(p_nrOfSamples);
61 timeout();
62
63 m_timer.start();
64 } // ModelParamVsParam::populate()
65
66
timeout()67 void ModelParamVsParam::timeout()
68 {
69 blockSignals(true);
70
71 for (int r = 0; r < rowCount(); r++)
72 for (int c = 0; c < columnCount(); c++)
73 {
74 // First column values in range 0..10, second column in range 10..20 etc.
75 qreal offset(c * 10);
76 qreal value(offset + (10.0 * rand()) / RAND_MAX);
77 setData(index(r, c), value);
78 }
79
80 blockSignals(false);
81
82 QModelIndex topLeft(index(0, 0));
83 QModelIndex bottomRight(index(rowCount() - 1, columnCount() - 1));
84 Q_EMIT dataChanged(topLeft, bottomRight);
85 } // ModelParamVsParam::timeout()
86