QtNovelUI/WordsIDE/DocsManager.h

139 lines
4.1 KiB
C++

#ifndef DOCSMANAGER_H
#define DOCSMANAGER_H
#include "appcore.h"
#include <QHash>
#include <QObject>
#include <libConfig.h>
namespace MakeTools {
class CompileFeature {
public:
virtual ~CompileFeature() = default;
/**
* @brief 获取字符串表示的内容
* @return
*/
virtual QString getText() const = 0;
};
class PresentBase {
public:
/**
* @brief 获取新实例内的widget
* @return
*/
virtual QWidget *widget() const = 0;
/**
* @brief 获取实例的别名
* @return
*/
virtual QString name() const = 0;
};
class EditException : public Config::ParseException {};
/**
* @brief 内容编辑和呈现接口
*/
class FilePresent : public QObject, public PresentBase {
Q_OBJECT
public:
explicit FilePresent(QObject *parent = nullptr);
virtual ~FilePresent() = default;
enum class Feature{
HighLight = 0x01,
Compile = 0x02,
};
Q_DECLARE_FLAGS(Features, Feature)
virtual Features features() = 0;
/**
* @brief 载入设置和命名
* @param core
* @param name
*/
virtual void applySetting(const QString &name) = 0;
/**
* @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
*/
virtual QString relativeTargetPath(const QDir &base) const = 0;
/**
* @brief 完成载入返回绝对路径,反之,返回空字符串
* @return
*/
virtual QString absoluteTargetPath() const = 0;
/**
* @brief 是否处于修改状态
* @return
*/
virtual bool isModified() const = 0;
/**
* @brief 跳转到指定的路径
* @param path
*/
virtual void jumpTo(const QList<QString> &path) = 0;
signals:
/**
* @brief 内容变化
* @param filePath
*/
void dataChanged(const QString &filePath);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(FilePresent::Features);
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
#endif // DOCSMANAGER_H