2022-12-31 13:05:58 +00:00
|
|
|
|
#ifndef DOCSMANAGER_H
|
|
|
|
|
#define DOCSMANAGER_H
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
#include "appcore.h"
|
2022-11-17 08:26:05 +00:00
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QObject>
|
2023-08-15 14:14:00 +00:00
|
|
|
|
#include <libConfig.h>
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
|
|
|
|
namespace MakeTools {
|
2023-02-26 14:44:00 +00:00
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
class CompileFeature {
|
|
|
|
|
public:
|
2023-03-05 14:32:20 +00:00
|
|
|
|
virtual ~CompileFeature() = default;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 获取字符串表示的内容
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
virtual QString getText() const = 0;
|
2023-03-17 13:58:38 +00:00
|
|
|
|
};
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
class PresentBase {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* @brief 获取新实例内的widget
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
virtual QWidget *widget() const = 0;
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2023-03-17 13:58:38 +00:00
|
|
|
|
* @brief 获取实例的别名
|
|
|
|
|
* @return
|
2023-03-05 14:32:20 +00:00
|
|
|
|
*/
|
2023-03-17 13:58:38 +00:00
|
|
|
|
virtual QString name() const = 0;
|
2023-03-05 14:32:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
class EditException : public Config::ParseException {};
|
|
|
|
|
|
2022-11-17 08:26:05 +00:00
|
|
|
|
/**
|
2023-02-26 14:44:00 +00:00
|
|
|
|
* @brief 内容编辑和呈现接口
|
2022-11-17 08:26:05 +00:00
|
|
|
|
*/
|
2023-03-17 13:58:38 +00:00
|
|
|
|
class FilePresent : public QObject, public PresentBase {
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
explicit FilePresent(QObject *parent = nullptr);
|
|
|
|
|
virtual ~FilePresent() = default;
|
2023-02-26 14:44:00 +00:00
|
|
|
|
|
2023-03-05 14:32:20 +00:00
|
|
|
|
enum class Feature{
|
|
|
|
|
HighLight = 0x01,
|
|
|
|
|
Compile = 0x02,
|
|
|
|
|
};
|
|
|
|
|
Q_DECLARE_FLAGS(Features, Feature)
|
|
|
|
|
virtual Features features() = 0;
|
|
|
|
|
|
2023-02-26 14:44:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 载入设置和命名
|
|
|
|
|
* @param core
|
|
|
|
|
* @param name
|
|
|
|
|
*/
|
2023-08-15 14:40:40 +00:00
|
|
|
|
virtual void applySetting(const QString &name) = 0;
|
2023-02-26 14:44:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 使用此实例打开指定的路径文件,冲刷掉所有状态
|
|
|
|
|
* @param target_file 指定文件的info
|
|
|
|
|
*/
|
|
|
|
|
virtual void load(const QFileInfo &target_file) = 0;
|
|
|
|
|
/**
|
|
|
|
|
* @brief 保存内容到指定路径,默认保存到打开路径
|
|
|
|
|
* @param path 指定另存为路径
|
|
|
|
|
*/
|
|
|
|
|
virtual void saveAs(const QString &path = QString()) = 0;
|
|
|
|
|
/**
|
|
|
|
|
* @brief 如果完成内容载入,返回相对路径,反之,返回空字符串
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-02-28 12:19:45 +00:00
|
|
|
|
virtual QString relativeTargetPath(const QDir &base) const = 0;
|
2023-02-26 14:44:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 完成载入返回绝对路径,反之,返回空字符串
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-02-28 15:05:26 +00:00
|
|
|
|
virtual QString absoluteTargetPath() const = 0;
|
2023-02-26 14:44:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 是否处于修改状态
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
virtual bool isModified() const = 0;
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2023-02-26 14:44:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 跳转到指定的路径
|
|
|
|
|
* @param path
|
|
|
|
|
*/
|
2022-11-22 03:42:48 +00:00
|
|
|
|
virtual void jumpTo(const QList<QString> &path) = 0;
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
signals:
|
|
|
|
|
/**
|
|
|
|
|
* @brief 内容变化
|
|
|
|
|
* @param filePath
|
|
|
|
|
*/
|
|
|
|
|
void dataChanged(const QString &filePath);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
};
|
2023-03-17 13:58:38 +00:00
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(FilePresent::Features);
|
2023-08-15 14:14:00 +00:00
|
|
|
|
|
|
|
|
|
class PresentFactory : public QObject {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~PresentFactory() = default;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 在指定路径下创建合法新文件,指定文件一定存在,但内容可能并不合法
|
|
|
|
|
* @param target 文件路径
|
|
|
|
|
* @throw EditException 编辑错误
|
|
|
|
|
*/
|
|
|
|
|
virtual void create(const QFileInfo &target) = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 生成一个新Present实例
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
virtual FilePresent *newInst(QObject *parent = nullptr) const = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <class PresentType> class TypedPresentFactory : public PresentFactory {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~TypedPresentFactory() = default;
|
|
|
|
|
/**
|
|
|
|
|
* @brief 插件针对文件类型
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
static QString suffix() { return PresentType::file_suffix; }
|
|
|
|
|
virtual FilePresent *newInst(QObject *parent) const { return new PresentType(parent); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define DECL_PRESENT(type) \
|
|
|
|
|
private: \
|
|
|
|
|
static QString file_suffix; \
|
|
|
|
|
friend class MakeTools::TypedPresentFactory<type>;
|
|
|
|
|
|
|
|
|
|
} // namespace MakeTools
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-12-31 13:05:58 +00:00
|
|
|
|
#endif // DOCSMANAGER_H
|