]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix usage of Qt::CheckStateRole in preview model
authorNicolas Fella <nicolas.fella@gmx.de>
Sat, 8 Jul 2023 20:34:08 +0000 (22:34 +0200)
committerNicolas Fella <nicolas.fella@gmx.de>
Sat, 8 Jul 2023 22:11:23 +0000 (00:11 +0200)
Qt::CheckStateRole expects an enum, not a bool

Also set the flag that the item it user checkable, otherwise it can't be changed

BUG: 471999

src/settings/contextmenu/contextmenusettingspage.cpp
src/settings/general/previewssettingspage.cpp
src/settings/serviceitemdelegate.cpp
src/settings/servicemodel.cpp
src/settings/servicemodel.h

index 0f43d0b7abf2af3db066b694cddad01940dbed2e..07deb778a29daada9ec6c36e8af0e119cf6180ff 100644 (file)
@@ -175,7 +175,7 @@ void ContextMenuSettingsPage::applySettings()
     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();
+        const bool checked = model->data(index, Qt::CheckStateRole).value<Qt::CheckState>() == Qt::Checked;
 
         if (service.startsWith(VersionControlServicePrefix)) {
             if (checked) {
@@ -240,7 +240,7 @@ void ContextMenuSettingsPage::restoreDefaults()
 
         const bool checked =
             !service.startsWith(VersionControlServicePrefix) && service != QLatin1String(DeleteService) && service != QLatin1String(CopyToMoveToService);
-        model->setData(index, checked, Qt::CheckStateRole);
+        model->setData(index, checked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
     }
 }
 
@@ -357,7 +357,7 @@ void ContextMenuSettingsPage::addRow(const QString &icon, const QString &text, c
     m_serviceModel->setData(index, icon, Qt::DecorationRole);
     m_serviceModel->setData(index, text, Qt::DisplayRole);
     m_serviceModel->setData(index, value, ServiceModel::DesktopEntryNameRole);
-    m_serviceModel->setData(index, checked, Qt::CheckStateRole);
+    m_serviceModel->setData(index, checked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
 }
 
 #include "moc_contextmenusettingspage.cpp"
index 7c63e94ba079a610dc6e6b54f9cbf86dc691214e..1e96025fd502545d4710dba44de6085ca3468e8c 100644 (file)
@@ -104,7 +104,7 @@ void PreviewsSettingsPage::applySettings()
         m_enabledPreviewPlugins.clear();
         for (int i = 0; i < rowCount; ++i) {
             const QModelIndex index = model->index(i, 0);
-            const bool checked = model->data(index, Qt::CheckStateRole).toBool();
+            const bool checked = model->data(index, Qt::CheckStateRole).value<Qt::CheckState>() == Qt::Checked;
             if (checked) {
                 const QString enabledPlugin = model->data(index, Qt::UserRole).toString();
                 m_enabledPreviewPlugins.append(enabledPlugin);
@@ -153,7 +153,7 @@ void PreviewsSettingsPage::loadPreviewPlugins()
 
         model->insertRow(0);
         const QModelIndex index = model->index(0, 0);
-        model->setData(index, show, Qt::CheckStateRole);
+        model->setData(index, show ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
         model->setData(index, plugin.name(), Qt::DisplayRole);
         model->setData(index, plugin.pluginId(), ServiceModel::DesktopEntryNameRole);
     }
index 97fafc631aef7bbfd598254306ca198759c83c7b..929e699d8f0864788ff7e761aefbadb03e45242d 100644 (file)
@@ -74,7 +74,7 @@ void ServiceItemDelegate::updateItemWidgets(const QList<QWidget *> &widgets, con
     if (!iconName.isEmpty()) {
         checkBox->setIcon(QIcon::fromTheme(iconName));
     }
-    checkBox->setChecked(model->data(index, Qt::CheckStateRole).toBool());
+    checkBox->setChecked(model->data(index, Qt::CheckStateRole).value<Qt::CheckState>() == Qt::Checked);
 
     const bool configurable = model->data(index, ServiceModel::ConfigurableRole).toBool();
 
@@ -98,7 +98,7 @@ void ServiceItemDelegate::updateItemWidgets(const QList<QWidget *> &widgets, con
 void ServiceItemDelegate::slotCheckBoxClicked(bool checked)
 {
     QAbstractItemModel *model = const_cast<QAbstractItemModel *>(focusedIndex().model());
-    model->setData(focusedIndex(), checked, Qt::CheckStateRole);
+    model->setData(focusedIndex(), checked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
 }
 
 void ServiceItemDelegate::slotConfigureButtonClicked()
index 07a804e339bb269c284399387332ce417eda5fe1..5333e88b957b1e6c662d007378466ea380ae401a 100644 (file)
@@ -29,7 +29,7 @@ bool ServiceModel::insertRows(int row, int count, const QModelIndex &parent)
     beginInsertRows(parent, row, row + count - 1);
     for (int i = 0; i < count; ++i) {
         ServiceItem item;
-        item.checked = false;
+        item.checked = Qt::Unchecked;
         item.configurable = false;
         m_items.insert(row, item);
     }
@@ -47,7 +47,7 @@ bool ServiceModel::setData(const QModelIndex &index, const QVariant &value, int
 
     switch (role) {
     case Qt::CheckStateRole:
-        m_items[row].checked = value.toBool();
+        m_items[row].checked = value.value<Qt::CheckState>();
         break;
     case ConfigurableRole:
         m_items[row].configurable = value.toBool();
@@ -105,4 +105,9 @@ void ServiceModel::clear()
     endRemoveRows();
 }
 
+Qt::ItemFlags ServiceModel::flags(const QModelIndex &index) const
+{
+    return QAbstractListModel::flags(index) | Qt::ItemIsUserCheckable;
+}
+
 #include "moc_servicemodel.cpp"
index 23c752e934ddd196b387892e5e4cc87875aa7566..7a8607926d59d1ecd14eb95cf4582fba14a6df94 100644 (file)
@@ -35,10 +35,11 @@ public:
     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
     void clear();
+    Qt::ItemFlags flags(const QModelIndex &index) const override;
 
 private:
     struct ServiceItem {
-        bool checked;
+        Qt::CheckState checked;
         bool configurable;
         QString icon;
         QString text;