┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicolas Fella <[email protected]>2023-07-08 22:34:08 +0200
committerNicolas Fella <[email protected]>2023-07-09 00:11:23 +0200
commit31a8866ac0aa3966cd77e87e14974f0a6a66f940 (patch)
tree85df580684c1467808d02b9b182091e4b453f907 /src
parent88ebcd42db91466ac32fa4a43482ee96e599bf7c (diff)
Fix usage of Qt::CheckStateRole in preview model
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
Diffstat (limited to 'src')
-rw-r--r--src/settings/contextmenu/contextmenusettingspage.cpp6
-rw-r--r--src/settings/general/previewssettingspage.cpp4
-rw-r--r--src/settings/serviceitemdelegate.cpp4
-rw-r--r--src/settings/servicemodel.cpp9
-rw-r--r--src/settings/servicemodel.h3
5 files changed, 16 insertions, 10 deletions
diff --git a/src/settings/contextmenu/contextmenusettingspage.cpp b/src/settings/contextmenu/contextmenusettingspage.cpp
index 0f43d0b7a..07deb778a 100644
--- a/src/settings/contextmenu/contextmenusettingspage.cpp
+++ b/src/settings/contextmenu/contextmenusettingspage.cpp
@@ -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"
diff --git a/src/settings/general/previewssettingspage.cpp b/src/settings/general/previewssettingspage.cpp
index 7c63e94ba..1e96025fd 100644
--- a/src/settings/general/previewssettingspage.cpp
+++ b/src/settings/general/previewssettingspage.cpp
@@ -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);
}
diff --git a/src/settings/serviceitemdelegate.cpp b/src/settings/serviceitemdelegate.cpp
index 97fafc631..929e699d8 100644
--- a/src/settings/serviceitemdelegate.cpp
+++ b/src/settings/serviceitemdelegate.cpp
@@ -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()
diff --git a/src/settings/servicemodel.cpp b/src/settings/servicemodel.cpp
index 07a804e33..5333e88b9 100644
--- a/src/settings/servicemodel.cpp
+++ b/src/settings/servicemodel.cpp
@@ -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"
diff --git a/src/settings/servicemodel.h b/src/settings/servicemodel.h
index 23c752e93..7a8607926 100644
--- a/src/settings/servicemodel.h
+++ b/src/settings/servicemodel.h
@@ -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;