Refactor setup and modelprinter
This commit is contained in:
@@ -57,7 +57,10 @@ QString TimerData::countdownBeepToString() const
|
||||
|
||||
QString TimerData::countdownStartToString() const
|
||||
{
|
||||
return countdownStartToString(countdownStart);
|
||||
if (countdownBeep == COUNTDOWNBEEP_SILENT)
|
||||
return "";
|
||||
else
|
||||
return countdownStartToString(countdownStart);
|
||||
}
|
||||
|
||||
QString TimerData::persistentToString(const bool verbose) const
|
||||
@@ -70,6 +73,18 @@ QString TimerData::pvalueToString() const
|
||||
return pvalueToString(pvalue);
|
||||
}
|
||||
|
||||
QString TimerData::valToString() const
|
||||
{
|
||||
return valToString(val);
|
||||
}
|
||||
|
||||
void TimerData::setCountdownBeep(const unsigned int value)
|
||||
{
|
||||
countdownBeep = value;
|
||||
if (value == COUNTDOWNBEEP_SILENT)
|
||||
countdownStart = 0;
|
||||
}
|
||||
|
||||
// static
|
||||
QString TimerData::countdownBeepToString(const int value)
|
||||
{
|
||||
@@ -122,7 +137,13 @@ QString TimerData::persistentToString(const int value, const bool verbose)
|
||||
// static
|
||||
QString TimerData::pvalueToString(const int value)
|
||||
{
|
||||
return DataHelpers::timeToString(value, TIMESTR_MASK_HRSMINS);
|
||||
return DataHelpers::timeToString(value, TIMESTR_MASK_HRSMINS | TIMESTR_MASK_HRSMINS);
|
||||
}
|
||||
|
||||
// static
|
||||
QString TimerData::valToString(const int value)
|
||||
{
|
||||
return DataHelpers::timeToString(value, TIMESTR_MASK_HRSMINS | TIMESTR_MASK_ZEROHRS);
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -132,7 +153,7 @@ AbstractStaticItemModel * TimerData::countdownBeepItemModel()
|
||||
mdl->setName(AIM_TIMER_COUNTDOWNBEEP);
|
||||
|
||||
for (int i = 0; i < COUNTDOWNBEEP_COUNT; i++) {
|
||||
QString str = countdownBeepToString(i);
|
||||
mdl->appendToItemList(countdownBeepToString(i), i);
|
||||
}
|
||||
|
||||
mdl->loadItemList();
|
||||
@@ -146,7 +167,7 @@ AbstractStaticItemModel * TimerData::countdownStartItemModel()
|
||||
mdl->setName(AIM_TIMER_COUNTDOWNSTART);
|
||||
|
||||
for (int i = COUNTDOWNSTART_LAST - 1; i >= COUNTDOWNSTART_FIRST; i--) {
|
||||
QString str = countdownStartToString(i);
|
||||
mdl->appendToItemList(countdownStartToString(i), i);
|
||||
}
|
||||
|
||||
mdl->loadItemList();
|
||||
@@ -160,7 +181,7 @@ AbstractStaticItemModel * TimerData::persistentItemModel()
|
||||
mdl->setName(AIM_TIMER_PERSISTENT);
|
||||
|
||||
for (int i = 0; i < PERSISTENT_COUNT; i++) {
|
||||
QString str = persistentToString(i);
|
||||
mdl->appendToItemList(persistentToString(i), i);
|
||||
}
|
||||
|
||||
mdl->loadItemList();
|
||||
|
||||
@@ -83,11 +83,14 @@ class TimerData {
|
||||
QString countdownStartToString() const;
|
||||
QString persistentToString(const bool verbose = true) const;
|
||||
QString pvalueToString() const;
|
||||
QString valToString() const;
|
||||
void setCountdownBeep(const unsigned int value);
|
||||
|
||||
static QString countdownBeepToString(const int value);
|
||||
static QString countdownStartToString(const int value);
|
||||
static QString persistentToString(const int value, const bool verbose = true);
|
||||
static QString pvalueToString(const int value);
|
||||
static QString valToString(const int value);
|
||||
static AbstractStaticItemModel * countdownBeepItemModel();
|
||||
static AbstractStaticItemModel * countdownStartItemModel();
|
||||
static AbstractStaticItemModel * persistentItemModel();
|
||||
|
||||
@@ -70,7 +70,6 @@ TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, Ge
|
||||
else {
|
||||
ui->persistent->setModel(panelItemModels->getItemModel(AIM_TIMER_PERSISTENT));
|
||||
ui->persistent->setField(timer.persistent, this);
|
||||
ui->persistentValue->setText(timer.pvalueToString());
|
||||
}
|
||||
|
||||
ui->countdownStart->setModel(panelItemModels->getItemModel(AIM_TIMER_COUNTDOWNSTART));
|
||||
@@ -108,9 +107,15 @@ void TimerPanel::update()
|
||||
|
||||
ui->countdownBeep->updateValue();
|
||||
ui->minuteBeep->updateValue();
|
||||
if (firmware->getCapability(PermTimers))
|
||||
if (firmware->getCapability(PermTimers)) {
|
||||
ui->persistent->updateValue();
|
||||
ui->persistentValue->setText(timer.pvalueToString());
|
||||
}
|
||||
ui->countdownStart->updateValue();
|
||||
if(timer.countdownBeep == TimerData::COUNTDOWNBEEP_SILENT)
|
||||
ui->countdownStart->setEnabled(false);
|
||||
else
|
||||
ui->countdownStart->setEnabled(true);
|
||||
lock = false;
|
||||
}
|
||||
|
||||
@@ -122,14 +127,10 @@ QWidget * TimerPanel::getLastFocus()
|
||||
void TimerPanel::on_countdownBeep_currentIndexChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
const int start = ui->countdownStart->itemData(index).toInt();
|
||||
if (start != timer.countdownStart) {
|
||||
timer.countdownStart = start;
|
||||
const unsigned int val = ui->countdownStart->itemData(index).toUInt();
|
||||
if (val != timer.countdownBeep) {
|
||||
timer.setCountdownBeep(val);
|
||||
emit modified();
|
||||
if(index == TimerData::COUNTDOWNBEEP_SILENT)
|
||||
ui->countdownStart->setEnabled(false);
|
||||
else
|
||||
ui->countdownStart->setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,9 +202,20 @@ void TimerPanel::onItemModelUpdateComplete()
|
||||
void TimerPanel::on_countdownStart_currentIndexChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
const int start = ui->countdownStart->itemData(index).toInt();
|
||||
if (start != timer.countdownStart) {
|
||||
timer.countdownStart = start;
|
||||
const int val = ui->countdownStart->itemData(index).toInt();
|
||||
if (val != timer.countdownStart) {
|
||||
timer.countdownStart = val;
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimerPanel::on_persistent_currentIndexChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
const unsigned int val = ui->persistent->itemData(index).toUInt();
|
||||
if (val != timer.persistent) {
|
||||
timer.persistent = val;
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ class TimerPanel : public ModelPanel
|
||||
void onItemModelAboutToBeUpdated();
|
||||
void onItemModelUpdateComplete();
|
||||
void on_countdownStart_currentIndexChanged(int index);
|
||||
void on_persistent_currentIndexChanged(int index);
|
||||
|
||||
signals:
|
||||
void nameChanged();
|
||||
|
||||
@@ -298,27 +298,6 @@ QString ModelPrinter::printCenterBeep()
|
||||
return (strl.isEmpty() ? tr("None") : strl.join(" "));
|
||||
}
|
||||
|
||||
QString ModelPrinter::printTimer(int idx)
|
||||
{
|
||||
return printTimer(model.timers[idx]);
|
||||
}
|
||||
|
||||
QString ModelPrinter::printTimer(const TimerData & timer)
|
||||
{
|
||||
QStringList result;
|
||||
if (firmware->getCapability(TimersName) && timer.name[0])
|
||||
result += tr("Name") + QString("(%1)").arg(timer.name);
|
||||
result += printTimeValue(timer.val, MASK_TIMEVALUE_HRSMINS | MASK_TIMEVALUE_ZEROHRS);
|
||||
result += timer.mode.toString();
|
||||
if (timer.countdownBeep)
|
||||
result += tr("Countdown") + QString("(%1)").arg(printTimerCountdownBeep(timer.countdownBeep));
|
||||
if (timer.minuteBeep)
|
||||
result += tr("Minute call");
|
||||
if (timer.persistent)
|
||||
result += tr("Persistent") + QString("(%1)").arg(printTimerPersistent(timer.persistent));
|
||||
return result.join(", ");
|
||||
}
|
||||
|
||||
QString ModelPrinter::printTrim(int flightModeIndex, int stickIndex)
|
||||
{
|
||||
const FlightModeData & fm = model.flightModeData[flightModeIndex];
|
||||
@@ -1002,16 +981,6 @@ QString ModelPrinter::printPPMFrameLength(int ppmFL)
|
||||
return QString::number(result);
|
||||
}
|
||||
|
||||
QString ModelPrinter::printTimerName(int idx)
|
||||
{
|
||||
QString result;
|
||||
result = tr("Tmr") + QString("%1").arg(idx+1);
|
||||
if (firmware->getCapability(TimersName) && model.timers[idx].name[0])
|
||||
result.append(":" + QString(model.timers[idx].name));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QString ModelPrinter::printTelemetryProtocol(unsigned int val)
|
||||
{
|
||||
switch (val) {
|
||||
|
||||
@@ -67,8 +67,6 @@ class ModelPrinter: public QObject
|
||||
QString printTrim(int flightModeIndex, int stickIndex);
|
||||
QString printGlobalVar(int flightModeIndex, int gvarIndex);
|
||||
QString printRotaryEncoder(int flightModeIndex, int reIndex);
|
||||
QString printTimer(int idx);
|
||||
QString printTimer(const TimerData & timer);
|
||||
QString printInputName(int idx);
|
||||
QString printInputLine(int idx);
|
||||
QString printInputLine(const ExpoData & ed);
|
||||
@@ -105,7 +103,6 @@ class ModelPrinter: public QObject
|
||||
QString printFailsafeMode(unsigned int fsmode);
|
||||
QString printFailsafeValue(int val);
|
||||
QString printPPMFrameLength(int ppmFL);
|
||||
QString printTimerName(int idx);
|
||||
QString printTimeValue(const int value, const unsigned int mask);
|
||||
QString printTelemetryProtocol(unsigned int val);
|
||||
QString printLabelValue(const QString & lbl, const QString & val, const bool sep = false);
|
||||
|
||||
@@ -334,18 +334,19 @@ QString MultiModelPrinter::printTimers()
|
||||
QString str;
|
||||
MultiColumns columns(modelPrinterMap.size());
|
||||
columns.appendSectionTableStart();
|
||||
columns.appendRowHeader(QStringList() << tr("Timers") << tr("Time") << tr("Switch") << tr("Countdown") << tr("Min.call") << tr("Persist"));
|
||||
columns.appendRowHeader(QStringList() << tr("Timers") << tr("Time") << tr("Switch") << tr("Countdown") << tr("Start") << tr("Min.call") << tr("Persist"));
|
||||
|
||||
for (int i=0; i<firmware->getCapability(Timers); i++) {
|
||||
columns.appendRowStart();
|
||||
columns.appendCellStart(20, true);
|
||||
COMPARE(modelPrinter->printTimerName(i));
|
||||
COMPARE(model->timers[i].nameToString(i));
|
||||
columns.appendCellEnd(true);
|
||||
COMPARECELLWIDTH(DataHelpers::timeToString(model->timers[i].val, TIMESTR_MASK_HRSMINS), 15);
|
||||
COMPARECELLWIDTH(model->timers[i].mode.toString(), 15);
|
||||
COMPARECELLWIDTH(model->timers[i].countdownBeepToString(), 15);
|
||||
COMPARECELLWIDTH(DataHelpers::boolToString(model->timers[i].minuteBeep, DataHelpers::BOOL_FMT_YESNO), 15);
|
||||
COMPARECELLWIDTH(model->timers[i].persistentToString(false), 20);
|
||||
COMPARECELLWIDTH(model->timers[i].valToString(), 10);
|
||||
COMPARECELLWIDTH(model->timers[i].mode.toString(), 10);
|
||||
COMPARECELLWIDTH(model->timers[i].countdownBeepToString(), 10);
|
||||
COMPARECELLWIDTH(model->timers[i].countdownStartToString(), 10);
|
||||
COMPARECELLWIDTH(DataHelpers::boolToString(model->timers[i].minuteBeep, DataHelpers::BOOL_FMT_YESNO), 10);
|
||||
COMPARECELLWIDTH(model->timers[i].persistentToString(false), 15);
|
||||
columns.appendRowEnd();
|
||||
}
|
||||
columns.appendTableEnd();
|
||||
|
||||
Reference in New Issue
Block a user