1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-07 10:51:45 +00:00

Process correct model when applying service menu changes

The listview's model is a filter model, we must iterate through the source,
otherwise we get incorrect results

BUG: 475547
This commit is contained in:
Nicolas Fella 2023-10-19 00:58:15 +02:00
parent 8ef3c7bc42
commit ef59e42c40

View 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);
}
}