Replace QWinRegistryKey::dwordValue with QWinRegistryKey::value<T>
QWinRegistryKey::value<T> returns an optional<T> which can make code a bit more readable than the std::pair<DWORD, bool> return value from QWinRegistryKey::dwordValue. This implements part of the "TODO: Remove once all usages are migrated to new interface." comment in QWinRegistry class because it allows us to remove the QWinRegistryKey::dwordValue function. Change-Id: If568de4e31778e91ce7aadadb4aac90e41222826 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 7a63a25ef71fbbe7b3eaa6ecb9a26c3e497e582a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
5e72d97436
commit
8a23001ca6
@ -125,10 +125,4 @@ QString QWinRegistryKey::stringValue(QStringView subKey) const
|
||||
return value<QString>(subKey).value_or(QString());
|
||||
}
|
||||
|
||||
std::pair<DWORD, bool> QWinRegistryKey::dwordValue(QStringView subKey) const
|
||||
{
|
||||
const std::optional<DWORD> val = value<DWORD>(subKey);
|
||||
return {val.value_or(0), val.has_value()};
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -58,7 +58,6 @@ public:
|
||||
|
||||
// ### TODO: Remove once all usages are migrated to new interface.
|
||||
QString stringValue(QStringView subKey) const;
|
||||
std::pair<DWORD, bool> dwordValue(QStringView subKey) const;
|
||||
|
||||
private:
|
||||
HKEY m_key = nullptr;
|
||||
|
@ -538,9 +538,9 @@ void QWinTimeZonePrivate::init(const QByteArray &ianaId)
|
||||
QWinRegistryKey dynamicKey(HKEY_LOCAL_MACHINE, dynamicKeyPath);
|
||||
if (dynamicKey.isValid()) {
|
||||
// Find out the start and end years stored, then iterate over them
|
||||
const auto startYear = dynamicKey.dwordValue(L"FirstEntry");
|
||||
const auto endYear = dynamicKey.dwordValue(L"LastEntry");
|
||||
for (int year = int(startYear.first); year <= int(endYear.first); ++year) {
|
||||
const int startYear = dynamicKey.value<int>(L"FirstEntry").value_or(0);
|
||||
const int endYear = dynamicKey.value<int>(L"LastEntry").value_or(0);
|
||||
for (int year = startYear; year <= endYear; ++year) {
|
||||
bool ruleOk;
|
||||
QWinTransitionRule rule =
|
||||
readRegistryRule(dynamicKey,
|
||||
|
@ -1446,11 +1446,9 @@ void QWindowsContext::setAsyncExpose(bool value)
|
||||
|
||||
DWORD QWindowsContext::readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue)
|
||||
{
|
||||
const auto value =
|
||||
QWinRegistryKey(HKEY_CURRENT_USER,
|
||||
LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced)")
|
||||
.dwordValue(subKey);
|
||||
return value.second ? value.first : defaultValue;
|
||||
const auto advancedSettings = QWinRegistryKey(
|
||||
HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced)");
|
||||
return advancedSettings.value<DWORD>(subKey).value_or(defaultValue);
|
||||
}
|
||||
|
||||
static inline bool isEmptyRect(const RECT &rect)
|
||||
|
@ -668,16 +668,16 @@ void QWindowsCursor::setPos(const QPoint &pos)
|
||||
*/
|
||||
QSize QWindowsCursor::size() const
|
||||
{
|
||||
const QPair<DWORD,bool> cursorSizeSetting =
|
||||
const auto cursorSizeSetting =
|
||||
QWinRegistryKey(HKEY_CURRENT_USER, LR"(Control Panel\Cursors)")
|
||||
.dwordValue(L"CursorBaseSize");
|
||||
.value<DWORD>(L"CursorBaseSize");
|
||||
const int baseSize = screenCursorSize(m_screen).width() / 2;
|
||||
if (!cursorSizeSetting.second)
|
||||
if (!cursorSizeSetting)
|
||||
return QSize(baseSize / 2, baseSize / 2);
|
||||
|
||||
// The registry values are dpi-independent, so we need to scale the result.
|
||||
int cursorSizeValue = cursorSizeSetting.first * m_screen->logicalDpi().first
|
||||
/ m_screen->logicalBaseDpi().first;
|
||||
int cursorSizeValue = *cursorSizeSetting * m_screen->logicalDpi().first
|
||||
/ m_screen->logicalBaseDpi().first;
|
||||
|
||||
// map from registry value 32-256 to 0-14, and from there to pixels
|
||||
cursorSizeValue = (cursorSizeValue - 2 * baseSize) / baseSize;
|
||||
|
@ -1167,9 +1167,11 @@ Qt::ColorScheme QWindowsTheme::queryColorScheme()
|
||||
if (queryHighContrast())
|
||||
return Qt::ColorScheme::Unknown;
|
||||
|
||||
const auto setting = QWinRegistryKey(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)")
|
||||
.dwordValue(L"AppsUseLightTheme");
|
||||
return setting.second && setting.first == 0 ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light;
|
||||
QWinRegistryKey personalizeKey{
|
||||
HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)"
|
||||
};
|
||||
const bool useDarkTheme = personalizeKey.value<DWORD>(L"AppsUseLightTheme") == 0;
|
||||
return useDarkTheme ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light;
|
||||
}
|
||||
|
||||
bool QWindowsTheme::queryHighContrast()
|
||||
|
@ -1205,8 +1205,8 @@ void tst_QFileInfo::fileTimes()
|
||||
const auto disabledAccessTimes =
|
||||
QWinRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
LR"(SYSTEM\CurrentControlSet\Control\FileSystem)")
|
||||
.dwordValue(L"NtfsDisableLastAccessUpdate");
|
||||
if (disabledAccessTimes.second && disabledAccessTimes.first != 0)
|
||||
.value<DWORD>(L"NtfsDisableLastAccessUpdate");
|
||||
if (disabledAccessTimes.value_or(0) != 0)
|
||||
noAccessTime = true;
|
||||
#endif
|
||||
|
||||
|
@ -225,15 +225,14 @@ void tst_qwinregistrykey::qwinregistrykey()
|
||||
QVERIFY(registry.stringValue(TEST_NOT_EXIST.first).isEmpty());
|
||||
|
||||
{
|
||||
const auto value = registry.dwordValue(TEST_DWORD.first);
|
||||
QVERIFY(value.second);
|
||||
QCOMPARE(value.first, TEST_DWORD.second);
|
||||
const auto value = registry.value<DWORD>(TEST_DWORD.first);
|
||||
QVERIFY(value);
|
||||
QCOMPARE(*value, TEST_DWORD.second);
|
||||
}
|
||||
|
||||
{
|
||||
const auto value = registry.dwordValue(TEST_NOT_EXIST.first);
|
||||
QVERIFY(!value.second);
|
||||
QCOMPARE(value.first, DWORD(0));
|
||||
const auto value = registry.value<DWORD>(TEST_NOT_EXIST.first);
|
||||
QVERIFY(!value);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user