]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Process correct model when applying service menu changes
authorNicolas Fella <nicolas.fella@gmx.de>
Wed, 18 Oct 2023 22:58:15 +0000 (00:58 +0200)
committerNicolas Fella <nicolas.fella@gmx.de>
Tue, 24 Oct 2023 20:30:21 +0000 (20:30 +0000)
The listview's model is a filter model, we must iterate through the source,
otherwise we get incorrect results

BUG: 475547

src/settings/contextmenu/contextmenusettingspage.cpp

index 23ddfba31deed43f865162294b397e845266879c..c81078095c1574e3023faf5a7c80bd41e196afc8 100644 (file)
@@ -176,15 +176,14 @@ void ContextMenuSettingsPage::applySettings()
 
     QStringList enabledPlugins;
 
-    const QAbstractItemModel *model = m_listView->model();
-    for (int i = 0; i < model->rowCount(); ++i) {
-        const QModelIndex index = model->index(i, 0);
-        const QString service = model->data(index, ServiceModel::DesktopEntryNameRole).toString();
-        const bool checked = model->data(index, Qt::CheckStateRole).toBool();
+    for (int i = 0; i < m_serviceModel->rowCount(); ++i) {
+        const QModelIndex index = m_serviceModel->index(i, 0);
+        const QString service = m_serviceModel->data(index, ServiceModel::DesktopEntryNameRole).toString();
+        const bool checked = m_serviceModel->data(index, Qt::CheckStateRole).toBool();
 
         if (service.startsWith(VersionControlServicePrefix)) {
             if (checked) {
-                enabledPlugins.append(model->data(index, Qt::DisplayRole).toString());
+                enabledPlugins.append(m_serviceModel->data(index, Qt::DisplayRole).toString());
             }
         } else if (service == QLatin1String(DeleteService)) {
             KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals);
@@ -229,14 +228,13 @@ void ContextMenuSettingsPage::applySettings()
 
 void ContextMenuSettingsPage::restoreDefaults()
 {
-    QAbstractItemModel *model = m_listView->model();
-    for (int i = 0; i < model->rowCount(); ++i) {
-        const QModelIndex index = model->index(i, 0);
-        const QString service = model->data(index, ServiceModel::DesktopEntryNameRole).toString();
+    for (int i = 0; i < m_serviceModel->rowCount(); ++i) {
+        const QModelIndex index = m_serviceModel->index(i, 0);
+        const QString service = m_serviceModel->data(index, ServiceModel::DesktopEntryNameRole).toString();
 
         const bool checked =
             !service.startsWith(VersionControlServicePrefix) && service != QLatin1String(DeleteService) && service != QLatin1String(CopyToMoveToService);
-        model->setData(index, checked, Qt::CheckStateRole);
+        m_serviceModel->setData(index, checked, Qt::CheckStateRole);
     }
 }