chore(cpn): implement ui bindings to auto widgets and apply to timers (#7331)
This commit is contained in:
@@ -23,52 +23,82 @@
|
||||
#include "ui_setup_timer.h"
|
||||
#include "namevalidator.h"
|
||||
|
||||
TimerPanel::TimerPanel(QWidget * parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware,
|
||||
QWidget * prevFocus, FilteredItemModelFactory * panelFilteredModels, CompoundItemModelFactory * panelItemModels):
|
||||
TimerPanel::TimerPanel(QWidget * parent, ModelData & model, TimerData & timer,
|
||||
GeneralSettings & generalSettings, Firmware * firmware,
|
||||
QWidget * prevFocus,
|
||||
FilteredItemModelFactory * panelFilteredModels,
|
||||
CompoundItemModelFactory * panelItemModels):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
timer(timer),
|
||||
ui(new Ui::Timer),
|
||||
modelsUpdateCnt(0)
|
||||
ui(new Ui::Timer)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connectItemModelEvents(panelFilteredModels->getItemModel(FIM_TIMERSWITCH));
|
||||
|
||||
lock = true;
|
||||
imEventHandler = new ItemModelEventHandler(
|
||||
panelFilteredModels->getItemModel(FIM_TIMERSWITCH),
|
||||
lock,
|
||||
[this] { this->update(); }
|
||||
);
|
||||
|
||||
// Name
|
||||
int length = firmware->getCapability(TimersName);
|
||||
if (length == 0)
|
||||
ui->name->hide();
|
||||
else {
|
||||
ui->name->setValidator(new NameValidator(firmware->getBoard(), 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());
|
||||
connect(ui->value, &AutoTimeEdit::currentDataChanged, [=](const int val) {
|
||||
update();
|
||||
ui->name->setValidator(new NameValidator(firmware->getBoard(), this));
|
||||
ui->name->setField(timer.name, firmware->getCapability(TimersName), this);
|
||||
ui->name->setBindPostChanged([this] {
|
||||
emit this->nameChanged();
|
||||
});
|
||||
|
||||
// Start
|
||||
ui->value->setField(timer.val, this);
|
||||
ui->value->setMaximumTime(firmware->getMaxTimerStart());
|
||||
ui->value->setBindPostChanged([this]{
|
||||
this->update();
|
||||
});
|
||||
|
||||
// Mode
|
||||
ui->mode->setModel(panelItemModels->getItemModel(AIM_TIMER_MODE));
|
||||
ui->mode->setField(timer.mode, this);
|
||||
connect(ui->mode, SIGNAL(currentDataChanged(int)), this, SLOT(onModeChanged(int)));
|
||||
ui->mode->setBindPostChanged([this] {
|
||||
this->timer.modeChanged();
|
||||
this->update();
|
||||
emit this->modeChanged();
|
||||
});
|
||||
|
||||
// Switch
|
||||
ui->swtch->setModel(panelFilteredModels->getItemModel(FIM_TIMERSWITCH));
|
||||
ui->swtch->setField(timer.swtch, this);
|
||||
ui->swtch->setBindEnabled([this] {
|
||||
return this->timer.mode != TimerData::TIMERMODE_OFF;
|
||||
});
|
||||
|
||||
// Countdown
|
||||
ui->countdownBeep->setModel(panelItemModels->getItemModel(AIM_TIMER_COUNTDOWNBEEP));
|
||||
ui->countdownBeep->setField(timer.countdownBeep, this);
|
||||
connect(ui->countdownBeep, SIGNAL(currentDataChanged(int)), this, SLOT(onCountdownBeepChanged(int)));
|
||||
|
||||
ui->minuteBeep->setField(timer.minuteBeep, this);
|
||||
ui->persistent->setModel(panelItemModels->getItemModel(AIM_TIMER_PERSISTENT));
|
||||
ui->persistent->setField(timer.persistent, this);
|
||||
ui->countdownBeep->setBindPostChanged([this] {
|
||||
this->timer.countdownBeepChanged();
|
||||
this->update();
|
||||
});
|
||||
ui->countdownStart->setModel(panelItemModels->getItemModel(AIM_TIMER_COUNTDOWNSTART));
|
||||
ui->countdownStart->setField(timer.countdownStart, this);
|
||||
ui->countdownStart->setBindEnabled([this] {
|
||||
return this->timer.countdownBeep != TimerData::COUNTDOWNBEEP_SILENT;
|
||||
});
|
||||
ui->countdownStart->addBuddyWidget(ui->countdownStartLabel);
|
||||
|
||||
// Minute call
|
||||
ui->minuteBeep->setField(timer.minuteBeep, this);
|
||||
|
||||
// Persistence
|
||||
ui->persistent->setModel(panelItemModels->getItemModel(AIM_TIMER_PERSISTENT));
|
||||
ui->persistent->setField(timer.persistent, this);
|
||||
|
||||
// Time type
|
||||
ui->showElapsed->setModel(panelItemModels->getItemModel(AIM_TIMER_SHOWELAPSED));
|
||||
ui->showElapsed->setField(timer.showElapsed, this);
|
||||
ui->showElapsed->setBindEnabled([this] { return this->timer.val; });
|
||||
|
||||
// Time
|
||||
// do not use setField as the raw value is meaningless
|
||||
ui->persistentValue->setBindText([this] { return this->timer.pvalueToString(); });
|
||||
|
||||
disableMouseScrolling();
|
||||
QWidget::setTabOrder(prevFocus, ui->name);
|
||||
@@ -81,51 +111,18 @@ TimerPanel::TimerPanel(QWidget * parent, ModelData & model, TimerData & timer, G
|
||||
QWidget::setTabOrder(ui->persistent, ui->showElapsed);
|
||||
|
||||
update();
|
||||
lock = false;
|
||||
}
|
||||
|
||||
TimerPanel::~TimerPanel()
|
||||
{
|
||||
delete ui;
|
||||
delete imEventHandler;
|
||||
}
|
||||
|
||||
void TimerPanel::update()
|
||||
{
|
||||
lock = true;
|
||||
|
||||
ui->name->updateValue();
|
||||
ui->mode->updateValue();
|
||||
ui->swtch->updateValue();
|
||||
ui->value->updateValue();
|
||||
ui->countdownBeep->updateValue();
|
||||
ui->minuteBeep->updateValue();
|
||||
ui->countdownStart->updateValue();
|
||||
ui->showElapsed->updateValue();
|
||||
|
||||
if (timer.mode != TimerData::TIMERMODE_OFF)
|
||||
ui->swtch->setEnabled(true);
|
||||
else
|
||||
ui->swtch->setEnabled(false);
|
||||
|
||||
if (timer.countdownBeep == TimerData::COUNTDOWNBEEP_SILENT) {
|
||||
ui->countdownStartLabel->setEnabled(false);
|
||||
ui->countdownStart->setEnabled(false);
|
||||
}
|
||||
else {
|
||||
ui->countdownStartLabel->setEnabled(true);
|
||||
ui->countdownStart->setEnabled(true);
|
||||
}
|
||||
|
||||
ui->persistent->updateValue();
|
||||
ui->persistentValue->setText(timer.pvalueToString());
|
||||
|
||||
if (timer.val) {
|
||||
ui->showElapsed->setEnabled(true);
|
||||
}
|
||||
else {
|
||||
ui->showElapsed->setEnabled(false);
|
||||
}
|
||||
|
||||
updateAutoWidgets();
|
||||
lock = false;
|
||||
}
|
||||
|
||||
@@ -133,42 +130,3 @@ QWidget * TimerPanel::getLastFocus()
|
||||
{
|
||||
return ui->persistent;
|
||||
}
|
||||
|
||||
void TimerPanel::connectItemModelEvents(const FilteredItemModel * itemModel)
|
||||
{
|
||||
connect(itemModel, &FilteredItemModel::aboutToBeUpdated, this, &TimerPanel::onItemModelAboutToBeUpdated);
|
||||
connect(itemModel, &FilteredItemModel::updateComplete, this, &TimerPanel::onItemModelUpdateComplete);
|
||||
}
|
||||
|
||||
void TimerPanel::onItemModelAboutToBeUpdated()
|
||||
{
|
||||
lock = true;
|
||||
modelsUpdateCnt++;
|
||||
}
|
||||
|
||||
void TimerPanel::onItemModelUpdateComplete()
|
||||
{
|
||||
modelsUpdateCnt--;
|
||||
if (modelsUpdateCnt < 1) {
|
||||
update();
|
||||
lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
void TimerPanel::onNameChanged()
|
||||
{
|
||||
emit nameChanged();
|
||||
}
|
||||
|
||||
void TimerPanel::onCountdownBeepChanged(int index)
|
||||
{
|
||||
timer.countdownBeepChanged();
|
||||
update();
|
||||
}
|
||||
|
||||
void TimerPanel::onModeChanged(int index)
|
||||
{
|
||||
timer.modeChanged();
|
||||
update();
|
||||
emit modeChanged();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "modeledit.h"
|
||||
#include "eeprominterface.h"
|
||||
#include "filtereditemmodels.h"
|
||||
#include "itemmodeleventhandler.h"
|
||||
|
||||
constexpr char FIM_TIMERSWITCH[] {"Timer Switch"};
|
||||
constexpr char MIMETYPE_TIMER[] {"application/x-companion-timer"};
|
||||
@@ -44,15 +44,6 @@ class TimerPanel : public ModelPanel
|
||||
virtual void update();
|
||||
QWidget * getLastFocus();
|
||||
|
||||
public slots:
|
||||
void onNameChanged();
|
||||
void onModeChanged(int index);
|
||||
|
||||
private slots:
|
||||
void onItemModelAboutToBeUpdated();
|
||||
void onItemModelUpdateComplete();
|
||||
void onCountdownBeepChanged(int index);
|
||||
|
||||
signals:
|
||||
void nameChanged();
|
||||
void modeChanged();
|
||||
@@ -60,6 +51,5 @@ class TimerPanel : public ModelPanel
|
||||
private:
|
||||
TimerData & timer;
|
||||
Ui::Timer * ui;
|
||||
void connectItemModelEvents(const FilteredItemModel * itemModel);
|
||||
int modelsUpdateCnt;
|
||||
ItemModelEventHandler *imEventHandler;
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="currentSection">
|
||||
<enum>QDateTimeEdit::HourSection</enum>
|
||||
<enum>QDateTimeEdit::Section::HourSection</enum>
|
||||
</property>
|
||||
<property name="displayFormat">
|
||||
<string notr="true">hh:mm:ss</string>
|
||||
@@ -62,7 +62,7 @@
|
||||
<widget class="AutoComboBox" name="swtch"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="countdownBeepLabel">
|
||||
<widget class="AutoLabel" name="countdownBeepLabel">
|
||||
<property name="text">
|
||||
<string>Countdown</string>
|
||||
</property>
|
||||
@@ -72,7 +72,7 @@
|
||||
<widget class="AutoComboBox" name="countdownBeep"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="countdownStartLabel">
|
||||
<widget class="AutoLabel" name="countdownStartLabel">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
@@ -95,7 +95,7 @@
|
||||
<widget class="AutoComboBox" name="showElapsed"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="persistentValue">
|
||||
<widget class="AutoLabel" name="persistentValue">
|
||||
<property name="text">
|
||||
<string notr="true"> (00:00:00)</string>
|
||||
</property>
|
||||
@@ -104,7 +104,7 @@
|
||||
<item>
|
||||
<spacer name="spacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -137,6 +137,11 @@
|
||||
<extends>QTimeEdit</extends>
|
||||
<header>autotimeedit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>AutoLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>autolabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
Reference in New Issue
Block a user