2024-03-17 07:58:28 +00:00
|
|
|
#include "htmlprint.h"
|
|
|
|
|
|
|
|
using namespace example_novel;
|
2024-03-28 13:11:12 +00:00
|
|
|
using namespace printer;
|
2024-03-17 07:58:28 +00:00
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
Access::Access(std::shared_ptr<const ast_gen::ElementAccess> handle) :access_handle(handle) {}
|
2024-03-28 13:11:12 +00:00
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
std::shared_ptr<const ast_gen::ElementAccess> Access::accessPeers() const { return access_handle; }
|
2024-03-28 13:11:12 +00:00
|
|
|
|
|
|
|
void Access::setHtmlRefer(const QString& href) { this->refers_store = href; }
|
|
|
|
|
|
|
|
QString Access::htmlRefer() const { return this->refers_store; }
|
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
Element::Element(std::shared_ptr<const ast_gen::ElementAccess> handle) :Access(handle) {}
|
2024-03-28 13:11:12 +00:00
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
Group::Group(std::shared_ptr<const ast_gen::ElementAccess> handle) : Access(handle) {}
|
2024-03-28 13:11:12 +00:00
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
void Group::append(std::shared_ptr<Element> elm)
|
|
|
|
{
|
|
|
|
element_store.append(elm);
|
2024-03-28 13:11:12 +00:00
|
|
|
}
|
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
QList<std::shared_ptr<Element>> Group::elements() const
|
|
|
|
{
|
2024-03-28 13:11:12 +00:00
|
|
|
return this->element_store;
|
|
|
|
}
|
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
StoryLine::StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle) :Group(handle) {}
|
2024-03-28 13:11:12 +00:00
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
QString StoryLine::toHTML() const
|
2024-03-28 13:11:12 +00:00
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
StoryVolume::StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle) : Group(handle) {}
|
2024-03-28 13:11:12 +00:00
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
QString StoryVolume::toHTML() const
|
2024-03-17 07:58:28 +00:00
|
|
|
{
|
2024-03-28 13:11:12 +00:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
FragmentRef::FragmentRef(std::shared_ptr<const ast_gen::ElementAccess> handle) : Element(handle) {}
|
2024-03-28 13:11:12 +00:00
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
QString FragmentRef::toOutsideHTML() const
|
2024-03-17 07:58:28 +00:00
|
|
|
{
|
2024-03-28 13:11:12 +00:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
QString FragmentRef::toDefinitionHTML() const
|
2024-03-28 13:11:12 +00:00
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
2024-03-17 07:58:28 +00:00
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
Fragment::Fragment(std::shared_ptr<const ast_gen::ElementAccess> handle) : Element(handle) {}
|
2024-03-17 07:58:28 +00:00
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
void Fragment::appendRefers(std::shared_ptr<FragmentRef> inst) {
|
2024-03-28 13:11:12 +00:00
|
|
|
this->additionals_store.append(inst);
|
|
|
|
}
|
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
QList<std::shared_ptr<FragmentRef>> Fragment::additionals() const {
|
2024-03-28 13:11:12 +00:00
|
|
|
return this->additionals_store;
|
|
|
|
}
|
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
QString Fragment::toOutsideHTML() const
|
2024-03-28 13:11:12 +00:00
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2024-03-28 16:16:24 +00:00
|
|
|
QString Fragment::toDefinitionHTML() const
|
2024-03-28 13:11:12 +00:00
|
|
|
{
|
|
|
|
return QString();
|
2024-03-17 07:58:28 +00:00
|
|
|
}
|
2024-03-28 16:16:24 +00:00
|
|
|
|
|
|
|
#include <ast_novel.h>
|
|
|
|
void tools_printer::build_fragments(std::shared_ptr<const ast_gen::ElementAccess> novel_root)
|
|
|
|
{
|
|
|
|
if (novel_root->element()->typeMark() == (int)example_novel::NovelNode::FragmentDefine) {
|
|
|
|
auto inst = std::make_shared<Fragment>(novel_root);
|
|
|
|
this->fragment_defines[novel_root->element()->signature()] = inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& inst_c : novel_root->children()) {
|
|
|
|
build_fragments(inst_c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tools_printer::build_refers_network(std::shared_ptr<const ast_gen::ElementAccess> novel_node)
|
|
|
|
{
|
|
|
|
switch ((example_novel::NovelNode)novel_node->element()->typeMark()) {
|
|
|
|
case example_novel::NovelNode::StoryDefine: {
|
|
|
|
auto storyinst = std::make_shared<StoryLine>(novel_node);
|
|
|
|
this->storyline_defines[novel_node->element()->signature()] = storyinst;
|
|
|
|
build_storyline(storyinst);
|
|
|
|
}return;
|
|
|
|
case example_novel::NovelNode::VolumeDefine: {
|
|
|
|
auto volumeinst = std::make_shared<StoryVolume>(novel_node);
|
|
|
|
this->volume_defines[novel_node->element()->signature()] = volumeinst;
|
|
|
|
build_volumeline(volumeinst);
|
|
|
|
}return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& inst_c : novel_node->children())
|
|
|
|
build_refers_network(inst_c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tools_printer::build_storyline(std::shared_ptr<StoryLine> line, std::shared_ptr<const ast_gen::ElementAccess> novel_node)
|
|
|
|
{
|
|
|
|
if (!novel_node) {
|
|
|
|
for (auto& inst_c : line->accessPeers()->children()) {
|
|
|
|
build_storyline(line, inst_c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch ((example_novel::NovelNode)novel_node->element()->typeMark())
|
|
|
|
{
|
|
|
|
case example_novel::NovelNode::FragmentDefine: {
|
|
|
|
auto inst = this->fragment_defines[novel_node->element()->signature()];
|
|
|
|
line->append(inst);
|
|
|
|
}return;
|
|
|
|
case example_novel::NovelNode::FragmentRefer: {
|
|
|
|
auto refer_node = std::dynamic_pointer_cast<const example_novel::FragmentRefers>(novel_node->element());
|
|
|
|
auto refer_fragment = this->fragment_defines[refer_node->signature().mid(1)];
|
|
|
|
auto inst = std::make_shared<FragmentRef>(novel_node);
|
|
|
|
refer_fragment->appendRefers(inst);
|
|
|
|
line->append(inst);
|
|
|
|
}return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& inst_c : novel_node->children())
|
|
|
|
build_storyline(line, inst_c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tools_printer::build_volumeline(std::shared_ptr<StoryVolume> line, std::shared_ptr<const ast_gen::ElementAccess> novel_node)
|
|
|
|
{
|
|
|
|
if (!novel_node) {
|
|
|
|
for (auto& inst_c : line->accessPeers()->children())
|
|
|
|
build_volumeline(line, inst_c);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (example_novel::NovelNode::FragmentRefer == (example_novel::NovelNode)novel_node->element()->typeMark()) {
|
|
|
|
auto refer_node = std::dynamic_pointer_cast<const example_novel::FragmentRefers>(novel_node->element());
|
|
|
|
auto refer_fragment = this->fragment_defines[refer_node->signature().mid(1)];
|
|
|
|
auto inst = std::make_shared<FragmentRef>(novel_node);
|
|
|
|
refer_fragment->appendRefers(inst);
|
|
|
|
line->append(inst);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& inst_c : novel_node->children())
|
|
|
|
build_volumeline(line, inst_c);
|
|
|
|
}
|
|
|
|
}
|