-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServiceCostPieDialog.cpp
More file actions
154 lines (129 loc) · 3.97 KB
/
ServiceCostPieDialog.cpp
File metadata and controls
154 lines (129 loc) · 3.97 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "ServiceCostPieDialog.h"
#include "ui_ServiceCostPieDialog.h"
ServiceCostPieDialog::ServiceCostPieDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ServiceCostPieDialog)
{
ui->setupUi(this);
setWindowFlags( Qt::Dialog | Qt::WindowTitleHint | Qt::WindowCloseButtonHint );
ui->widget->setTagFont(this->font());
ui->widget->setLegendFont(this->font());
QFont sumFont = this->font();
sumFont.setPointSizeF(sumFont.pointSizeF() * 2);
ui->widget->setSumFont(sumFont);
ui->widget->setTitle("Title");
//White background
ui->widget->setAutoFillBackground(true);
QPalette palette = ui->widget->palette();
palette.setColor(QPalette::Window, Qt::white);
ui->widget->setPalette(palette);
}
ServiceCostPieDialog::~ServiceCostPieDialog()
{
delete ui;
}
QStringList extendColors()
{
const QStringList colors = { "palevioletred", "darkred", "tomato", "chocolate", "sandybrown", "gold", "yellowgreen", "seagreen", "mediumturquoise", "deepskyblue" };
QStringList extendedColors = colors;
// add bright colors
for (const auto& colorName : colors) {
QColor color(colorName);
color = color.lighter(130); // 130% brighter
extendedColors.append(color.name());
}
// add dark colors
for (const auto& colorName : colors) {
QColor color(colorName);
color = color.darker(150); // 150% darker
extendedColors.append(color.name());
}
return extendedColors;
}
void ServiceCostPieDialog::SetData(QStringList nameList, QList<double> costListM, QList<int> costListT, QString currency)
{
//Error? Nothing to do...
if( nameList.count() != costListM.count() ) return;
if( nameList.count() != costListT.count() ) return;
m_nameList = nameList;
m_costListM = costListM;
m_costListT = costListT;
m_currency = currency;
drawCostM();
}
void ServiceCostPieDialog::on_pushButtonClose_clicked()
{
close();
}
void ServiceCostPieDialog::drawCostM()
{
QStringList nameList = m_nameList;
QList<double> costListM = m_costListM;
//Filter empty entries
for( int i = nameList.count() - 1; i >= 0; i-- )
{
if( costListM.at(i) == 0.0 )
{
nameList.removeAt(i);
costListM.removeAt(i);
}
}
//Colors
QStringList extendedColors = extendColors();
QList<QColor> colorList;
for( int i = 0; i < nameList.count(); i++ )
{
colorList.append( QPalette( extendedColors[i%extendedColors.size()] ).brush( QPalette::Window ).color() );
}
//Setup
ui->widget->setSumUnit( m_currency );
ui->widget->setSeries( nameList, costListM, colorList );
//White background
ui->widget->setAutoFillBackground(true);
QPalette palette = ui->widget->palette();
palette.setColor(QPalette::Window, Qt::white);
ui->widget->setPalette(palette);
ui->widget->repaint();
}
void ServiceCostPieDialog::drawCostT()
{
QStringList nameList = m_nameList;
QList<double> costListT;
//Filter empty entries
for( int i = nameList.count() - 1; i >= 0; i-- )
{
if( m_costListT.at(i) == 0 )
{
nameList.removeAt(i);
}
else
{
costListT.prepend(m_costListT.at(i));
}
}
//Colors
QStringList extendedColors = extendColors();
QList<QColor> colorList;
for( int i = 0; i < nameList.count(); i++ )
{
colorList.append( QPalette( extendedColors[i%extendedColors.size()] ).brush( QPalette::Window ).color() );
}
//Setup
ui->widget->setSumUnit( "hh:mm" );
ui->widget->setSeries( nameList, costListT, colorList );
ui->widget->repaint();
}
void ServiceCostPieDialog::on_pushButtonMoney_clicked()
{
blockSignals( true );
ui->pushButtonTime->setChecked( false );
blockSignals( false );
drawCostM();
}
void ServiceCostPieDialog::on_pushButtonTime_clicked()
{
blockSignals( true );
ui->pushButtonMoney->setChecked( false );
blockSignals( false );
drawCostT();
}