Commit 47c07529 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Extract code

parent 8238ad2e
......@@ -261,6 +261,7 @@ set(libmessageviewer_remotecontent
remote-content/remotecontentconfigurewidget.cpp
remote-content/remotecontentdialog.cpp
remote-content/remotecontentwidget.cpp
remote-content/remotecontentstatustypecombobox.cpp
)
set(libmessageviewer_SRCS
......
......@@ -8,6 +8,7 @@
#include "remotecontentdialog.h"
#include "remotecontentinfo.h"
#include "remotecontentmanager.h"
#include "remotecontentstatustypecombobox.h"
#include <KLocalizedString>
#include <KMessageBox>
#include <KTreeWidgetSearchLine>
......@@ -22,10 +23,8 @@ using namespace MessageViewer;
RemoteContentWidgetItem::RemoteContentWidgetItem(QTreeWidget *parent)
: QTreeWidgetItem(parent)
, mStatusTypeCombobox(new QComboBox)
, mStatusTypeCombobox(new RemoteContentStatusTypeComboBox)
{
mStatusTypeCombobox->addItem(i18n("Authorized"), QVariant::fromValue(RemoteContentInfo::RemoteContentInfoStatus::Authorized));
mStatusTypeCombobox->addItem(i18n("Blocked"), QVariant::fromValue(RemoteContentInfo::RemoteContentInfoStatus::Blocked));
treeWidget()->setItemWidget(this, ColumnType::RuleType, mStatusTypeCombobox);
}
......@@ -35,15 +34,12 @@ RemoteContentWidgetItem::~RemoteContentWidgetItem()
void RemoteContentWidgetItem::setStatus(MessageViewer::RemoteContentInfo::RemoteContentInfoStatus type)
{
const int index = mStatusTypeCombobox->findData(QVariant::fromValue(type));
if (index != -1) {
mStatusTypeCombobox->setCurrentIndex(index);
}
mStatusTypeCombobox->setStatus(type);
}
RemoteContentInfo::RemoteContentInfoStatus RemoteContentWidgetItem::status() const
{
return mStatusTypeCombobox->currentData().value<RemoteContentInfo::RemoteContentInfoStatus>();
return mStatusTypeCombobox->status();
}
RemoteContentConfigureWidget::RemoteContentConfigureWidget(QWidget *parent)
......
......@@ -13,11 +13,11 @@
#include "remotecontentinfo.h"
#include <QTreeWidgetItem>
class QTreeWidget;
class QComboBox;
namespace MessageViewer
{
class RemoteContentStatusTypeComboBox;
class RemoteContentInfo;
class MESSAGEVIEWER_EXPORT RemoteContentWidgetItem : public QTreeWidgetItem
class MESSAGEVIEWER_TESTS_EXPORT RemoteContentWidgetItem : public QTreeWidgetItem
{
public:
enum ColumnType {
......@@ -33,7 +33,7 @@ public:
private:
void updateInfo();
QComboBox *const mStatusTypeCombobox;
RemoteContentStatusTypeComboBox *const mStatusTypeCombobox;
};
class MESSAGEVIEWER_TESTS_EXPORT RemoteContentConfigureWidget : public QWidget
......
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "remotecontentstatustypecombobox.h"
#include <KLocalizedString>
using namespace MessageViewer;
RemoteContentStatusTypeComboBox::RemoteContentStatusTypeComboBox(QWidget *parent)
: QComboBox(parent)
{
addItem(i18n("Authorized"), QVariant::fromValue(RemoteContentInfo::RemoteContentInfoStatus::Authorized));
addItem(i18n("Blocked"), QVariant::fromValue(RemoteContentInfo::RemoteContentInfoStatus::Blocked));
}
RemoteContentStatusTypeComboBox::~RemoteContentStatusTypeComboBox()
{
}
void RemoteContentStatusTypeComboBox::setStatus(MessageViewer::RemoteContentInfo::RemoteContentInfoStatus type)
{
const int index = findData(QVariant::fromValue(type));
if (index != -1) {
setCurrentIndex(index);
}
}
RemoteContentInfo::RemoteContentInfoStatus RemoteContentStatusTypeComboBox::status() const
{
return currentData().value<RemoteContentInfo::RemoteContentInfoStatus>();
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include <QComboBox>
#include "messageviewer_private_export.h"
#include "remotecontentinfo.h"
namespace MessageViewer
{
class MESSAGEVIEWER_TESTS_EXPORT RemoteContentStatusTypeComboBox : public QComboBox
{
Q_OBJECT
public:
explicit RemoteContentStatusTypeComboBox(QWidget *parent = nullptr);
~RemoteContentStatusTypeComboBox() override;
void setStatus(MessageViewer::RemoteContentInfo::RemoteContentInfoStatus type);
Q_REQUIRED_RESULT RemoteContentInfo::RemoteContentInfoStatus status() const;
};
}
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