Skip to content

Commit

Permalink
TemplateTrack: Add test function for supported file name
Browse files Browse the repository at this point in the history
TemplateTrack no longer supports anything but GPX. The new function
leverages this property for TemplateTrack compatibility in OgrTemplate
without capturing the details in OgrTemplate.
  • Loading branch information
dg0yt committed Dec 3, 2020
1 parent b910d1f commit 1a1d5e6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
13 changes: 1 addition & 12 deletions src/gdal/ogr_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@

#include "ogr_template.h"

#include <algorithm>
#include <iosfwd>
#include <iterator>
#include <memory>
#include <utility>

#include <Qt>
#include <QtGlobal>
#include <QByteArray>
#include <QDialog>
#include <QLatin1String>
#include <QPoint>
Expand Down Expand Up @@ -214,6 +210,7 @@ std::unique_ptr<Georeferencing> OgrTemplate::makeGeoreferencing(const QString& s
bool OgrTemplate::preLoadSetup(QWidget* dialog_parent)
try
{
template_track_compatibility = TemplateTrack::supports(template_path);
is_georeferenced = false;
explicit_georef.reset();
map_configuration_georef.reset();
Expand All @@ -222,14 +219,6 @@ try
transform = {};
updateTransformationMatrices();

auto ends_with_any_of = [](const QString& path, const std::vector<QByteArray>& list) -> bool {
using namespace std;
return any_of(begin(list), end(list), [path](const QByteArray& extension) {
return path.endsWith(QLatin1String(extension), Qt::CaseInsensitive);
} );
};
template_track_compatibility = ends_with_any_of(template_path, TemplateTrack::supportedExtensions());

auto data_georef = std::unique_ptr<Georeferencing>();
if (map->getGeoreferencing().getState() != Georeferencing::Geospatial)
{
Expand Down
6 changes: 6 additions & 0 deletions src/templates/template_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ const std::vector<QByteArray>& TemplateTrack::supportedExtensions()
return extensions;
}

bool TemplateTrack::supports(const QString& filename)
{
return filename.endsWith(QLatin1String(".gpx"), Qt::CaseInsensitive);
}


TemplateTrack::TemplateTrack(const QString& path, Map* map)
: Template(path, map)
{
Expand Down
15 changes: 14 additions & 1 deletion src/templates/template_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,29 @@ class Georeferencing;
class Map;


/** A template consisting of a set of tracks (polylines) and waypoints */
/**
* A template class for visualizing of GPX files.
*
* This class offers specialized support for visualizing tracks and waypoints
* from GPX files.
*/
class TemplateTrack : public Template
{
Q_OBJECT
public:
/**
* Returns the filename extensions supported by this template class.
*
* Class TemplateTrack only supports ".gpx".
*/
static const std::vector<QByteArray>& supportedExtensions();

/**
* Tests if a filename ends with the supported extension, ".gpx".
*/
static bool supports(const QString& filename);


TemplateTrack(const QString& path, Map* map);
protected:
TemplateTrack(const TemplateTrack& proto);
Expand Down

0 comments on commit 1a1d5e6

Please sign in to comment.