Commit 7e979110 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Improve++

parent 99bc7e11
......@@ -22,6 +22,7 @@
#include <QTest>
#include <QVBoxLayout>
#include <QListWidget>
#include <QLabel>
ConfirmAddressWidgetTest::ConfirmAddressWidgetTest(QObject *parent)
: QObject(parent)
......@@ -44,6 +45,29 @@ void ConfirmAddressWidgetTest::shouldHaveDefaultValue()
QListWidget *listEmails = w.findChild<QListWidget *>(QStringLiteral("listemails"));
QVERIFY(listEmails);
QCOMPARE(listEmails->count(), 0);
QLabel *lab = w.findChild<QLabel *>(QStringLiteral("label"));
QVERIFY(lab);
QVERIFY(!lab->text().isEmpty());
}
void ConfirmAddressWidgetTest::shouldAddAddress()
{
ConfirmAddressWidget w;
QListWidget *listEmails = w.findChild<QListWidget *>(QStringLiteral("listemails"));
const QStringList lst{ QStringLiteral("foo"), QStringLiteral("bla"), QStringLiteral("blo")};
w.setValidAddresses(lst);
QCOMPARE(listEmails->count(), lst.count());
}
void ConfirmAddressWidgetTest::shouldAddValidAndInvalidAddresses()
{
ConfirmAddressWidget w;
QListWidget *listEmails = w.findChild<QListWidget *>(QStringLiteral("listemails"));
const QStringList lst{ QStringLiteral("foo"), QStringLiteral("foo"), QStringLiteral("foo")};
w.setValidAddresses(lst);
w.setInvalidAddresses(lst);
QCOMPARE(listEmails->count(), lst.count()*2);
}
QTEST_MAIN(ConfirmAddressWidgetTest)
......@@ -31,6 +31,8 @@ public:
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAddAddress();
void shouldAddValidAndInvalidAddresses();
};
#endif // CONFIRMADDRESSWIDGETTEST_H
......@@ -20,6 +20,7 @@
#include "confirmaddresswidget.h"
#include <KLocalizedString>
#include <QLabel>
#include <QListWidget>
#include <QVBoxLayout>
......@@ -30,9 +31,13 @@ ConfirmAddressWidget::ConfirmAddressWidget(QWidget *parent)
mainLayout->setMargin(0);
mainLayout->setObjectName(QStringLiteral("mainlayout"));
listEmails = new QListWidget(this);
listEmails->setObjectName(QStringLiteral("listemails"));
mainLayout->addWidget(listEmails);
QLabel *lab = new QLabel(i18n("Potential emails errors are displayed in red:"), this);
lab->setObjectName(QStringLiteral("label"));
mainLayout->addWidget(lab);
mListEmails = new QListWidget(this);
mListEmails->setObjectName(QStringLiteral("listemails"));
mainLayout->addWidget(mListEmails);
}
ConfirmAddressWidget::~ConfirmAddressWidget()
......@@ -52,5 +57,10 @@ void ConfirmAddressWidget::setInvalidAddresses(const QStringList &addresses)
void ConfirmAddressWidget::createAddressItems(const QStringList &address, bool valid)
{
//TODO
Q_FOREACH(const QString &email, address) {
QListWidgetItem *item = new QListWidgetItem(email, mListEmails);
if (!valid) {
item->setTextColor(Qt::red);
}
}
}
......@@ -33,7 +33,7 @@ public:
void setInvalidAddresses(const QStringList &addresses);
private:
void createAddressItems(const QStringList &address, bool valid);
QListWidget *listEmails;
QListWidget *mListEmails;
};
#endif // CONFIRMADDRESSWIDGET_H
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