QtNovelUI/libProjectManager/libProjectManager.h

256 lines
7.2 KiB
C++
Raw Permalink 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.

#ifndef LIBPROJECTMANAGER_H
#define LIBPROJECTMANAGER_H
#include <libConfig.h>
#include <QFileInfo>
#include <QObject>
#include <QStandardItemModel>
namespace Project {
/**
* @brief 项目解析过程异常
*/
class ProjectException : public Config::ParseException {};
class FilesOperate {
public:
virtual ~FilesOperate() = default;
/**
* @brief 建立新的包路径
* @param path_defs 包路径定义
* @return
*/
virtual QModelIndex newPackage(const QList<QString> &path_defs) = 0;
/**
* @brief 在指定包路径下建立创建空白文本文件占位,并将路径地址记录入项目树
* @param package_appoint 指定包节点路径
* @param node 节点名称
* @param suffix 文件类型,使用文件拓展名
* @return 树节点索引
* @throw ProjectException
*/
virtual QModelIndex newFile(const QModelIndex &package_appoint, const QString &node, const QString &suffix = "txt") = 0;
/**
* @brief 重命名该节点名称
* @param node
* @param name
*/
virtual void rename(const QModelIndex &node, const QString &name) = 0;
/**
* @brief 移动到新的分类中
* @param node_frompath 移动的源文件节点路径
* @param target_group 移动目标包路径
* @return
*/
virtual void moveTo(const QModelIndex &node_frompath, const QModelIndex &target_group, int index = -1) = 0;
/**
* @brief 删除指定的文件或者包组织节点
* @param node_path 节点路径,包路径或文件路径
* @throw ProjectException
*/
virtual void deleteT(const QModelIndex &node_path) = 0;
};
class FilesQuery {
public:
virtual ~FilesQuery() = default;
/**
* @brief 汇总该节点下管理的磁盘文件信息
* @param node
* @return
*/
virtual QList<QModelIndex> filesGather(const QModelIndex &node) const = 0;
/**
* @brief 获取所有指定后缀名的文件
* @param suffix 后缀名类型
* @return 文件集合
*/
virtual QList<std::tuple<QString, QFileInfo>> filesWithEnds(const QString &suffix) const = 0;
/**
* @brief 查询节点文件信息文件节点返回文件的info包节点返回文简介的info
* @param path 树节点路径
* @return QFileInfo 文件或文件夹的info实例
*/
virtual QFileInfo queryInfo(const QModelIndex &path) = 0;
/**
* @brief 通过文件反查获取ModelIndex
* @param file
* @return
*/
virtual QModelIndex queryIndex(const QFileInfo &file) = 0;
/**
* @brief 转换QModexIndex为逻辑路径
* @param path
* @return
*/
virtual QStringList packagePath(const QModelIndex &path) const = 0;
};
class ManagerListener{
public:
/**
* @brief 新建项目文件
* @param project_file
*/
virtual void ProjectNEW(const QString &project_file) = 0;
/**
* @brief 打开项目文件
* @param project_file
*/
virtual void ProjectOPEN(const QString &project_file) = 0;
/**
* @brief 项目管理已经执行了保存操作
*/
virtual void hasBeenSAVE() = 0;
/**
* @brief 项目已经被关闭
*/
virtual void hasBeenCLOSE() = 0;
/**
* @brief 项目树节点重命名
* @param path
* @param new_name
*/
virtual void hasBeenRENAME(const QModelIndex &path, const QString &new_name) = 0;
/**
* @brief 项目树上新增节点
* @param new_path 新节点路径
*/
virtual void hasBeenAPPEND(const QModelIndex &new_path) = 0;
/**
* @brief 项目树上节点已被移动
* @param new_path 移动后新路径
*/
virtual void hasBeenMOVE(const QModelIndex &new_path) = 0;
/**
* @brief 项目管理将要执行保存操作
*/
virtual void aboutToBeSAVE() = 0;
/**
* @brief 项目将要被关闭
*/
virtual void aboutToBeCLOSE() = 0;
/**
* @brief 项目树节点将要被删除
* @param path 节点路径
*/
virtual void aboutToBeDELETE(const QModelIndex &path) = 0;
/**
* @brief 项目树节点将要被移动
* @param old_path 节点旧路径
*/
virtual void aboutToBeMOVE(const QModelIndex &old_path) = 0;
};
/**
* @brief 项目管理
* 项目名称
* ==包名称
* ==文件名称
* ==包名称
* ==包名称
*/
class ProjectManager
{
public:
virtual ~ProjectManager() = default;
/**
* @brief 添加ManagerListener实例
* @param inst
*/
virtual void addListener(ManagerListener *inst) = 0;
virtual void removeListener(ManagerListener *inst) = 0;
/**
* @brief 项目树结构模型
* @return
*/
virtual QStandardItemModel* model() const = 0;
/**
* @brief 获取项目配置
* @return 配置实例
*/
virtual Config::Configration *configraions() const = 0;
virtual FilesOperate *operateAccess() const = 0;
virtual FilesQuery *queryAccess() const = 0;
// 项目操作=========================================================
/**
* @brief 获取适用的项目文件后缀
* @return
*/
virtual QString suffix() const = 0;
/**
* @brief 载入项目组织文件
* @param project_file 项目文件路径
* @throw ProjectException*, ParseException*
*/
virtual void openProject(const QString &project_file) = 0;
/**
* @brief 指定项目文件夹,建立项目文件,一个文件夹只能建立一个项目
* @param project_dir 项目文件夹
* @param name 项目文件名
* @throw ProjectException*, ParseException*
*/
virtual void newProject(const QDir &project_dir, const QString &name) = 0;
/**
* @brief 关闭当前项目
*/
virtual void closeProject() = 0;
/**
* @brief save 保存当前项目
* @throw ProjectException, ParseException
*/
virtual void save() = 0;
/**
* @brief 获取项目名称
* @return
*/
virtual QString name() const = 0;
/**
* @brief 重置项目名称
* @param name
*/
virtual void resetName(const QString &name) = 0;
/**
* @brief 获取项目文件所在文件夹
* @return
*/
virtual QDir directory() const = 0;
/**
* @brief 项目出于打开状态
* @return
*/
virtual bool isOpenning() const noexcept = 0;
};
} // namespace Project
#endif // LIBPROJECTMANAGER_H