@@ -1,67 +1,68 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef MODEL_H_ |
|
21 | #ifndef MODEL_H_ | |
22 | #define MODEL_H_ |
|
22 | #define MODEL_H_ | |
23 |
|
23 | |||
24 | #include <QList> |
|
24 | #include <QList> | |
25 | #include <QPair> |
|
25 | #include <QPair> | |
26 | #include <QPointF> |
|
26 | #include <QPointF> | |
27 | #include <QTime> |
|
27 | #include <QTime> | |
|
28 | #include <stdlib.h> | |||
28 |
|
29 | |||
29 | typedef QPair<QPointF, QString> Data; |
|
30 | typedef QPair<QPointF, QString> Data; | |
30 | typedef QList<Data> DataList; |
|
31 | typedef QList<Data> DataList; | |
31 | typedef QList<DataList> DataTable; |
|
32 | typedef QList<DataList> DataTable; | |
32 |
|
33 | |||
33 |
|
34 | |||
34 | class Model |
|
35 | class Model | |
35 | { |
|
36 | { | |
36 | private: |
|
37 | private: | |
37 | Model(){} |
|
38 | Model(){} | |
38 |
|
39 | |||
39 | public: |
|
40 | public: | |
40 | static DataTable generateRandomData(int listCount, int valueMax, int valueCount) |
|
41 | static DataTable generateRandomData(int listCount, int valueMax, int valueCount) | |
41 | { |
|
42 | { | |
42 | DataTable dataTable; |
|
43 | DataTable dataTable; | |
43 |
|
44 | |||
44 | // set seed for random stuff |
|
45 | // set seed for random stuff | |
45 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
46 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
46 |
|
47 | |||
47 | // generate random data |
|
48 | // generate random data | |
48 | for (int i(0); i < listCount; i++) { |
|
49 | for (int i(0); i < listCount; i++) { | |
49 | DataList dataList; |
|
50 | DataList dataList; | |
50 | qreal yValue(0); |
|
51 | qreal yValue(0); | |
51 | for (int j(0); j < valueCount; j++) { |
|
52 | for (int j(0); j < valueCount; j++) { | |
52 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
53 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; | |
53 | QPointF value( |
|
54 | QPointF value( | |
54 | (j + (qreal) qrand() / (qreal) RAND_MAX) |
|
55 | (j + (qreal) qrand() / (qreal) RAND_MAX) | |
55 | * ((qreal) valueMax / (qreal) valueCount), yValue); |
|
56 | * ((qreal) valueMax / (qreal) valueCount), yValue); | |
56 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); |
|
57 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); | |
57 | dataList << Data(value, label); |
|
58 | dataList << Data(value, label); | |
58 | } |
|
59 | } | |
59 | dataTable << dataList; |
|
60 | dataTable << dataList; | |
60 | } |
|
61 | } | |
61 |
|
62 | |||
62 | return dataTable; |
|
63 | return dataTable; | |
63 | } |
|
64 | } | |
64 |
|
65 | |||
65 | }; |
|
66 | }; | |
66 |
|
67 | |||
67 | #endif |
|
68 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now