WsParser_VS/WsNovelParser/htmlprint.h

200 lines
5.3 KiB
C
Raw Normal View History

2024-03-17 07:58:28 +00:00
#pragma once
#include <QList>
#include <QFileInfo>
2024-09-22 02:18:33 +00:00
#include <QDir>
2024-04-02 12:39:25 +00:00
#include <QDomDocument>
2024-03-17 07:58:28 +00:00
#include <ast_gen.h>
#include <parse_novel.h>
2024-03-28 13:11:12 +00:00
namespace printer {
2025-02-17 05:59:25 +00:00
/**
*
*
*
* .
*
*
*
*
*
*
*
*
*/
2024-03-28 13:11:12 +00:00
/*
2025-02-17 05:59:25 +00:00
* @brief 访线
2024-03-28 13:11:12 +00:00
*/
class Access : public std::enable_shared_from_this<Access> {
public:
2024-03-28 16:16:24 +00:00
Access(std::shared_ptr<const ast_gen::ElementAccess> handle);
2024-03-28 13:11:12 +00:00
virtual ~Access() = default;
2024-03-17 07:58:28 +00:00
2024-04-02 12:39:25 +00:00
/*
2025-02-15 15:47:42 +00:00
* @brief
* @return
2024-04-02 12:39:25 +00:00
*/
2024-03-28 16:16:24 +00:00
std::shared_ptr<const ast_gen::ElementAccess> accessPeers() const;
2024-03-28 13:11:12 +00:00
2024-04-02 12:39:25 +00:00
/*
2025-02-15 15:47:42 +00:00
* @brief
* @param href
2024-04-02 12:39:25 +00:00
*/
void setPageRefers(const QString& href);
QString pageRefers() const;
/*
2025-02-15 15:47:42 +00:00
* @brief HTML
2024-04-02 12:39:25 +00:00
*/
2024-04-02 15:32:48 +00:00
virtual void buildPageHTML(QDomElement& doc) const = 0;
2024-03-28 13:11:12 +00:00
private:
2024-03-28 16:16:24 +00:00
std::shared_ptr<const ast_gen::ElementAccess> access_handle;
2024-04-02 12:39:25 +00:00
QString summary_refer_store;
2024-03-28 13:11:12 +00:00
};
/*
2025-02-15 15:47:42 +00:00
* @brief 访
2024-03-28 13:11:12 +00:00
*/
class Element : public Access {
public:
2024-03-28 16:16:24 +00:00
Element(std::shared_ptr<const ast_gen::ElementAccess> handle);
2024-03-28 13:11:12 +00:00
virtual ~Element() = default;
2024-04-02 12:39:25 +00:00
/*
2025-02-15 15:47:42 +00:00
* @brief URL
2024-04-02 12:39:25 +00:00
*/
2024-04-02 15:23:21 +00:00
virtual void setSliceRefer(const QString& href);
virtual QString sliceRefers() const;
2024-04-02 12:39:25 +00:00
/*
2025-02-15 15:47:42 +00:00
* @brief HTML
2024-04-02 12:39:25 +00:00
*/
2024-04-02 15:37:40 +00:00
virtual void buildSliceHTML(QDomElement &doc) const = 0;
2024-04-02 12:39:25 +00:00
private:
QString refer_store;
2024-03-28 13:11:12 +00:00
};
/*
2025-02-15 15:47:42 +00:00
* @brief 访线
2024-03-28 13:11:12 +00:00
*/
class Group : public Access {
public:
2024-03-28 16:16:24 +00:00
Group(std::shared_ptr<const ast_gen::ElementAccess> handle);
2024-03-28 13:11:12 +00:00
virtual ~Group() = default;
2024-03-28 16:16:24 +00:00
void append(std::shared_ptr<Element> elm);
QList<std::shared_ptr<Element>> elements() const;
2024-04-02 12:39:25 +00:00
std::shared_ptr<Element> getElement(const QString& signature) const;
2024-03-28 13:11:12 +00:00
private:
2024-03-28 16:16:24 +00:00
QList<std::shared_ptr<Element>> element_store;
2024-03-28 13:11:12 +00:00
};
class StoryLine : public Group {
public:
2024-03-28 16:16:24 +00:00
StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle);
2024-03-28 13:11:12 +00:00
2025-02-15 15:47:42 +00:00
// 通过 Group 继承
2024-04-02 15:32:48 +00:00
void buildPageHTML(QDomElement& doc) const override;
2024-03-28 13:11:12 +00:00
};
class StoryVolume : public Group {
public:
2024-03-28 16:16:24 +00:00
StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle);
2024-03-28 13:11:12 +00:00
2025-02-15 15:47:42 +00:00
// 通过 Group 继承
2024-04-02 15:32:48 +00:00
void buildPageHTML(QDomElement& doc) const override;
2024-03-28 13:11:12 +00:00
};
2024-04-02 12:39:25 +00:00
class Fragment;
2024-03-28 16:16:24 +00:00
/*
2025-02-15 15:47:42 +00:00
* @brief
2024-03-28 16:16:24 +00:00
*/
2024-03-28 13:11:12 +00:00
class FragmentRef : public Element {
public:
2024-03-28 16:16:24 +00:00
FragmentRef(std::shared_ptr<const ast_gen::ElementAccess> handle);
2024-03-28 13:11:12 +00:00
2024-04-02 12:39:25 +00:00
void setHost(std::shared_ptr<Fragment> frag_inst);
std::shared_ptr<Fragment> hostFragment() const;
2025-02-15 15:47:42 +00:00
// 通过 Access 继承
2024-04-02 15:32:48 +00:00
void buildPageHTML(QDomElement& doc) const override;
2024-04-02 12:39:25 +00:00
2025-02-15 15:47:42 +00:00
// 通过 Element 继承
2024-04-02 15:37:40 +00:00
void buildSliceHTML(QDomElement& doc) const override;
2024-04-02 12:39:25 +00:00
private:
std::weak_ptr<Fragment> host_inst;
2024-03-28 13:11:12 +00:00
};
/*
2025-02-15 15:47:42 +00:00
* @brief
2024-03-28 13:11:12 +00:00
*/
class Fragment : public Element{
private:
QList<std::shared_ptr<FragmentRef>> additionals_store;
public:
2024-03-28 16:16:24 +00:00
Fragment(std::shared_ptr<const ast_gen::ElementAccess> handle);
2024-03-28 13:11:12 +00:00
void appendRefers(std::shared_ptr<FragmentRef> inst);
QList<std::shared_ptr<FragmentRef>> additionals() const;
2025-02-15 15:47:42 +00:00
// 通过 Access 继承
2024-04-02 15:32:48 +00:00
void buildPageHTML(QDomElement& doc) const override;
2024-03-28 13:11:12 +00:00
2025-02-15 15:47:42 +00:00
// 通过 Element 继承
2024-04-02 15:37:40 +00:00
void buildSliceHTML(QDomElement& doc) const override;
2024-03-28 13:11:12 +00:00
};
2024-03-28 16:16:24 +00:00
class tools_printer {
2024-03-31 05:59:17 +00:00
public:
2024-03-28 16:16:24 +00:00
QHash<QString, std::shared_ptr<Fragment>> fragment_defines;
QHash<QString, std::shared_ptr<StoryLine>> storyline_defines;
QHash<QString, std::shared_ptr<StoryVolume>> volume_defines;
public:
void build_fragments(std::shared_ptr<const ast_gen::ElementAccess> novel_root);
void build_refers_network(std::shared_ptr<const ast_gen::ElementAccess> novel_node);
void build_storyline(std::shared_ptr<StoryLine> line, std::shared_ptr<const ast_gen::ElementAccess> novel_node = nullptr);
void build_volumeline(std::shared_ptr<StoryVolume> line, std::shared_ptr<const ast_gen::ElementAccess> novel_node = nullptr);
2024-03-31 05:59:17 +00:00
void fragments_anchors_define(const QList<std::shared_ptr<Fragment>> &list, const QDir &destdir);
void storylines_anchors_define(const QList<std::shared_ptr<StoryLine>> &list, const QDir &destdir);
void volumes_anchors_define(const QList<std::shared_ptr<StoryVolume>> &list, const QDir &destdir);
2024-04-16 15:40:13 +00:00
2024-04-17 17:56:44 +00:00
QString storylines_paint(const QList<std::shared_ptr<StoryLine>> &lines);
QString volumes_paint(const QList<std::shared_ptr<StoryVolume>> &vols, const QList<std::shared_ptr<StoryLine>> &lines);
2024-07-12 23:13:56 +00:00
void plain_html_output(const std::shared_ptr<const ast_gen::ElementAccess> root, const QDir &destinationdir) const;
2024-03-28 16:16:24 +00:00
};
2024-06-22 15:19:14 +00:00
2025-02-15 15:47:42 +00:00
/**
* @brief Ast输出构建器.
*/
2024-06-22 15:19:14 +00:00
class AstGenerate : public lib_parse::TreeVisitor {
private:
2024-09-22 02:18:33 +00:00
QDir src_root;
2024-06-22 15:19:14 +00:00
QDomDocument doc;
QList<QDomElement> element_stack;
void append_tokens(QDomElement _elm, std::shared_ptr<const ast_gen::SyntaxElement> inst);
public:
2024-09-22 02:18:33 +00:00
AstGenerate(const QDir &src_root);
2024-06-22 15:19:14 +00:00
QString content() const;
2025-02-15 15:47:42 +00:00
// 通过 TreeVisitor 继承
2024-06-22 15:19:14 +00:00
lib_parse::VisitMode mode() const override;
2025-02-15 15:47:42 +00:00
bool visit(std::shared_ptr<const ast_gen::ElementAccess> ast_element) override;
2024-06-22 15:19:14 +00:00
};
2024-03-28 13:11:12 +00:00
}