kylin-tablet-desktop-general/kylin-tablet-desktop-backend/database-operation.h

201 lines
6.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 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第一页的idlistSet第二页的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 pageIdpage 页的 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 desktopNameitem的 desktop 名字
/// \param nameitem 的名字
/// \param iconNameitem 图标的名字
/// \param typeitem 的类型
/// \param _placeholderitem 的占位符
/// \param _categoriesitem 的分类
/// \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 sequenceset 内的应用列表
/// \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 pageIdpage 页的 id
/// \param sequencepage 内的应用列表
///
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 setIdcontainer 或 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 nameSet的名字
/// \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