-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqchart.cpp
93 lines (65 loc) · 2.31 KB
/
qchart.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "qchart.h"
#include <QPainter>
#include <QDebug>
// QVector<QVector<QString>>
// QHash<QString, Qstring> "name", "Ricardo"; "name", "Sergey"
// QVector <QHash<QString, float>>
// Qhash<QString, float>. 1. "Mon", 5.6; "Thu", 10; "Wed"
// QVariant
//struct SunDay;
//QHash<QString, QVariant>
// "DownloadTime", QDateTime
// onDataChanged(const SunDay &data)
Qchart::Qchart(QWidget *parent) :
QWidget(parent)
{
}
void Qchart::onDataChanged(const QList<float> &data)
{
_data = data;
emit repaint();
}
/*------------------------------------------------------------------------------------------------
;
; chart paintings - All paints doing only in this fuction
;
;------------------------------------------------------------------------------------------------*/
void Qchart::paintEvent(QPaintEvent *)
{
QPainter p(this);
QPen pen(Qt::black);
if( _data.size() == 0 ) return;
// qDebug() << "== paint chart : " << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm");
// -- paint background ----------------------------
QColor bgColor = palette().color(QPalette::Window);
pen.setBrush( QBrush(bgColor) );
QColor kool(92, 92, 92 ); //, 200);
p.setPen(pen);
p.setBrush(kool);
p.drawRect(0, 0, rect().width(), rect().height());
// -- write update time
p.setPen(Qt::white);
p.setFont(QFont("Verdana", 10));
QString s = "Sunshine Forecast, ";
s += QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm");
p.drawText( 10, 15, s );
// == paint the chart =============
int res = rect().height()/12; // max 14 hours sun by day
int dx, dy, colWidth;
colWidth = rect().width() / _data.size() - 1;
for (int i=0; i < _data.size(); i++) {
dx = colWidth * i;
dy = res * _data.at(i);
QRect rectBar( dx+5, rect().height()-dy, colWidth-6, dy );
// -- Border color for each column in distribution
p.setPen(QColor(0, 0x80, 0xff));
p.drawRect( rectBar );
// -- Fill color for each column in distribution
p.setBrush(QBrush(Qt::blue));
p.drawRect( rectBar );
// -- write day value label
p.setPen(Qt::white);
p.setFont(QFont("Verdana", 12));
p.drawText( dx+12, rect().height() - 3, QString("%1").arg( _data.at(i), 0, 'g', 2) );
}
}