Use autotimeedit in setup timers

This commit is contained in:
elecpower
2021-03-17 20:26:11 +11:00
parent 3eed78dbd5
commit 521bdde1fd
4 changed files with 25 additions and 27 deletions
+12 -19
View File
@@ -48,8 +48,13 @@ TimerPanel::TimerPanel(QWidget * parent, ModelData & model, TimerData & timer, G
int length = firmware->getCapability(TimersName); int length = firmware->getCapability(TimersName);
if (length == 0) if (length == 0)
ui->name->hide(); ui->name->hide();
else else {
ui->name->setField(timer.name, length, this); ui->name->setField(timer.name, length, this);
connect(ui->name, SIGNAL(currentDataChanged()), this, SLOT(onNameChanged()));
}
ui->value->setField(timer.val, this);
ui->value->setMaximumTime(firmware->getMaxTimerStart());
// Mode // Mode
ui->mode->setModel(panelFilteredModels->getItemModel(FIM_TIMERSWITCH)); ui->mode->setModel(panelFilteredModels->getItemModel(FIM_TIMERSWITCH));
@@ -60,8 +65,6 @@ TimerPanel::TimerPanel(QWidget * parent, ModelData & model, TimerData & timer, G
ui->countdownBeep->setField(timer.countdownBeep, this); ui->countdownBeep->setField(timer.countdownBeep, this);
connect(ui->countdownBeep, SIGNAL(currentDataChanged(int)), this, SLOT(onCountdownBeepDataChanged(int))); connect(ui->countdownBeep, SIGNAL(currentDataChanged(int)), this, SLOT(onCountdownBeepDataChanged(int)));
ui->value->setMaximumTime(firmware->getMaxTimerStart());
ui->minuteBeep->setField(timer.minuteBeep, this); ui->minuteBeep->setField(timer.minuteBeep, this);
if (firmware->getCapability(PermTimers)) { if (firmware->getCapability(PermTimers)) {
@@ -100,11 +103,7 @@ void TimerPanel::update()
ui->name->updateValue(); ui->name->updateValue();
ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue())); ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue()));
ui->value->updateValue();
int hour = timer.val / 3600;
int min = (timer.val - (hour * 3600)) / 60;
int sec = (timer.val - (hour * 3600)) % 60;
ui->value->setTime(QTime(hour, min, sec));
ui->countdownBeep->updateValue(); ui->countdownBeep->updateValue();
ui->minuteBeep->updateValue(); ui->minuteBeep->updateValue();
@@ -129,17 +128,6 @@ QWidget * TimerPanel::getLastFocus()
return ui->persistent; return ui->persistent;
} }
void TimerPanel::on_value_editingFinished()
{
if (!lock) {
unsigned val = ui->value->time().hour() * 3600 + ui->value->time().minute() * 60 + ui->value->time().second();
if (timer.val != val) {
timer.val = val;
emit modified();
}
}
}
void TimerPanel::onModeChanged(int index) void TimerPanel::onModeChanged(int index)
{ {
if (!lock) { if (!lock) {
@@ -173,6 +161,11 @@ void TimerPanel::onItemModelUpdateComplete()
} }
} }
void TimerPanel::onNameChanged()
{
emit nameChanged();
}
void TimerPanel::onCountdownBeepDataChanged(int index) void TimerPanel::onCountdownBeepDataChanged(int index)
{ {
timer.countdownBeepChanged(); timer.countdownBeepChanged();
+1 -1
View File
@@ -47,7 +47,7 @@ class TimerPanel : public ModelPanel
private slots: private slots:
void onModeChanged(int index); void onModeChanged(int index);
void on_value_editingFinished(); void onNameChanged();
void onItemModelAboutToBeUpdated(); void onItemModelAboutToBeUpdated();
void onItemModelUpdateComplete(); void onItemModelUpdateComplete();
void onCountdownBeepDataChanged(int index); void onCountdownBeepDataChanged(int index);
+6 -1
View File
@@ -43,7 +43,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QTimeEdit" name="value"> <widget class="AutoTimeEdit" name="value">
<property name="accelerated"> <property name="accelerated">
<bool>true</bool> <bool>true</bool>
</property> </property>
@@ -126,6 +126,11 @@
<extends>QCheckBox</extends> <extends>QCheckBox</extends>
<header>autocheckbox.h</header> <header>autocheckbox.h</header>
</customwidget> </customwidget>
<customwidget>
<class>AutoTimeEdit</class>
<extends>QTimeEdit</extends>
<header>autotimeedit.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>
+6 -6
View File
@@ -37,21 +37,21 @@ class AutoTimeEdit: public QTimeEdit
connect(this, SIGNAL(timeChanged(QTime)), this, SLOT(onTimeChanged(QTime))); connect(this, SIGNAL(timeChanged(QTime)), this, SLOT(onTimeChanged(QTime)));
} }
void setField(int & field, GenericPanel * panel = nullptr) void setField(unsigned int & field, GenericPanel * panel = nullptr)
{ {
this->field = &field; this->field = &field;
this->panel = panel; this->panel = panel;
updateValue(); updateValue();
} }
void setMinimumTime(QTime time) void setMinimumTime(const QTime time)
{ {
QTimeEdit::setMinimumTime(QTime time); QTimeEdit::setMinimumTime(time);
} }
void setMaximumTime(QTime time) void setMaximumTime(const QTime time)
{ {
QTimeEdit::setMaximumTime(QTime time); QTimeEdit::setMaximumTime(time);
} }
void setEnabled(bool enabled) void setEnabled(bool enabled)
@@ -90,7 +90,7 @@ class AutoTimeEdit: public QTimeEdit
} }
protected: protected:
int *field = nullptr; unsigned int *field = nullptr;
GenericPanel *panel = nullptr; GenericPanel *panel = nullptr;
bool lock = false; bool lock = false;
}; };