Skip to content

Commit

Permalink
Expose GeoPackage to the browser tree
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Aug 9, 2017
1 parent 425aa30 commit 61504e7
Show file tree
Hide file tree
Showing 16 changed files with 539 additions and 10 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@
<file>themes/default/mActionMapSettings.svg</file>
<file>themes/default/mActionLockExtent.svg</file>
<file>icons/qgis_icon.svg</file>
<file>themes/default/mGeoPackage.png</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
Binary file added images/themes/default/mGeoPackage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions python/core/qgsdataitem.sip
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ class QgsLayerItem : QgsDataItem
Plugin
};


QgsLayerItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &uri, LayerType layerType, const QString &providerKey );


Expand Down Expand Up @@ -410,6 +411,13 @@ Returns provider key
:rtype: str
%End

static QString layerTypeAsString( const LayerType &layerType );
%Docstring
Returns the string representatio of the given ``layerType``
.. versionadded:: 3
:rtype: str
%End

protected:


Expand Down
3 changes: 2 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4488,6 +4488,7 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
}
}

// Check if the current layer uri contains the

// We initialize a selection dialog and display it.
QgsSublayersDialog chooseSublayersDialog( QgsSublayersDialog::Ogr, QStringLiteral( "ogr" ), this );
Expand Down Expand Up @@ -9807,7 +9808,7 @@ QgsVectorLayer *QgisApp::addVectorLayer( const QString &vectorLayerPath, const Q

// If the newly created layer has more than 1 layer of data available, we show the
// sublayers selection dialog so the user can select the sublayers to actually load.
if ( sublayers.count() > 1 )
if ( sublayers.count() > 1 && ! vectorLayerPath.contains( QStringLiteral( "layerid=" ) ) )
{
askUserForOGRSublayers( layer );

Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,12 @@ QgsMapLayer::LayerType QgsLayerItem::mapLayerType() const
return QgsMapLayer::VectorLayer;
}

QString QgsLayerItem::layerTypeAsString( const QgsLayerItem::LayerType &layerType )
{
static int enumIdx = staticMetaObject.indexOfEnumerator( "LayerType" );
return staticMetaObject.enumerator( enumIdx ).valueToKey( layerType );
}

bool QgsLayerItem::equal( const QgsDataItem *other )
{
//QgsDebugMsg ( mPath + " x " + other->mPath );
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsdataitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataItem::Capabilities )
class CORE_EXPORT QgsLayerItem : public QgsDataItem
{
Q_OBJECT
Q_ENUMS( LayerType )
public:
enum LayerType
{
Expand All @@ -343,6 +344,8 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
Plugin //!< Added in 2.10
};

Q_ENUMS( LayerType )

QgsLayerItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &uri, LayerType layerType, const QString &providerKey );

// --- reimplemented from QgsDataItem ---
Expand Down Expand Up @@ -379,6 +382,11 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
*/
virtual QString comments() const { return QString(); }

/** Returns the string representatio of the given \a layerType
* \since QGIS 3
*/
static QString layerTypeAsString( const LayerType &layerType );

protected:

//! The provider key
Expand Down
4 changes: 4 additions & 0 deletions src/providers/ogr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ SET (OGR_SRCS
qgsogrconnpool.cpp
qgsogrexpressioncompiler.cpp
qgsogrsourceselect.cpp
qgsgeopackagedataitems.cpp
qgsgeopackageconnection.cpp
)

SET(OGR_MOC_HDRS
qgsogrprovider.h
qgsogrdataitems.h
qgsogrconnpool.h
qgsogrsourceselect.h
qgsgeopackagedataitems.h
qgsgeopackageconnection.h
)

########################################################
Expand Down
89 changes: 89 additions & 0 deletions src/providers/ogr/qgsgeopackageconnection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/***************************************************************************
qgsgeopackageconnection.cpp - selector for geopackage
-------------------
begin : August 2017
copyright : (C) 2017 by Alessandro Pasotti
email : apasotti at boundlessgeo 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 "qgis.h"
#include "qgsdatasourceuri.h"
#include "qgssettings.h"
#include "qgsgeopackageconnection.h"
#include "qgslogger.h"
#include <QInputDialog>
#include <QMessageBox>

const QString QgsGeoPackageConnection::SETTINGS_PREFIX = QStringLiteral( "providers/geopackage" );


QgsGeoPackageConnection::QgsGeoPackageConnection( const QString &connName )
: mConnName( connName )
{
QgsSettings settings;

QString key = QStringLiteral( "%1/%2/path" ).arg( connectionsPath( ), mConnName );
mPath = settings.value( key ).toString();
}

QgsGeoPackageConnection::~QgsGeoPackageConnection()
{

}

QgsDataSourceUri QgsGeoPackageConnection::uri()
{
QgsDataSourceUri uri;
uri.setEncodedUri( mPath );
return uri;
}

void QgsGeoPackageConnection::setPath( QString &path )
{
mPath = path;
}

void QgsGeoPackageConnection::save( )
{
QgsSettings settings;
settings.setValue( QStringLiteral( "%1/%2/path" ).arg( connectionsPath( ), mConnName ), mPath );
}

QString QgsGeoPackageConnection::connectionsPath()
{
return QStringLiteral( "%1/connections" ).arg( SETTINGS_PREFIX );
}

QStringList QgsGeoPackageConnection::connectionList()
{
QgsSettings settings;
settings.beginGroup( connectionsPath( ) );
return settings.childGroups();
}

QString QgsGeoPackageConnection::selectedConnection()
{
QgsSettings settings;
return settings.value( QStringLiteral( "%1/selected" ).arg( SETTINGS_PREFIX ) ).toString();
}

void QgsGeoPackageConnection::setSelectedConnection( const QString &name )
{
QgsSettings settings;
settings.setValue( QStringLiteral( "%1/selected" ).arg( SETTINGS_PREFIX ), name );
}

void QgsGeoPackageConnection::deleteConnection( const QString &name )
{
QgsSettings settings;
settings.remove( QStringLiteral( "%1/%2" ).arg( connectionsPath(), name ) );
}
67 changes: 67 additions & 0 deletions src/providers/ogr/qgsgeopackageconnection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/***************************************************************************
qgsgeopackageconnection.h - GeoPackage connection
-------------------
begin : August 2017
copyright : (C) 2017 by Alessandro Pasotti
email : apasotti at boundlessgeo 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 QGSGEOPACKAGECONNECTION_H
#define QGSGEOPACKAGECONNECTION_H

#include "qgsdatasourceuri.h"

#include <QStringList>

/*!
* \brief Connections management
*/
class QgsGeoPackageConnection : public QObject
{
Q_OBJECT

public:
//! Constructor
explicit QgsGeoPackageConnection( const QString &connName );

~QgsGeoPackageConnection();

static QStringList connectionList();

static void deleteConnection( const QString &name );

static QString selectedConnection();
static void setSelectedConnection( const QString &name );

public:
//! Return the uri
//! \see QgsDataSourceUri
QgsDataSourceUri uri();
//! Return the path
QString path( ) { return mPath; }
//! Returns the connection name
QString name() { return mConnName; }
//! Set the \a path fo the connection
void setPath( QString &path );
//! Store the connection data in the settings
void save();
const static QString SETTINGS_PREFIX;

private:

static QString connectionsPath( );
QString mConnName;
QString mPath;

};

#endif // QGSGEOPACKAGECONNECTION_H
Loading

0 comments on commit 61504e7

Please sign in to comment.