[utilities/kdebugsettings] src: Fix edit rules
Laurent Montel <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 65d91e53c7ac8df3661cb29e2244cd292428a634 by Laurent Montel.
Committed on 22/07/2026 at 18:43.
Pushed by mlaurent into branch 'master'.
Fix edit rules
M +17 -0 src/core/model/customloggingcategorymodel.cpp
M +2 -0 src/core/model/customloggingcategorymodel.h
M +4 -0 src/quickapps/qml/CustomRulesPage.qml
M +2 -1 src/quickapps/qml/EditCustomRuleDialog.qml
https://invent.kde.org/utilities/kdebugsettings/-/commit/65d91e53c7ac8df3661cb29e2244cd292428a634
diff --git a/src/core/model/customloggingcategorymodel.cpp b/src/core/model/customloggingcategorymodel.cpp
index f007d32f..3547d738 100644
--- a/src/core/model/customloggingcategorymodel.cpp
+++ b/src/core/model/customloggingcategorymodel.cpp
@@ -17,6 +17,7 @@ CustomLoggingCategoryModel::CustomLoggingCategoryModel(QObject *parent)
mRoleNames.insert(DefaultCategoryRole, "defaultCategory");
mRoleNames.insert(DisplayRuleRole, "displayRule");
mRoleNames.insert(LoggingTypeRole, "loggingType");
+ mRoleNames.insert(EnabledRole, "enabled");
}
CustomLoggingCategoryModel::~CustomLoggingCategoryModel() = default;
@@ -60,6 +61,20 @@ bool CustomLoggingCategoryModel::setData(const QModelIndex &modelIndex, const QV
return false;
}
+void CustomLoggingCategoryModel::updateCategory(int row, const QString &categoryName, bool enabled, LoggingCategory::LoggingType type)
+{
+ if (row < 0 || row >= mLoggingCategories.count()) {
+ qCWarning(KDEBUGSETTINGSCORE_LOG) << "invalid row: " << row;
+ return;
+ }
+ LoggingCategory &cat = mLoggingCategories[row];
+ cat.categoryName = categoryName;
+ cat.enabled = enabled;
+ cat.loggingType = type;
+ const QModelIndex modelIndex = index(row, 0);
+ Q_EMIT dataChanged(modelIndex, modelIndex);
+}
+
QVariant CustomLoggingCategoryModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= mLoggingCategories.count()) {
@@ -82,6 +97,8 @@ QVariant CustomLoggingCategoryModel::data(const QModelIndex &index, int role) co
return category.generateDisplayRule();
case LoggingTypeRole:
return category.loggingType;
+ case EnabledRole:
+ return category.enabled;
case CategoryRole:
return QVariant::fromValue(category);
}
diff --git a/src/core/model/customloggingcategorymodel.h b/src/core/model/customloggingcategorymodel.h
index 8265a9ab..50b7f606 100644
--- a/src/core/model/customloggingcategorymodel.h
+++ b/src/core/model/customloggingcategorymodel.h
@@ -21,6 +21,7 @@ public:
DisplayRuleRole,
LoggingTypeRole,
CategoryRole,
+ EnabledRole,
};
explicit CustomLoggingCategoryModel(QObject *parent = nullptr);
@@ -51,6 +52,7 @@ public:
void removeCategory(int row);
Q_INVOKABLE void addCategory(const QString &categoryName, bool enabled, LoggingCategory::LoggingType type);
+ Q_INVOKABLE void updateCategory(int row, const QString &categoryName, bool enabled, LoggingCategory::LoggingType type);
private:
LoggingCategory::List mLoggingCategories;
diff --git a/src/quickapps/qml/CustomRulesPage.qml b/src/quickapps/qml/CustomRulesPage.qml
index 3a262b47..44c5beb1 100644
--- a/src/quickapps/qml/CustomRulesPage.qml
+++ b/src/quickapps/qml/CustomRulesPage.qml
@@ -34,6 +34,8 @@ Kirigami.ScrollablePage {
required property string displayRule
required property string categoryName
required property int index
+ required property bool enabled
+ required property int loggingType
text: displayRule
highlighted: ListView.isCurrentItem
@@ -65,8 +67,10 @@ Kirigami.ScrollablePage {
const categoryEnabled = listviewRules.currentItem ? listviewRules.currentItem.enabled : false;
const categoryLoggingType = listviewRules.currentItem ? listviewRules.currentItem.loggingType : LoggingCategory.LoggingType.Debug;
editCustomRuleDialog.editMode = true;
+ editCustomRuleDialog.editRowIndex = listviewRules.currentIndex;
editCustomRuleDialog.categoryName = categoryName;
editCustomRuleDialog.categoryEnabled = categoryEnabled;
+ editCustomRuleDialog.categoryType = categoryLoggingType;
editCustomRuleDialog.open();
}
}
diff --git a/src/quickapps/qml/EditCustomRuleDialog.qml b/src/quickapps/qml/EditCustomRuleDialog.qml
index 1e0e4b00..05fba138 100644
--- a/src/quickapps/qml/EditCustomRuleDialog.qml
+++ b/src/quickapps/qml/EditCustomRuleDialog.qml
@@ -15,6 +15,7 @@ Kirigami.Dialog {
property alias categoryEnabled: categoryEnabled.checked
property alias categoryType: categoryType.loggingType
property bool editMode: false
+ property int editRowIndex: -1
standardButtons: QQC2.Dialog.Ok | QQC2.Dialog.Cancel
RowLayout {
@@ -48,7 +49,7 @@ Kirigami.Dialog {
}
onAccepted: {
if (editMode) {
- console.debug("Edit custom Not implemented yet");
+ LoggingManager.customCategoryModel.updateCategory(editRowIndex, categoryNameField.text, categoryEnabled.checked, categoryType.currentValue);
} else {
LoggingManager.customCategoryModel.addCategory(categoryNameField.text, categoryEnabled.checked, categoryType.currentValue);
}