Browse Source

thermostat: edit_dlg: suppress a line

master
Richard Genoud 4 years ago
parent
commit
e4210ac3b6
2 changed files with 61 additions and 19 deletions
  1. +2
    -2
      soft/thermostat/inc/edit_dlg.h
  2. +59
    -17
      soft/thermostat/src/edit_dlg.cpp

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

@ -14,7 +14,7 @@
#include <QObject>
#include <QSpinBox>
#include <QDateTime>
#include <QGridLayout>
#include <QVBoxLayout>
#include <QDoubleSpinBox>
class EditDlg : public QWidget
@ -30,7 +30,7 @@ private:
void set_font(QWidget *widget);
QDoubleSpinBox m_default_temperature;
QGridLayout *m_progLayout;
QVBoxLayout *m_progsLayout;
QVector<struct Program> m_progs;
int m_idx; // room index


+ 59
- 17
soft/thermostat/src/edit_dlg.cpp View File

@ -6,6 +6,7 @@
*
*/
#include <QLoggingCategory>
#include <QDialogButtonBox>
#include <QSpinBox>
#include <QPushButton>
@ -89,11 +90,13 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent,
topLayout->addLayout(upperLayout);
m_progLayout = new QGridLayout;
m_progsLayout = new QVBoxLayout;
for (int i = 0; i < m_progs.count(); i++) {
p = &(m_progs.at(i));
QHBoxLayout *progLayout = new QHBoxLayout;
text = QString("");
if (p->temperature == FORCE_OFF) {
text += QString("-");
@ -108,7 +111,7 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent,
QLabel *prog_temperature = new QLabel(QString(text));
set_font(prog_temperature);
m_progLayout->addWidget(prog_temperature, i, 0, Qt::AlignHCenter);
progLayout->addWidget(prog_temperature, 0, Qt::AlignHCenter);
text = QString("");
if (p->DoW == 0) {
@ -137,7 +140,7 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent,
}
QLabel *prog_DoW = new QLabel(QString(text));
set_font(prog_DoW);
m_progLayout->addWidget(prog_DoW, i, 1, Qt::AlignHCenter);
progLayout->addWidget(prog_DoW, 0, Qt::AlignHCenter);
text = QString("");
text += p->start_time.toString(QString(" HH:mm"));
@ -145,7 +148,7 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent,
QLabel *prog_time= new QLabel(QString(text));
set_font(prog_time);
m_progLayout->addWidget(prog_time, i, 2, Qt::AlignHCenter);
progLayout->addWidget(prog_time, 0, Qt::AlignHCenter);
QPushButton *edit_btn = new QPushButton(tr("Edit"), this);
QPushButton *delete_btn = new QPushButton(tr("Delete"), this);
@ -161,11 +164,12 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent,
connect(delete_btn, SIGNAL(clicked(void)), this, SLOT(delete_prog_clicked(void)));
m_progLayout->addWidget(edit_btn, i, 3, Qt::AlignHCenter);
m_progLayout->addWidget(delete_btn, i, 4, Qt::AlignHCenter);
progLayout->addWidget(edit_btn, 0, Qt::AlignHCenter);
progLayout->addWidget(delete_btn, 0, Qt::AlignHCenter);
topLayout->addLayout(m_progLayout);
m_progsLayout->addLayout(progLayout);
}
topLayout->addLayout(m_progsLayout);
topLayout->addLayout(btnLayout);
@ -202,10 +206,11 @@ void EditDlg::reject(void)
void EditDlg::delete_prog_clicked(void)
{
QLayoutItem *item;
QLayoutItem *lineItem, *item;
QLayout *layout;
QObject* obj = sender();
QVariant v;
QWidget *w;
QVariant v;
int idx;
v = obj->property("idx");
@ -213,27 +218,64 @@ void EditDlg::delete_prog_clicked(void)
return;
idx = v.toInt();
if (idx >= m_progLayout->rowCount()) {
if (idx >= m_progsLayout->count()) {
// TODO ERROR: index mismatch
return;
}
// remove the corresponding program
m_progs.remove(idx);
for (int i = 0; i < m_progLayout->columnCount(); i++) {
item = m_progLayout->itemAtPosition(idx, i);
// retrieve the corresponding line
lineItem = m_progsLayout->itemAt(idx);
if (lineItem == NULL) {
// TODO: hum, this should not happend
return;
}
// and remove it
m_progsLayout->removeItem(lineItem);
// We also need to remove the Hlayout and all widgets attached
layout = lineItem->layout();
if (layout == NULL) {
// TODO: this shouldn't happend neither
return;
}
while (layout->count()) {
item = layout->itemAt(0);
if (item && item->widget()) {
w = item->widget();
m_progLayout->removeWidget(w);
layout->removeWidget(w);
w->hide();
delete w;
} else {
layout->removeItem(item);
delete item;
}
}
for (int j = idx; j < (m_progLayout->rowCount() - 1); j++) {
delete lineItem;
// renumber the buttons' properties
for (int i = idx; i < m_progsLayout->count(); i++) {
lineItem = m_progsLayout->itemAt(i);
if (lineItem && lineItem->layout()) {
layout = lineItem->layout();
for (int j = 0; j < layout->count(); j++) {
item = layout->itemAt(j);
if (item && item->widget()) {
w = item->widget();
v = w->property("idx");
if (v.isValid()) {
qDebug() << "new:" << v.toInt()-1;
w->setProperty("idx", v.toInt() - 1);
}
}
}
}
}
}
EditDlg::~EditDlg()


Loading…
Cancel
Save