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

Base class for all exporters. More...

#include <file_import_export.h>

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

Public Member Functions

 Exporter (const QString &path, const Map *map, const MapView *view)
 Creates a new Exporter with the given path, map, and view. More...
 
 ~Exporter () override
 Destroys the current Exporter. More...
 
bool doExport ()
 Exports 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 bool exportImplementation ()=0
 Actual implementation of the export. More...
 

Protected Attributes

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

Detailed Description

Base class for all exporters.

An Exporter has the following lifecycle:

  1. The constructor is called with a path, map and view. The path may be empty if the output device can be (and is) set later. The view may be nullptr. The constructor must also set default values for any options the exporter will read. (ImportExport will throw an exception if the exporter reads an option that has not been set.)
  2. setOption() can be called zero or more times to customize the options.
  3. doExport() will be called to perform the export.

Constructor & Destructor Documentation

◆ Exporter()

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

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

◆ ~Exporter()

OpenOrienteering::Exporter::~Exporter ( )
overridedefault

Destroys the current Exporter.

Member Function Documentation

◆ doExport()

bool OpenOrienteering::Exporter::doExport ( )

Exports the map and view.

This function calls exportImplementation() and catches exceptions thrown there. It returns false on errors and true on success. All error and warning messages are 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 exporter supports input from QIODevice but a device hasn't been set yet, this function will open a QSaveFile with the given path, make it available via device(), and commit the changes if exportImplementation() returns successfully.

◆ exportImplementation()

virtual bool OpenOrienteering::Exporter::exportImplementation ( )
protectedpure virtual

Actual implementation of the export.

Exporters which support input from QIODevice shall use the device(). They must not open or close the device.

If information might be lost in the export, 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.

There is no default implementation.

Implemented in OpenOrienteering::OgrFileExport, OpenOrienteering::OCAD8FileExport, OpenOrienteering::OcdFileExport, OpenOrienteering::OcdFileExport, and OpenOrienteering::XMLFileExporter.

Member Data Documentation

◆ map

const Map* const OpenOrienteering::Exporter::map
protected

The Map to import or export.

◆ path

const QString OpenOrienteering::Exporter::path
protected

The output path.

◆ view

const MapView* const OpenOrienteering::Exporter::view
protected

The MapView to import or export.


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