summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-12-10 15:21:50 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-12-17 07:37:32 -0800
commitabf942f30300e6d46652c312f2b531dc3540b19a (patch)
tree786e7b00fb7dd9ea0b54c1dfc3d989d6c1d29036
parent6184f5d2761b559edf85063eca61389bb82ad343 (diff)
downloadsubsurface-abf942f30300e6d46652c312f2b531dc3540b19a.tar.gz
Cleanup: make DCDeviceData a "normal" singleton
DCDeviceData was using that weird pattern where the instance variable was set in the constructor. There is no apparent reason to do so, therefore convert to a "normal" singleton. Access that directly in QMLManager instead of saving it in a member variable first. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/downloadfromdcthread.cpp12
-rw-r--r--core/downloadfromdcthread.h1
-rw-r--r--mobile-widgets/qmlmanager.cpp47
3 files changed, 25 insertions, 35 deletions
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp
index 8e937346d..ec0705cc1 100644
--- a/core/downloadfromdcthread.cpp
+++ b/core/downloadfromdcthread.cpp
@@ -24,7 +24,6 @@ static QString str_error(const char *fmt, ...)
return str;
}
-
static void updateRememberedDCs()
{
QString current = qPrefDiveComputer::vendor() + " - " + qPrefDiveComputer::product() + " - " + qPrefDiveComputer::device();
@@ -254,7 +253,6 @@ void show_computer_list()
qDebug() << msg;
}
}
-DCDeviceData *DCDeviceData::m_instance = NULL;
DCDeviceData::DCDeviceData()
{
@@ -276,18 +274,12 @@ DCDeviceData::DCDeviceData()
#else
data.libdc_log = false;
#endif
- if (m_instance) {
- qDebug() << "already have an instance of DCDevieData";
- return;
- }
- m_instance = this;
}
DCDeviceData *DCDeviceData::instance()
{
- if (!m_instance)
- m_instance = new DCDeviceData;
- return m_instance;
+ static DCDeviceData self;
+ return &self;
}
QStringList DCDeviceData::getProductListFromVendor(const QString &vendor)
diff --git a/core/downloadfromdcthread.h b/core/downloadfromdcthread.h
index 3e2d7ddc0..1ae6a4087 100644
--- a/core/downloadfromdcthread.h
+++ b/core/downloadfromdcthread.h
@@ -51,7 +51,6 @@ public:
void setSaveDump(bool dumpMode);
void setSaveLog(bool saveLog);
private:
- static DCDeviceData *m_instance;
device_data_t data;
// Bluetooth name is managed outside of libdivecomputer
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 70ab87ea5..f2f5fe897 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -144,7 +144,6 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
m_updateSelectedDive(-1),
m_selectedDiveTimestamp(0),
alreadySaving(false),
- m_device_data(new DCDeviceData),
m_pluggedInDeviceName("")
{
LOG_STP("qmlmgr starting");
@@ -1673,117 +1672,117 @@ void QMLManager::setStatusbarColor(QColor)
QString QMLManager::DC_vendor() const
{
- return m_device_data->vendor();
+ return DCDeviceData::instance()->vendor();
}
QString QMLManager::DC_product() const
{
- return m_device_data->product();
+ return DCDeviceData::instance()->product();
}
QString QMLManager::DC_devName() const
{
- return m_device_data->devName();
+ return DCDeviceData::instance()->devName();
}
QString QMLManager::DC_devBluetoothName() const
{
- return m_device_data->devBluetoothName();
+ return DCDeviceData::instance()->devBluetoothName();
}
QString QMLManager::DC_descriptor() const
{
- return m_device_data->descriptor();
+ return DCDeviceData::instance()->descriptor();
}
bool QMLManager::DC_forceDownload() const
{
- return m_device_data->forceDownload();
+ return DCDeviceData::instance()->forceDownload();
}
bool QMLManager::DC_bluetoothMode() const
{
- return m_device_data->bluetoothMode();
+ return DCDeviceData::instance()->bluetoothMode();
}
bool QMLManager::DC_createNewTrip() const
{
- return m_device_data->createNewTrip();
+ return DCDeviceData::instance()->createNewTrip();
}
bool QMLManager::DC_saveDump() const
{
- return m_device_data->saveDump();
+ return DCDeviceData::instance()->saveDump();
}
int QMLManager::DC_deviceId() const
{
- return m_device_data->deviceId();
+ return DCDeviceData::instance()->deviceId();
}
void QMLManager::DC_setDeviceId(int deviceId)
{
- m_device_data->setDeviceId(deviceId);
+ DCDeviceData::instance()->setDeviceId(deviceId);
}
void QMLManager::DC_setVendor(const QString& vendor)
{
- m_device_data->setVendor(vendor);
+ DCDeviceData::instance()->setVendor(vendor);
}
void QMLManager::DC_setProduct(const QString& product)
{
- m_device_data->setProduct(product);
+ DCDeviceData::instance()->setProduct(product);
}
void QMLManager::DC_setDevName(const QString& devName)
{
- m_device_data->setDevName(devName);
+ DCDeviceData::instance()->setDevName(devName);
}
void QMLManager::DC_setDevBluetoothName(const QString& devBluetoothName)
{
- m_device_data->setDevBluetoothName(devBluetoothName);
+ DCDeviceData::instance()->setDevBluetoothName(devBluetoothName);
}
void QMLManager::DC_setBluetoothMode(bool mode)
{
- m_device_data->setBluetoothMode(mode);
+ DCDeviceData::instance()->setBluetoothMode(mode);
}
void QMLManager::DC_setForceDownload(bool force)
{
- m_device_data->setForceDownload(force);
+ DCDeviceData::instance()->setForceDownload(force);
}
void QMLManager::DC_setCreateNewTrip(bool create)
{
- m_device_data->setCreateNewTrip(create);
+ DCDeviceData::instance()->setCreateNewTrip(create);
}
void QMLManager::DC_setSaveDump(bool dumpMode)
{
- m_device_data->setSaveDump(dumpMode);
+ DCDeviceData::instance()->setSaveDump(dumpMode);
}
QStringList QMLManager::getProductListFromVendor(const QString &vendor)
{
- return m_device_data->getProductListFromVendor(vendor);
+ return DCDeviceData::instance()->getProductListFromVendor(vendor);
}
int QMLManager::getMatchingAddress(const QString &vendor, const QString &product)
{
- return m_device_data->getMatchingAddress(vendor, product);
+ return DCDeviceData::instance()->getMatchingAddress(vendor, product);
}
int QMLManager::getDetectedVendorIndex()
{
- return m_device_data->getDetectedVendorIndex();
+ return DCDeviceData::instance()->getDetectedVendorIndex();
}
int QMLManager::getDetectedProductIndex(const QString &currentVendorText)
{
- return m_device_data->getDetectedProductIndex(currentVendorText);
+ return DCDeviceData::instance()->getDetectedProductIndex(currentVendorText);
}
int QMLManager::getConnectionIndex(const QString &deviceSubstr)