1 /* 2 * Copyright 2012-2014 Thomas Schöps 3 * Copyright 2013-2019 Kai Pastor 4 * 5 * This file is part of OpenOrienteering. 6 * 7 * OpenOrienteering is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * OpenOrienteering is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 22 #ifndef OPENORIENTEERING_TEMPLATE_TRACK_H 23 #define OPENORIENTEERING_TEMPLATE_TRACK_H 24 25 #include <memory> 26 #include <vector> 27 28 #include <QtGlobal> 29 #include <QObject> 30 #include <QRectF> 31 #include <QString> 32 33 #include "core/track.h" 34 #include "templates/template.h" 35 36 class QByteArray; 37 class QPainter; 38 class QRectF; 39 class QWidget; 40 class QXmlStreamReader; 41 class QXmlStreamWriter; 42 43 namespace OpenOrienteering { 44 45 class Georeferencing; 46 class Map; 47 class MapCoordF; 48 class PathObject; 49 class PointObject; 50 51 52 /** A template consisting of a set of tracks (polylines) and waypoints */ 53 class TemplateTrack : public Template 54 { 55 Q_OBJECT 56 public: 57 /** 58 * Returns the filename extensions supported by this template class. 59 */ 60 static const std::vector<QByteArray>& supportedExtensions(); 61 62 TemplateTrack(const QString& path, Map* map); 63 protected: 64 TemplateTrack(const TemplateTrack& proto); 65 public: 66 ~TemplateTrack() override; 67 68 TemplateTrack* duplicate() const override; 69 getTemplateType()70 const char* getTemplateType() const override {return "TemplateTrack";} isRasterGraphics()71 bool isRasterGraphics() const override {return false;} 72 73 bool saveTemplateFile() const override; 74 75 bool loadTemplateFileImpl(bool configuring) override; 76 bool postLoadConfiguration(QWidget* dialog_parent, bool& out_center_in_view) override; 77 void unloadTemplateFileImpl() override; 78 79 void drawTemplate(QPainter* painter, const QRectF& clip_rect, double scale, bool on_screen, qreal opacity) const override; 80 QRectF getTemplateExtent() const override; 81 QRectF calculateTemplateBoundingBox() const override; 82 int getTemplateBoundingBoxPixelBorder() override; 83 84 bool hasAlpha() const override; 85 86 /// Draws all tracks. 87 void drawTracks(QPainter* painter, bool on_screen) const; 88 89 /// Draws all waypoints. 90 void drawWaypoints(QPainter* painter) const; 91 92 /// Import the track as map object(s), returns true if something has been imported. 93 /// TODO: should this be moved to the Track class? 94 bool import(QWidget* dialog_parent = nullptr); 95 96 /// Replaces the calls to pre/postLoadConfiguration() if creating a new GPS track. 97 /// Assumes that the map's georeferencing is valid. 98 void configureForGPSTrack(); 99 100 /// Returns the Track data object. getTrack()101 inline Track& getTrack() {return track;} 102 103 public slots: 104 void updateGeoreferencing(); 105 106 protected: 107 void saveTypeSpecificTemplateConfiguration(QXmlStreamWriter& xml) const override; 108 bool loadTypeSpecificTemplateConfiguration(QXmlStreamReader& xml) override; 109 110 /// Projects the track in non-georeferenced mode 111 QString calculateLocalGeoreferencing() const; 112 113 void applyProjectedCrsSpec(); 114 115 PathObject* importPathStart(); 116 void importPathEnd(PathObject* path); 117 PointObject* importWaypoint(const MapCoordF& position, const QString &name = QString()); 118 119 120 Track track; 121 QString track_crs_spec; 122 QString projected_crs_spec; 123 friend class OgrTemplate; // for migration 124 std::unique_ptr<Georeferencing> preserved_georef; 125 }; 126 127 128 } // namespace OpenOrienteering 129 130 #endif 131