File indexing completed on 2024-05-12 03:50:31

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2016 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 #ifndef MARBLE_GEODATADOCUMENTWRITER_H
0007 #define MARBLE_GEODATADOCUMENTWRITER_H
0008 
0009 #include "marble_export.h"
0010 
0011 #include <QIODevice>
0012 #include <QSet>
0013 
0014 namespace Marble
0015 {
0016 
0017 class GeoWriterBackend;
0018 class GeoDataDocument;
0019 
0020 /**
0021  * Write GeoDataDocument content to I/O devices (e.g. a file)
0022  */
0023 class MARBLE_EXPORT GeoDataDocumentWriter
0024 {
0025 public:
0026     /**
0027      * Write the content of the given GeoDataDocument to the given I/O device
0028      * @param device An I/O device open for writing
0029      * @param document A GeoDataDocument with content to write
0030      * @param documentIdentifier XML document identifier or file extension that determines
0031      * @return True if writing is successful, false otherwise
0032      */
0033     static bool write(QIODevice* device, const GeoDataDocument &document, const QString &documentIdentifier);
0034 
0035     /**
0036      * Convenience method that uses a QFile as QIODevice and determines the document type from the filename extension
0037      * @param filename Target file's name
0038      * @param document Document to write
0039      * @param documentIdentifier XML document identifier or filename extension that determines the content type.
0040      * Use an empty string (default) to determine it automatically
0041      * @return True if writing is successful, false otherwise
0042      */
0043     static bool write(const QString &filename, const GeoDataDocument &document, const QString &documentIdentifier = QString());
0044 
0045     /**
0046      * Registers a plugin as a backend for writing a certain file extension. Usually called by the MARBLE_ADD_WRITER macro.
0047      * @param writer Backend to register
0048      * @param fileExtension File extension to associate the backend with
0049      */
0050     static void registerWriter(GeoWriterBackend* writer, const QString &fileExtension);
0051     static void unregisterWriter(GeoWriterBackend* writer, const QString &fileExtension);
0052 
0053 private:
0054     static QString determineDocumentIdentifier(const QString &filename);
0055     static QSet<QPair<QString, GeoWriterBackend*> > s_backends;
0056 };
0057 
0058 }
0059 
0060 #endif