QtNovelUI/WordsIDE/DocsManager.h

139 lines
4.1 KiB
C
Raw Normal View History

2022-12-31 13:05:58 +00:00
#ifndef DOCSMANAGER_H
#define DOCSMANAGER_H
2022-11-17 08:26:05 +00:00
#include "appcore.h"
2022-11-17 08:26:05 +00:00
#include <QHash>
#include <QObject>
#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:
virtual ~CompileFeature() = default;
/**
* @brief
* @return
*/
virtual QString getText() const = 0;
2023-03-17 13:58:38 +00:00
};
2023-03-17 13:58:38 +00:00
class PresentBase {
public:
/**
* @brief widget
* @return
*/
virtual QWidget *widget() const = 0;
/**
2023-03-17 13:58:38 +00:00
* @brief
* @return
*/
2023-03-17 13:58:38 +00:00
virtual QString name() const = 0;
};
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
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
*/
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;
2023-02-26 14:44:00 +00:00
/**
* @brief
* @return
*/
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
*/
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);
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