201 lines
6.6 KiB
C++
201 lines
6.6 KiB
C++
/*
|
||
* Copyright 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 DATABASEOPERATION_H
|
||
#define DATABASEOPERATION_H
|
||
|
||
#include "types.h"
|
||
#include <QObject>
|
||
#include <QSqlDatabase>
|
||
|
||
class dataBaseOperation : public QObject
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
explicit dataBaseOperation(QObject *parent = nullptr);
|
||
~dataBaseOperation();
|
||
///
|
||
/// \brief openDataBase:打开数据库
|
||
/// \return 成功 or 失败
|
||
///
|
||
bool openDataBase();
|
||
///
|
||
/// \brief 关闭数据库
|
||
///
|
||
void closeDataBase();
|
||
|
||
public:
|
||
///
|
||
/// \brief getIdleItemID:获取未被使用的 item 的 ID
|
||
/// \return
|
||
///
|
||
quint32 getIdleItemID();
|
||
///
|
||
/// \brief queryAllItemData:查询系统中全部的 Item 数据
|
||
/// \warning 注意指针数组一定要进行释放
|
||
/// \return 存储所有应用指针的map
|
||
///
|
||
QMap<quint32, UKUI::BaseItem *> queryAllItemData();
|
||
///
|
||
/// \brief queryAllSetData:查询可以翻页的 Sets 中全部的 Item 数据
|
||
/// \return 存储 Sets 中所有的 Item 指针 <setId, <Set第一页的idlist,Set第二页的idlist>>
|
||
///
|
||
QMap<quint32, QList<QList<quint32>>> queryAllFlipSetData();
|
||
|
||
///
|
||
/// \brief queryAllScrollSetData:查询可以滚动的 Sets 中全部的 Item 数据
|
||
/// \return
|
||
///
|
||
QMap<quint32, QList<quint32>> queryAllScrollSetData();
|
||
///
|
||
/// \brief queryAllPageData:查询 Page 中全部的 Item 数据
|
||
/// \return 存储 Page 中所有的 Item 指针 <pageId, <itemId>>
|
||
///
|
||
QMap<quint32, QList<quint32>> queryAllPageData();
|
||
///
|
||
/// \brief queryItemDataFromID:根据 ID 查询全部 Item 数据
|
||
/// \param id:应用的 id
|
||
///
|
||
void queryItemDataFromID(int id);
|
||
///
|
||
/// \brief queryPageDataFromID:根据 ID 查询第 page 页的数据
|
||
/// \param pageId:page 页的 id
|
||
/// \return pageId 页的所有 item
|
||
///
|
||
QList<quint32> queryPageDataFromID(int pageId);
|
||
///
|
||
/// \brief queryIdFromDesktopName:根据 desktop 名字查询 id
|
||
/// \param desktopName:应用的 desktop 名字
|
||
/// \return 应用的 id
|
||
///
|
||
quint32 queryIdFromDesktopName(QString desktopName);
|
||
///
|
||
/// \brief addItem:在数据库中插入 Item 对象
|
||
/// \param desktopName:item的 desktop 名字
|
||
/// \param name:item 的名字
|
||
/// \param iconName:item 图标的名字
|
||
/// \param type:item 的类型
|
||
/// \param _placeholder:item 的占位符
|
||
/// \param _categories:item 的分类
|
||
/// \return
|
||
///
|
||
QVariant addItem(quint32 itemId, const QString &desktopName, const QString &name, const QString &iconName, const QVariant &type,
|
||
const QList<quint32> &_placeholder = {1, 1}, const QList<int> &_categories = {-1});
|
||
///
|
||
/// \brief addFlipSet:在数据库中添加 container 或 group 数据
|
||
/// \param setId:可翻页的set 的 id
|
||
/// \param sequence:set 内的应用列表
|
||
/// \return
|
||
///
|
||
QVariant addFlipSet(quint32 setId, const QList<QList<quint32>> &sequence);
|
||
///
|
||
/// \brief addScrollSet:在数据库中添加 container 或 group 数据
|
||
/// \param setId:可滚动的set 的 id
|
||
/// \param sequence
|
||
/// \return
|
||
///
|
||
QVariant addScrollSet(quint32 setId, const QList<quint32> &sequence);
|
||
///
|
||
/// \brief addPage:在数据库中添加 page 数据
|
||
/// \param pageId:page 页的 id
|
||
/// \param sequence:page 内的应用列表
|
||
///
|
||
void addPage(quint32 pageId, const QList<quint32> &sequence);
|
||
///
|
||
/// \brief modifyItemData:修改应用的数据
|
||
/// \param id:应用 id
|
||
/// \param desktopName:应用的 desktop 名字
|
||
/// \param name:应用显示的名字
|
||
/// \param iconName:应用图标的名字
|
||
/// \param _categories:应用的分类
|
||
///
|
||
void modifyItemData(quint32 id, const QString &desktopName, const QString &name, const QString &iconName, const QList<int> &_categories);
|
||
///
|
||
/// \brief modifyFlipSetData:修改 container 或者 group 里的应用列表
|
||
/// \param setId:container 或 group 的 id
|
||
/// \param sequence:应用列表
|
||
///
|
||
void modifyFlipSetData(quint32 setId, const QList<QList<quint32>> &sequence);
|
||
|
||
///
|
||
/// \brief modifyScrollSetData
|
||
/// \param setId
|
||
/// \param sequence
|
||
///
|
||
void modifyScrollSetData(quint32 setId, const QList<quint32> &sequence);
|
||
///
|
||
/// \brief modifySetName:修改 container 或者 group 的名字
|
||
/// \param setId:待修改的 group/container 的id
|
||
/// \param name:Set的名字
|
||
/// \return true为修改成功,false修改失败
|
||
///
|
||
bool modifySetName(quint32 setId, QString name);
|
||
///
|
||
/// \brief modifyPageData 修改 page 页的数据
|
||
/// \param pageId page 页的 id
|
||
/// \param sequence page 页即将存储的应用列表
|
||
///
|
||
void modifyPageData(quint32 pageId, const QList<quint32> &sequence);
|
||
///
|
||
/// \brief deleteItemListData 从列表中删除应用
|
||
/// \param id 应用的 id
|
||
///
|
||
void deleteItemListData(int id);
|
||
///
|
||
/// \brief deletePageData 删除页数据
|
||
/// \param id 页的 id
|
||
///
|
||
void deletePageData(int id);
|
||
///
|
||
/// \brief deleteSetsData 删除分组数据
|
||
/// \param id 分组的 id
|
||
///
|
||
void deleteSetsData(int id);
|
||
///
|
||
/// \brief 删除数据表
|
||
/// \param tableName 数据表名字
|
||
///
|
||
void deleteTable(const QString &tableName);
|
||
|
||
private:
|
||
///
|
||
/// \brief createDefaultTable:创建默认数据表
|
||
///
|
||
void createDefaultTable();
|
||
///
|
||
/// \brief createItemsData:创建默认的 item 数据
|
||
///
|
||
void createItemsData();
|
||
///
|
||
/// \brief updatePageTable:根据 item 表和 sets 表确定 page 表
|
||
///
|
||
void updatePageTable();
|
||
///
|
||
/// \brief isTableExist:判断数据表是否存在
|
||
/// \param tableName:表的名字
|
||
/// \return 存在 or 不存在
|
||
///
|
||
bool isTableExist(const QString &tableName);
|
||
|
||
signals:
|
||
|
||
private:
|
||
QSqlDatabase db;
|
||
quint32 idleItemId;
|
||
};
|
||
|
||
#endif // DATABASEOPERATION_H
|