-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyparam.cpp
More file actions
69 lines (63 loc) · 1.66 KB
/
myparam.cpp
File metadata and controls
69 lines (63 loc) · 1.66 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
#include "myparam.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QBoxLayout>
void
MyParamD::setDisplay(const QString& label, QWidget *parent, QBoxLayout *layout)
{
if (this->ledit) delete this->ledit;
QHBoxLayout *hl = new QHBoxLayout(parent);
hl->addWidget(new QLabel(label));
hl->addWidget(this->ledit = new QLineEdit);
if (layout) layout->addLayout(hl);
connect(ledit,SIGNAL(returnPressed()),this,SLOT(textToValue()));
updateDisplay();
}
void MyParamD::textToValue()
{
if (!ledit) return;
double t = this->ledit->text().toDouble();
if (t != this->v)
{
this->v = t;
emit valueChanged();
}
}
void MyParamD::updateDisplay()
{
if (!ledit) return;
QString aText;
aText.sprintf("%lg",this->v);
this->ledit->setText(aText);
}
//--------------------------------------------------------------------
void
MyParamI::setDisplay(const QString& label, QWidget *parent, QBoxLayout *layout)
{
if (this->ledit) delete this->ledit;
QHBoxLayout *hl = new QHBoxLayout(parent);
hl->addWidget(new QLabel(label));
hl->addWidget(this->ledit = new QLineEdit);
if (layout) layout->addLayout(hl);
connect(ledit,SIGNAL(returnPressed()),this,SLOT(textToValue()));
// connect(this,SIGNAL(valueChanged()),this,SLOT(updateDisplay()));
updateDisplay();
}
void MyParamI::textToValue()
{
if (!ledit) return;
int t = this->ledit->text().toInt();
if (t != this->v)
{
this->v = t;
emit valueChanged();
}
}
void MyParamI::updateDisplay()
{
if (!ledit) return;
QString aText;
aText.sprintf("%i",this->v);
this->ledit->setText(aText);
}