QtNovelUI/WordsIDE/DocsManager.h

129 lines
3.9 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"
2023-08-27 14:09:46 +00:00
#include "route.h"
2022-11-17 08:26:05 +00:00
#include <QHash>
#include <QObject>
#include <libConfig.h>
2022-11-17 08:26:05 +00:00
2023-08-27 14:09:46 +00:00
namespace Core {
class DocumentsManager;
}
2023-08-27 14:09:46 +00:00
namespace Components {
/**
* @brief
*/
class FilePresent : public QObject {
Q_OBJECT
2023-08-27 14:09:46 +00:00
public:
explicit FilePresent(QObject *parent = nullptr);
virtual ~FilePresent() = default;
2023-03-17 13:58:38 +00:00
/**
* @brief
2023-03-17 13:58:38 +00:00
* @return
*/
virtual QString name() const = 0;
virtual Core::Route accessPath() const = 0;
/**
* @brief widget
2023-03-17 13:58:38 +00:00
* @return
*/
virtual QWidget *widget() const = 0;
virtual Core::DocumentsManager *docsManager() const = 0;
2023-08-27 14:09:46 +00:00
/**
* @brief
*/
virtual void beforeClose() = 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
*/
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-08-27 14:09:46 +00:00
signals:
2023-03-17 13:58:38 +00:00
/**
* @brief
* @param filePath
*/
void dataChanged(const QString &filePath);
2022-11-17 08:26:05 +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(Core::DocumentsManager *mgr, const Core::Route &path, 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(Core::DocumentsManager *mgr, const Core::Route &path, QObject *parent = nullptr) const {
2023-08-27 14:09:46 +00:00
return new PresentType(mgr, path, parent);
}
};
#define DECL_PRESENT(type) \
private: \
static QString file_suffix; \
2023-08-27 14:09:46 +00:00
friend class Components::TypedPresentFactory<type>;
2023-08-27 14:09:46 +00:00
} // namespace Components
2022-11-17 08:26:05 +00:00
2022-12-31 13:05:58 +00:00
#endif // DOCSMANAGER_H