Skip to content
Permalink
Browse files

Expose GeoPackage to the browser tree

  • Loading branch information
elpaso committed Aug 3, 2017
1 parent 425aa30 commit 61504e7073ec7704ea655bf4f498191c16a16a6a
@@ -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>
Binary file not shown.
@@ -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 );


@@ -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:


@@ -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 );
@@ -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 );

@@ -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 );
@@ -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
{
@@ -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 ---
@@ -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
@@ -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
)

########################################################
@@ -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 ) );
}
@@ -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

0 comments on commit 61504e7

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