Read@CVL
PageParser.h
Go to the documentation of this file.
1 /*******************************************************************************************************
2  ReadFramework is the basis for modules developed at CVL/TU Wien for the EU project READ.
3 
4  Copyright (C) 2016 Markus Diem <diem@caa.tuwien.ac.at>
5  Copyright (C) 2016 Stefan Fiel <fiel@caa.tuwien.ac.at>
6  Copyright (C) 2016 Florian Kleber <kleber@caa.tuwien.ac.at>
7 
8  This file is part of ReadFramework.
9 
10  ReadFramework is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  ReadFramework is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23  The READ project has received funding from the European Union’s Horizon 2020
24  research and innovation programme under grant agreement No 674943
25 
26  related links:
27  [1] http://www.caa.tuwien.ac.at/cvl/
28  [2] https://transkribus.eu/Transkribus/
29  [3] https://github.com/TUWien/
30  [4] http://nomacs.org
31  *******************************************************************************************************/
32 
33 #pragma once
34 
35 #pragma warning(push, 0) // no warnings from includes
36 #include <QString>
37 #include <QSharedPointer>
38 #pragma warning(pop)
39 
40 #pragma warning(disable: 4251) // dll interface warning
41 
42 #ifndef DllCoreExport
43 #ifdef DLL_CORE_EXPORT
44 #define DllCoreExport Q_DECL_EXPORT
45 #else
46 #define DllCoreExport Q_DECL_IMPORT
47 #endif
48 #endif
49 
50 // Qt defines
51 class QXmlStreamReader;
52 class QXmlStreamWriter;
53 
54 namespace rdf {
55 
56 class PageElement;
57 class Region;
58 
59 // read defines
61 
62 public:
63  PageXmlParser();
64 
65  enum RootTags {
73 
81 
82  tag_end
83  };
84 
85  enum LoadStatus {
86  status_not_loaded = 0, // ::load was not called
87  status_file_not_found, // xml file does not exist
88  status_file_locked, // file is not readable
89  status_file_empty, // file is empty - empty xml?!
90  status_not_downloaded, // xml file is an url but could not be loaded
91  status_ok, // we could parse the xml (now that's good news : )
92 
93  status_end
94  };
95 
96  bool read(const QString& xmlPath, bool ignoreLayers = false);
97  void write(const QString& xmlPath, const QSharedPointer<PageElement> pageElement);
98 
99  LoadStatus loadStatus() const;
100  QString loadStatusMessage() const;
101 
102  QString tagName(const RootTags& tag) const;
103 
104  void setPage(QSharedPointer<PageElement> page);
105  QSharedPointer<PageElement> page() const;
106 
107  static QString imagePathToXmlPath(const QString& path, const QString& subDir = "");
108 
109 protected:
110 
111  QSharedPointer<PageElement> mPage;
112  LoadStatus mStatus = status_not_loaded;
113 
114  virtual QSharedPointer<PageElement> parse(const QByteArray& ba, LoadStatus& status, bool ignoreLayers = false) const;
115  virtual void parseRegion(QXmlStreamReader& reader, QSharedPointer<Region> parent) const;
116  virtual void parseMetadata(QXmlStreamReader& reader, QSharedPointer<PageElement> page) const;
117  virtual void parseLayers(QXmlStreamReader& reader, QSharedPointer<PageElement> page, bool ignoreLayers = false) const;
118 
119  QByteArray writePageElement() const;
120  void writeMetaData(QXmlStreamWriter& writer) const;
121 };
122 
123 }
Definition: PageParser.h:72
Definition: PageParser.h:79
Definition: PageParser.h:80
Definition: PageParser.h:89
Definition: PageParser.h:71
Definition: PageParser.h:68
Definition: PageParser.h:78
Definition: PageParser.h:74
Definition: PageParser.h:69
Definition: PageParser.h:76
Definition: PageParser.h:91
LoadStatus
Definition: PageParser.h:85
RootTags
Definition: PageParser.h:65
Definition: PageParser.h:66
Definition: PageParser.h:88
Definition: PageParser.h:60
Definition: PageParser.h:67
Definition: PageParser.h:70
#define DllCoreExport
Definition: PageParser.h:46
Definition: PageParser.h:77
QSharedPointer< PageElement > mPage
Definition: PageParser.h:111
Definition: Algorithms.cpp:45
Definition: PageParser.h:75