Browse Source

thermostat: edit_dlg: factorize "add prog" code for future use

master
Richard Genoud 4 years ago
parent
commit
f92e208db9
2 changed files with 76 additions and 64 deletions
  1. +1
    -0
      soft/thermostat/inc/edit_dlg.h
  2. +75
    -64
      soft/thermostat/src/edit_dlg.cpp

+ 1
- 0
soft/thermostat/inc/edit_dlg.h View File

@ -28,6 +28,7 @@ public:
private:
void set_font(QWidget *widget);
QHBoxLayout *add_prog_layout(const struct Program *p, int idx);
QDoubleSpinBox m_default_temperature;
QVBoxLayout *m_progsLayout;


+ 75
- 64
soft/thermostat/src/edit_dlg.cpp View File

@ -30,7 +30,6 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent,
{
Settings *s = Settings::getInstance();
const struct Room r = s->getRoom(idx);
const struct Program *p = NULL;
QString sheet;
QString text;
@ -98,87 +97,99 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent,
m_progsLayout = new QVBoxLayout;
for (int i = 0; i < m_progs.count(); i++) {
p = &(m_progs.at(i));
QHBoxLayout *progLayout = add_prog_layout(&(m_progs.at(i)), i);
m_progsLayout->addLayout(progLayout);
}
QHBoxLayout *progLayout = new QHBoxLayout;
topLayout->addLayout(m_progsLayout);
text = QString("");
if (p->temperature == FORCE_OFF) {
text += QString("-");
} else {
if (p->temperature == FORCE_ON) {
text += QString("+");
} else {
text += QString::number(p->temperature);
}
}
text += QString("°C");
topLayout->addLayout(btnLayout);
this->setLayout(topLayout);
}
QHBoxLayout *EditDlg::add_prog_layout(const struct Program *p, int idx)
{
QString sheet;
QString text;
QLabel *prog_temperature = new QLabel(QString(text));
set_font(prog_temperature);
progLayout->addWidget(prog_temperature, 0, Qt::AlignHCenter);
QHBoxLayout *progLayout = new QHBoxLayout;
text = QString("");
if (p->DoW == 0) {
text += QString("-");
QSizePolicy *szPolicy = new QSizePolicy(QSizePolicy::Minimum,
QSizePolicy::MinimumExpanding,
QSizePolicy::PushButton);
text = QString("");
if (p->temperature == FORCE_OFF) {
text += QString("-");
} else {
if (p->temperature == FORCE_ON) {
text += QString("+");
} else {
bool isFirst = true;
for (int j = 0; j < 7; j++) {
if (p->DoW & (1 << j)) {
if (isFirst) {
isFirst = false;
} else {
text += QString("/");
}
text += QString::number(p->temperature);
}
}
text += QString("°C");
QLabel *prog_temperature = new QLabel(QString(text));
set_font(prog_temperature);
progLayout->addWidget(prog_temperature, 0, Qt::AlignHCenter);
text = QString("");
if (p->DoW == 0) {
text += QString("-");
} else {
bool isFirst = true;
for (int j = 0; j < 7; j++) {
if (p->DoW & (1 << j)) {
if (isFirst) {
isFirst = false;
} else {
text += QString("/");
}
switch (j) {
case 0: text += QString(tr("Mo")); break;
case 1: text += QString(tr("Tu")); break;
case 2: text += QString(tr("We")); break;
case 3: text += QString(tr("Th")); break;
case 4: text += QString(tr("Fr")); break;
case 5: text += QString(tr("Sa")); break;
case 6: text += QString(tr("Su")); break;
}
switch (j) {
case 0: text += QString(tr("Mo")); break;
case 1: text += QString(tr("Tu")); break;
case 2: text += QString(tr("We")); break;
case 3: text += QString(tr("Th")); break;
case 4: text += QString(tr("Fr")); break;
case 5: text += QString(tr("Sa")); break;
case 6: text += QString(tr("Su")); break;
}
}
}
QLabel *prog_DoW = new QLabel(QString(text));
set_font(prog_DoW);
progLayout->addWidget(prog_DoW, 0, Qt::AlignHCenter);
text = QString("");
text += p->start_time.toString(QString(" HH:mm"));
text += p->end_time.toString(QString("-HH:mm"));
}
QLabel *prog_DoW = new QLabel(QString(text));
set_font(prog_DoW);
progLayout->addWidget(prog_DoW, 0, Qt::AlignHCenter);
QLabel *prog_time= new QLabel(QString(text));
set_font(prog_time);
progLayout->addWidget(prog_time, 0, Qt::AlignHCenter);
text = QString("");
text += p->start_time.toString(QString(" HH:mm"));
text += p->end_time.toString(QString("-HH:mm"));
QPushButton *edit_btn = new QPushButton(tr("Edit"), this);
QPushButton *delete_btn = new QPushButton(tr("Delete"), this);
QLabel *prog_time= new QLabel(QString(text));
set_font(prog_time);
progLayout->addWidget(prog_time, 0, Qt::AlignHCenter);
set_font(edit_btn);
set_font(delete_btn);
QPushButton *edit_btn = new QPushButton(tr("Edit"), this);
QPushButton *delete_btn = new QPushButton(tr("Delete"), this);
edit_btn->setSizePolicy(*szPolicy);
delete_btn->setSizePolicy(*szPolicy);
set_font(edit_btn);
set_font(delete_btn);
edit_btn->setProperty("idx", i);
delete_btn->setProperty("idx", i);
edit_btn->setSizePolicy(*szPolicy);
delete_btn->setSizePolicy(*szPolicy);
connect(delete_btn, SIGNAL(clicked(void)), this, SLOT(delete_prog_clicked(void)));
edit_btn->setProperty("idx", idx);
delete_btn->setProperty("idx", idx);
progLayout->addWidget(edit_btn, 0, Qt::AlignHCenter);
progLayout->addWidget(delete_btn, 0, Qt::AlignHCenter);
connect(delete_btn, SIGNAL(clicked(void)), this, SLOT(delete_prog_clicked(void)));
m_progsLayout->addLayout(progLayout);
}
topLayout->addLayout(m_progsLayout);
progLayout->addWidget(edit_btn, 0, Qt::AlignHCenter);
progLayout->addWidget(delete_btn, 0, Qt::AlignHCenter);
topLayout->addLayout(btnLayout);
this->setLayout(topLayout);
return progLayout;
}
void EditDlg::set_font(QWidget *widget)


Loading…
Cancel
Save