Skip to content

Commit

Permalink
refactor(weffectchainpresetbutton): Deduplicate some code
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Nov 7, 2024
1 parent c9fa513 commit b8125d5
Showing 1 changed file with 20 additions and 46 deletions.
66 changes: 20 additions & 46 deletions src/widget/weffectchainpresetbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,61 +135,35 @@ void WEffectChainPresetButton::populateMenu() {
static_cast<EffectManifestParameter::ParameterType>(parameterTypeId);

const auto& loadedParameters = pEffectSlot->getLoadedParameters().value(parameterType);
for (const auto& pParameter : loadedParameters) {
auto pCheckbox = make_parented<QCheckBox>(pEffectMenu);
pCheckbox->setChecked(true);
pCheckbox->setText(pParameter->manifest()->name());
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
auto handler = [pEffectSlot, pParameter](Qt::CheckState state) {
if (state == Qt::Checked) {
#else
auto handler = [pEffectSlot, pParameter](int state) {
if (static_cast<bool>(state)) {
#endif
pEffectSlot->showParameter(pParameter);
} else {
pEffectSlot->hideParameter(pParameter);
}
};
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
connect(pCheckbox.get(), &QCheckBox::checkStateChanged, this, handler);
#else
connect(pCheckbox.get(), &QCheckBox::stateChanged, this, handler);
#endif

auto pAction = make_parented<QWidgetAction>(pEffectMenu);
pAction->setDefaultWidget(pCheckbox.get());

pEffectMenu->addAction(pAction.get());
}

const auto& hiddenParameters = pEffectSlot->getHiddenParameters().value(parameterType);
for (const auto& pParameter : hiddenParameters) {
auto pCheckbox = make_parented<QCheckBox>(pEffectMenu);
pCheckbox->setChecked(false);
pCheckbox->setText(pParameter->manifest()->name());
for (const auto& parameters : {loadedParameters, hiddenParameters}) {
for (const auto& pParameter : parameters) {
auto pCheckbox = make_parented<QCheckBox>(pEffectMenu);
pCheckbox->setChecked(true);
pCheckbox->setText(pParameter->manifest()->name());
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
auto handler = [pEffectSlot, pParameter](Qt::CheckState state) {
if (state == Qt::Checked) {
auto handler = [pEffectSlot, pParameter](Qt::CheckState state) {
if (state == Qt::Checked) {
#else
auto handler = [pEffectSlot, pParameter](int state) {
if (static_cast<bool>(state)) {
auto handler = [pEffectSlot, pParameter](int state) {
if (static_cast<bool>(state)) {
#endif
pEffectSlot->showParameter(pParameter);
} else {
pEffectSlot->hideParameter(pParameter);
}
};
pEffectSlot->showParameter(pParameter);
} else {
pEffectSlot->hideParameter(pParameter);
}
};
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
connect(pCheckbox.get(), &QCheckBox::checkStateChanged, this, handler);
connect(pCheckbox.get(), &QCheckBox::checkStateChanged, this, handler);
#else
connect(pCheckbox.get(), &QCheckBox::stateChanged, this, handler);
connect(pCheckbox.get(), &QCheckBox::stateChanged, this, handler);
#endif

auto pAction = make_parented<QWidgetAction>(pEffectMenu);
pAction->setDefaultWidget(pCheckbox.get());
auto pAction = make_parented<QWidgetAction>(pEffectMenu);
pAction->setDefaultWidget(pCheckbox.get());

pEffectMenu->addAction(pAction.get());
pEffectMenu->addAction(pAction.get());
}
}
}
pEffectMenu->addSeparator();
Expand Down

0 comments on commit b8125d5

Please sign in to comment.