Libksieve

selectrelationalmatchtype.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
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 
14 using namespace KSieveUi;
15 
16 SelectRelationalMatchType::SelectRelationalMatchType(QWidget *parent)
17  : QWidget(parent)
18 {
19  initialize();
20 }
21 
22 SelectRelationalMatchType::~SelectRelationalMatchType()
23 {
24 }
25 
26 void 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 
45 QString SelectRelationalMatchType::code() const
46 {
47  return QStringLiteral("%1 \"%2\"").arg(mType->itemData(mType->currentIndex()).toString(), mMatch->itemData(mMatch->currentIndex()).toString());
48 }
49 
50 void SelectRelationalMatchType::initialize()
51 {
52  auto lay = new QHBoxLayout(this);
53  lay->setContentsMargins({});
54 
55  mType = new QComboBox(this);
56  mType->addItem(i18n("Value"), QStringLiteral(":value"));
57  mType->addItem(i18n("Count"), QStringLiteral(":count"));
58  lay->addWidget(mType);
59  connect(mType, QOverload<int>::of(&QComboBox::activated), this, &SelectRelationalMatchType::valueChanged);
60 
61  mMatch = new QComboBox(this);
62  mMatch->addItem(i18n("Greater than"), QStringLiteral("gt"));
63  mMatch->addItem(i18n("Greater than or equal"), QStringLiteral("ge"));
64  mMatch->addItem(i18n("Less than"), QStringLiteral("lt"));
65  mMatch->addItem(i18n("Less than or equal"), QStringLiteral("le"));
66  mMatch->addItem(i18n("Equal to"), QStringLiteral("eq"));
67  mMatch->addItem(i18n("Not equal to"), QStringLiteral("ne"));
68  connect(mMatch, QOverload<int>::of(&QComboBox::activated), this, &SelectRelationalMatchType::valueChanged);
69  lay->addWidget(mMatch);
70 }
KCRASH_EXPORT void initialize()
void activated(int index)
QString i18n(const char *text, const TYPE &arg...)
char * toString(const T &value)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:09:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.