Enroute Flight Navigation
A navigation app for VFR pilots
DataFileAbstract.h
1/***************************************************************************
2 * Copyright (C) 2023.2024 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include <QFileDevice>
24#include <QFile>
25#include <QObject>
26#include <QSharedPointer>
27
28namespace FileFormats
29{
30
43
44class DataFileAbstract
45{
46
47public:
48 DataFileAbstract() = default;
49 ~DataFileAbstract() = default;
50
51
52 //
53 // Getter methods
54 //
55
67 [[nodiscard]] bool isValid() const { return m_error.isEmpty(); }
68
76 [[nodiscard]] QString error() const { return m_error; }
77
85 [[nodiscard]] QStringList warnings() const { return m_warnings; }
86
87
88
89 //
90 // Methods
91 //
92
103 [[nodiscard]] static QSharedPointer<QFile> openFileURL(const QString& fileName);
104
123 [[nodiscard]] static bool saveFileAtomically(const QString& path, const QByteArray& data, QString* error = nullptr, QFileDevice::Permissions permissions = {});
124
125protected:
126 void addWarning(const QString& warning) { m_warnings += warning; }
127 void setError(const QString& newError) { m_error = newError; }
128
129private:
130 QString m_error;
131 QStringList m_warnings;
132};
133
134} // namespace FileFormats
static QSharedPointer< QFile > openFileURL(const QString &fileName)
Open file, file URL or Android content URL.
QString error() const
Error string.
static bool saveFileAtomically(const QString &path, const QByteArray &data, QString *error=nullptr, QFileDevice::Permissions permissions={})
Write data to a file atomically.
bool isValid() const
Validity check.
QStringList warnings() const
Warnings.