Skip to content
Permalink
Browse files

add UX to edit the basemap paths registry

  • Loading branch information
3nids committed May 14, 2020
1 parent 1ec35d9 commit 85b62695e434312bc37d0f985a96d62ee51106e1
@@ -40,6 +40,7 @@
#include "qgsnumericformatwidget.h"

#include "qgsattributetablefiltermodel.h"
#include "qgsbasemappathregistry.h"
#include "qgsrasterformatsaveoptionswidget.h"
#include "qgsrasterpyramidsoptionswidget.h"
#include "qgsdatumtransformtablewidget.h"
@@ -308,6 +309,22 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
connect( mBtnAddTemplatePath, &QAbstractButton::clicked, this, &QgsOptions::addTemplatePath );
connect( mBtnRemoveTemplatePath, &QAbstractButton::clicked, this, &QgsOptions::removeTemplatePath );

// basemap paths
connect( mBasemapPathAddButton, &QAbstractButton::clicked, this, &QgsOptions::addBasemapPath );
connect( mBasemapPathRemoveButton, &QAbstractButton::clicked, this, &QgsOptions::removeBasemapPath );
connect( mBasemapPathUpButton, &QAbstractButton::clicked, this, &QgsOptions::moveBasemapPathUp );
connect( mBasemapPathDownButton, &QAbstractButton::clicked, this, &QgsOptions::moveBasemapPathDown );

// basemap paths
const QStringList basemapPaths = QgsApplication::basemapPathRegistry()->paths();
for ( const QString &path : basemapPaths )
{
QListWidgetItem *newItem = new QListWidgetItem( mBasemapPathListWidget );
newItem->setText( path );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mBasemapPathListWidget->addItem( newItem );
}

//paths hidden from browser
const QStringList hiddenPathList = mSettings->value( QStringLiteral( "/browser/hiddenPaths" ) ).toStringList();
for ( const QString &path : hiddenPathList )
@@ -1409,6 +1426,11 @@ void QgsOptions::saveOptions()
}
mSettings->setValue( QStringLiteral( "Layout/searchPathsForTemplates" ), pathsList, QgsSettings::Core );

pathsList.clear();
for ( int r = 0; r < mBasemapPathListWidget->count(); r++ )
pathsList << mBasemapPathListWidget->item( r )->text();
QgsApplication::basemapPathRegistry()->setPaths( pathsList );

pathsList.clear();
for ( int i = 0; i < mListHiddenBrowserPaths->count(); ++i )
{
@@ -2528,6 +2550,55 @@ void QgsOptions::addColor()
mTreeCustomColors->addColor( newColor, QgsSymbolLayerUtils::colorToName( newColor ) );
}

void QgsOptions::removeBasemapPath()
{
qDeleteAll( mBasemapPathListWidget->selectedItems() );
}

void QgsOptions::addBasemapPath()
{
QString myDir = QFileDialog::getExistingDirectory(
this,
tr( "Choose a directory" ),
QDir::toNativeSeparators( QDir::homePath() ),
QFileDialog::ShowDirsOnly
);

if ( ! myDir.isEmpty() )
{
QListWidgetItem *newItem = new QListWidgetItem( mBasemapPathListWidget );
newItem->setText( myDir );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mBasemapPathListWidget->addItem( newItem );
mBasemapPathListWidget->setCurrentItem( newItem );
}
}

void QgsOptions::moveBasemapPathUp()
{
QList<QListWidgetItem *> selectedItems = mBasemapPathListWidget->selectedItems();
QList<QListWidgetItem *>::iterator itemIt = selectedItems.begin();
for ( ; itemIt != selectedItems.end(); ++itemIt )
{
int row = mBasemapPathListWidget->row( *itemIt );
mBasemapPathListWidget->takeItem( row );
mBasemapPathListWidget->insertItem( row - 1, *itemIt );
}
}

void QgsOptions::moveBasemapPathDown()
{
QList<QListWidgetItem *> selectedItems = mBasemapPathListWidget->selectedItems();
QList<QListWidgetItem *>::iterator itemIt = selectedItems.begin();
for ( ; itemIt != selectedItems.end(); ++itemIt )
{
int row = mBasemapPathListWidget->row( *itemIt );
mBasemapPathListWidget->takeItem( row );
mBasemapPathListWidget->insertItem( row + 1, *itemIt );
}
}


QListWidgetItem *QgsOptions::addScaleToScaleList( const QString &newScale )
{
QListWidgetItem *newItem = new QListWidgetItem( newScale );
@@ -241,6 +241,12 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption

void addColor();

private slots:
void removeBasemapPath();
void addBasemapPath();
void moveBasemapPathUp();
void moveBasemapPathDown();

private:
QgsSettings *mSettings = nullptr;
QStringList i18nList();
@@ -16,12 +16,12 @@
#include <QDir>

#include "qgsbasemappathregistry.h"

#include "qgssettings.h"
#include "qgis.h"

QgsBasemapPathRegistry::QgsBasemapPathRegistry()
{

readFromSettings();
}

QString QgsBasemapPathRegistry::fullPath( const QString &relativePath ) const
@@ -60,6 +60,8 @@ void QgsBasemapPathRegistry::setPaths( const QStringList &paths )
if ( !mPaths.contains( dir ) )
mPaths << dir;
}

writeToSettings();
}

void QgsBasemapPathRegistry::registerPath( const QString &path, int position )
@@ -72,9 +74,22 @@ void QgsBasemapPathRegistry::registerPath( const QString &path, int position )
mPaths.insert( position, dir );
else
mPaths.append( dir );

writeToSettings();
}

void QgsBasemapPathRegistry::unregisterPath( const QString &path )
{
mPaths.removeAll( QDir( path ) );
writeToSettings();
}

void QgsBasemapPathRegistry::readFromSettings()
{
setPaths( QgsSettings().value( QStringLiteral( "/qgis/basemap_paths" ) ).toStringList() );
}

void QgsBasemapPathRegistry::writeToSettings()
{
QgsSettings().setValue( QStringLiteral( "/qgis/basemap_paths" ), paths() );
}
@@ -60,6 +60,9 @@ class CORE_EXPORT QgsBasemapPathRegistry
void unregisterPath( const QString &path );

private:
void readFromSettings();
void writeToSettings();

QList<QDir> mPaths;
};

@@ -52,7 +52,7 @@ QString QgsPathResolver::readPath( const QString &f ) const

if ( src.startsWith( QLatin1String( "basemap:" ) ) )
{
// strip away "inbuilt:" prefix, replace with actual inbuilt data folder path
// strip away "basemap:" prefix, replace with actual inbuilt data folder path
return QgsApplication::basemapPathRegistry()->fullPath( src.mid( 8 ) ) ;
}

0 comments on commit 85b6269

Please sign in to comment.
You can’t perform that action at this time.