Commit d756b016 authored by Carl Schwan's avatar Carl Schwan 🚴
Browse files

Don't wrap ContentTypeWidget and IncidencesForWidget inside Layout

Instead inherit from QComboBox and expose a QString that should be used
as a base for a QLabel.

Part of the effort of poring collection pages to QFormLayout. See
mailcommon!5
parent e9dd71a0
Pipeline #71738 passed with stage
in 9 minutes and 59 seconds
......@@ -23,46 +23,8 @@ ContentTypeWidgetTest::~ContentTypeWidgetTest()
void ContentTypeWidgetTest::shouldHaveDefaultValue()
{
PimCommon::ContentTypeWidget widget;
auto label = widget.findChild<QLabel *>(QStringLiteral("contenttypewidgetlabel"));
QVERIFY(label);
auto combo = widget.findChild<QComboBox *>(QStringLiteral("contentcombobox"));
QVERIFY(combo);
QVERIFY(combo->count() > 0);
QVERIFY(widget.count() > 0);
QCOMPARE(widget.currentIndex(), 0);
}
void ContentTypeWidgetTest::shouldChangeComboBoxIndex()
{
PimCommon::ContentTypeWidget contentType;
auto combo = contentType.findChild<QComboBox *>(QStringLiteral("contentcombobox"));
for (int i = 0; i < combo->count(); ++i) {
contentType.setCurrentIndex(i);
QCOMPARE(contentType.currentIndex(), i);
QCOMPARE(combo->currentIndex(), i);
}
}
void ContentTypeWidgetTest::shouldEmitSignalWhenIndexChanged()
{
PimCommon::ContentTypeWidget contentType;
contentType.show();
QVERIFY(QTest::qWaitForWindowExposed(&contentType));
QSignalSpy spy(&contentType, &PimCommon::ContentTypeWidget::activated);
contentType.setCurrentIndex(1);
// FIXME
// QCOMPARE(spy.at(0).count(), 1);
}
void ContentTypeWidgetTest::shouldChangeItem()
{
PimCommon::ContentTypeWidget contentType;
contentType.show();
QVERIFY(QTest::qWaitForWindowExposed(&contentType));
auto combo = contentType.findChild<QComboBox *>(QStringLiteral("contentcombobox"));
for (int i = 0; i < combo->count(); ++i) {
contentType.setCurrentIndex(i);
QCOMPARE(contentType.currentText(), combo->currentText());
}
}
QTEST_MAIN(ContentTypeWidgetTest)
......@@ -17,8 +17,5 @@ public:
~ContentTypeWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldChangeComboBoxIndex();
void shouldEmitSignalWhenIndexChanged();
void shouldChangeItem();
};
......@@ -24,33 +24,8 @@ IncidencesForWidgetTest::~IncidencesForWidgetTest()
void IncidencesForWidgetTest::shouldHaveDefaultValue()
{
PimCommon::IncidencesForWidget contentType;
auto label = contentType.findChild<QLabel *>(QStringLiteral("contentstypelabel"));
QVERIFY(label);
auto combo = contentType.findChild<QComboBox *>(QStringLiteral("contentstypecombobox"));
QVERIFY(combo);
QVERIFY(combo->count() > 0);
QVERIFY(contentType.count() == 3);
QCOMPARE(contentType.currentIndex(), 0);
}
void IncidencesForWidgetTest::shouldChangeComboBoxIndex()
{
PimCommon::IncidencesForWidget contentType;
auto combo = contentType.findChild<QComboBox *>(QStringLiteral("contentstypecombobox"));
for (int i = 0; i < combo->count(); ++i) {
contentType.setCurrentIndex(i);
QCOMPARE(contentType.currentIndex(), i);
QCOMPARE(combo->currentIndex(), i);
}
}
void IncidencesForWidgetTest::shouldEmitSignalWhenIndexChanged()
{
PimCommon::IncidencesForWidget contentType;
contentType.show();
QVERIFY(QTest::qWaitForWindowExposed(&contentType));
QSignalSpy spy(&contentType, &PimCommon::IncidencesForWidget::currentIndexChanged);
contentType.setCurrentIndex(1);
QCOMPARE(spy.at(0).count(), 1);
}
QTEST_MAIN(IncidencesForWidgetTest)
......@@ -16,7 +16,5 @@ public:
~IncidencesForWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldChangeComboBoxIndex();
void shouldEmitSignalWhenIndexChanged();
};
/*
SPDX-FileCopyrightText: 2014-2021 Laurent Montel <montel@kde.org>
SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "contenttypewidget.h"
#include "collectiontypeutil.h"
#include <KLocalizedString>
#include <QComboBox>
#include <QHBoxLayout>
#include <QLabel>
using namespace PimCommon;
class PimCommon::ContentTypeWidgetPrivate
{
public:
ContentTypeWidgetPrivate()
{
}
QComboBox *mContentsComboBox = nullptr;
};
ContentTypeWidget::ContentTypeWidget(QWidget *parent)
: QWidget(parent)
, d(new PimCommon::ContentTypeWidgetPrivate)
: QComboBox(parent)
{
auto hbox = new QHBoxLayout(this);
hbox->setContentsMargins(0, 0, 0, 0);
auto label = new QLabel(i18n("&Folder contents:"), this);
label->setObjectName(QStringLiteral("contenttypewidgetlabel"));
hbox->addWidget(label);
d->mContentsComboBox = new QComboBox(this);
d->mContentsComboBox->setObjectName(QStringLiteral("contentcombobox"));
label->setBuddy(d->mContentsComboBox);
hbox->addWidget(d->mContentsComboBox);
setObjectName(QStringLiteral("contentcombobox"));
PimCommon::CollectionTypeUtil collectionUtil;
d->mContentsComboBox->addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeMail));
d->mContentsComboBox->addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeCalendar));
d->mContentsComboBox->addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeContact));
d->mContentsComboBox->addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeNote));
d->mContentsComboBox->addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeTask));
d->mContentsComboBox->addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeJournal));
d->mContentsComboBox->addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeConfiguration));
d->mContentsComboBox->addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeFreebusy));
d->mContentsComboBox->addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeFile));
connect(d->mContentsComboBox, QOverload<int>::of(&QComboBox::activated), this, &ContentTypeWidget::activated);
addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeMail));
addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeCalendar));
addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeContact));
addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeNote));
addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeTask));
addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeJournal));
addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeConfiguration));
addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeFreebusy));
addItem(collectionUtil.folderContentDescription(CollectionTypeUtil::ContentsTypeFile));
}
ContentTypeWidget::~ContentTypeWidget()
{
delete d;
}
int ContentTypeWidget::currentIndex() const
{
return d->mContentsComboBox->currentIndex();
}
void ContentTypeWidget::setCurrentIndex(int index)
{
d->mContentsComboBox->setCurrentIndex(index);
}
ContentTypeWidget::~ContentTypeWidget() = default;
void ContentTypeWidget::setCurrentItem(const QString &name)
{
const int pos = d->mContentsComboBox->findText(name);
const int pos = findText(name);
if (pos != -1) {
d->mContentsComboBox->setCurrentIndex(pos);
QComboBox::setCurrentIndex(pos);
}
}
QString ContentTypeWidget::currentText() const
QString ContentTypeWidget::labelName()
{
return d->mContentsComboBox->currentText();
return i18n("&Folder contents:");
}
/*
SPDX-FileCopyrightText: 2014-2021 Laurent Montel <montel@kde.org>
SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
......@@ -8,31 +9,26 @@
#pragma once
#include "pimcommonakonadi_export.h"
#include <QWidget>
#include <QComboBox>
namespace PimCommon
{
class ContentTypeWidgetPrivate;
/**
* @brief The ContentTypeWidget class
* @brief The ContentTypeWidget class is a combobox allowing the
* user to select one of the multiple collection types.
*
* @author Laurent Montel <montel@kde.org>
*/
class PIMCOMMONAKONADI_EXPORT ContentTypeWidget : public QWidget
class PIMCOMMONAKONADI_EXPORT ContentTypeWidget : public QComboBox
{
Q_OBJECT
public:
explicit ContentTypeWidget(QWidget *parent = nullptr);
~ContentTypeWidget() override;
Q_REQUIRED_RESULT int currentIndex() const;
void setCurrentIndex(int index);
void setCurrentItem(const QString &name);
Q_REQUIRED_RESULT QString currentText() const;
Q_SIGNALS:
void activated(int index);
private:
ContentTypeWidgetPrivate *const d;
/// Label name that should be used in a QFormLayout with a ContentTypeWidget
static QString labelName();
};
}
/*
SPDX-FileCopyrightText: 2014-2021 Laurent Montel <montel@kde.org>
SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "incidencesforwidget.h"
#include <KLocalizedString>
#include <QComboBox>
#include <QHBoxLayout>
#include <QLabel>
using namespace PimCommon;
class PimCommon::IncidencesForWidgetPrivate
{
public:
IncidencesForWidgetPrivate()
{
}
QComboBox *mIncidencesForComboBox = nullptr;
};
IncidencesForWidget::IncidencesForWidget(QWidget *parent)
: QWidget(parent)
, d(new PimCommon::IncidencesForWidgetPrivate)
: QComboBox(parent)
{
auto hbox = new QHBoxLayout(this);
hbox->setContentsMargins(0, 0, 0, 0);
addItem(i18n("Nobody"));
addItem(i18n("Admins of This Folder"));
addItem(i18n("All Readers of This Folder"));
auto label = new QLabel(i18n("Generate free/&busy and activate alarms for:"), this);
label->setObjectName(QStringLiteral("contentstypelabel"));
hbox->addWidget(label);
d->mIncidencesForComboBox = new QComboBox(this);
label->setBuddy(d->mIncidencesForComboBox);
hbox->addWidget(d->mIncidencesForComboBox);
d->mIncidencesForComboBox->addItem(i18n("Nobody"));
d->mIncidencesForComboBox->addItem(i18n("Admins of This Folder"));
d->mIncidencesForComboBox->addItem(i18n("All Readers of This Folder"));
setObjectName(QStringLiteral("contentstypecombobox"));
const QString whatsThisForMyOwnFolders = i18n(
"This setting defines which users sharing "
"this folder should get \"busy\" periods in their freebusy lists "
......@@ -53,23 +31,12 @@ IncidencesForWidget::IncidencesForWidget(QWidget *parent)
"as busy for meetings.\n"
"A company-wide folder with optional events in it would use \"Nobody\" "
"since it is not known who will go to those events.");
d->mIncidencesForComboBox->setObjectName(QStringLiteral("contentstypecombobox"));
d->mIncidencesForComboBox->setWhatsThis(whatsThisForMyOwnFolders);
connect(d->mIncidencesForComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &IncidencesForWidget::currentIndexChanged);
setWhatsThis(whatsThisForMyOwnFolders);
}
IncidencesForWidget::~IncidencesForWidget()
{
delete d;
}
int IncidencesForWidget::currentIndex() const
{
return d->mIncidencesForComboBox->currentIndex();
}
IncidencesForWidget::~IncidencesForWidget() = default;
void IncidencesForWidget::setCurrentIndex(int index)
QString IncidencesForWidget::labelName()
{
d->mIncidencesForComboBox->setCurrentIndex(index);
return i18n("Generate free/&busy and activate alarms for:");
}
/*
SPDX-FileCopyrightText: 2014-2021 Laurent Montel <montel@kde.org>
SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "pimcommonakonadi_export.h"
#include <QWidget>
#include <QComboBox>
namespace PimCommon
{
class IncidencesForWidgetPrivate;
/**
* @brief The IncidencesForWidget class
* @brief The IncidencesForWidget class is used for configuring which
* users sharing this folder should get "busy" periods in their freebusy
* lists.
* @author Laurent Montel <montel@kde.org>
*/
class PIMCOMMONAKONADI_EXPORT IncidencesForWidget : public QWidget
class PIMCOMMONAKONADI_EXPORT IncidencesForWidget : public QComboBox
{
Q_OBJECT
public:
explicit IncidencesForWidget(QWidget *parent = nullptr);
~IncidencesForWidget() override;
Q_REQUIRED_RESULT int currentIndex() const;
void setCurrentIndex(int index);
Q_SIGNALS:
void currentIndexChanged(int value);
private:
IncidencesForWidgetPrivate *const d;
/// Label name of the combobox.
static QString labelName();
};
}
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