Merge with latest 2.3
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
#include "ui_setup.h"
|
||||
#include "ui_setup_timer.h"
|
||||
#include "ui_setup_module.h"
|
||||
#include "filtereditemmodels.h"
|
||||
#include "appdata.h"
|
||||
#include "modelprinter.h"
|
||||
#include "multiprotocols.h"
|
||||
@@ -31,54 +30,53 @@
|
||||
|
||||
#include <QDir>
|
||||
|
||||
TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware,
|
||||
QWidget * prevFocus, FilteredItemModel * rawSwitchFilteredModel):
|
||||
constexpr char FIM_TIMERSWITCH[] {"Timer Switch"};
|
||||
constexpr char FIM_THRSOURCE[] {"Throttle Source"};
|
||||
|
||||
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)
|
||||
ui(new Ui::Timer),
|
||||
modelsUpdateCnt(0)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connectItemModelEvents(rawSwitchFilteredModel);
|
||||
connectItemModelEvents(panelFilteredModels->getItemModel(FIM_TIMERSWITCH));
|
||||
|
||||
lock = true;
|
||||
|
||||
// Name
|
||||
int length = firmware->getCapability(TimersName);
|
||||
if (length == 0) {
|
||||
if (length == 0)
|
||||
ui->name->hide();
|
||||
else {
|
||||
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());
|
||||
|
||||
ui->mode->setModel(panelFilteredModels->getItemModel(FIM_TIMERSWITCH));
|
||||
ui->mode->setField(timer.mode, this);
|
||||
|
||||
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);
|
||||
|
||||
if (firmware->getCapability(PermTimers)) {
|
||||
ui->persistent->setModel(panelItemModels->getItemModel(AIM_TIMER_PERSISTENT));
|
||||
ui->persistent->setField(timer.persistent, this);
|
||||
}
|
||||
else {
|
||||
ui->name->setMaxLength(length);
|
||||
}
|
||||
|
||||
// Mode
|
||||
ui->mode->setModel(rawSwitchFilteredModel);
|
||||
ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue()));
|
||||
connect(ui->mode, SIGNAL(activated(int)), this, SLOT(onModeChanged(int)));
|
||||
|
||||
if (!firmware->getCapability(PermTimers)) {
|
||||
ui->persistent->hide();
|
||||
ui->persistentValue->hide();
|
||||
}
|
||||
|
||||
ui->countdownBeep->setField(timer.countdownBeep, this);
|
||||
ui->countdownBeep->addItem(tr("Silent"), TimerData::COUNTDOWN_SILENT);
|
||||
ui->countdownBeep->addItem(tr("Beeps"), TimerData::COUNTDOWN_BEEPS);
|
||||
ui->countdownBeep->addItem(tr("Voice"), TimerData::COUNTDOWN_VOICE);
|
||||
ui->countdownBeep->addItem(tr("Haptic"), TimerData::COUNTDOWN_HAPTIC);
|
||||
|
||||
ui->value->setMaximumTime(firmware->getMaxTimerStart());
|
||||
|
||||
ui->persistent->setField(timer.persistent, this);
|
||||
ui->persistent->addItem(tr("Not persistent"), 0);
|
||||
ui->persistent->addItem(tr("Persistent (flight)"), 1);
|
||||
ui->persistent->addItem(tr("Persistent (manual reset)"), 2);
|
||||
|
||||
ui->countdownStart->setModel(panelItemModels->getItemModel(AIM_TIMER_COUNTDOWNSTART));
|
||||
ui->countdownStart->setField(timer.countdownStart, this);
|
||||
ui->countdownStart->addItem("5s", 1);
|
||||
ui->countdownStart->addItem("10s", 0);
|
||||
ui->countdownStart->addItem("20s", -1);
|
||||
ui->countdownStart->addItem("30s", -2);
|
||||
|
||||
disableMouseScrolling();
|
||||
QWidget::setTabOrder(prevFocus, ui->name);
|
||||
@@ -102,33 +100,27 @@ void TimerPanel::update()
|
||||
{
|
||||
lock = true;
|
||||
|
||||
ui->name->setText(timer.name);
|
||||
ui->name->updateValue();
|
||||
ui->mode->updateValue();
|
||||
ui->value->updateValue();
|
||||
ui->countdownBeep->updateValue();
|
||||
ui->minuteBeep->updateValue();
|
||||
ui->countdownStart->updateValue();
|
||||
|
||||
int hour = timer.val / 3600;
|
||||
int min = (timer.val - (hour * 3600)) / 60;
|
||||
int sec = (timer.val - (hour * 3600)) % 60;
|
||||
if (timer.countdownBeep == TimerData::COUNTDOWNBEEP_SILENT) {
|
||||
ui->countdownStartLabel->setEnabled(false);
|
||||
ui->countdownStart->setEnabled(false);
|
||||
}
|
||||
else {
|
||||
ui->countdownStartLabel->setEnabled(true);
|
||||
ui->countdownStart->setEnabled(true);
|
||||
}
|
||||
|
||||
ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue()));
|
||||
ui->value->setTime(QTime(hour, min, sec));
|
||||
|
||||
if (firmware->getCapability(PermTimers)) {
|
||||
int sign = 1;
|
||||
int pvalue = timer.pvalue;
|
||||
if (pvalue < 0) {
|
||||
pvalue = -pvalue;
|
||||
sign = -1;
|
||||
}
|
||||
int hours = pvalue / 3600;
|
||||
pvalue -= hours * 3600;
|
||||
int minutes = pvalue / 60;
|
||||
int seconds = pvalue % 60;
|
||||
ui->persistentValue->setText(QString(" %1(%2:%3:%4)").arg(sign < 0 ? "-" :" ").arg(hours, 2, 10, QLatin1Char('0')).arg(minutes, 2, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0')));
|
||||
ui->persistent->updateValue();
|
||||
ui->persistentValue->setText(timer.pvalueToString());
|
||||
}
|
||||
|
||||
ui->countdownBeep->updateValue();
|
||||
ui->minuteBeep->setChecked(timer.minuteBeep);
|
||||
ui->persistent->updateValue();
|
||||
ui->countdownStart->updateValue();
|
||||
lock = false;
|
||||
}
|
||||
|
||||
@@ -137,57 +129,6 @@ QWidget * TimerPanel::getLastFocus()
|
||||
return ui->persistent;
|
||||
}
|
||||
|
||||
void TimerPanel::on_countdownBeep_currentIndexChanged(int index)
|
||||
{
|
||||
if(index == TimerData::COUNTDOWN_SILENT)
|
||||
ui->countdownStart->hide();
|
||||
else
|
||||
ui->countdownStart->show();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (!lock) {
|
||||
bool ok;
|
||||
const RawSwitch rs(ui->mode->itemData(index).toInt(&ok));
|
||||
if (ok && timer.mode.toValue() != rs.toValue()) {
|
||||
timer.mode = rs;
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimerPanel::on_minuteBeep_toggled(bool checked)
|
||||
{
|
||||
if (!lock) {
|
||||
timer.minuteBeep = checked;
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
|
||||
void TimerPanel::on_name_editingFinished()
|
||||
{
|
||||
if (!lock) {
|
||||
if (QString(timer.name) != ui->name->text()) {
|
||||
int length = ui->name->maxLength();
|
||||
strncpy(timer.name, ui->name->text().toLatin1(), length);
|
||||
emit nameChanged();
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimerPanel::connectItemModelEvents(const FilteredItemModel * itemModel)
|
||||
{
|
||||
connect(itemModel, &FilteredItemModel::aboutToBeUpdated, this, &TimerPanel::onItemModelAboutToBeUpdated);
|
||||
@@ -197,12 +138,27 @@ void TimerPanel::connectItemModelEvents(const FilteredItemModel * itemModel)
|
||||
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();
|
||||
lock = false;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
@@ -710,6 +666,7 @@ void ModulePanel::onProtocolChanged(int index)
|
||||
module.protocol = ui->protocol->itemData(index).toInt();
|
||||
module.channelsCount = module.getMaxChannelCount();
|
||||
update();
|
||||
emit updateItemModels();
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
@@ -810,6 +767,7 @@ void ModulePanel::onMultiProtocolChanged(int index)
|
||||
module.subType = std::min(module.subType, maxSubTypes - 1);
|
||||
module.channelsCount = module.getMaxChannelCount();
|
||||
update();
|
||||
emit updateItemModels();
|
||||
emit modified();
|
||||
lock = false;
|
||||
}
|
||||
@@ -1035,16 +993,26 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
rawSwitchFilteredModel = new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSwitch), RawSwitch::TimersContext);
|
||||
connectItemModelEvents(rawSwitchFilteredModel);
|
||||
lock = true;
|
||||
|
||||
thrSourceFilteredModel = new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_ThrSource));
|
||||
connectItemModelEvents(thrSourceFilteredModel);
|
||||
panelFilteredModels = new FilteredItemModelFactory();
|
||||
|
||||
panelFilteredModels->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSwitch),
|
||||
RawSwitch::TimersContext),
|
||||
FIM_TIMERSWITCH);
|
||||
connectItemModelEvents(panelFilteredModels->getItemModel(FIM_TIMERSWITCH));
|
||||
|
||||
panelFilteredModels->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_ThrSource)),
|
||||
FIM_THRSOURCE);
|
||||
connectItemModelEvents(panelFilteredModels->getItemModel(FIM_THRSOURCE));
|
||||
|
||||
panelItemModels = new CompoundItemModelFactory(&generalSettings, &model);
|
||||
panelItemModels->registerItemModel(TimerData::countdownBeepItemModel());
|
||||
panelItemModels->registerItemModel(TimerData::countdownStartItemModel());
|
||||
panelItemModels->registerItemModel(TimerData::persistentItemModel());
|
||||
|
||||
Board::Type board = firmware->getBoard();
|
||||
|
||||
lock = true;
|
||||
|
||||
memset(modules, 0, sizeof(modules));
|
||||
|
||||
QRegExp rx(CHAR_FOR_NAMES_REGEX);
|
||||
@@ -1124,7 +1092,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
|
||||
for (int i = 0; i < CPN_MAX_TIMERS; i++) {
|
||||
if (i < timersCount) {
|
||||
timers[i] = new TimerPanel(this, model, model.timers[i], generalSettings, firmware, prevFocus, rawSwitchFilteredModel);
|
||||
timers[i] = new TimerPanel(this, model, model.timers[i], generalSettings, firmware, prevFocus, panelFilteredModels, panelItemModels);
|
||||
ui->gridLayout->addWidget(timers[i], 1+i, 1);
|
||||
connect(timers[i], &TimerPanel::modified, this, &SetupPanel::modified);
|
||||
connect(timers[i], &TimerPanel::nameChanged, this, &SetupPanel::onTimerNameChanged);
|
||||
@@ -1160,6 +1128,9 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
ui->toplcdTimer->hide();
|
||||
}
|
||||
|
||||
ui->throttleSource->setModel(panelFilteredModels->getItemModel(FIM_THRSOURCE));
|
||||
ui->throttleSource->setField(model.thrTraceSrc, this);
|
||||
|
||||
if (!firmware->getCapability(HasDisplayText)) {
|
||||
ui->displayText->hide();
|
||||
ui->editText->hide();
|
||||
@@ -1265,6 +1236,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
modules[i] = new ModulePanel(this, model, model.moduleData[i], generalSettings, firmware, i);
|
||||
ui->modulesLayout->addWidget(modules[i]);
|
||||
connect(modules[i], &ModulePanel::modified, this, &SetupPanel::modified);
|
||||
connect(modules[i], &ModulePanel::updateItemModels, this, &SetupPanel::onModuleUpdateItemModels);
|
||||
connect(this, &SetupPanel::extendedLimitsToggled, modules[i], &ModulePanel::onExtendedLimitsToggled);
|
||||
}
|
||||
|
||||
@@ -1290,8 +1262,8 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
SetupPanel::~SetupPanel()
|
||||
{
|
||||
delete ui;
|
||||
delete rawSwitchFilteredModel;
|
||||
delete thrSourceFilteredModel;
|
||||
delete panelFilteredModels;
|
||||
delete panelItemModels;
|
||||
}
|
||||
|
||||
void SetupPanel::on_extendedLimits_toggled(bool checked)
|
||||
@@ -1325,14 +1297,6 @@ void SetupPanel::on_trimIncrement_currentIndexChanged(int index)
|
||||
emit modified();
|
||||
}
|
||||
|
||||
void SetupPanel::on_throttleSource_currentIndexChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
model->thrTraceSrc = ui->throttleSource->currentData().toUInt();
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
|
||||
void SetupPanel::on_throttleTrimSwitch_currentIndexChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
@@ -1391,28 +1355,6 @@ void SetupPanel::on_image_currentIndexChanged(int index)
|
||||
}
|
||||
}
|
||||
|
||||
void SetupPanel::populateThrottleSourceCB()
|
||||
{
|
||||
Board::Type board = firmware->getBoard();
|
||||
lock = true;
|
||||
ui->throttleSource->clear();
|
||||
ui->throttleSource->addItem(tr("THR"), 0);
|
||||
|
||||
int idx = 1;
|
||||
for (int i = 0; i < getBoardCapability(board, Board::Pots) + getBoardCapability(board, Board::Sliders); i++, idx++) {
|
||||
if (RawSource(SOURCE_TYPE_STICK, 4 + i).isAvailable(model, &generalSettings, board)) {
|
||||
ui->throttleSource->addItem(firmware->getAnalogInputName(4 + i), idx);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < firmware->getCapability(Outputs); i++, idx++) {
|
||||
ui->throttleSource->addItem(RawSource(SOURCE_TYPE_CH, i).toString(model, &generalSettings), idx);
|
||||
}
|
||||
|
||||
int thrTraceSrcIdx = ui->throttleSource->findData(model->thrTraceSrc);
|
||||
ui->throttleSource->setCurrentIndex(thrTraceSrcIdx);
|
||||
lock = false;
|
||||
}
|
||||
|
||||
void SetupPanel::populateThrottleTrimSwitchCB()
|
||||
{
|
||||
Board::Type board = firmware->getBoard();
|
||||
@@ -1440,7 +1382,7 @@ void SetupPanel::update()
|
||||
{
|
||||
ui->name->setText(model->name);
|
||||
ui->throttleReverse->setChecked(model->throttleReversed);
|
||||
populateThrottleSourceCB();
|
||||
ui->throttleSource->updateValue();
|
||||
populateThrottleTrimSwitchCB();
|
||||
ui->throttleWarning->setChecked(!model->disableThrottleWarning);
|
||||
ui->trimIncrement->setCurrentIndex(model->trimInc+2);
|
||||
@@ -1811,4 +1753,10 @@ void SetupPanel::onItemModelUpdateComplete()
|
||||
void SetupPanel::updateItemModels()
|
||||
{
|
||||
sharedItemModels->update(AbstractItemModel::IMUE_Timers);
|
||||
emit updated();
|
||||
}
|
||||
|
||||
void SetupPanel::onModuleUpdateItemModels()
|
||||
{
|
||||
sharedItemModels->update(AbstractItemModel::IMUE_Modules);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user