From a648553be01e335ff4f5b81c0e0bcb19397c60e2 Mon Sep 17 00:00:00 2001 From: Ismael Asensio Date: Mon, 16 Jan 2023 20:25:12 +0100 Subject: [PATCH] kcms/tabbox: Improve model initialization - Add the switchers to the model directly, instead of using temporal lists and a second loop over them - Use the same model for main and alternative forms This makes this code a little more clear and efficient --- src/kcms/tabbox/main.cpp | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/kcms/tabbox/main.cpp b/src/kcms/tabbox/main.cpp index 398d12f262..7e38117b48 100644 --- a/src/kcms/tabbox/main.cpp +++ b/src/kcms/tabbox/main.cpp @@ -139,20 +139,26 @@ static QList availableLnFPackages() void KWinTabBoxConfig::initLayoutLists() { QList offers = KPackage::PackageLoader::self()->listPackages("KWin/WindowSwitcher"); - QStringList layoutNames, layoutPlugins, layoutPaths; + QStandardItemModel *model = new QStandardItemModel; + + auto addToModel = [model](const QString &name, const QString &pluginId, const QString &path) { + QStandardItem *item = new QStandardItem(name); + item->setData(pluginId, Qt::UserRole); + item->setData(path, KWinTabBoxConfigForm::LayoutPath); + item->setData(true, KWinTabBoxConfigForm::AddonEffect); + model->appendRow(item); + }; const auto lnfPackages = availableLnFPackages(); for (const auto &package : lnfPackages) { const auto &metaData = package.metadata(); - const QString switcherFile = package.filePath("windowswitcher", QStringLiteral("WindowSwitcher.qml")); if (switcherFile.isEmpty()) { // Skip lnfs that don't actually ship a switcher continue; } - layoutNames << metaData.name(); - layoutPlugins << metaData.pluginId(); - layoutPaths << switcherFile; + + addToModel(metaData.name(), metaData.pluginId(), switcherFile); } for (const auto &offer : offers) { @@ -172,25 +178,13 @@ void KWinTabBoxConfig::initLayoutLists() continue; } - layoutNames << offer.name(); - layoutPlugins << pluginName; - layoutPaths << scriptFile; + addToModel(offer.name(), pluginName, scriptFile); } - KWinTabBoxConfigForm *ui[2] = {m_primaryTabBoxUi, m_alternativeTabBoxUi}; - for (int i = 0; i < 2; ++i) { - QStandardItemModel *model = new QStandardItemModel; + model->sort(0); - for (int j = 0; j < layoutNames.count(); ++j) { - QStandardItem *item = new QStandardItem(layoutNames[j]); - item->setData(layoutPlugins[j], Qt::UserRole); - item->setData(layoutPaths[j], KWinTabBoxConfigForm::LayoutPath); - item->setData(true, KWinTabBoxConfigForm::AddonEffect); - model->appendRow(item); - } - model->sort(0); - ui[i]->setEffectComboModel(model); - } + m_primaryTabBoxUi->setEffectComboModel(model); + m_alternativeTabBoxUi->setEffectComboModel(model); } void KWinTabBoxConfig::setEnabledUi(KWinTabBoxConfigForm *form, const TabBoxSettings *config)