Skip to content
Permalink
Browse files

[FEATURE] Config dialog for XYZ tile connections + editing of existin…

…g ones

As a bonus, also made zmin/zmax configuration visible to users
  • Loading branch information
wonder-sk committed Feb 25, 2017
1 parent 1182816 commit 4cd4ea1b859f829f3f8c87dbe09f2f8d75640b77
@@ -11,6 +11,7 @@ SET (WMS_SRCS
qgstilescalewidget.cpp
qgswmtsdimensions.cpp
qgsxyzconnection.cpp
qgsxyzconnectiondialog.cpp
)
SET (WMS_MOC_HDRS
qgswmscapabilities.h
@@ -20,6 +21,7 @@ SET (WMS_MOC_HDRS
qgswmsdataitems.h
qgstilescalewidget.h
qgswmtsdimensions.h
qgsxyzconnectiondialog.h
)

QT5_WRAP_CPP (WMS_MOC_SRCS ${WMS_MOC_HDRS})
@@ -24,6 +24,7 @@
#include "qgsnewhttpconnection.h"
#include "qgstilescalewidget.h"
#include "qgsxyzconnection.h"
#include "qgsxyzconnectiondialog.h"

#include <QInputDialog>

@@ -504,20 +505,11 @@ QList<QAction *> QgsXyzTileRootItem::actions()

void QgsXyzTileRootItem::newConnection()
{
QString url = QInputDialog::getText( nullptr, tr( "New XYZ tile layer" ),
tr( "Please enter XYZ tile layer URL. {x}, {y}, {z} will be replaced by actual tile coordinates." ) );
if ( url.isEmpty() )
QgsXyzConnectionDialog dlg;
if ( !dlg.exec() )
return;

QString name = QInputDialog::getText( nullptr, tr( "New XYZ tile layer" ),
tr( "Please enter name of the tile layer:" ) );
if ( name.isEmpty() )
return;

QgsXyzConnection conn;
conn.name = name;
conn.url = url;
QgsXyzConnectionUtils::addConnection( conn );
QgsXyzConnectionUtils::addConnection( dlg.connection() );

refresh();
}
@@ -536,13 +528,30 @@ QList<QAction *> QgsXyzLayerItem::actions()
{
QList<QAction*> lst = QgsLayerItem::actions();

QAction* actionEdit = new QAction( tr( "Edit..." ), this );
connect( actionEdit, &QAction::triggered, this, &QgsXyzLayerItem::editConnection );
lst << actionEdit;

QAction* actionDelete = new QAction( tr( "Delete" ), this );
connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteConnection() ) );
lst << actionDelete;

return lst;
}

void QgsXyzLayerItem::editConnection()
{
QgsXyzConnectionDialog dlg;
dlg.setConnection( QgsXyzConnectionUtils::connection( mName ) );
if ( !dlg.exec() )
return;

QgsXyzConnectionUtils::deleteConnection( mName );
QgsXyzConnectionUtils::addConnection( dlg.connection() );

mParent->refresh();
}

void QgsXyzLayerItem::deleteConnection()
{
QgsXyzConnectionUtils::deleteConnection( mName );
@@ -144,6 +144,7 @@ class QgsXyzLayerItem : public QgsLayerItem
virtual QList<QAction*> actions() override;

public slots:
void editConnection();
void deleteConnection();
};

@@ -24,6 +24,10 @@ QString QgsXyzConnection::encodedUri() const
QgsDataSourceUri uri;
uri.setParam( QStringLiteral( "type" ), QStringLiteral( "xyz" ) );
uri.setParam( QStringLiteral( "url" ), url );
if ( zMin != -1 )
uri.setParam( QStringLiteral( "zmin" ), QString::number( zMin ) );
if ( zMax != -1 )
uri.setParam( QStringLiteral( "zmax" ), QString::number( zMax ) );
return uri.encodedUri();
}

@@ -42,6 +46,8 @@ QgsXyzConnection QgsXyzConnectionUtils::connection( const QString &name )
QgsXyzConnection conn;
conn.name = name;
conn.url = settings.value( QStringLiteral( "url" ) ).toString();
conn.zMin = settings.value( QStringLiteral( "zmin" ), -1 ).toInt();
conn.zMax = settings.value( QStringLiteral( "zmax" ), -1 ).toInt();
return conn;
}

@@ -56,4 +62,6 @@ void QgsXyzConnectionUtils::addConnection( const QgsXyzConnection &conn )
QSettings settings;
settings.beginGroup( "/Qgis/connections-xyz/" + conn.name );
settings.setValue( QStringLiteral( "url" ), conn.url );
settings.setValue( QStringLiteral( "zmin" ), conn.zMin );
settings.setValue( QStringLiteral( "zmax" ), conn.zMax );
}
@@ -22,6 +22,8 @@ struct QgsXyzConnection
{
QString name;
QString url;
int zMin = -1;
int zMax = -1;

QString encodedUri() const;
};
@@ -0,0 +1,46 @@
/***************************************************************************
qgsxyzconnectiondialog.cpp
---------------------
begin : February 2017
copyright : (C) 2017 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsxyzconnectiondialog.h"

#include "qgsxyzconnection.h"

QgsXyzConnectionDialog::QgsXyzConnectionDialog( QWidget *parent )
: QDialog( parent )
{
setupUi( this );
}

void QgsXyzConnectionDialog::setConnection( const QgsXyzConnection& conn )
{
mEditName->setText( conn.name );
mEditUrl->setText( conn.url );
mCheckBoxZMin->setChecked( conn.zMin != -1 );
mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
mCheckBoxZMax->setChecked( conn.zMax != -1 );
mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 18 );
}

QgsXyzConnection QgsXyzConnectionDialog::connection() const
{
QgsXyzConnection conn;
conn.name = mEditName->text();
conn.url = mEditUrl->text();
if ( mCheckBoxZMin->isChecked() )
conn.zMin = mSpinZMin->value();
if ( mCheckBoxZMax->isChecked() )
conn.zMax = mSpinZMax->value();
return conn;
}
@@ -0,0 +1,38 @@
/***************************************************************************
qgsxyzconnectiondialog.h
---------------------
begin : February 2017
copyright : (C) 2017 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSXYZCONNECTIONDIALOG_H
#define QGSXYZCONNECTIONDIALOG_H

#include <QDialog>

#include "ui_qgsxyzconnectiondialog.h"

struct QgsXyzConnection;


class QgsXyzConnectionDialog : public QDialog, public Ui::QgsXyzConnectionDialog
{
Q_OBJECT
public:
explicit QgsXyzConnectionDialog( QWidget *parent = 0 );

void setConnection( const QgsXyzConnection& conn );

QgsXyzConnection connection() const;

};

#endif // QGSXYZCONNECTIONDIALOG_H
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsXyzConnectionDialog</class>
<widget class="QDialog" name="QgsXyzConnectionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>746</width>
<height>426</height>
</rect>
</property>
<property name="windowTitle">
<string>XYZ Connection</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="mEditName"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>URL</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mEditUrl">
<property name="placeholderText">
<string>http://example.com/{z}/{x}/{y}.png</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="mCheckBoxZMin">
<property name="text">
<string>Min. Zoom Level</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="mSpinZMin"/>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="mCheckBoxZMax">
<property name="text">
<string>Max. Zoom Level</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="mSpinZMax">
<property name="value">
<number>18</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>mEditName</tabstop>
<tabstop>mEditUrl</tabstop>
<tabstop>mCheckBoxZMin</tabstop>
<tabstop>mSpinZMin</tabstop>
<tabstop>mCheckBoxZMax</tabstop>
<tabstop>mSpinZMax</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QgsXyzConnectionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>224</x>
<y>381</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsXyzConnectionDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>292</x>
<y>387</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

2 comments on commit 4cd4ea1

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Feb 25, 2017

Nice!

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Feb 25, 2017

@wonder-sk , thanks for the z min/max bonus, it's v. useful.

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