Modernize the "settings" feature

Change-Id: I9b8a61ecb1413b513ae5c9e77d3ee1b3e8b6562c
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
bb10
Liang Qi 2018-11-12 09:40:47 +01:00
parent cd201b2c2c
commit 527406cbd9
23 changed files with 83 additions and 59 deletions

View File

@ -126,11 +126,13 @@
#define QT_FEATURE_commandlineparser -1
#define QT_NO_COMPRESS
#define QT_JSON_READONLY
#define QT_FEATURE_settings 1
#define QT_NO_STANDARDPATHS
#define QT_FEATURE_textcodec -1
#else
#define QT_FEATURE_codecs -1
#define QT_FEATURE_commandlineparser 1
#define QT_FEATURE_settings -1
#define QT_FEATURE_textcodec 1
#endif

View File

@ -41,7 +41,9 @@
#include "qdir.h"
#include "qstringlist.h"
#include "qfile.h"
#if QT_CONFIG(settings)
#include "qsettings.h"
#endif
#include "qlibraryinfo.h"
#include "qscopedpointer.h"
@ -67,7 +69,7 @@ QT_BEGIN_NAMESPACE
extern void qDumpCPUFeatures(); // in qsimd.cpp
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
struct QLibrarySettings
{
@ -204,7 +206,7 @@ QSettings *QLibraryInfoPrivate::findConfiguration()
return 0; //no luck
}
#endif // QT_NO_SETTINGS
#endif // settings
/*!
\class QLibraryInfo
@ -464,7 +466,7 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
#endif // QT_BUILD_QMAKE, started inside location !
QString ret;
bool fromConf = false;
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
#ifdef QT_BUILD_QMAKE
// Logic for choosing the right data source: if EffectivePaths are requested
// and qt.conf with that section is present, use it, otherwise fall back to
@ -547,7 +549,7 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
ret = QDir::fromNativeSeparators(ret);
}
}
#endif // QT_NO_SETTINGS
#endif // settings
#ifndef QT_BUILD_QMAKE_BOOTSTRAP
if (!fromConf) {
@ -646,7 +648,7 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
QStringList QLibraryInfo::platformPluginArguments(const QString &platformName)
{
#if !defined(QT_BUILD_QMAKE) && !defined(QT_NO_SETTINGS)
#if !defined(QT_BUILD_QMAKE) && QT_CONFIG(settings)
QScopedPointer<const QSettings> settings(QLibraryInfoPrivate::findConfiguration());
if (!settings.isNull()) {
const QString key = QLatin1String(platformsSection)
@ -657,7 +659,7 @@ QStringList QLibraryInfo::platformPluginArguments(const QString &platformName)
}
#else
Q_UNUSED(platformName);
#endif // !QT_BUILD_QMAKE && !QT_NO_SETTINGS
#endif // !QT_BUILD_QMAKE && settings
return QStringList();
}

View File

@ -34,8 +34,6 @@ HEADERS += \
io/qurlquery.h \
io/qurltlds_p.h \
io/qtldurl_p.h \
io/qsettings.h \
io/qsettings_p.h \
io/qfsfileengine_p.h \
io/qfsfileengine_iterator_p.h \
io/qfilesystementry_p.h \
@ -73,7 +71,6 @@ SOURCES += \
io/qurlidna.cpp \
io/qurlquery.cpp \
io/qurlrecode.cpp \
io/qsettings.cpp \
io/qfsfileengine.cpp \
io/qfsfileengine_iterator.cpp \
io/qfilesystementry.cpp \
@ -121,6 +118,24 @@ qtConfig(processenvironment) {
SOURCES += io/qprocess_unix.cpp
}
qtConfig(settings) {
SOURCES += \
io/qsettings.cpp
HEADERS += \
io/qsettings.h \
io/qsettings_p.h
win32 {
!winrt {
SOURCES += io/qsettings_win.cpp
} else {
SOURCES += io/qsettings_winrt.cpp
}
} else: darwin:!nacl {
SOURCES += io/qsettings_mac.cpp
}
}
win32 {
SOURCES += io/qfsfileengine_win.cpp
SOURCES += io/qlockfile_win.cpp
@ -136,7 +151,6 @@ win32 {
io/qwindowspipewriter_p.h
SOURCES += \
io/qsettings_win.cpp \
io/qstandardpaths_win.cpp \
io/qstorageinfo_win.cpp \
io/qwindowspipereader.cpp \
@ -146,7 +160,6 @@ win32 {
} else {
SOURCES += \
io/qstandardpaths_winrt.cpp \
io/qsettings_winrt.cpp \
io/qstorageinfo_stub.cpp
}
} else:unix {
@ -162,9 +175,6 @@ win32 {
../3rdparty/forkfd/forkfd.h
INCLUDEPATH += ../3rdparty/forkfd
}
!nacl:mac: {
SOURCES += io/qsettings_mac.cpp
}
mac {
SOURCES += io/qstorageinfo_mac.cpp
qtConfig(processenvironment): \

View File

@ -41,8 +41,6 @@
#include "qplatformdefs.h"
#include "qsettings.h"
#ifndef QT_NO_SETTINGS
#include "qsettings_p.h"
#include "qcache.h"
#include "qfile.h"
@ -3573,5 +3571,3 @@ QT_END_NAMESPACE
#ifndef QT_BOOTSTRAPPED
#include "moc_qsettings.cpp"
#endif
#endif // QT_NO_SETTINGS

View File

@ -45,10 +45,7 @@
#include <QtCore/qstring.h>
#include <QtCore/qscopedpointer.h>
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
#ifndef QT_NO_SETTINGS
QT_REQUIRE_CONFIG(settings);
#include <ctype.h>
@ -208,6 +205,4 @@ private:
QT_END_NAMESPACE
#endif // QT_NO_SETTINGS
#endif // QSETTINGS_H

View File

@ -38,7 +38,6 @@
****************************************************************************/
#include "qsettings.h"
#ifndef QT_NO_SETTINGS
#include "qsettings_p.h"
#include "qdatetime.h"
@ -664,4 +663,3 @@ bool QConfFileSettingsPrivate::writePlistFile(QIODevice &file, const ParsedSetti
}
QT_END_NAMESPACE
#endif //QT_NO_SETTINGS

View File

@ -39,8 +39,6 @@
#include "qsettings.h"
#ifndef QT_NO_SETTINGS
#include "qsettings_p.h"
#include "qvector.h"
#include "qmap.h"
@ -859,4 +857,3 @@ QSettingsPrivate *QSettingsPrivate::create(const QString &fileName, QSettings::F
}
QT_END_NAMESPACE
#endif // QT_NO_SETTINGS

View File

@ -39,8 +39,6 @@
#include "qsettings.h"
#ifndef QT_NO_SETTINGS
#include "qsettings_p.h"
#include "qvector.h"
#include "qmap.h"
@ -690,4 +688,3 @@ QSettingsPrivate *QSettingsPrivate::create(const QString &fileName, QSettings::F
}
QT_END_NAMESPACE
#endif // QT_NO_SETTINGS

View File

@ -53,7 +53,9 @@
#include "QtCore/qcoreapplication.h"
#include "QtCore/qtranslator.h"
#if QT_CONFIG(settings)
#include "QtCore/qsettings.h"
#endif
#ifndef QT_NO_QOBJECT
#include "private/qobject_p.h"
#endif

View File

@ -50,7 +50,9 @@
#include <QtCore/qmath.h>
#include <QtCore/QList>
#include <QtCore/QDir>
#if QT_CONFIG(settings)
#include <QtCore/QSettings>
#endif
#include <QtGui/QPainter>
#include <private/qhexstring_p.h>
@ -338,7 +340,7 @@ QIconTheme::QIconTheme(const QString &themeName)
m_valid = true;
}
}
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
if (themeIndex.exists()) {
const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
const QStringList keys = indexReader.allKeys();
@ -397,7 +399,7 @@ QIconTheme::QIconTheme(const QString &themeName)
if (!m_parents.contains(QLatin1String("hicolor")))
m_parents.append(QLatin1String("hicolor"));
}
#endif //QT_NO_SETTINGS
#endif // settings
}
QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,

View File

@ -42,7 +42,9 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QVariant>
#include <QtCore/QSharedData>
#if QT_CONFIG(settings)
#include <QtCore/QSettings>
#endif
#include <QtCore/QUrl>
#include <QtGui/QColor>
@ -283,7 +285,7 @@ QColorDialogStaticData::QColorDialogStaticData() : customSet(false)
void QColorDialogStaticData::readSettings()
{
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
const QSettings settings(QSettings::UserScope, QStringLiteral("QtProject"));
for (int i = 0; i < int(CustomColorCount); ++i) {
const QVariant v = settings.value(QLatin1String("Qt/customColors/") + QString::number(i));
@ -295,7 +297,7 @@ void QColorDialogStaticData::readSettings()
void QColorDialogStaticData::writeSettings() const
{
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
if (customSet) {
const_cast<QColorDialogStaticData*>(this)->customSet = false;
QSettings settings(QSettings::UserScope, QStringLiteral("QtProject"));

View File

@ -48,14 +48,14 @@
QT_BEGIN_NAMESPACE
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
(QPlatformInputContextFactoryInterface_iid, QLatin1String("/platforminputcontexts"), Qt::CaseInsensitive))
#endif
QStringList QPlatformInputContextFactory::keys()
{
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
return loader()->keyMap().values();
#else
return QStringList();
@ -70,7 +70,7 @@ QString QPlatformInputContextFactory::requested()
QPlatformInputContext *QPlatformInputContextFactory::create(const QString& key)
{
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
if (!key.isEmpty()) {
QStringList paramList = key.split(QLatin1Char(':'));
const QString platform = paramList.takeFirst().toLower();

View File

@ -50,7 +50,9 @@
#include "qcoretextfontdatabase_p.h"
#include "qfontengine_coretext_p.h"
#if QT_CONFIG(settings)
#include <QtCore/QSettings>
#endif
#include <QtCore/QtEndian>
#ifndef QT_NO_FREETYPE
#include <QtFontDatabaseSupport/private/qfontengine_ft_p.h>
@ -116,21 +118,25 @@ QCoreTextFontDatabase::QCoreTextFontDatabase()
: m_hasPopulatedAliases(false)
{
#ifdef Q_OS_MACX
QSettings appleSettings(QLatin1String("apple.com"));
QVariant appleValue = appleSettings.value(QLatin1String("AppleAntiAliasingThreshold"));
if (appleValue.isValid())
QCoreTextFontEngine::antialiasingThreshold = appleValue.toInt();
/*
font_smoothing = 0 means no smoothing, while 1-3 means subpixel
antialiasing with different hinting styles (but we don't care about the
exact value, only if subpixel rendering is available or not)
*/
int font_smoothing = 0;
#if QT_CONFIG(settings)
QSettings appleSettings(QLatin1String("apple.com"));
QVariant appleValue = appleSettings.value(QLatin1String("AppleAntiAliasingThreshold"));
if (appleValue.isValid())
QCoreTextFontEngine::antialiasingThreshold = appleValue.toInt();
appleValue = appleSettings.value(QLatin1String("AppleFontSmoothing"));
if (appleValue.isValid()) {
font_smoothing = appleValue.toInt();
} else {
} else
#endif // settings
{
// non-Apple displays do not provide enough information about subpixel rendering so
// draw text with cocoa and compare pixel colors to see if subpixel rendering is enabled
int w = 10;

View File

@ -41,7 +41,9 @@
#include <qpa/qplatformfontdatabase.h>
#include <QtCore/qendian.h>
#if QT_CONFIG(settings)
#include <QtCore/qsettings.h>
#endif
#include <private/qimage_p.h>

View File

@ -45,7 +45,9 @@
#if QT_CONFIG(process)
# include <QtCore/QProcess>
#endif
#if QT_CONFIG(settings)
#include <QtCore/QSettings>
#endif
#include <QtCore/QStandardPaths>
#include <QtCore/QUrl>
@ -93,7 +95,7 @@ static inline QByteArray detectDesktopEnvironment()
// This can be a path in /usr/share/xsessions
int slash = desktopSession.lastIndexOf('/');
if (slash != -1) {
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
QSettings desktopFile(QFile::decodeName(desktopSession + ".desktop"), QSettings::IniFormat);
desktopFile.beginGroup(QStringLiteral("Desktop Entry"));
QByteArray desktopName = desktopFile.value(QStringLiteral("DesktopNames")).toByteArray();

View File

@ -53,7 +53,9 @@
#include <QtCore/QMimeDatabase>
#endif
#include <QtCore/QLoggingCategory>
#if QT_CONFIG(settings)
#include <QtCore/QSettings>
#endif
#include <QtCore/QVariant>
#include <QtCore/QStandardPaths>
#include <QtCore/QStringList>
@ -261,7 +263,7 @@ static QIcon xdgFileIcon(const QFileInfo &fileInfo)
}
#endif
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
class QKdeThemePrivate : public QPlatformThemePrivate
{
public:
@ -688,7 +690,7 @@ QPlatformSystemTrayIcon *QKdeTheme::createPlatformSystemTrayIcon() const
}
#endif
#endif // QT_NO_SETTINGS
#endif // settings
/*!
\class QGnomeTheme
@ -834,7 +836,7 @@ QPlatformTheme *QGenericUnixTheme::createUnixTheme(const QString &name)
{
if (name == QLatin1String(QGenericUnixTheme::name))
return new QGenericUnixTheme;
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
if (name == QLatin1String(QKdeTheme::name))
if (QPlatformTheme *kdeTheme = QKdeTheme::createKdeTheme())
return kdeTheme;
@ -859,7 +861,7 @@ QStringList QGenericUnixTheme::themeNames()
const QList<QByteArray> desktopNames = desktopEnvironment.split(':');
for (const QByteArray &desktopName : desktopNames) {
if (desktopEnvironment == "KDE") {
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
result.push_back(QLatin1String(QKdeTheme::name));
#endif
} else if (gtkBasedEnvironments.contains(desktopName)) {

View File

@ -96,7 +96,7 @@ public:
static const char *name;
};
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
class QKdeThemePrivate;
class QKdeTheme : public QPlatformTheme
@ -123,7 +123,7 @@ public:
static const char *name;
};
#endif // QT_NO_SETTINGS
#endif // settings
class QGnomeThemePrivate;

View File

@ -57,7 +57,9 @@
#include "qpainter.h"
#include "qpixmap.h"
#include "qpushbutton.h"
#if QT_CONFIG(settings)
#include "qsettings.h"
#endif
#include "qsharedpointer.h"
#include "qstyle.h"
#include "qstyleoption.h"

View File

@ -57,7 +57,9 @@
#include <qmessagebox.h>
#endif
#include <stdlib.h>
#if QT_CONFIG(settings)
#include <qsettings.h>
#endif
#include <qdebug.h>
#if QT_CONFIG(mimetype)
#include <qmimedatabase.h>
@ -383,7 +385,7 @@ QFileDialog::QFileDialog(const QFileDialogArgs &args)
*/
QFileDialog::~QFileDialog()
{
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
Q_D(QFileDialog);
d->saveSettings();
#endif
@ -2723,7 +2725,7 @@ void QFileDialog::accept()
}
}
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
void QFileDialogPrivate::saveSettings()
{
Q_Q(QFileDialog);
@ -2781,7 +2783,7 @@ bool QFileDialogPrivate::restoreFromSettings()
return restoreWidgetState(history, settings.value(QLatin1String("sidebarWidth"), -1).toInt());
}
#endif // QT_NO_SETTINGS
#endif // settings
bool QFileDialogPrivate::restoreWidgetState(QStringList &history, int splitterPosition)
{
@ -2854,7 +2856,7 @@ void QFileDialogPrivate::init(const QUrl &directory, const QString &nameFilter,
else
q->selectUrl(directory);
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
// Try to restore from the FileDialog settings group; if it fails, fall back
// to the pre-5.5 QByteArray serialized settings.
if (!restoreFromSettings()) {
@ -3019,7 +3021,7 @@ void QFileDialogPrivate::createWidgets()
createToolButtons();
createMenuActions();
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
// Try to restore from the FileDialog settings group; if it fails, fall back
// to the pre-5.5 QByteArray serialized settings.
if (!restoreFromSettings()) {

View File

@ -187,7 +187,7 @@ public:
#endif
}
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
void saveSettings();
bool restoreFromSettings();
#endif

View File

@ -113,7 +113,7 @@ public:
bool tryCloseAllWindows() override;
#if 0 // Used to be included in Qt4 for Q_WS_X11
#ifndef QT_NO_SETTINGS
#if QT_CONFIG(settings)
static bool x11_apply_settings();
#endif
static void reset_instance_pointer();

View File

@ -102,7 +102,9 @@
#endif
#include <qfileinfo.h>
#include <qdir.h>
#if QT_CONFIG(settings)
#include <qsettings.h>
#endif
#include <qvariant.h>
#include <qpixmapcache.h>
#if QT_CONFIG(animation)

View File

@ -65,6 +65,9 @@ win32:!qtConfig(private_tests): SUBDIRS -= \
qprocess \
qprocess-noapplication
!qtConfig(settings): SUBDIRS -= \
qsettings
winrt: SUBDIRS -= \
qstorageinfo