mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 18:13:24 +00:00
qPref: add ability to remember recently used dive computers
This does feel clumsy and complicated. This is a lot of special case handling and a lot of boilerplate for something that really should be quite simple. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5b37d87e2d
commit
77a5c9ac65
4 changed files with 167 additions and 20 deletions
|
@ -99,6 +99,10 @@ struct preferences {
|
|||
|
||||
// ********** DiveComputer **********
|
||||
dive_computer_prefs_t dive_computer;
|
||||
dive_computer_prefs_t dive_computer1;
|
||||
dive_computer_prefs_t dive_computer2;
|
||||
dive_computer_prefs_t dive_computer3;
|
||||
dive_computer_prefs_t dive_computer4;
|
||||
|
||||
// ********** Display **********
|
||||
bool display_invalid_dives;
|
||||
|
|
|
@ -17,19 +17,48 @@ qPrefDiveComputer *qPrefDiveComputer::instance()
|
|||
|
||||
void qPrefDiveComputer::loadSync(bool doSync)
|
||||
{
|
||||
// last computer used
|
||||
disk_device(doSync);
|
||||
disk_device_name(doSync);
|
||||
disk_download_mode(doSync);
|
||||
disk_product(doSync);
|
||||
disk_vendor(doSync);
|
||||
|
||||
// the four shortcuts
|
||||
#define DISK_DC(num) \
|
||||
disk_device##num(doSync); \
|
||||
disk_device_name##num(doSync); \
|
||||
disk_product##num(doSync); \
|
||||
disk_vendor##num(doSync);
|
||||
|
||||
DISK_DC(1)
|
||||
DISK_DC(2)
|
||||
DISK_DC(3)
|
||||
DISK_DC(4)
|
||||
|
||||
}
|
||||
|
||||
HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "dive_computer_device", device, dive_computer.);
|
||||
// these are the 'active' settings
|
||||
HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "dive_computer_device", device, dive_computer.)
|
||||
HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "dive_computer_device_name", device_name, dive_computer.)
|
||||
HANDLE_PREFERENCE_INT_EXT(DiveComputer, "dive_computer_download_mode", download_mode, dive_computer.)
|
||||
HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "dive_computer_product", product, dive_computer.)
|
||||
HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "dive_computer_vendor", vendor, dive_computer.)
|
||||
|
||||
HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "dive_computer_device_name", device_name, dive_computer.);
|
||||
|
||||
HANDLE_PREFERENCE_INT_EXT(DiveComputer, "dive_computer_download_mode", download_mode, dive_computer.);
|
||||
|
||||
HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "dive_computer_product", product, dive_computer.);
|
||||
|
||||
HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "dive_computer_vendor", vendor, dive_computer.);
|
||||
// these are the previous four to make it easy to go back and forth between multiple dive computers
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_device1", device, dive_computer, 1)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_device2", device, dive_computer, 2)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_device3", device, dive_computer, 3)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_device4", device, dive_computer, 4)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_device_name1", device_name, dive_computer, 1)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_device_name2", device_name, dive_computer, 2)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_device_name3", device_name, dive_computer, 3)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_device_name4", device_name, dive_computer, 4)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_product1", product, dive_computer, 1)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_product2", product, dive_computer, 2)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_product3", product, dive_computer, 3)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_product4", product, dive_computer, 4)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_vendor1", vendor, dive_computer, 1)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_vendor2", vendor, dive_computer, 2)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_vendor3", vendor, dive_computer, 3)
|
||||
HANDLE_PREFERENCE_TXT_EXT_ALT(DiveComputer, "dive_computer_vendor4", vendor, dive_computer, 4)
|
||||
|
|
|
@ -5,13 +5,36 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
#define IMPLEMENT5GETTERS(name) \
|
||||
static QString name() { return prefs.dive_computer.name; } \
|
||||
static QString name##1() { return prefs.dive_computer##1 .name; } \
|
||||
static QString name##2() { return prefs.dive_computer##2 .name; } \
|
||||
static QString name##3() { return prefs.dive_computer##3 .name; } \
|
||||
static QString name##4() { return prefs.dive_computer##4 .name; }
|
||||
|
||||
class qPrefDiveComputer : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString device READ device WRITE set_device NOTIFY deviceChanged);
|
||||
Q_PROPERTY(QString device_name READ device_name WRITE set_device_name NOTIFY device_nameChanged);
|
||||
Q_PROPERTY(int download_mode READ download_mode WRITE set_download_mode NOTIFY download_modeChanged);
|
||||
Q_PROPERTY(QString product READ product WRITE set_product NOTIFY productChanged);
|
||||
Q_PROPERTY(QString vendor READ vendor WRITE set_vendor NOTIFY vendorChanged);
|
||||
Q_PROPERTY(QString device READ device WRITE set_device NOTIFY deviceChanged)
|
||||
Q_PROPERTY(QString device1 READ device1 WRITE set_device1 NOTIFY device1Changed)
|
||||
Q_PROPERTY(QString device2 READ device2 WRITE set_device2 NOTIFY device2Changed)
|
||||
Q_PROPERTY(QString device3 READ device3 WRITE set_device3 NOTIFY device3Changed)
|
||||
Q_PROPERTY(QString device4 READ device4 WRITE set_device4 NOTIFY device4Changed)
|
||||
Q_PROPERTY(QString device_name READ device_name WRITE set_device_name NOTIFY device_nameChanged)
|
||||
Q_PROPERTY(QString device_name1 READ device_name1 WRITE set_device_name1 NOTIFY device_name1Changed)
|
||||
Q_PROPERTY(QString device_name2 READ device_name2 WRITE set_device_name2 NOTIFY device_name2Changed)
|
||||
Q_PROPERTY(QString device_name3 READ device_name3 WRITE set_device_name3 NOTIFY device_name3Changed)
|
||||
Q_PROPERTY(QString device_name4 READ device_name4 WRITE set_device_name4 NOTIFY device_name4Changed)
|
||||
Q_PROPERTY(QString product READ product WRITE set_product NOTIFY productChanged)
|
||||
Q_PROPERTY(QString product1 READ product1 WRITE set_product1 NOTIFY product1Changed)
|
||||
Q_PROPERTY(QString product2 READ product2 WRITE set_product2 NOTIFY product2Changed)
|
||||
Q_PROPERTY(QString product3 READ product3 WRITE set_product3 NOTIFY product3Changed)
|
||||
Q_PROPERTY(QString product4 READ product4 WRITE set_product4 NOTIFY product4Changed)
|
||||
Q_PROPERTY(QString vendor READ vendor WRITE set_vendor NOTIFY vendorChanged)
|
||||
Q_PROPERTY(QString vendor1 READ vendor1 WRITE set_vendor1 NOTIFY vendor1Changed)
|
||||
Q_PROPERTY(QString vendor2 READ vendor2 WRITE set_vendor2 NOTIFY vendor2Changed)
|
||||
Q_PROPERTY(QString vendor3 READ vendor3 WRITE set_vendor3 NOTIFY vendor3Changed)
|
||||
Q_PROPERTY(QString vendor4 READ vendor4 WRITE set_vendor4 NOTIFY vendor4Changed)
|
||||
Q_PROPERTY(int download_mode READ download_mode WRITE set_download_mode NOTIFY download_modeChanged)
|
||||
|
||||
public:
|
||||
qPrefDiveComputer(QObject *parent = NULL);
|
||||
|
@ -23,33 +46,95 @@ public:
|
|||
static void sync() { loadSync(true); }
|
||||
|
||||
public:
|
||||
static QString device() { return prefs.dive_computer.device; }
|
||||
static QString device_name() { return prefs.dive_computer.device_name; }
|
||||
IMPLEMENT5GETTERS(device)
|
||||
IMPLEMENT5GETTERS(device_name)
|
||||
IMPLEMENT5GETTERS(product)
|
||||
IMPLEMENT5GETTERS(vendor)
|
||||
static int download_mode() { return prefs.dive_computer.download_mode; }
|
||||
static QString product() { return prefs.dive_computer.product; }
|
||||
static QString vendor() { return prefs.dive_computer.vendor; }
|
||||
|
||||
public slots:
|
||||
static void set_device(const QString &device);
|
||||
static void set_device1(const QString &device);
|
||||
static void set_device2(const QString &device);
|
||||
static void set_device3(const QString &device);
|
||||
static void set_device4(const QString &device);
|
||||
|
||||
static void set_device_name(const QString &device_name);
|
||||
static void set_download_mode(int mode);
|
||||
static void set_device_name1(const QString &device_name);
|
||||
static void set_device_name2(const QString &device_name);
|
||||
static void set_device_name3(const QString &device_name);
|
||||
static void set_device_name4(const QString &device_name);
|
||||
|
||||
static void set_product(const QString &product);
|
||||
static void set_product1(const QString &product);
|
||||
static void set_product2(const QString &product);
|
||||
static void set_product3(const QString &product);
|
||||
static void set_product4(const QString &product);
|
||||
|
||||
static void set_vendor(const QString &vendor);
|
||||
static void set_vendor1(const QString &vendor);
|
||||
static void set_vendor2(const QString &vendor);
|
||||
static void set_vendor3(const QString &vendor);
|
||||
static void set_vendor4(const QString &vendor);
|
||||
|
||||
static void set_download_mode(int mode);
|
||||
|
||||
signals:
|
||||
void deviceChanged(const QString &device);
|
||||
void device1Changed(const QString &device);
|
||||
void device2Changed(const QString &device);
|
||||
void device3Changed(const QString &device);
|
||||
void device4Changed(const QString &device);
|
||||
|
||||
void device_nameChanged(const QString &device_name);
|
||||
void download_modeChanged(int mode);
|
||||
void device_name1Changed(const QString &device_name);
|
||||
void device_name2Changed(const QString &device_name);
|
||||
void device_name3Changed(const QString &device_name);
|
||||
void device_name4Changed(const QString &device_name);
|
||||
|
||||
void productChanged(const QString &product);
|
||||
void product1Changed(const QString &product);
|
||||
void product2Changed(const QString &product);
|
||||
void product3Changed(const QString &product);
|
||||
void product4Changed(const QString &product);
|
||||
|
||||
void vendorChanged(const QString &vendor);
|
||||
void vendor1Changed(const QString &vendor);
|
||||
void vendor2Changed(const QString &vendor);
|
||||
void vendor3Changed(const QString &vendor);
|
||||
void vendor4Changed(const QString &vendor);
|
||||
|
||||
void download_modeChanged(int mode);
|
||||
|
||||
private:
|
||||
// functions to load/sync variable with disk
|
||||
|
||||
static void disk_device(bool doSync);
|
||||
static void disk_device1(bool doSync);
|
||||
static void disk_device2(bool doSync);
|
||||
static void disk_device3(bool doSync);
|
||||
static void disk_device4(bool doSync);
|
||||
|
||||
static void disk_device_name(bool doSync);
|
||||
static void disk_download_mode(bool doSync);
|
||||
static void disk_device_name1(bool doSync);
|
||||
static void disk_device_name2(bool doSync);
|
||||
static void disk_device_name3(bool doSync);
|
||||
static void disk_device_name4(bool doSync);
|
||||
|
||||
static void disk_product(bool doSync);
|
||||
static void disk_product1(bool doSync);
|
||||
static void disk_product2(bool doSync);
|
||||
static void disk_product3(bool doSync);
|
||||
static void disk_product4(bool doSync);
|
||||
|
||||
static void disk_vendor(bool doSync);
|
||||
static void disk_vendor1(bool doSync);
|
||||
static void disk_vendor2(bool doSync);
|
||||
static void disk_vendor3(bool doSync);
|
||||
static void disk_vendor4(bool doSync);
|
||||
|
||||
static void disk_download_mode(bool doSync);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -145,6 +145,20 @@ extern QString keyFromGroupAndName(QString group, QString name);
|
|||
current_state = QString(prefs.usestruct field); \
|
||||
} \
|
||||
}
|
||||
#define DISK_LOADSYNC_TXT_EXT_ALT(usegroup, name, field, usestruct, alt) \
|
||||
void qPref##usegroup::disk_##field##alt(bool doSync) \
|
||||
{ \
|
||||
static QString current_state; \
|
||||
if (doSync) { \
|
||||
if (current_state != QString(prefs.usestruct ## alt .field)) { \
|
||||
current_state = QString(prefs.usestruct ## alt .field); \
|
||||
qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct ##alt .field, default_prefs.usestruct ##alt .field); \
|
||||
} \
|
||||
} else { \
|
||||
prefs.usestruct ##alt .field = copy_qstring(qPrefPrivate::propValue(keyFromGroupAndName(group, name), default_prefs.usestruct ##alt .field).toString()); \
|
||||
current_state = QString(prefs.usestruct ##alt .field); \
|
||||
} \
|
||||
}
|
||||
#define DISK_LOADSYNC_TXT(usegroup, name, field) \
|
||||
DISK_LOADSYNC_TXT_EXT(usegroup, name, field, )
|
||||
|
||||
|
@ -218,6 +232,17 @@ extern QString keyFromGroupAndName(QString group, QString name);
|
|||
emit instance()->field##Changed(value); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SET_PREFERENCE_TXT_EXT_ALT(usegroup, field, usestruct, alt) \
|
||||
void qPref##usegroup::set_##field##alt(const QString &value) \
|
||||
{ \
|
||||
if (value != prefs.usestruct ##alt .field) { \
|
||||
qPrefPrivate::copy_txt(&prefs.usestruct ##alt .field, value); \
|
||||
disk_##field##alt(true); \
|
||||
emit instance()->field##alt##Changed(value); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SET_PREFERENCE_TXT(usegroup, field) \
|
||||
SET_PREFERENCE_TXT_EXT(usegroup, field, )
|
||||
|
||||
|
@ -264,6 +289,10 @@ extern QString keyFromGroupAndName(QString group, QString name);
|
|||
#define HANDLE_PREFERENCE_TXT(usegroup, name, field) \
|
||||
HANDLE_PREFERENCE_TXT_EXT(usegroup, name, field, )
|
||||
|
||||
#define HANDLE_PREFERENCE_TXT_EXT_ALT(usegroup, name, field, usestruct, alt) \
|
||||
SET_PREFERENCE_TXT_EXT_ALT(usegroup, field, usestruct, alt); \
|
||||
DISK_LOADSYNC_TXT_EXT_ALT(usegroup, name, field, usestruct, alt);
|
||||
|
||||
#define HANDLE_PROP_QPOINTF(useclass, name, field) \
|
||||
void qPref##useclass::set_##field(const QPointF& value) \
|
||||
{ \
|
||||
|
|
Loading…
Add table
Reference in a new issue