Skip to content

Commit

Permalink
Upgrade settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Sep 3, 2024
1 parent 98c5c49 commit f0085c6
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/app/options/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,12 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
connect( mRemoveUrlPushButton, &QAbstractButton::clicked, this, &QgsOptions::removeNoProxyUrl );

// cache settings
mCacheDirectory->setText( mSettings->value( QStringLiteral( "cache/directory" ) ).toString() );
mCacheDirectory->setText( QgsSettingsRegistryCore::settingsNetworkCacheDirectory->value() );
mCacheDirectory->setPlaceholderText( QStandardPaths::writableLocation( QStandardPaths::CacheLocation ) );
mCacheSize->setMinimum( 0 );
mCacheSize->setMaximum( std::numeric_limits<int>::max() );
mCacheSize->setSingleStep( 50 );
qint64 cacheSize = mSettings->value( QStringLiteral( "cache/size_bytes" ), 0 ).toLongLong();
qint64 cacheSize = QgsSettingsRegistryCore::settingsNetworkCacheSize->value();
mCacheSize->setValue( static_cast<int>( cacheSize / 1024 / 1024 ) );
mCacheSize->setClearValue( 0 );
connect( mBrowseCacheDirectory, &QAbstractButton::clicked, this, &QgsOptions::browseCacheDirectory );
Expand Down Expand Up @@ -1579,11 +1579,11 @@ void QgsOptions::saveOptions()
mSettings->setValue( QStringLiteral( "proxy/proxyType" ), mProxyTypeComboBox->currentText() );

if ( !mCacheDirectory->text().isEmpty() )
mSettings->setValue( QStringLiteral( "cache/directory" ), mCacheDirectory->text() );
QgsSettingsRegistryCore::settingsNetworkCacheDirectory->setValue( mCacheDirectory->text() );
else
mSettings->remove( QStringLiteral( "cache/directory" ) );
QgsSettingsRegistryCore::settingsNetworkCacheDirectory->remove();

mSettings->setValue( QStringLiteral( "cache/size_bytes" ), QVariant::fromValue( mCacheSize->value() * 1024LL * 1024LL ) );
QgsSettingsRegistryCore::settingsNetworkCacheSize->setValue( mCacheSize->value() * 1024LL * 1024LL );

//url with no proxy at all
QStringList noProxyUrls;
Expand Down Expand Up @@ -2260,7 +2260,7 @@ void QgsOptions::clearCache()
QgsNetworkAccessManager::instance()->cache()->clear();

// Clear WFS XSD cache used by OGR GMLAS driver
QString cacheDirectory = mSettings->value( QStringLiteral( "cache/directory" ) ).toString();
QString cacheDirectory = QgsSettingsRegistryCore::settingsNetworkCacheDirectory->value();
if ( cacheDirectory.isEmpty() )
cacheDirectory = QStandardPaths::writableLocation( QStandardPaths::CacheLocation );
if ( !cacheDirectory.endsWith( QDir::separator() ) )
Expand Down
5 changes: 3 additions & 2 deletions src/core/network/qgsnetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "qgsapplication.h"
#include "qgsmessagelog.h"
#include "qgssettings.h"
#include "qgssettingsregistrycore.h"
#include "qgslogger.h"
#include "qgis.h"
#include "qgsnetworkdiskcache.h"
Expand Down Expand Up @@ -749,11 +750,11 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache( Qt::ConnectionType conn
if ( !newcache )
newcache = new QgsNetworkDiskCache( this );

QString cacheDirectory = settings.value( QStringLiteral( "cache/directory" ) ).toString();
QString cacheDirectory = QgsSettingsRegistryCore::settingsNetworkCacheDirectory->value();
if ( cacheDirectory.isEmpty() )
cacheDirectory = QStandardPaths::writableLocation( QStandardPaths::CacheLocation );
newcache->setCacheDirectory( cacheDirectory );
qint64 cacheSize = settings.value( QStringLiteral( "cache/size_bytes" ), 0 ).toLongLong();
qint64 cacheSize = QgsSettingsRegistryCore::settingsNetworkCacheSize->value();
newcache->setMaximumCacheSize( cacheSize );

QgsDebugMsgLevel( QStringLiteral( "cacheDirectory: %1" ).arg( newcache->cacheDirectory() ), 4 );
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgstiledownloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "qgsnetworkaccessmanager.h"
#include "qgsrangerequestcache.h"
#include "qgssettings.h"
#include "qgssettingsregistrycore.h"
#include "qgssettingsentryimpl.h"

#include <QElapsedTimer>
#include <QNetworkReply>
Expand Down Expand Up @@ -190,7 +192,7 @@ QgsTileDownloadManager::QgsTileDownloadManager()
mRangesCache.reset( new QgsRangeRequestCache );

const QgsSettings settings;
QString cacheDirectory = settings.value( QStringLiteral( "cache/directory" ) ).toString();
QString cacheDirectory = QgsSettingsRegistryCore::settingsNetworkCacheDirectory->value();
if ( cacheDirectory.isEmpty() )
cacheDirectory = QStandardPaths::writableLocation( QStandardPaths::CacheLocation );
if ( !cacheDirectory.endsWith( QDir::separator() ) )
Expand All @@ -199,7 +201,7 @@ QgsTileDownloadManager::QgsTileDownloadManager()
}
cacheDirectory += QLatin1String( "http-ranges" );
mRangesCache->setCacheDirectory( cacheDirectory );
qint64 cacheSize = settings.value( QStringLiteral( "cache/size_bytes" ), 0 ).toLongLong();
qint64 cacheSize = QgsSettingsRegistryCore::settingsNetworkCacheSize->value();
mRangesCache->setCacheSize( cacheSize );
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/settings/qgssettingsregistrycore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ const QgsSettingsEntryInteger *QgsSettingsRegistryCore::settingsLayerParallelLoa

const QgsSettingsEntryBool *QgsSettingsRegistryCore::settingsLayerParallelLoading = new QgsSettingsEntryBool( QStringLiteral( "provider-parallel-loading" ), QgsSettingsTree::sTreeCore, true, QStringLiteral( "Load layers in parallel (only available for some providers (GDAL and PostgreSQL)" ), Qgis::SettingsOption() );

const QgsSettingsEntryString *QgsSettingsRegistryCore::settingsNetworkCacheDirectory = new QgsSettingsEntryString( QStringLiteral( "directory" ), QgsSettingsTree::sTreeNetworkCache, QString(), QStringLiteral( "Network disk cache directory" ) );

const QgsSettingsEntryInteger64 *QgsSettingsRegistryCore::settingsNetworkCacheSize = new QgsSettingsEntryInteger64( QStringLiteral( "size-bytes" ), QgsSettingsTree::sTreeNetworkCache, 0, QStringLiteral( "Network disk cache size in bytes (0 = automatic size)" ) );

QgsSettingsRegistryCore::QgsSettingsRegistryCore()
: QgsSettingsRegistry()
{
Expand Down
7 changes: 7 additions & 0 deletions src/core/settings/qgssettingsregistrycore.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class QgsSettingsEntryBool;
class QgsSettingsEntryColor;
class QgsSettingsEntryDouble;
class QgsSettingsEntryInteger;
class QgsSettingsEntryInteger64;
class QgsSettingsEntryString;
class QgsSettingsEntryStringList;
template<class T> class QgsSettingsEntryEnumFlag;
Expand Down Expand Up @@ -165,6 +166,12 @@ class CORE_EXPORT QgsSettingsRegistryCore : public QgsSettingsRegistry
//! Settings entry whether layer are loading in parallel
static const QgsSettingsEntryBool *settingsLayerParallelLoading;

//! Settings entry network cache directory
static const QgsSettingsEntryString *settingsNetworkCacheDirectory;

//! Settings entry network cache directory
static const QgsSettingsEntryInteger64 *settingsNetworkCacheSize;

private:
friend class QgsApplication;

Expand Down
1 change: 1 addition & 0 deletions src/core/settings/qgssettingstree.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class CORE_EXPORT QgsSettingsTree
static inline QgsSettingsTreeNode *sTreeWms = treeRoot()->createChildNode( QStringLiteral( "wms" ) );
static inline QgsSettingsTreeNode *sTreeMeasure = treeRoot()->createChildNode( QStringLiteral( "measure" ) );
static inline QgsSettingsTreeNode *sTreeAnnotations = treeRoot()->createChildNode( QStringLiteral( "annotations" ) );
static inline QgsSettingsTreeNode *sTreeNetworkCache = treeRoot()->createChildNode( QStringLiteral( "cache" ) );

#endif

Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsserversettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void QgsServerSettings::initSettings()
const Setting sCacheSize = { QgsServerSettingsEnv::QGIS_SERVER_CACHE_SIZE,
QgsServerSettingsEnv::DEFAULT_VALUE,
QStringLiteral( "Specify the cache size (0 = automatic size)" ),
QStringLiteral( "/cache/size_bytes" ),
QStringLiteral( "/cache/size-bytes" ),
QMetaType::Type::LongLong,
0,
QVariant()
Expand Down
2 changes: 1 addition & 1 deletion tests/testdata/qgis_server_settings/conf0.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[cache]
directory=
size_bytes=@Variant(\0\0\0\x81\0\0\0\0\x3 \0\0)
size-bytes=@Variant(\0\0\0\x81\0\0\0\0\x3 \0\0)

[qgis]
parallel_rendering=true
Expand Down
2 changes: 1 addition & 1 deletion tests/testdata/qgis_server_settings/conf1.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[cache]
directory=/tmp/mycache
size_bytes=@Variant(\0\0\0\x81\0\0\0\0\x3 \0\0)
size-bytes=@Variant(\0\0\0\x81\0\0\0\0\x3 \0\0)

[qgis]
parallel_rendering=false
Expand Down

0 comments on commit f0085c6

Please sign in to comment.