Mapper  0.9.0
API documentation
Public Types | Public Member Functions | List of all members
OpenOrienteering::FileFormat Class Reference

Describes a file format understood by this application. More...

#include <file_format.h>

Inheritance diagram for OpenOrienteering::FileFormat:
Inheritance graph
[legend]

Public Types

enum  FileType { MapFile = 0x01, OgrFile = 0x02, AllFiles = MapFile, EndOfFileTypes }
 File type enumeration. More...
 
enum  Feature {
  Feature::FileOpen = 0x01, Feature::FileSave = 0x02, Feature::FileSaveAs = 0x04, Feature::FileImport = 0x08,
  Feature::FileExport = 0x10, Feature::ReadingLossy = 0x100, Feature::WritingLossy = 0x200
}
 A type which handles OR-combinations of file types. More...
 
enum  ImportSupportAssumption { NotSupported = 0, Unknown = 1, FullySupported = 2 }
 A type which handles OR-combinations of format implementation features. More...
 

Public Member Functions

 FileFormat (FileType file_type, const char *id, const QString &description, const QString &file_extension, Features features)
 Creates a new file format with the given parameters. More...
 
 FileFormat (const FileFormat &)=delete
 
 FileFormat (FileFormat &&)=delete
 
virtual ~FileFormat ()
 Destroys the file format information. More...
 
FileFormatoperator= (const FileFormat &)=delete
 
FileFormatoperator= (FileFormat &&)=delete
 
void addExtension (const QString &file_extension)
 Registers an alternative file name extension. More...
 
FileType fileType () const
 Returns the type of file. More...
 
const char * id () const
 Returns the internal ID of the file format. More...
 
const QStringdescription () const
 Returns a short human-readable description of the file format. More...
 
const QStringprimaryExtension () const
 Returns the primary file name extension used by this file format. More...
 
const QStringListfileExtensions () const
 Returns all file name extension supported by this file format. More...
 
const QStringfilter () const
 Returns the filter that represents this format in file dialogs. More...
 
bool supportsReading () const
 Returns true if this format supports reading a Map from a file. More...
 
bool supportsWriting () const
 Returns true if this format supports writing a Map to a file. More...
 
bool supportsFileOpen () const
 Returns true if this format is available for File > Open... More...
 
bool supportsFileSave () const
 Returns true if this format is available for File > Save. More...
 
bool supportsFileSaveAs () const
 Returns true if this format is available for File > Save as... More...
 
bool supportsFileImport () const
 Returns true if this format is available for File > Import... More...
 
bool supportsFileExport () const
 Returns true if this format is available for File > Export... More...
 
bool isReadingLossy () const
 Returns true if an importer for this file format is potentially lossy. More...
 
bool isWritingLossy () const
 Returns true if an exporter for this file format is potentially lossy. More...
 
virtual ImportSupportAssumption understands (const char *buffer, int size) const
 Determines whether this FileFormat is capable of understanding a file which starts with the given byte sequence. More...
 
virtual std::unique_ptr< ImportermakeImporter (const QString &path, Map *map, MapView *view) const
 Creates an Importer that will read a map file from the given stream. More...
 
virtual std::unique_ptr< ExportermakeExporter (const QString &path, const Map *map, const MapView *view) const
 Creates an Exporter that will save a map to the given path. More...
 

Detailed Description

Describes a file format understood by this application.

Each file format has an ID (an internal, non-translated string); a description (translated); a file extension (non-translated); and methods to indicate their support for import or export. Formats are installed into a FormatRegistry, and can be looked up in a variety of ways.

A typical FileFormat subclass will look like this:

class MyCustomFileFormat : public FileFormat {
public:
MyCustomFileFormat : FileFormat("custom", ::OpenOrienteering::ImportExport::tr("Custom file"), "custom", true, true) {
}
Importer *createImporter(QIODevice* stream, Map *map, MapView *view) const {
return new CustomImporter(stream, map, view);
}
Exporter *createExporter(QIODevice* stream, Map *map, MapView *view) const {
return new CustomExporter(stream, map, view);
}
}

Member Enumeration Documentation

◆ Feature

A type which handles OR-combinations of file types.

File format features.

Each feature shall use a distinct bit so that they may be OR-combined.

Enumerator
FileOpen 

This format supports reading and is to be used for File > Open...

FileSave 

This format supports writing and is to be used for File > Save.

FileSaveAs 

This format supports writing and is to be used for File > Save as...

FileImport 

This format supports reading and is to be used for File > Import...

FileExport 

This format supports writing and is to be used for File > Export...

ReadingLossy 

The importer cannot handle all file format features.

WritingLossy 

The exporter cannot handle all Mapper features.

◆ FileType

File type enumeration.

Each file type shall use a distinct bit so that they may be OR-combined.

Currently the program is only used for mapping, and "Map" is the only element. "Course" or "Event" are possible additions.

Enumerator
MapFile 
OgrFile 

Geospatial vector data supported by OGR.

AllFiles 

All types which can be handled by an editor.

EndOfFileTypes 

◆ ImportSupportAssumption

A type which handles OR-combinations of format implementation features.

A type which indicates the level of support for importing a file.

If a file format fully supports a file format, errors during import must be regard as fatal. If the level of support is Unknown, an import can be attempted, but an import failure allows no conclusion about whether the file format is actually unsupported or the file contains invalid data for a supported format.

Enumerator
NotSupported 

The FileFormat does not support the file.

Unknown 

The FileFormat support cannot be determine in advance.

FullySupported 

The FileFormat supports the file.

Constructor & Destructor Documentation

◆ FileFormat() [1/3]

OpenOrienteering::FileFormat::FileFormat ( FileFormat::FileType  file_type,
const char *  id,
const QString description,
const QString file_extension,
Features  features 
)

Creates a new file format with the given parameters.

Don't use a leading dot on the file extension.

◆ FileFormat() [2/3]

OpenOrienteering::FileFormat::FileFormat ( const FileFormat )
delete

◆ FileFormat() [3/3]

OpenOrienteering::FileFormat::FileFormat ( FileFormat &&  )
delete

◆ ~FileFormat()

OpenOrienteering::FileFormat::~FileFormat ( )
virtualdefault

Destroys the file format information.

Member Function Documentation

◆ addExtension()

void OpenOrienteering::FileFormat::addExtension ( const QString file_extension)

Registers an alternative file name extension.

It is used by the filter.

◆ description()

const QString & OpenOrienteering::FileFormat::description ( ) const
inline

Returns a short human-readable description of the file format.

◆ fileExtensions()

const QStringList & OpenOrienteering::FileFormat::fileExtensions ( ) const
inline

Returns all file name extension supported by this file format.

◆ fileType()

FileFormat::FileType OpenOrienteering::FileFormat::fileType ( ) const
inline

Returns the type of file.

◆ filter()

const QString & OpenOrienteering::FileFormat::filter ( ) const
inline

Returns the filter that represents this format in file dialogs.

◆ id()

const char * OpenOrienteering::FileFormat::id ( ) const
inline

Returns the internal ID of the file format.

◆ isReadingLossy()

bool OpenOrienteering::FileFormat::isReadingLossy ( ) const
inline

Returns true if an importer for this file format is potentially lossy.

When the importer is lossy, the created Map may not fully represent all features of the file.

◆ isWritingLossy()

bool OpenOrienteering::FileFormat::isWritingLossy ( ) const
inline

Returns true if an exporter for this file format is potentially lossy.

When the exporter is lossy, the created file may not fully represent all features of the Map in the program.

◆ makeExporter()

std::unique_ptr< Exporter > OpenOrienteering::FileFormat::makeExporter ( const QString path,
const Map map,
const MapView view 
) const
virtual

Creates an Exporter that will save a map to the given path.

The default implementation returns an unset unique_ptr.

Reimplemented in OpenOrienteering::OcdFileFormat, OpenOrienteering::OgrFileExportFormat, OpenOrienteering::OgrFileExportFormat, OpenOrienteering::XMLFileFormat, and OpenOrienteering::OCAD8FileFormat.

◆ makeImporter()

std::unique_ptr< Importer > OpenOrienteering::FileFormat::makeImporter ( const QString path,
Map map,
MapView view 
) const
virtual

Creates an Importer that will read a map file from the given stream.

The default implementation returns an unset unique_ptr.

Reimplemented in OpenOrienteering::OcdFileFormat, OpenOrienteering::OgrFileImportFormat, OpenOrienteering::OgrFileImportFormat, OpenOrienteering::XMLFileFormat, and OpenOrienteering::OCAD8FileFormat.

◆ operator=() [1/2]

FileFormat& OpenOrienteering::FileFormat::operator= ( const FileFormat )
delete

◆ operator=() [2/2]

FileFormat& OpenOrienteering::FileFormat::operator= ( FileFormat &&  )
delete

◆ primaryExtension()

const QString & OpenOrienteering::FileFormat::primaryExtension ( ) const
inline

Returns the primary file name extension used by this file format.

This shall only be used for constructing new file names. Otherwise you will probably need to use fileExtensions().

◆ supportsFileExport()

bool OpenOrienteering::FileFormat::supportsFileExport ( ) const
inline

Returns true if this format is available for File > Export...

◆ supportsFileImport()

bool OpenOrienteering::FileFormat::supportsFileImport ( ) const
inline

Returns true if this format is available for File > Import...

◆ supportsFileOpen()

bool OpenOrienteering::FileFormat::supportsFileOpen ( ) const
inline

Returns true if this format is available for File > Open...

◆ supportsFileSave()

bool OpenOrienteering::FileFormat::supportsFileSave ( ) const
inline

Returns true if this format is available for File > Save.

◆ supportsFileSaveAs()

bool OpenOrienteering::FileFormat::supportsFileSaveAs ( ) const
inline

Returns true if this format is available for File > Save as...

◆ supportsReading()

bool OpenOrienteering::FileFormat::supportsReading ( ) const

Returns true if this format supports reading a Map from a file.

◆ supportsWriting()

bool OpenOrienteering::FileFormat::supportsWriting ( ) const

Returns true if this format supports writing a Map to a file.

◆ understands()

FileFormat::ImportSupportAssumption OpenOrienteering::FileFormat::understands ( const char *  buffer,
int  size 
) const
virtual

Determines whether this FileFormat is capable of understanding a file which starts with the given byte sequence.

Magic numbers and version information are commonly placed at the beginning of a file. This method is used by the application to pre-screen for a suitable Importer.

The default implementation returns Unknown for file formats which support import, and NotSupported otherwise.

Reimplemented in OpenOrienteering::OcdFileFormat, OpenOrienteering::XMLFileFormat, and OpenOrienteering::OCAD8FileFormat.


The documentation for this class was generated from the following files: