Implement enum support in CachedSettingValue

Enums are stored as strings, that improves configuration file
readability and maintainability. String values are obtained via
QMetaEnum, and since with Qt 5.5 QMetaEnum::fromType() includes a
static_assert, this has to be a safe method.
This commit is contained in:
Eugene Shalygin
2017-07-05 12:19:58 +02:00
parent 8e6df572a8
commit a22d2f0139
5 changed files with 71 additions and 49 deletions

View File

@@ -29,10 +29,11 @@
#ifndef TOFFENTFILEGURAD_H
#define TOFFENTFILEGURAD_H
#include <QObject>
#include <QString>
#include <QMetaType>
class QMetaEnum;
template <typename T> class CachedSettingValue;
/// Utility class to defer file deletion
class FileGuard
{
@@ -62,7 +63,7 @@ public:
void markAsAddedToSession();
using FileGuard::setAutoRemove;
enum AutoDeleteMode // do not change these names: they are stored in config file
enum AutoDeleteMode: int // do not change these names: they are stored in config file
{
Never,
IfAdded,
@@ -74,9 +75,8 @@ public:
static void setAutoDeleteMode(AutoDeleteMode mode);
private:
static QMetaEnum modeMetaEnum();
TorrentFileGuard(const QString &path, AutoDeleteMode mode);
static CachedSettingValue<AutoDeleteMode> &autoDeleteModeSetting();
Q_ENUM(AutoDeleteMode)
AutoDeleteMode m_mode;