openPilotLog
jsonhelper.h
1 /*
2  *openPilotLog - A FOSS Pilot Logbook Application
3  *Copyright (C) 2020-2022 Felix Turowsky
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, see <https://www.gnu.org/licenses/>.
17  */
18 #ifndef JSONHELPER_H
19 #define JSONHELPER_H
20 #include "src/opl.h"
21 #include <QJsonDocument>
22 #include <QJsonValue>
23 #include <QJsonObject>
24 
29 {
30 public:
31  JsonHelper();
32  JsonHelper(QFileInfo database_file);
33 
41  static void exportDatabase();
42 
46  static void importDatabase();
47 
52  static QJsonDocument readFileToDoc(const QString &file_path);
53 
57  static void writeDocToFile(const QJsonDocument &doc, const QString& file_name);
58 
59 private:
60 
64  const static inline QList<OPL::DbTable> TABLES = {
65  OPL::DbTable::Tails,
66  OPL::DbTable::Pilots,
67  OPL::DbTable::Currencies,
68  OPL::DbTable::Flights,
69  };
70 
71 };
72 
73 #endif // JSONHELPER_H
The JsonHelper class is responsible for parsing the database (sqlite) to and from JSON.
Definition: jsonhelper.h:29
static void writeDocToFile(const QJsonDocument &doc, const QString &file_name)
writes a QJsonDocument to a file
Definition: jsonhelper.cpp:66
static void importDatabase()
importDatabase imports a dataset from JSON. Files need to be at AStanardPaths::JSON for now.
Definition: jsonhelper.cpp:36
static void exportDatabase()
exportDatabase exports the currently active database to JSON.
Definition: jsonhelper.cpp:22
static QJsonDocument readFileToDoc(const QString &file_path)
readToDocument reads data from a JSON file into a QJSonDocument
Definition: jsonhelper.cpp:55