EHM DAL 0.2.3
Data abstraction layer for Eastside Hockey Manager
Loading...
Searching...
No Matches
abstract_file_manager.h
1#pragma once
2
3// Application headers
4#include "include/settings/folder_path.h"
5
6// Qt headers
7#include <QTime>
8class QDataStream;
9class QString;
10class QWidget;
11
12namespace ehm_dal::file_io {
18{
19public:
20 AbstractFileManager(const QString &folder_path_key);
21
22 // Close database/tables
28 bool close(const bool show_confirmation_dialog = true);
29
30 // Descriptor
35 virtual QString descriptor() const = 0;
39 virtual QString fileFilterString() const = 0;
40
41 // File i/o - read
47 bool open(const QString &path);
53 bool open(QWidget *parent = nullptr);
54
55 // File i/o - write
60 bool save();
66 bool saveAs(QWidget *parent = nullptr);
67
68 // Get data
72 inline bool isOpen() const { return is_open_; }
76 inline bool isSaved() const { return has_been_saved_; }
77
78protected:
79 // Status
80 inline void setOpenStatus(const bool is_open) { is_open_ = is_open; }
81 void setSaveStatus(const bool has_been_saved);
82
83private:
84 // Close database/tables
85 virtual void closeAll() = 0;
86
87 // File i/o - read
88 virtual bool read(const QString &path) = 0;
89
90 // File i/o - write
91 virtual bool write(const QString &path) = 0;
92
93 // Folder path cache
94 settings::FolderPath source_folder_;
95
96 // Status
97 bool has_been_saved_{false};
98 bool is_open_{false};
99 QTime last_saved_time_{QTime::currentTime()};
100};
101} // namespace ehm_dal::file_io
The AbstractFileManager class is a base class providing simple read and write file access to database...
Definition: abstract_file_manager.h:18
bool isSaved() const
Returns whether or not the file has been previously saved.
Definition: abstract_file_manager.h:76
virtual QString descriptor() const =0
Returns the file manager descriptor. E.g. This will return "database" for a database file manager.
bool open(QWidget *parent=nullptr)
Displays a file dialog window and opens the user selected file.
bool saveAs(QWidget *parent=nullptr)
Displays a file dialog window and saves the user selected destination.
bool save()
Saves the data to the existing file.
bool close(const bool show_confirmation_dialog=true)
Closes the active database/saved game and clears all tables.
virtual QString fileFilterString() const =0
Returns a list of supported file type filters for QFileDialog.
bool isOpen() const
Returns whether or not a file is presently open.
Definition: abstract_file_manager.h:72
bool open(const QString &path)
Opens the file at path.
Definition: folder_path.h:11