-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsm3_temps.cpp
175 lines (133 loc) · 5.15 KB
/
sm3_temps.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! \file sm_font.cpp
#include "sysmon3.h"
#include "sm3_temps.h"
#include "udp.h"
SM3_Temps::SM3_Temps( SM_Settings* setngs, QString dta )
{
settingsPtr = setngs;
data = dta;
QString family = settingsPtr->value( "fontFamily" );
int fontSize = settingsPtr->value( "fontSize" ).toInt();
QFont oldfont = QFont( family, fontSize );
widgetsPtr = new SM_Widgets( oldfont );
// Get current font; second parameter is default
QFont font = QFont( family, fontSize, QFont::Normal );
// Frame layout
setWindowTitle( "Temperature Selection Dialog" );
QVBoxLayout* topbox = new QVBoxLayout( this );
topbox->setSpacing( 2 );
get_saved_temp_config();
get_temp_data();
int row = 0;
tempsLayout = new QGridLayout();
QLabel* lblInterface = widgetsPtr->sm_banner( "Interface" );
QLabel* lblSensor = widgetsPtr->sm_banner( "Sensor" );
QLabel* lblSelected = widgetsPtr->sm_banner( "Selected" );
QLabel* lblLabel = widgetsPtr->sm_banner( "Label" );
tempsLayout->addWidget( lblInterface, row, 0 );
tempsLayout->addWidget( lblSensor, row, 1 );
tempsLayout->addWidget( lblSelected, row, 2 );
tempsLayout->addWidget( lblLabel, row++, 3 );
// A line (lines 2 to n) looks like:
// interface:<interface name>,<sensor name:value[,<sensor name:value...]
// Add temperature data
for ( int i = 1; i < sensors.size(); i++ ) // Skip first line -- not temps
{
// line[ 0 ] is "interface"
// line[ 1 ] is rest of line
QStringList line = sensors[ i ].split( ';' );
QStringList items = line[ 1 ].split( ',' );
QString interface = items[ 0 ]; // interface name
for ( int j = 1; j < items.size(); j++ )
{
QString sensor = items.at( j ).split( ":" )[ 0 ];
// Check with settings to see if the checkbox is should be set
// and the label cusomized
lblInterface = widgetsPtr->sm_label( interface );
lblSensor = widgetsPtr->sm_label( sensor );
QCheckBox* cbBox = new QCheckBox();
cbBox->setFont( font );
QLineEdit* leLabel = widgetsPtr->sm_lineedit( sensor, 0 );
// See if we have the entry in settings
QString key = interface + "," + sensor;
foreach (const QString value, config )
{
if ( value.contains( key ) )
{
cbBox->setCheckState( Qt::Checked );
QStringList entries = value.split( "," );
leLabel->setText( entries[ 2 ] );
break;
}
}
tempsLayout->addWidget( lblInterface, row, 0 );
tempsLayout->addWidget( lblSensor, row, 1 );
tempsLayout->addWidget( cbBox, row, 2, Qt::AlignHCenter );
tempsLayout->addWidget( leLabel, row++, 3 );
}
}
// Buttons
pb_apply = widgetsPtr->sm_pushbutton( tr( "Apply" ) );
connect( pb_apply, SIGNAL( clicked() ), SLOT( apply() ) );
//pb_help = sm_pushbutton( tr( "Help" ) );
//connect( pb_help, SIGNAL( clicked() ), SLOT( help() ) );
pb_exit = widgetsPtr->sm_pushbutton( tr( "Exit" ) );
connect( pb_exit, SIGNAL( clicked() ), SLOT( close() ) );
QBoxLayout* buttons = new QHBoxLayout();
buttons->addWidget( pb_apply );
//buttons->addWidget( pb_help );
buttons->addWidget( pb_exit );
topbox->addLayout( tempsLayout );
topbox->addLayout( buttons );
}
void SM3_Temps::get_temp_data( void )
{
sensors = data.split( '\n', Qt::SkipEmptyParts );
}
void SM3_Temps::get_saved_temp_config()
{
QString group = QString( "temperatures" );
config = settingsPtr->readGroup( group );
}
void SM3_Temps::apply()
{
QStringList config;
QString group = QString( "temperatures" );
// Remove the group
settingsPtr->removeGroup( group );
// Start over
int index = tempsLayout->rowCount();
// Write settings
// key = interface,sensor,label
for ( int i = 1; i < index ; i++ )
{
QWidget* item;
QString interface;
QString sensor;
QCheckBox* cb;
QString label;
QString key;
item = tempsLayout->itemAtPosition( i, 2 )->widget();
cb = dynamic_cast<QCheckBox*>(item);
if ( ! cb->isChecked() ) continue;
item = tempsLayout->itemAtPosition( i, 0 )->widget();
interface = dynamic_cast<QLabel*>(item)->text();
item = tempsLayout->itemAtPosition( i, 1 )->widget();
sensor = dynamic_cast<QLabel*>(item)->text();
// Get line edit entry, but remove any commas
item = tempsLayout->itemAtPosition( i, 3 )->widget();
label = dynamic_cast<QLineEdit*>(item)->text();
label.remove( "," );
// Set temperature entry in settings
key = "temp" + QString::number( i );
config << QString( key + ";" + interface + "," + sensor + "," + label );
}
settingsPtr->addGroup( group, config );
settingsPtr->sync();
emit updateTemps();
}
//void SM_Font::help()
//{
// US_Help* help = new US_Help();
// help->show_help( "manual/usfont.html" );
//}