mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
feat: 整理单元测试代码
整理单元测试代码,方便测试AppItem类 Log: Change-Id: Iff41154f8f9e968742c9f30c09f2f7a6b5aabde4
This commit is contained in:
parent
4f2e51fafa
commit
7e97570fc6
@ -41,7 +41,7 @@ DockItemManager::DockItemManager(QObject *parent)
|
||||
|
||||
// 应用区域
|
||||
for (auto entry : m_appInter->entries()) {
|
||||
AppItem *it = new AppItem(entry);
|
||||
AppItem *it = new AppItem(entry, QGSettingsInterface::Type::ImplType);
|
||||
manageItem(it);
|
||||
|
||||
connect(it, &AppItem::requestActivateWindow, m_appInter, &DBusDock::ActivateWindow, Qt::QueuedConnection);
|
||||
@ -190,7 +190,7 @@ void DockItemManager::appItemAdded(const QDBusObjectPath &path, const int index)
|
||||
++insertIndex;
|
||||
}
|
||||
|
||||
AppItem *item = new AppItem(path);
|
||||
AppItem *item = new AppItem(path, QGSettingsInterface::Type::ImplType);
|
||||
|
||||
if (m_appIDist.contains(item->appId())) {
|
||||
delete item;
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "xcb_misc.h"
|
||||
#include "appswingeffectbuilder.h"
|
||||
#include "appspreviewprovider.h"
|
||||
#include "qgsettingsinterfaceimpl.h"
|
||||
#include "qgsettingsinterfacemock.h"
|
||||
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
@ -45,26 +47,65 @@
|
||||
|
||||
QPoint AppItem::MousePressPos;
|
||||
|
||||
static QGSettings *GSettingsByApp()
|
||||
static QGSettingsInterface *GSettingsByApp(QGSettingsInterface::Type type)
|
||||
{
|
||||
static QGSettings settings("com.deepin.dde.dock.module.app");
|
||||
return &settings;
|
||||
switch (type) {
|
||||
case QGSettingsInterface::Type::ImplType:
|
||||
{
|
||||
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.app");
|
||||
return &settings;
|
||||
}
|
||||
case QGSettingsInterface::Type::MockType:
|
||||
{
|
||||
static QGSettingsInterfaceMock settings("com.deepin.dde.dock.module.app");
|
||||
return &settings;
|
||||
}
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static QGSettings *GSettingsByActiveApp()
|
||||
static QGSettingsInterface *GSettingsByActiveApp(QGSettingsInterface::Type type)
|
||||
{
|
||||
static QGSettings settings("com.deepin.dde.dock.module.activeapp");
|
||||
return &settings;
|
||||
switch (type) {
|
||||
case QGSettingsInterface::Type::ImplType:
|
||||
{
|
||||
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.activeapp");
|
||||
return &settings;
|
||||
}
|
||||
case QGSettingsInterface::Type::MockType:
|
||||
{
|
||||
static QGSettingsInterfaceMock settings("com.deepin.dde.dock.module.activeapp");
|
||||
return &settings;
|
||||
}
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static QGSettings *GSettingsByDockApp()
|
||||
static QGSettingsInterface *GSettingsByDockApp(QGSettingsInterface::Type type)
|
||||
{
|
||||
static QGSettings settings("com.deepin.dde.dock.module.dockapp");
|
||||
return &settings;
|
||||
switch (type) {
|
||||
case QGSettingsInterface::Type::ImplType:
|
||||
{
|
||||
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.dockapp");
|
||||
return &settings;
|
||||
}
|
||||
case QGSettingsInterface::Type::MockType:
|
||||
{
|
||||
static QGSettingsInterfaceMock settings("com.deepin.dde.dock.module.dockapp");
|
||||
return &settings;
|
||||
}
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
||||
AppItem::AppItem(const QDBusObjectPath &entry, QGSettingsInterface::Type type, QWidget *parent)
|
||||
: DockItem(parent)
|
||||
, m_qgAppInterface(GSettingsByApp(type))
|
||||
, m_qgActiveAppInterface(GSettingsByActiveApp(type))
|
||||
, m_qgDockedAppInterface(GSettingsByDockApp(type))
|
||||
, m_appNameTips(new TipsWidget(this))
|
||||
, m_appPreviewTips(nullptr)
|
||||
, m_itemEntryInter(new DockEntryInter("com.deepin.dde.daemon.Dock", entry.path(), QDBusConnection::sessionBus(), this))
|
||||
@ -120,9 +161,9 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
||||
updateWindowInfos(m_itemEntryInter->windowInfos());
|
||||
refreshIcon();
|
||||
|
||||
connect(GSettingsByApp(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
|
||||
connect(GSettingsByDockApp(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
|
||||
connect(GSettingsByActiveApp(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
|
||||
connect(m_qgAppInterface->gsettings(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
|
||||
connect(m_qgDockedAppInterface->gsettings(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
|
||||
connect(m_qgActiveAppInterface->gsettings(), &QGSettings::changed, this, &AppItem::onGSettingsChanged);
|
||||
|
||||
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &AppItem::onThemeTypeChanged);
|
||||
|
||||
@ -140,6 +181,13 @@ AppItem::~AppItem()
|
||||
stopSwingEffect();
|
||||
|
||||
m_appNameTips->deleteLater();
|
||||
|
||||
delete m_qgAppInterface;
|
||||
m_qgAppInterface = nullptr;
|
||||
delete m_qgActiveAppInterface;
|
||||
m_qgActiveAppInterface = nullptr;
|
||||
delete m_qgDockedAppInterface;
|
||||
m_qgDockedAppInterface = nullptr;
|
||||
}
|
||||
|
||||
void AppItem::checkEntry()
|
||||
@ -665,7 +713,7 @@ void AppItem::playSwingEffect()
|
||||
stopSwingEffect();
|
||||
|
||||
QPair<QGraphicsView *, QGraphicsItemAnimation *> pair = SwingEffect(
|
||||
this, m_appIcon, rect(), devicePixelRatioF());
|
||||
this, m_appIcon, rect(), devicePixelRatioF());
|
||||
|
||||
m_swingEffectView = pair.first;
|
||||
m_itemAnimation = pair.second;
|
||||
@ -711,24 +759,24 @@ void AppItem::onGSettingsChanged(const QString &key)
|
||||
return;
|
||||
}
|
||||
|
||||
QGSettings *setting = m_itemEntryInter->isDocked()
|
||||
? GSettingsByDockApp()
|
||||
: GSettingsByActiveApp();
|
||||
QGSettingsInterface *setting = m_itemEntryInter->isDocked()
|
||||
? m_qgDockedAppInterface
|
||||
: m_qgActiveAppInterface;
|
||||
|
||||
if (setting->keys().contains("enable")) {
|
||||
const bool isEnable = GSettingsByApp()->keys().contains("enable") && GSettingsByApp()->get("enable").toBool();
|
||||
const bool isEnable = m_qgAppInterface->keys().contains("enable") && m_qgAppInterface->get("enable").toBool();
|
||||
setVisible(isEnable && setting->get("enable").toBool());
|
||||
}
|
||||
}
|
||||
|
||||
bool AppItem::checkGSettingsControl() const
|
||||
{
|
||||
QGSettings *setting = m_itemEntryInter->isDocked()
|
||||
? GSettingsByDockApp()
|
||||
: GSettingsByActiveApp();
|
||||
QGSettingsInterface *setting = m_itemEntryInter->isDocked()
|
||||
? m_qgDockedAppInterface
|
||||
: m_qgActiveAppInterface;
|
||||
|
||||
return (setting->keys().contains("control") && setting->get("control").toBool()) ||
|
||||
(GSettingsByApp()->keys().contains("control") && GSettingsByApp()->get("control").toBool());
|
||||
(m_qgAppInterface->keys().contains("control") && m_qgAppInterface->get("control").toBool());
|
||||
}
|
||||
|
||||
void AppItem::onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType)
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "appdrag.h"
|
||||
#include "dbusclientmanager.h"
|
||||
#include "../widgets/tipswidget.h"
|
||||
#include "qgsettingsinterface.h"
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsItem>
|
||||
@ -43,7 +44,7 @@ class AppItem : public DockItem
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AppItem(const QDBusObjectPath &entry, QWidget *parent = nullptr);
|
||||
explicit AppItem(const QDBusObjectPath &entry, QGSettingsInterface::Type type, QWidget *parent = nullptr);
|
||||
~AppItem() override;
|
||||
|
||||
void checkEntry() override;
|
||||
@ -102,6 +103,9 @@ private slots:
|
||||
void onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType);
|
||||
|
||||
private:
|
||||
QGSettingsInterface *m_qgAppInterface;
|
||||
QGSettingsInterface *m_qgActiveAppInterface;
|
||||
QGSettingsInterface *m_qgDockedAppInterface;
|
||||
TipsWidget *m_appNameTips;
|
||||
PreviewContainer *m_appPreviewTips;
|
||||
DockEntryInter *m_itemEntryInter;
|
||||
|
@ -45,7 +45,7 @@ LauncherItem::LauncherItem(QGSettingsInterface *interface, QWidget *parent)
|
||||
m_tips->setVisible(false);
|
||||
m_tips->setObjectName("launcher");
|
||||
|
||||
if (m_gsettings->type() == QGSettingsInterface::REAL) {
|
||||
if (m_gsettings->type() == QGSettingsInterface::ImplType) {
|
||||
QGSettingsInterfaceImpl *impl = dynamic_cast<QGSettingsInterfaceImpl *>(m_gsettings);
|
||||
if (!impl)
|
||||
qWarning("Error!");
|
||||
|
@ -30,8 +30,8 @@ class QGSettingsInterface
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
REAL, // 持有真正的QGSettings指针
|
||||
FAKE // Mock类
|
||||
ImplType, // 持有真正的QGSettings指针
|
||||
MockType // Mock类
|
||||
};
|
||||
|
||||
virtual ~QGSettingsInterface() {}
|
||||
|
@ -36,7 +36,7 @@ QGSettingsInterfaceImpl::~QGSettingsInterfaceImpl()
|
||||
|
||||
QGSettingsInterface::Type QGSettingsInterfaceImpl::type()
|
||||
{
|
||||
return Type::REAL;
|
||||
return Type::ImplType;
|
||||
}
|
||||
|
||||
QGSettings *QGSettingsInterfaceImpl::gsettings()
|
||||
|
@ -35,7 +35,7 @@ QGSettingsInterfaceMock::~QGSettingsInterfaceMock()
|
||||
|
||||
QGSettingsInterface::Type QGSettingsInterfaceMock::type()
|
||||
{
|
||||
return Type::FAKE;
|
||||
return Type::MockType;
|
||||
}
|
||||
|
||||
QGSettings *QGSettingsInterfaceMock::gsettings()
|
||||
|
Loading…
x
Reference in New Issue
Block a user