Mapper  0.9.0
API documentation
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
OpenOrienteering::Importer Class Referenceabstract

Base class for all importers. More...

#include <file_import_export.h>

Inheritance diagram for OpenOrienteering::Importer:
Inheritance graph
[legend]
Collaboration diagram for OpenOrienteering::Importer:
Collaboration graph
[legend]

Public Member Functions

 Importer (const QString &path, Map *map, MapView *view)
 Creates a new Importer with the given input path, map, and view. More...
 
 ~Importer () override
 Destroys this Importer. More...
 
bool loadSymbolsOnly () const noexcept
 Returns true if only symbols (and colors) are to be imported. More...
 
void setLoadSymbolsOnly (bool value)
 If set to true, importers shall import only symbols (and colors). More...
 
bool doImport ()
 Imports the map and view. More...
 
- Public Member Functions inherited from OpenOrienteering::ImportExport
 ImportExport (QIODevice *device=nullptr)
 Creates a new importer or exporter with the given IO device. More...
 
 ImportExport (const ImportExport &)=delete
 
 ImportExport (ImportExport &&)=delete
 
virtual ~ImportExport ()
 Destroys an importer or exporter. More...
 
virtual bool supportsQIODevice () const noexcept
 Returns true when the importer/exporter supports QIODevice. More...
 
QIODevicedevice () const noexcept
 Returns the input device if it has been set or created. More...
 
void setDevice (QIODevice *device)
 Sets a custom input device to be used for import. More...
 
void setOption (const QString &name, const QVariant &value)
 Sets an option in this importer or exporter. More...
 
QVariant option (const QString &name) const
 Retrieves the value of an option in this instance. More...
 
void addWarning (const QString &str)
 Adds a string to the current list of warnings. More...
 
const std::vector< QString > & warnings () const noexcept
 Returns the current list of warnings collected by this object. More...
 

Protected Member Functions

virtual void prepare ()
 Event handler called from doImport() to prepare the import process. More...
 
virtual bool importImplementation ()=0
 Actual implementation of the import. More...
 
virtual void validate ()
 Event handler called from doImport() to complete to postprocess imported data. More...
 
virtual void importFailed ()
 Event handler called from doImport() to complete to cleanup a failed import attempt. More...
 

Protected Attributes

const QString path
 The input path. More...
 
Map *const map
 The Map to import or export. More...
 
MapView *const view
 The MapView to import or export. More...
 

Detailed Description

Base class for all importers.

An Importer has the following lifecycle:

  1. The Importer is constructed with the input path and with pointers to map and view. The constructor should also set default values for any options it will read. (ImportExport will throw an exception if the exporter reads an option that does not have a value.)
  2. setOption() can be called zero or more times to customize the options. setDevice() can be called to set a custom input device.
  3. doImport() will be called to perform the import.

Constructor & Destructor Documentation

◆ Importer()

OpenOrienteering::Importer::Importer ( const QString path,
Map map,
MapView view 
)
inline

Creates a new Importer with the given input path, map, and view.

◆ ~Importer()

OpenOrienteering::Importer::~Importer ( )
overridedefault

Destroys this Importer.

Member Function Documentation

◆ doImport()

bool OpenOrienteering::Importer::doImport ( )

Imports the map and view.

This is the function which is normally called to perform import. It must return false on errors and true on success. All error and warning messages must be logged in ImportExport::warnings().

In case of an error, the last warning can be assumed to be the error message. (The list of warnings won't be empty then.)

If the importer supports input from QIODevice, this function will open a QFile with the given path and make it available via device().

◆ importFailed()

void OpenOrienteering::Importer::importFailed ( )
protectedvirtual

Event handler called from doImport() to complete to cleanup a failed import attempt.

Overriding functions must call the the default implementation.

◆ importImplementation()

virtual bool OpenOrienteering::Importer::importImplementation ( )
protectedpure virtual

Actual implementation of the import.

This function shall read the input and populate the map and view from it. Importers which support input from QIODevice should use the device(). They must not open or close this device.

If information might be lost in the process, a message shall be recorded by calling addWarning() with a translated, useful description of the issue. If a fatal error is encountered, then this method may either throw an exception, or log an error message with addWarning() and return false. The line between errors and warnings is somewhat of a judgement call on the part of the author, but generally an Importer should not succeed unless the map is populated sufficiently to be useful.

Implemented in OpenOrienteering::OgrFileImport, OpenOrienteering::OcdFileImport, OpenOrienteering::OcdFileImport, OpenOrienteering::XMLFileImporter, and OpenOrienteering::OCAD8FileImport.

◆ loadSymbolsOnly()

bool OpenOrienteering::Importer::loadSymbolsOnly ( ) const
inlinenoexcept

Returns true if only symbols (and colors) are to be imported.

◆ prepare()

void OpenOrienteering::Importer::prepare ( )
protectedvirtual

Event handler called from doImport() to prepare the import process.

This function is called only when opening the input succeeded. However, the input is not passed to this function by intention: It is meant to be used also by importers which do not use QIODevice.

Overriding functions must call the the default implementation.

◆ setLoadSymbolsOnly()

void OpenOrienteering::Importer::setLoadSymbolsOnly ( bool  value)

If set to true, importers shall import only symbols (and colors).

◆ validate()

void OpenOrienteering::Importer::validate ( )
protectedvirtual

Event handler called from doImport() to complete to postprocess imported data.

Overriding functions must call the the default implementation early. It validates the object and symbols, and looks for templates. It may throw FileFormatException.

Member Data Documentation

◆ map

Map* const OpenOrienteering::Importer::map
protected

The Map to import or export.

◆ path

const QString OpenOrienteering::Importer::path
protected

The input path.

◆ view

MapView* const OpenOrienteering::Importer::view
protected

The MapView to import or export.


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