Commit c4b8409f authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add edit/remove/add rule buttons

parent 1422b0d0
Pipeline #175556 passed with stage
in 9 minutes and 48 seconds
......@@ -6,6 +6,7 @@
#include "confirmbeforedeletingwidgettest.h"
#include "confirmbeforedeletingwidget.h"
#include <QPushButton>
#include <QTest>
#include <QTreeWidget>
#include <QVBoxLayout>
......@@ -28,4 +29,16 @@ void ConfirmBeforeDeletingWidgetTest::shouldHaveDefaultValues()
QVERIFY(mTreeWidget->alternatingRowColors());
QVERIFY(!mTreeWidget->rootIsDecorated());
QCOMPARE(mTreeWidget->contextMenuPolicy(), Qt::CustomContextMenu);
auto mAddRule = w.findChild<QPushButton *>(QStringLiteral("mAddRule"));
QVERIFY(mAddRule);
QVERIFY(!mAddRule->text().isEmpty());
auto mRemoveRule = w.findChild<QPushButton *>(QStringLiteral("mRemoveRule"));
QVERIFY(mRemoveRule);
QVERIFY(!mRemoveRule->text().isEmpty());
auto mModifyRule = w.findChild<QPushButton *>(QStringLiteral("mModifyRule"));
QVERIFY(mModifyRule);
QVERIFY(!mModifyRule->text().isEmpty());
}
......@@ -13,18 +13,26 @@
#include <QIcon>
#include <QMenu>
#include <QPointer>
#include <QPushButton>
#include <QTreeWidget>
#include <QVBoxLayout>
ConfirmBeforeDeletingWidget::ConfirmBeforeDeletingWidget(QWidget *parent)
: QWidget(parent)
, mTreeWidget(new QTreeWidget(this))
, mAddRule(new QPushButton(i18n("Add Rule..."), this))
, mRemoveRule(new QPushButton(i18n("Remove Rule"), this))
, mModifyRule(new QPushButton(i18n("Modify Rule..."), this))
{
auto mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins({});
mainLayout->setObjectName(QStringLiteral("mainlayout"));
auto listLayout = new QHBoxLayout;
mainLayout->addLayout(listLayout);
mTreeWidget->setObjectName(QStringLiteral("mTreeWidget"));
mainLayout->addWidget(mTreeWidget);
listLayout->addWidget(mTreeWidget);
mTreeWidget->setAlternatingRowColors(true);
mTreeWidget->setRootIsDecorated(false);
mTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
......@@ -35,11 +43,42 @@ ConfirmBeforeDeletingWidget::ConfirmBeforeDeletingWidget(QWidget *parent)
mTreeWidget->setHeaderLabels(lst);
connect(mTreeWidget, &QTreeWidget::customContextMenuRequested, this, &ConfirmBeforeDeletingWidget::slotCustomContextMenuRequested);
connect(mTreeWidget, &QTreeWidget::itemDoubleClicked, this, &ConfirmBeforeDeletingWidget::slotEditRule);
connect(mTreeWidget, &QTreeWidget::itemSelectionChanged, this, &ConfirmBeforeDeletingWidget::updateButtons);
auto buttonLayout = new QVBoxLayout;
listLayout->addLayout(buttonLayout);
connect(mAddRule, &QPushButton::clicked, this, &ConfirmBeforeDeletingWidget::slotAddRule);
mAddRule->setObjectName(QStringLiteral("mAddRule"));
buttonLayout->addWidget(mAddRule);
connect(mModifyRule, &QPushButton::clicked, this, &ConfirmBeforeDeletingWidget::slotEditRule);
mModifyRule->setObjectName(QStringLiteral("mModifyRule"));
buttonLayout->addWidget(mModifyRule);
connect(mRemoveRule, &QPushButton::clicked, this, &ConfirmBeforeDeletingWidget::slotRemoveRule);
mRemoveRule->setObjectName(QStringLiteral("mRemoveRule"));
buttonLayout->addWidget(mRemoveRule);
buttonLayout->addStretch(1);
updateButtons();
fillRules();
}
ConfirmBeforeDeletingWidget::~ConfirmBeforeDeletingWidget() = default;
void ConfirmBeforeDeletingWidget::updateButtons()
{
QTreeWidgetItem *item = mTreeWidget->currentItem();
if (item) {
mRemoveRule->setEnabled(true);
mModifyRule->setEnabled(true);
} else {
mRemoveRule->setEnabled(false);
mModifyRule->setEnabled(false);
}
}
void ConfirmBeforeDeletingWidget::fillRules()
{
const QVector<ConfirmBeforeDeletingRule> rules = ConfirmBeforeDeletingManager::self()->rules();
......
......@@ -11,6 +11,7 @@
#include <QWidget>
class QTreeWidget;
class QTreeWidgetItem;
class QPushButton;
class KMAILCONFIRMBEFOREDELETING_TESTS_EXPORT ConfirmBeforeDeletingWidget : public QWidget
{
Q_OBJECT
......@@ -27,5 +28,9 @@ private:
void fillRules();
void slotEditRule();
void initializeItem(QTreeWidgetItem *item, const ConfirmBeforeDeletingCreateRuleWidget::ConfirmBeforeDeletingInfo &info);
void updateButtons();
QTreeWidget *const mTreeWidget;
QPushButton *const mAddRule;
QPushButton *const mRemoveRule;
QPushButton *const mModifyRule;
};
Supports Markdown
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