1 #ifndef DOCUMENT_H_
2 #define DOCUMENT_H_
3 
4 #include <QtXml>
5 
6 #include "IDocument.h"
7 #include "Layer.h"
8 #include "Coord.h"
9 #include "MerkaartorPreferences.h"
10 #include "LayerDock.h"
11 
12 #include <utility>
13 
14 class QString;
15 class QProgressDialog;
16 class QMainWindow;
17 
18 class Command;
19 class CommandHistory;
20 class Document;
21 class MapDocumentPrivate;
22 class ImageMapLayer;
23 class TrackLayer;
24 class DrawingLayer;
25 class DirtyLayer;
26 class UploadedLayer;
27 class DeletedLayer;
28 class FeaturePainter;
29 
30 class Document : public QObject, public IDocument
31 {
32 Q_OBJECT
33 public:
34     Document();
35     Document(LayerDock* aDock);
36 
37 private:
38     Document(const Document&, LayerDock* aDock);
39 
40 public:
41     ~Document();
42 
43     const QString& id() const;
44 
45     void addDefaultLayers();
46     void addFilterLayers();
47 
48     void setLayerDock(LayerDock* aDock);
49     LayerDock* getLayerDock(void);
50 
51     void add(Layer* aLayer);
52     void moveLayer(Layer* aLayer, int pos);
53     ImageMapLayer* addImageLayer(ImageMapLayer* aLayer = NULL);
54     DrawingLayer* addDrawingLayer(DrawingLayer* aLayer = NULL);
55     FilterLayer* addFilterLayer(FilterLayer* aLayer = NULL);
56     void remove(Layer* aLayer);
57     bool exists(Layer* aLayer) const;
58     bool exists(Feature* aFeature) const;
59     void deleteFeature(Feature* aFeature);
60     int layerSize() const;
61     Layer* getLayer(const QString& id);
62     Layer* getLayer(int i);
63     const Layer* getLayer(int i) const;
64     int size() const;
65 
66     Feature* getFeature(const IFeature::FId& id);
67     QList<Feature*> getFeatures(Layer::LayerType layerType = Layer::UndefinedType);
68     void setHistory(CommandHistory* h);
69     CommandHistory& history();
70     const CommandHistory& history() const;
71     void addHistory(Command* aCommand);
72     void redoHistory();
73     void undoHistory();
74     void rebuildHistory();
75     void clear();
76 
77     void setDirtyLayer(DirtyLayer* aLayer);
78     Layer* getDirtyLayer();
79     Layer* getDirtyOrOriginLayer(Layer* aLayer = NULL);
80     Layer* getDirtyOrOriginLayer(Feature* F);
81     int getDirtySize() const;
82 
83     void setUploadedLayer(UploadedLayer* aLayer);
84     UploadedLayer* getUploadedLayer() const;
85 
86     void exportOSM(QWidget* main, QIODevice* device, QList<Feature*> aFeatures);
87     QList<Feature*> exportCoreOSM(QList<Feature*> aFeatures, bool forCopyPaste=false, QProgressDialog * progress=NULL);
88     bool toXML(QXmlStreamWriter& stream, bool asTemplate, QProgressDialog * progress);
89     static Document* fromXML(QString title, QXmlStreamReader& stream, qreal version, LayerDock* aDock, QProgressDialog * progress);
90 
91     bool importNMEA(const QString& filename, TrackLayer* NewLayer);
92     bool importKML(const QString& filename, TrackLayer* NewLayer);
93     bool importCSV(const QString& filename, DrawingLayer* NewLayer);
94     bool importOSC(const QString& filename, DrawingLayer* NewLayer);
95 #ifndef _MOBILE
96     bool importGDAL(const QString& filename, DrawingLayer* NewLayer);
97 #endif
98 #ifdef USE_PROTOBUF
99     bool importPBF(const QString& filename, DrawingLayer* NewLayer);
100 #endif
101 
102     QDateTime getLastDownloadLayerTime() const;
103     Layer* getLastDownloadLayer() const;
104     void setLastDownloadLayer(Layer * aLayer);
105 
106     void addDownloadBox(Layer*l, CoordBox aBox);
107     void removeDownloadBox(Layer*l);
108     const QList<CoordBox> getDownloadBoxes() const;
109     const QList<CoordBox> getDownloadBoxes(Layer* l) const;
110     bool isDownloadedSafe(const CoordBox& bb) const;
111 
112     QPair<bool, CoordBox> boundingBox();
113 
114     bool setFilterType(FilterType aFilter);
115     TagSelector* getTagFilter();
116     int filterRevision() const;
117 
118     QString title() const;
119     void setTitle(const QString aTitle);
120 
121     QString toPropertiesHtml();
122 
123     virtual void setPainters(QList<Painter> aPainters);
124     virtual int getPaintersSize();
125     void lockPainters();
126     void lockPaintersForWrite();
127     void unlockPainters();
128     virtual const Painter* getPainter(int i);
129 
130     QStringList getCurrentSourceTags();
131 
132     static Document* getDocumentFromXml(QDomDocument* theXmlDoc);
133     static Document* getDocumentFromClipboard();
134 
135     QList<Feature*> mergeDocument(Document *otherDoc, Layer* layer, CommandList* theList=NULL);
136 private:
137     MapDocumentPrivate* p;
138 
139 protected slots:
140     void on_imageRequested(ImageMapLayer* anImageLayer);
141     void on_imageReceived(ImageMapLayer* anImageLayer);
142     void on_loadingFinished(ImageMapLayer* anImageLayer);
143 
144 signals:
145     void imageRequested(ImageMapLayer*);
146     void imageReceived(ImageMapLayer*);
147     void loadingFinished(ImageMapLayer*);
148     void historyChanged();
149 
150 };
151 
152 class FeatureIterator
153 {
154 
155 public:
156     FeatureIterator(Document* aDoc);
157     virtual ~FeatureIterator();
158 
159     bool isEnd() const;
160     FeatureIterator& operator ++();
161     Feature* get();
162     int index();
163 
164 protected:
165     virtual bool check();
166     Document* theDocument;
167     int curLayerIdx;
168     int curFeatureIdx;
169     bool isAtEnd;
170     int docSize;
171     int curLayerSize;
172 };
173 
174 class VisibleFeatureIterator: public FeatureIterator
175 {
176 
177 public:
178     VisibleFeatureIterator(Document* aDoc);
179     virtual ~VisibleFeatureIterator();
180 
181 protected:
182     virtual bool check();
183 };
184 
185 
186 #endif
187 
188 
189