新增数据插件接口

This commit is contained in:
hewenfei 2022-12-28 15:38:44 +08:00
parent b8a4a009b1
commit 50791a5be1
3 changed files with 81 additions and 14 deletions

View File

@ -85,6 +85,7 @@ set(SOURCE_FILES
src/windows/menu-main-window.cpp src/windows/menu-main-window.h src/windows/menu-main-window.cpp src/windows/menu-main-window.h
src/extension/menu-extension.cpp src/extension/menu-extension.h src/extension/menu-extension.cpp src/extension/menu-extension.h
src/extension/menu-extension-iface.h src/extension/menu-extension-iface.h
src/appdata/data-provider-plugin-iface.h
) )
# qrc # qrc

View File

@ -0,0 +1,73 @@
/*
* Copyright (C) 2022, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef UKUI_MENU_DATA_PROVIDER_PLUGIN_IFACE_H
#define UKUI_MENU_DATA_PROVIDER_PLUGIN_IFACE_H
#include <QObject>
#include <QString>
#include <QVector>
#include <QMutex>
#include <QMutexLocker>
#include "commons.h"
namespace UkuiMenu {
class PluginGroup
{
Q_GADGET
public:
enum Group {
Button,
SortMenuItem
};
Q_ENUM(Group)
};
class DataProviderPluginIFace : public QObject
{
Q_OBJECT
public:
virtual int index() = 0;
virtual QString name() = 0;
virtual QString icon() = 0;
virtual QString title() = 0;
virtual PluginGroup::Group group() = 0;
/**
*
* @return
*/
virtual QVector<DataEntity> data() = 0;
/**
* dataChange信号
*/
virtual void forceUpdate() = 0;
Q_SIGNALS:
/**
*
*/
void dataChanged(QVector<DataEntity> newData);
};
} // UkuiMenu
#endif //UKUI_MENU_DATA_PROVIDER_PLUGIN_IFACE_H

View File

@ -37,18 +37,6 @@ public:
Q_ENUM(Type) Q_ENUM(Type)
}; };
class SortType
{
Q_GADGET
public:
enum Type {
All,
Alphabetically,
Function
};
Q_ENUM(Type);
};
class DataType class DataType
{ {
Q_GADGET Q_GADGET
@ -72,6 +60,13 @@ class DataEntity
Q_PROPERTY(QString comment READ comment WRITE setComment) Q_PROPERTY(QString comment READ comment WRITE setComment)
Q_PROPERTY(QString extraData READ extraData WRITE setExtraData) Q_PROPERTY(QString extraData READ extraData WRITE setExtraData)
public: public:
enum PropertyName {
Type = 0,
Icon,
Name,
Comment,
ExtraData
};
DataEntity() = default; DataEntity() = default;
DataEntity(const DataEntity& obj); DataEntity(const DataEntity& obj);
DataEntity(DataType::Type type, QString name, QString icon, QString comment, QString extraData); DataEntity(DataType::Type type, QString name, QString icon, QString comment, QString extraData);
@ -103,12 +98,10 @@ class CommonsModule
{ {
public: public:
static void defineModule(const char *uri, int versionMajor, int versionMinor) { static void defineModule(const char *uri, int versionMajor, int versionMinor) {
qRegisterMetaType<UkuiMenu::SortType::Type>("SortType::Type");
qRegisterMetaType<UkuiMenu::DataType::Type>("DataType::Type"); qRegisterMetaType<UkuiMenu::DataType::Type>("DataType::Type");
qRegisterMetaType<UkuiMenu::DataEntity>("DataEntity"); qRegisterMetaType<UkuiMenu::DataEntity>("DataEntity");
qmlRegisterUncreatableType<Display>(uri, versionMajor, versionMinor, "Display", "Use enums only."); qmlRegisterUncreatableType<Display>(uri, versionMajor, versionMinor, "Display", "Use enums only.");
qmlRegisterUncreatableType<UkuiMenu::SortType>(uri, versionMajor, versionMinor, "SortType", "Use enums only");
qmlRegisterUncreatableType<UkuiMenu::DataType>(uri, versionMajor, versionMinor, "DataType", "Use enums only"); qmlRegisterUncreatableType<UkuiMenu::DataType>(uri, versionMajor, versionMinor, "DataType", "Use enums only");
// qmlRegisterUncreatableType<UkuiMenu::DataEntity>(uri, versionMajor, versionMinor, "DataEntity", "unknown"); // qmlRegisterUncreatableType<UkuiMenu::DataEntity>(uri, versionMajor, versionMinor, "DataEntity", "unknown");
} }