QtNovelUI/WordsIDE/DocsManager.h

122 lines
3.2 KiB
C++

#ifndef DOCSMANAGER_H
#define DOCSMANAGER_H
#include "ContentPresent.h"
#include <QHash>
#include <QObject>
#include <StoryTool.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;
};
/**
* @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 适配的文件后缀
* @return
*/
virtual QList<QString> suffixes() const = 0;
/**
* @brief 创建新的空文件,允许实际路径名和传入的文件名相对
* @param target
* @param name
* @param suffix
* @return 成功或失败,目标文件相对路径
*/
virtual std::tuple<bool, QString> create(const QDir &target, const QString &name, const QString &suffix) = 0;
/**
* @brief 生成一个新实例
* @return
*/
virtual FilePresent *newInst() const = 0;
/**
* @brief 载入设置和命名
* @param core
* @param name
*/
virtual void applySetting(const QString &name, Core::AppCore *core = nullptr) = 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);
}
#endif // DOCSMANAGER_H