[utilities/kdebugsettings] src: Allow to remove custom rule

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 66d8332e115133508031634bb61a81ad6352f4a9 by Laurent Montel.
Committed on 21/07/2026 at 11:37.
Pushed by mlaurent into branch 'master'.

Allow to remove custom rule

M  +11   -0    src/core/model/customloggingcategorymodel.cpp
M  +2    -0    src/core/model/customloggingcategorymodel.h
M  +18   -0    src/core/model/customloggingcategoryproxymodel.cpp
M  +2    -0    src/core/model/customloggingcategoryproxymodel.h
M  +1    -2    src/quickapps/qml/CustomRulesPage.qml

https://invent.kde.org/utilities/kdebugsettings/-/commit/66d8332e115133508031634bb61a81ad6352f4a9

diff --git a/src/core/model/customloggingcategorymodel.cpp b/src/core/model/customloggingcategorymodel.cpp
index f3f8100a..f7ff9108 100644
--- a/src/core/model/customloggingcategorymodel.cpp
+++ b/src/core/model/customloggingcategorymodel.cpp
@@ -104,6 +104,17 @@ void CustomLoggingCategoryModel::clear()
     }
 }
 
+void CustomLoggingCategoryModel::removeCategory(int row)
+{
+    if (row < 0 || row >= mLoggingCategories.count()) {
+        qCWarning(KDEBUGSETTINGSCORE_LOG) << "invalid row: " << row;
+        return;
+    }
+    beginRemoveRows(QModelIndex(), row, row);
+    mLoggingCategories.removeAt(row);
+    endRemoveRows();
+}
+
 void CustomLoggingCategoryModel::removeCategory(const LoggingCategory::List &categories)
 {
     beginResetModel();
diff --git a/src/core/model/customloggingcategorymodel.h b/src/core/model/customloggingcategorymodel.h
index f12e493e..6432463e 100644
--- a/src/core/model/customloggingcategorymodel.h
+++ b/src/core/model/customloggingcategorymodel.h
@@ -48,6 +48,8 @@ public:
 
     void refreshModel();
 
+    void removeCategory(int row);
+
 private:
     LoggingCategory::List mLoggingCategories;
     QHash<int, QByteArray> mRoleNames;
diff --git a/src/core/model/customloggingcategoryproxymodel.cpp b/src/core/model/customloggingcategoryproxymodel.cpp
index 9d89f751..a0beedd0 100644
--- a/src/core/model/customloggingcategoryproxymodel.cpp
+++ b/src/core/model/customloggingcategoryproxymodel.cpp
@@ -14,6 +14,24 @@ CustomLoggingCategoryProxyModel::CustomLoggingCategoryProxyModel(QObject *parent
 
 CustomLoggingCategoryProxyModel::~CustomLoggingCategoryProxyModel() = default;
 
+void CustomLoggingCategoryProxyModel::removeCategory(int proxyRow)
+{
+    if (proxyRow < 0 || proxyRow >= rowCount()) {
+        return;
+    }
+
+    const QModelIndex proxyIndex = index(proxyRow, 0);
+    if (!proxyIndex.isValid()) {
+        return;
+    }
+
+    const QModelIndex sourceIndex = mapToSource(proxyIndex);
+    if (!sourceIndex.isValid() || !sourceModel()) {
+        return;
+    }
+    return static_cast<CustomLoggingCategoryModel *>(sourceModel())->removeCategory(sourceIndex.row());
+}
+
 bool CustomLoggingCategoryProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
 {
     if (mFilterText.isEmpty()) {
diff --git a/src/core/model/customloggingcategoryproxymodel.h b/src/core/model/customloggingcategoryproxymodel.h
index f76e879a..6451d1da 100644
--- a/src/core/model/customloggingcategoryproxymodel.h
+++ b/src/core/model/customloggingcategoryproxymodel.h
@@ -18,6 +18,8 @@ public:
     [[nodiscard]] QString filterText() const;
     void setFilterText(const QString &newFilterText);
 
+    Q_INVOKABLE void removeCategory(int proxyRow);
+
 protected:
     [[nodiscard]] bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
 
diff --git a/src/quickapps/qml/CustomRulesPage.qml b/src/quickapps/qml/CustomRulesPage.qml
index bbb97f7f..e03d0a7e 100644
--- a/src/quickapps/qml/CustomRulesPage.qml
+++ b/src/quickapps/qml/CustomRulesPage.qml
@@ -79,7 +79,6 @@ Kirigami.ScrollablePage {
                 }
                 Kirigami.PromptDialog {
                      id: removeRulePrompt
-
                      parent: QQC2.Overlay.overlay
 
                      title: i18nc("@title:window", "Remove Rule")
@@ -87,7 +86,7 @@ Kirigami.ScrollablePage {
                      standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
 
                      onAccepted: {
-                         // TODO
+                         LoggingManager.customLoggingCategoryProxyModel.removeCategory(listviewRules.currentIndex)
                      }
                  }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.