Skip to content

Commit

Permalink
[FEATURE] Config dialog for XYZ tile connections + editing of existin…
Browse files Browse the repository at this point in the history
…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 4cd4ea1
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/providers/wms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SET (WMS_SRCS
qgstilescalewidget.cpp
qgswmtsdimensions.cpp
qgsxyzconnection.cpp
qgsxyzconnectiondialog.cpp
)
SET (WMS_MOC_HDRS
qgswmscapabilities.h
Expand All @@ -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})
Expand Down
33 changes: 21 additions & 12 deletions src/providers/wms/qgswmsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "qgsnewhttpconnection.h"
#include "qgstilescalewidget.h"
#include "qgsxyzconnection.h"
#include "qgsxyzconnectiondialog.h"

#include <QInputDialog>

Expand Down Expand Up @@ -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();
}
Expand All @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/providers/wms/qgswmsdataitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class QgsXyzLayerItem : public QgsLayerItem
virtual QList<QAction*> actions() override;

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

Expand Down
8 changes: 8 additions & 0 deletions src/providers/wms/qgsxyzconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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;
}

Expand All @@ -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 );
}
2 changes: 2 additions & 0 deletions src/providers/wms/qgsxyzconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ struct QgsXyzConnection
{
QString name;
QString url;
int zMin = -1;
int zMax = -1;

QString encodedUri() const;
};
Expand Down
46 changes: 46 additions & 0 deletions src/providers/wms/qgsxyzconnectiondialog.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
38 changes: 38 additions & 0 deletions src/providers/wms/qgsxyzconnectiondialog.h
Original file line number Diff line number Diff line change
@@ -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
125 changes: 125 additions & 0 deletions src/ui/qgsxyzconnectiondialog.ui
Original file line number Diff line number Diff line change
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 4cd4ea1 Feb 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.