mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 19:40:18 -07:00
Simplify the saving & loading of a setting
Remove excessive usage of constexpr.
This commit is contained in:
parent
ceaf755ac6
commit
eb72b9ca7d
2 changed files with 13 additions and 25 deletions
|
@ -44,7 +44,6 @@
|
|||
#include "base/net/downloadmanager.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/settingsstorage.h"
|
||||
#include "base/settingvalue.h"
|
||||
#include "base/torrentfileguard.h"
|
||||
#include "base/unicodestrings.h"
|
||||
#include "base/utils/fs.h"
|
||||
|
@ -79,8 +78,8 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
constexpr int AddNewTorrentDialog::minPathHistoryLength;
|
||||
constexpr int AddNewTorrentDialog::maxPathHistoryLength;
|
||||
const int AddNewTorrentDialog::minPathHistoryLength;
|
||||
const int AddNewTorrentDialog::maxPathHistoryLength;
|
||||
|
||||
AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inParams, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
|
@ -186,30 +185,21 @@ void AddNewTorrentDialog::setTopLevel(bool value)
|
|||
|
||||
int AddNewTorrentDialog::savePathHistoryLength()
|
||||
{
|
||||
return savePathHistoryLengthSetting();
|
||||
const int defaultHistoryLength = 8;
|
||||
const int value = settings()->loadValue(KEY_SAVEPATHHISTORYLENGTH, defaultHistoryLength).toInt();
|
||||
return qBound(minPathHistoryLength, value, maxPathHistoryLength);
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::setSavePathHistoryLength(int value)
|
||||
{
|
||||
Q_ASSERT(value >= minPathHistoryLength);
|
||||
Q_ASSERT(value <= maxPathHistoryLength);
|
||||
const int clampedValue = qBound(minPathHistoryLength, value, maxPathHistoryLength);
|
||||
const int oldValue = savePathHistoryLength();
|
||||
if (oldValue != value) {
|
||||
savePathHistoryLengthSetting() = value;
|
||||
settings()->storeValue(KEY_SAVEPATHHISTORY,
|
||||
QStringList(settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList().mid(0, value)));
|
||||
}
|
||||
}
|
||||
if (clampedValue == oldValue)
|
||||
return;
|
||||
|
||||
CachedSettingValue<int> &AddNewTorrentDialog::savePathHistoryLengthSetting()
|
||||
{
|
||||
const int defaultHistoryLength = 8;
|
||||
static CachedSettingValue<int> setting(KEY_SAVEPATHHISTORYLENGTH.toUtf8().constData(), defaultHistoryLength,
|
||||
[](int v)
|
||||
{
|
||||
return std::max(minPathHistoryLength, std::min(maxPathHistoryLength, v));
|
||||
});
|
||||
return setting;
|
||||
settings()->storeValue(KEY_SAVEPATHHISTORYLENGTH, clampedValue);
|
||||
settings()->storeValue(KEY_SAVEPATHHISTORY
|
||||
, QStringList(settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList().mid(0, clampedValue)));
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::loadState()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue