Browse Source

Clean up code

Add const.
Move template implementation to .cpp file.
adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
114c6d36d1
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 19
      src/base/net/geoipdatabase.cpp
  2. 19
      src/base/net/geoipdatabase.h
  3. 6
      src/gui/advancedsettings.cpp
  4. 5
      src/gui/advancedsettings.h

19
src/base/net/geoipdatabase.cpp

@ -516,3 +516,22 @@ QVariant GeoIPDatabase::readArrayValue(quint32 &offset, const quint32 count) con @@ -516,3 +516,22 @@ QVariant GeoIPDatabase::readArrayValue(quint32 &offset, const quint32 count) con
return array;
}
template <typename T>
QVariant GeoIPDatabase::readPlainValue(quint32 &offset, const quint8 len) const
{
T value = 0;
const uchar *const data = m_data + offset;
const quint32 availSize = m_size - offset;
if ((len > 0) && (len <= sizeof(T) && (availSize >= len)))
{
// copy input data to last 'len' bytes of 'value'
uchar *dst = reinterpret_cast<uchar *>(&value) + (sizeof(T) - len);
memcpy(dst, data, len);
fromBigEndian(reinterpret_cast<uchar *>(&value), sizeof(T));
offset += len;
}
return QVariant::fromValue(value);
}

19
src/base/net/geoipdatabase.h

@ -70,24 +70,7 @@ private: @@ -70,24 +70,7 @@ private:
QVariant readMapValue(quint32 &offset, quint32 count) const;
QVariant readArrayValue(quint32 &offset, quint32 count) const;
template<typename T>
QVariant readPlainValue(quint32 &offset, quint8 len) const
{
T value = 0;
const uchar *const data = m_data + offset;
const quint32 availSize = m_size - offset;
if ((len > 0) && (len <= sizeof(T) && (availSize >= len)))
{
// copy input data to last 'len' bytes of 'value'
uchar *dst = reinterpret_cast<uchar *>(&value) + (sizeof(T) - len);
memcpy(dst, data, len);
fromBigEndian(reinterpret_cast<uchar *>(&value), sizeof(T));
offset += len;
}
return QVariant::fromValue(value);
}
template <typename T> QVariant readPlainValue(quint32 &offset, quint8 len) const;
// Metadata
quint16 m_ipVersion;

6
src/gui/advancedsettings.cpp

@ -156,7 +156,7 @@ AdvancedSettings::AdvancedSettings(QWidget *parent) @@ -156,7 +156,7 @@ AdvancedSettings::AdvancedSettings(QWidget *parent)
{
// column
setColumnCount(COL_COUNT);
QStringList header = {tr("Setting"), tr("Value", "Value set for this setting")};
const QStringList header = {tr("Setting"), tr("Value", "Value set for this setting")};
setHorizontalHeaderLabels(header);
// row
setRowCount(ROW_COUNT);
@ -171,7 +171,7 @@ AdvancedSettings::AdvancedSettings(QWidget *parent) @@ -171,7 +171,7 @@ AdvancedSettings::AdvancedSettings(QWidget *parent)
horizontalHeader()->setStretchLastSection(true);
}
void AdvancedSettings::saveAdvancedSettings()
void AdvancedSettings::saveAdvancedSettings() const
{
Preferences *const pref = Preferences::instance();
BitTorrent::Session *const session = BitTorrent::Session::instance();
@ -314,7 +314,7 @@ void AdvancedSettings::saveAdvancedSettings() @@ -314,7 +314,7 @@ void AdvancedSettings::saveAdvancedSettings()
}
#ifndef QBT_USES_LIBTORRENT2
void AdvancedSettings::updateCacheSpinSuffix(int value)
void AdvancedSettings::updateCacheSpinSuffix(const int value)
{
if (value == 0)
m_spinBoxCache.setSuffix(tr(" (disabled)"));

5
src/gui/advancedsettings.h

@ -34,15 +34,16 @@ @@ -34,15 +34,16 @@
#include <QSpinBox>
#include <QTableWidget>
class AdvancedSettings : public QTableWidget
class AdvancedSettings final : public QTableWidget
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(AdvancedSettings)
public:
AdvancedSettings(QWidget *parent);
public slots:
void saveAdvancedSettings();
void saveAdvancedSettings() const;
signals:
void settingsChanged();

Loading…
Cancel
Save