This repository has been archived by the owner on Nov 29, 2020. It is now read-only.
/
ProjectReader.h
113 lines (82 loc) · 3 KB
/
ProjectReader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROJECTREADER_H_
#define PROJECTREADER_H_
#include "ImageId.h"
#include "PageId.h"
#include "ImageInfo.h"
#include "ImageMetadata.h"
#include "SelectedPage.h"
#include "IntrusivePtr.h"
#include <QString>
#include <QDomDocument>
#include <Qt>
#include <vector>
#include <map>
class QDomElement;
class ProjectData;
class ProjectPages;
class FileNameDisambiguator;
class AbstractFilter;
class ProjectReader
{
public:
typedef IntrusivePtr<AbstractFilter> FilterPtr;
ProjectReader(QDomDocument const& doc);
~ProjectReader();
void readFilterSettings(std::vector<FilterPtr> const& filters) const;
bool success() const { return m_ptrPages.get() != 0; }
QString const& outputDirectory() const { return m_outDir; }
IntrusivePtr<ProjectPages> const& pages() const { return m_ptrPages; }
SelectedPage const& selectedPage() const { return m_selectedPage; }
IntrusivePtr<FileNameDisambiguator> const& namingDisambiguator() const {
return m_ptrDisambiguator;
}
ImageId imageId(int numeric_id) const;
PageId pageId(int numeric_id) const;
private:
struct FileRecord
{
QString filePath;
bool compatMultiPage; // Backwards compatibility.
FileRecord() : compatMultiPage(false) {}
FileRecord(QString const& file_path, bool compat_multi_page)
: filePath(file_path), compatMultiPage(compat_multi_page) {}
};
typedef std::map<int, QString> DirMap;
typedef std::map<int, FileRecord> FileMap;
typedef std::map<int, ImageInfo> ImageMap;
typedef std::map<int, PageId> PageMap;
void processDirectories(QDomElement const& dirs_el);
void processFiles(QDomElement const& files_el);
void processImages(QDomElement const& images_el,
Qt::LayoutDirection layout_direction);
ImageMetadata processImageMetadata(QDomElement const& image_el);
void processPages(QDomElement const& pages_el);
QString getDirPath(int id) const;
FileRecord getFileRecord(int id) const;
QString expandFilePath(QString const& path_shorthand) const;
ImageInfo getImageInfo(int id) const;
QDomDocument m_doc;
QString m_outDir;
DirMap m_dirMap;
FileMap m_fileMap;
ImageMap m_imageMap;
PageMap m_pageMap;
SelectedPage m_selectedPage;
IntrusivePtr<ProjectPages> m_ptrPages;
IntrusivePtr<FileNameDisambiguator> m_ptrDisambiguator;
};
#endif