Browse Source

thermostat: edit_dlg: prog is updated on screen now

master
Richard Genoud 4 years ago
parent
commit
797769c94c
3 changed files with 92 additions and 51 deletions
  1. +2
    -2
      soft/thermostat/inc/edit_dlg.h
  2. +88
    -48
      soft/thermostat/src/edit_dlg.cpp
  3. +2
    -1
      soft/thermostat/src/mainwindow.cpp

+ 2
- 2
soft/thermostat/inc/edit_dlg.h View File

@ -27,10 +27,11 @@ public:
EditDlg(int idx, QWidget *parent = Q_NULLPTR,
Qt::WindowFlags f = Qt::WindowFlags());
~EditDlg();
void refresh_progs(void);
private:
void set_font(QWidget *widget);
QHBoxLayout *add_prog_layout(const struct Program *p, int idx);
QHBoxLayout *add_prog_layout(int idx);
QDoubleSpinBox m_default_temperature;
QVBoxLayout *m_progsLayout;
@ -43,7 +44,6 @@ private slots:
void reject(void);
void delete_prog_clicked(void);
void edit_prog_clicked(void);
void refresh_progs(void);
signals:
void close_edit_dlg(void);


+ 88
- 48
soft/thermostat/src/edit_dlg.cpp View File

@ -97,7 +97,7 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent,
m_progsLayout = new QVBoxLayout;
for (int i = 0; i < m_progs.count(); i++) {
QHBoxLayout *progLayout = add_prog_layout(&(m_progs.at(i)), i);
QHBoxLayout *progLayout = add_prog_layout(i);
m_progsLayout->addLayout(progLayout);
}
@ -106,12 +106,13 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent,
topLayout->addLayout(btnLayout);
this->setLayout(topLayout);
refresh_progs();
}
QHBoxLayout *EditDlg::add_prog_layout(const struct Program *p, int idx)
QHBoxLayout *EditDlg::add_prog_layout(int idx)
{
QString sheet;
QString text;
QHBoxLayout *progLayout = new QHBoxLayout;
@ -119,56 +120,15 @@ QHBoxLayout *EditDlg::add_prog_layout(const struct Program *p, int idx)
QSizePolicy::MinimumExpanding,
QSizePolicy::PushButton);
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");
QLabel *prog_temperature = new QLabel(QString(text));
QLabel *prog_temperature = new QLabel();
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("M")); break;
case 1: text += QString(tr("Tu")); break;
case 2: text += QString(tr("W")); break;
case 3: text += QString(tr("Th")); break;
case 4: text += QString(tr("F")); break;
case 5: text += QString(tr("Sa")); break;
case 6: text += QString(tr("Su")); break;
}
}
}
}
QLabel *prog_DoW = new QLabel(QString(text));
QLabel *prog_DoW = new QLabel();
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_time= new QLabel(QString(text));
QLabel *prog_time = new QLabel();
set_font(prog_time);
progLayout->addWidget(prog_time, 0, Qt::AlignHCenter);
@ -208,6 +168,86 @@ void EditDlg::set_font(QWidget *widget)
void EditDlg::refresh_progs(void)
{
QLayoutItem *lineItem, *item;
QLayout *layout;
struct Program *p;
QWidget *w;
QLabel *l;
QString text;
if (m_progsLayout->count() != m_progs.count()) {
// TODO ERROR: index mismatch
return;
}
for (int i = 0; i < m_progsLayout->count(); i++) {
lineItem = m_progsLayout->itemAt(i);
if (lineItem && lineItem->layout()) {
layout = lineItem->layout();
// temperature
item = layout->itemAt(0);
w = item->widget();
l = qobject_cast<QLabel *>(w);
p = &m_progs[i];
qDebug() << "temperature:" << p->temperature;
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");
l->setText(QString(text));
// DoW
item = layout->itemAt(1);
w = item->widget();
l = qobject_cast<QLabel *>(w);
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("M")); break;
case 1: text += QString(tr("Tu")); break;
case 2: text += QString(tr("W")); break;
case 3: text += QString(tr("Th")); break;
case 4: text += QString(tr("F")); break;
case 5: text += QString(tr("Sa")); break;
case 6: text += QString(tr("Su")); break;
}
}
}
}
l->setText(QString(text));
// time
item = layout->itemAt(2);
w = item->widget();
l = qobject_cast<QLabel *>(w);
text = QString("");
text += p->start_time.toString(QString(" HH:mm"));
text += p->end_time.toString(QString("-HH:mm"));
l->setText(QString(text));
}
}
}
void EditDlg::save(void)
@ -242,7 +282,7 @@ void EditDlg::add(void)
p.end_time = QTime(0,0);
m_progs << p;
layout = add_prog_layout(&(m_progs.at(idx)), idx);
layout = add_prog_layout(idx);
m_progsLayout->addLayout(layout);
}


+ 2
- 1
soft/thermostat/src/mainwindow.cpp View File

@ -219,7 +219,6 @@ void MainWindow::do_show_edit_prog_dlg(struct Program &p)
m_central_widget.addWidget(edit_prog_dlg);
m_central_widget.setCurrentWidget(edit_prog_dlg);
connect(edit_prog_dlg, SIGNAL(close_edit_prog_dlg(void)), this, SLOT(do_close_edit_prog_dlg(void)));
connect(edit_prog_dlg, SIGNAL(close_edit_prog_dlg(void)), m_edit_dlg, SLOT(refresh_progs(void)));
}
void MainWindow::do_close_edit_prog_dlg(void)
@ -231,6 +230,8 @@ void MainWindow::do_close_edit_prog_dlg(void)
m_central_widget.removeWidget(current);
delete current;
m_edit_dlg->refresh_progs();
}
void MainWindow::show_menu(void)


Loading…
Cancel
Save