Skip to content

Commit aceddae

Browse files
committed
Fix dynamic refresh
1 parent 340964d commit aceddae

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

companion/src/datamodels/compounditemmodels.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ BacklightSourceItemModel::BacklightSourceItemModel(const GeneralSettings * const
676676
AbstractDynamicItemModel(generalSettings, modelData, firmware, board, boardType)
677677
{
678678
setId(IMID_BacklightSource);
679-
setUpdateMask(IMUE_SystemRefresh);
679+
setUpdateMask(IMUE_Hardware);
680680

681681
// Descending source direction: inverted (!) sources
682682
addItems(SOURCE_TYPE_SWITCH, -board->getCapability(Board::Switches));

companion/src/datamodels/compounditemmodels.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class AbstractItemModel: public QStandardItemModel
8282
IMUE_Timers = 1 << 9,
8383
IMUE_Modules = 1 << 10,
8484
IMUE_FunctionSwitches = 1 << 11,
85+
IMUE_Hardware = 1 << 12,
8586
IMUE_All = IMUE_SystemRefresh | IMUE_Channels | IMUE_Curves | IMUE_FlightModes | IMUE_GVars | IMUE_Inputs |
8687
IMUE_LogicalSwitches | IMUE_Scripts | IMUE_TeleSensors | IMUE_Timers | IMUE_Modules | IMUE_FunctionSwitches
8788
};

companion/src/generaledit/hardware.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
416416
addParams();
417417
}
418418

419+
connect(this, &HardwarePanel::inputFlexTypeChanged, [=](AutoComboBox *cb, int index)
420+
{ setFlexTypeModel(cb, index); }
421+
);
422+
connect(this, &HardwarePanel::refreshItemModels, [=]() { updateItemModels(); });
419423
addVSpring(grid, 0, grid->rowCount());
420424
addHSpring(grid, grid->columnCount(), 0);
421425
disableMouseScrolling();
@@ -497,6 +501,7 @@ void HardwarePanel::addFlex(int index)
497501
name->setValidator(new NameValidator(board, this));
498502
name->setField(config.name, HARDWARE_NAME_LEN, this);
499503
params->append(name);
504+
connect(name, &AutoLineEdit::editingFinished, [=] () { emit refreshItemModels(); });
500505

501506
AutoComboBox *type = new AutoComboBox(this);
502507
setFlexTypeModel(type, index);
@@ -516,11 +521,10 @@ void HardwarePanel::addFlex(int index)
516521
} else {
517522
invertToggles[index - Boards::getCapability(board, Board::Sticks)]->show();
518523
}
519-
emit InputFlexTypeChanged();
524+
emit inputFlexTypeChanged(type, index);
525+
emit refreshItemModels();
520526
});
521527

522-
connect(this, &HardwarePanel::InputFlexTypeChanged, [=]() { setFlexTypeModel(type, index); });
523-
524528
params->append(type);
525529

526530
AutoCheckBox *inverted = new AutoCheckBox(this);
@@ -559,6 +563,7 @@ void HardwarePanel::addSwitch(int index)
559563
name->setValidator(new NameValidator(board, this));
560564
name->setField(config.name, HARDWARE_NAME_LEN, this);
561565
params->append(name);
566+
connect(name, &AutoLineEdit::editingFinished, [=] () { emit refreshItemModels(); });
562567

563568
AutoComboBox *input = nullptr;
564569

@@ -589,6 +594,12 @@ void HardwarePanel::addSwitch(int index)
589594
type->setField(config.type, this);
590595
params->append(type);
591596

597+
if (!generalSettings.isSwitchFlex(index) && !generalSettings.isSwitchFunc(index)) {
598+
connect(type, &AutoComboBox::currentDataChanged, [=] (int val) {
599+
emit refreshItemModels();
600+
});
601+
}
602+
592603
if (generalSettings.isSwitchFlex(index)) {
593604
connect(input, &AutoComboBox::currentDataChanged, [=] (int val) {
594605
if (val < 0) {
@@ -598,6 +609,8 @@ void HardwarePanel::addSwitch(int index)
598609
}
599610
else
600611
type->setModel(tabFilteredModels->getItemModel(FIM_SWITCHTYPE3POS));
612+
613+
emit refreshItemModels();
601614
});
602615
}
603616

@@ -613,6 +626,7 @@ void HardwarePanel::addSwitch(int index)
613626

614627
connect(type, &AutoComboBox::currentDataChanged, [=] (int val) {
615628
start->setEnabled(val == Board::SWITCH_2POS);
629+
emit refreshItemModels();
616630
});
617631

618632
if (Boards::getCapability(board, Board::FunctionSwitchColors)) {
@@ -728,3 +742,8 @@ void HardwarePanel::updateSerialPortUSBVCP()
728742
view->setRowHidden(i, false);
729743
}
730744
}
745+
746+
void HardwarePanel::updateItemModels()
747+
{
748+
editorItemModels->update(AbstractItemModel::IMUE_Hardware);
749+
}

companion/src/generaledit/hardware.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class HardwarePanel : public GeneralPanel
4141

4242
signals:
4343
void internalModuleChanged();
44-
void InputFlexTypeChanged();
44+
void inputFlexTypeChanged(AutoComboBox *cb, int index);
45+
void refreshItemModels();
4546

4647
private slots:
4748
void on_internalModuleChanged();
@@ -73,4 +74,5 @@ class HardwarePanel : public GeneralPanel
7374

7475
void setFlexTypeModel(AutoComboBox * cb, int index);
7576
void updateSerialPortUSBVCP();
77+
void updateItemModels();
7678
};

0 commit comments

Comments
 (0)