Libksieve

selectrelationalmatchtype.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "selectrelationalmatchtype.h"
7#include "autocreatescripts/autocreatescriptutil_p.h"
8
9#include <QComboBox>
10
11#include <KLocalizedString>
12#include <QHBoxLayout>
13
14using namespace KSieveUi;
15
16SelectRelationalMatchType::SelectRelationalMatchType(QWidget *parent)
17 : QWidget(parent)
18 , mType(new QComboBox(this))
19 , mMatch(new QComboBox(this))
20{
21 initialize();
22}
23
24SelectRelationalMatchType::~SelectRelationalMatchType() = default;
25
26void SelectRelationalMatchType::setCode(const QString &type, const QString &comparatorStr, const QString &name, QString &error)
27{
28 int index = mType->findData(type);
29 if (index != -1) {
30 mType->setCurrentIndex(index);
31 } else {
32 AutoCreateScriptUtil::comboboxItemNotFound(type, name, error);
33 mType->setCurrentIndex(0);
34 }
35
36 index = mMatch->findData(comparatorStr);
37 if (index != -1) {
38 mMatch->setCurrentIndex(index);
39 } else {
40 AutoCreateScriptUtil::comboboxItemNotFound(comparatorStr, name, error);
41 mMatch->setCurrentIndex(0);
42 }
43}
44
45QString SelectRelationalMatchType::code() const
46{
47 return QStringLiteral("%1 \"%2\"").arg(mType->itemData(mType->currentIndex()).toString(), mMatch->itemData(mMatch->currentIndex()).toString());
48}
49
50void SelectRelationalMatchType::initialize()
51{
52 auto lay = new QHBoxLayout(this);
53 lay->setContentsMargins({});
54
55 mType->addItem(i18n("Value"), QStringLiteral(":value"));
56 mType->addItem(i18n("Count"), QStringLiteral(":count"));
57 lay->addWidget(mType);
58 connect(mType, &QComboBox::activated, this, &SelectRelationalMatchType::valueChanged);
59
60 mMatch->addItem(i18n("Greater than"), QStringLiteral("gt"));
61 mMatch->addItem(i18n("Greater than or equal"), QStringLiteral("ge"));
62 mMatch->addItem(i18n("Less than"), QStringLiteral("lt"));
63 mMatch->addItem(i18n("Less than or equal"), QStringLiteral("le"));
64 mMatch->addItem(i18n("Equal to"), QStringLiteral("eq"));
65 mMatch->addItem(i18n("Not equal to"), QStringLiteral("ne"));
66 connect(mMatch, &QComboBox::activated, this, &SelectRelationalMatchType::valueChanged);
67 lay->addWidget(mMatch);
68}
69
70#include "moc_selectrelationalmatchtype.cpp"
QString i18n(const char *text, const TYPE &arg...)
void initialize(StandardShortcut id)
void activated(int index)
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
void setCurrentIndex(int index)
int findData(const QVariant &data, int role, Qt::MatchFlags flags) const const
QVariant itemData(int index, int role) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString arg(Args &&... args) const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:19 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.