Commit 481cc71d authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix item

parent 8dc31a43
Pipeline #69534 passed with stage
in 40 minutes and 17 seconds
......@@ -27,7 +27,7 @@ ConfirmBeforeDeletingWidget::ConfirmBeforeDeletingWidget(QWidget *parent)
mTreeWidget->setAlternatingRowColors(true);
mTreeWidget->setRootIsDecorated(false);
mTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
const QStringList lst = {i18n("Pattern"), i18n("Type")};
const QStringList lst = {i18n("Type"), i18n("Pattern")};
mTreeWidget->setHeaderLabels(lst);
connect(mTreeWidget, &QTreeWidget::customContextMenuRequested, this, &ConfirmBeforeDeletingWidget::slotCustomContextMenuRequested);
connect(mTreeWidget, &QTreeWidget::itemDoubleClicked, this, &ConfirmBeforeDeletingWidget::slotEditRule);
......@@ -42,9 +42,11 @@ void ConfirmBeforeDeletingWidget::fillRules()
{
const QVector<ConfirmBeforeDeletingRule> rules = ConfirmBeforeDeletingManager::self()->rules();
for (const ConfirmBeforeDeletingRule &r : rules) {
auto item = new QTreeWidgetItem(mTreeWidget, {ConfirmBeforeDeletingRule::ruleTypeToString(r.ruleType()), r.pattern()});
item->setText(0, r.pattern());
item->setText(1, ConfirmBeforeDeletingRule::ruleTypeToString(r.ruleType()));
auto item = new QTreeWidgetItem(mTreeWidget);
ConfirmBeforeDeletingCreateRuleWidget::ConfirmBeforeDeletingInfo info;
info.pattern = r.pattern();
info.ruleType = ConfirmBeforeDeletingRule::ruleTypeToString(r.ruleType());
initializeItem(item, info);
}
}
......@@ -54,18 +56,22 @@ void ConfirmBeforeDeletingWidget::slotEditRule()
if (item) {
QPointer<ConfirmBeforeDeletingCreateRuleDialog> dlg = new ConfirmBeforeDeletingCreateRuleDialog(this);
ConfirmBeforeDeletingCreateRuleWidget::ConfirmBeforeDeletingInfo currentInfo;
currentInfo.pattern = item->text(0);
currentInfo.ruleType = item->text(1);
currentInfo.pattern = item->text(1);
currentInfo.ruleType = item->text(0);
dlg->setInfo(currentInfo);
if (dlg->exec()) {
const ConfirmBeforeDeletingCreateRuleWidget::ConfirmBeforeDeletingInfo info = dlg->info();
item->setText(0, info.pattern);
item->setText(1, info.ruleType);
initializeItem(item, dlg->info());
}
delete dlg;
}
}
void ConfirmBeforeDeletingWidget::initializeItem(QTreeWidgetItem *item, const ConfirmBeforeDeletingCreateRuleWidget::ConfirmBeforeDeletingInfo &info)
{
item->setText(1, info.pattern);
item->setText(0, info.ruleType);
}
void ConfirmBeforeDeletingWidget::slotCustomContextMenuRequested(const QPoint &p)
{
QMenu menu(this);
......@@ -95,8 +101,7 @@ void ConfirmBeforeDeletingWidget::slotAddRule()
if (dlg->exec()) {
const ConfirmBeforeDeletingCreateRuleWidget::ConfirmBeforeDeletingInfo info = dlg->info();
auto item = new QTreeWidgetItem(mTreeWidget);
item->setText(0, info.pattern);
item->setText(1, info.ruleType);
initializeItem(item, dlg->info());
}
delete dlg;
}
......@@ -107,8 +112,8 @@ void ConfirmBeforeDeletingWidget::save()
for (int i = 0, total = mTreeWidget->topLevelItemCount(); i < total; ++i) {
QTreeWidgetItem *item = mTreeWidget->topLevelItem(i);
ConfirmBeforeDeletingRule r;
r.setPattern(item->text(0));
r.setRuleType(ConfirmBeforeDeletingRule::stringToRuleType(item->text(1)));
r.setPattern(item->text(1));
r.setRuleType(ConfirmBeforeDeletingRule::stringToRuleType(item->text(0)));
rules.append(r);
}
ConfirmBeforeDeletingManager::self()->setRules(rules);
......
......@@ -7,8 +7,10 @@
#pragma once
#include "confirmbeforedeleting_private_export.h"
#include "confirmbeforedeletingcreaterulewidget.h"
#include <QWidget>
class QTreeWidget;
class QTreeWidgetItem;
class KMAILCONFIRMBEFOREDELETING_TESTS_EXPORT ConfirmBeforeDeletingWidget : public QWidget
{
Q_OBJECT
......@@ -24,5 +26,6 @@ private:
void slotAddRule();
void fillRules();
void slotEditRule();
void initializeItem(QTreeWidgetItem *item, const ConfirmBeforeDeletingCreateRuleWidget::ConfirmBeforeDeletingInfo &info);
QTreeWidget *const mTreeWidget;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment