2018-06-16 14:03:31 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef QPREFPRIVATE_H
|
|
|
|
#define QPREFPRIVATE_H
|
|
|
|
|
|
|
|
// Header used by all qPref<class> implementations to avoid duplicating code
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QVariant>
|
2018-06-30 09:23:33 +00:00
|
|
|
#include <QObject>
|
2018-06-16 14:03:31 +00:00
|
|
|
#include "core/qthelper.h"
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
//****** Macros to be used in the set functions ******
|
2018-06-16 14:03:31 +00:00
|
|
|
#define COPY_TXT(name, string) \
|
|
|
|
{ \
|
|
|
|
free((void *)prefs.name); \
|
|
|
|
prefs.name = copy_qstring(string); \
|
|
|
|
}
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
//****** Macros to be used in the disk functions, which are special ******
|
|
|
|
#define LOADSYNC_BOOL(name, field) \
|
2018-06-16 14:03:31 +00:00
|
|
|
{ \
|
2018-06-30 09:23:33 +00:00
|
|
|
if (doSync) \
|
|
|
|
setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-06-30 09:23:33 +00:00
|
|
|
prefs.field = setting.value(group + name, default_prefs.field).toBool(); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
#define LOADSYNC_DOUBLE(name, field) \
|
2018-06-16 14:03:31 +00:00
|
|
|
{ \
|
|
|
|
if (doSync) \
|
2018-06-30 09:23:33 +00:00
|
|
|
setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-06-30 09:23:33 +00:00
|
|
|
prefs.field = setting.value(group + name, default_prefs.field).toDouble(); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define LOADSYNC_ENUM(name, type, field) \
|
|
|
|
{ \
|
|
|
|
if (doSync) \
|
2018-06-30 09:23:33 +00:00
|
|
|
setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-06-30 09:23:33 +00:00
|
|
|
prefs.field = (enum type)setting.value(group + name, default_prefs.field).toInt(); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
#define LOADSYNC_INT(name, field) \
|
2018-06-16 14:03:31 +00:00
|
|
|
{ \
|
2018-06-30 09:23:33 +00:00
|
|
|
if (doSync) \
|
|
|
|
setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-06-30 09:23:33 +00:00
|
|
|
prefs.field = setting.value(group + name, default_prefs.field).toInt(); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
#define LOADSYNC_INT_DEF(name, field, defval) \
|
2018-06-16 14:03:31 +00:00
|
|
|
{ \
|
|
|
|
if (doSync) \
|
2018-06-30 09:23:33 +00:00
|
|
|
setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-06-30 09:23:33 +00:00
|
|
|
prefs.field = setting.value(group + name, defval).toInt(); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define LOADSYNC_TXT(name, field) \
|
|
|
|
{ \
|
|
|
|
if (doSync) \
|
2018-06-30 09:23:33 +00:00
|
|
|
setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-06-30 09:23:33 +00:00
|
|
|
prefs.field = copy_qstring(setting.value(group + name, default_prefs.field).toString()); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
//******* Macros to generate disk function
|
|
|
|
#define DISK_LOADSYNC_BOOL(class, name, field) \
|
|
|
|
void qPref ## class::disk_ ## field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
LOADSYNC_BOOL(name, field); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DISK_LOADSYNC_DOUBLE(class, name, field) \
|
|
|
|
void qPref ## class::disk_ ## field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
LOADSYNC_DOUBLE(name, field); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DISK_LOADSYNC_ENUM(class, name, type, field) \
|
|
|
|
void qPref ## class::disk_ ## field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
LOADSYNC_ENUM(name, type, field); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DISK_LOADSYNC_INT(class, name, field) \
|
|
|
|
void qPref ## class::disk_ ## field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
LOADSYNC_DOUBLE(name, field); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DISK_LOADSYNC_INT_DEF(class, name, field, defval) \
|
|
|
|
void qPref ## class::disk_ ## field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
LOADSYNC_INT_DEF(name, field, defval); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DISK_LOADSYNC_TXT(class, name, field) \
|
|
|
|
void qPref ## class::disk_ ## field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
LOADSYNC_TXT(name, field); \
|
|
|
|
}
|
2018-07-01 20:26:27 +00:00
|
|
|
|
|
|
|
//******* Macros to generate get function
|
|
|
|
#define GET_PREFERENCE_BOOL(class, field) \
|
|
|
|
bool qPref ## class::field () const \
|
|
|
|
{ \
|
|
|
|
return prefs.field; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_PREFERENCE_DOUBLE(class, field) \
|
|
|
|
double qPref ## class::field () const \
|
|
|
|
{ \
|
|
|
|
return prefs.field; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_PREFERENCE_ENUM(class, type, field) \
|
|
|
|
struct type qPref ## class:: ## field () const \
|
|
|
|
{ \
|
|
|
|
return prefs.field; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_PREFERENCE_INT(class, field) \
|
|
|
|
int qPref ## class::field () const \
|
|
|
|
{ \
|
|
|
|
return prefs.field; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_PREFERENCE_TXT(class, field) \
|
|
|
|
const QString qPref ## class::field () const \
|
|
|
|
{ \
|
|
|
|
return prefs.field; \
|
|
|
|
}
|
2018-07-02 07:25:20 +00:00
|
|
|
|
|
|
|
//******* Macros to generate set function
|
|
|
|
#define SET_PREFERENCE_BOOL(class, field) \
|
|
|
|
void qPref ## class::set_ ## field (bool value) \
|
|
|
|
{ \
|
|
|
|
if (value != prefs.field) { \
|
|
|
|
prefs.field = value; \
|
|
|
|
disk_ ## field(true); \
|
|
|
|
emit field ## _changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SET_PREFERENCE_DOUBLE(class, field) \
|
|
|
|
void qPref ## class::set_ ## field (double value) \
|
|
|
|
{ \
|
|
|
|
if (value != prefs.field) { \
|
|
|
|
prefs.field = value; \
|
|
|
|
disk_ ## field(true); \
|
|
|
|
emit field ## _changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SET_PREFERENCE_ENUM(class, type, field) \
|
|
|
|
void qPref ## class::set_ ## field (type value) \
|
|
|
|
{ \
|
|
|
|
if (value != prefs.field) { \
|
|
|
|
prefs.field = value; \
|
|
|
|
disk_ ## field(true); \
|
|
|
|
emit field ## _changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SET_PREFERENCE_INT(class, field) \
|
|
|
|
void qPref ## class::set_ ## field (int value) \
|
|
|
|
{ \
|
|
|
|
if (value != prefs.field) { \
|
|
|
|
prefs.field = value; \
|
|
|
|
disk_ ## field(true); \
|
|
|
|
emit field ## _changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SET_PREFERENCE_TXT(class, field) \
|
|
|
|
void qPref ## class::set_ ## field (const QString& value) \
|
|
|
|
{ \
|
|
|
|
if (value != prefs.field) { \
|
|
|
|
COPY_TXT(field, value); \
|
|
|
|
disk_ ## field(true); \
|
|
|
|
emit field ## _changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
2018-06-16 14:03:31 +00:00
|
|
|
#endif
|