Skip to content

Commit

Permalink
Merge pull request #4953 from boundlessgeo/gpkg-enhancements
Browse files Browse the repository at this point in the history
Expose GeoPackage to the browser tree
  • Loading branch information
elpaso authored Aug 9, 2017
2 parents 267286e + 92da308 commit d9a2492
Show file tree
Hide file tree
Showing 22 changed files with 710 additions and 46 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.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
29 changes: 29 additions & 0 deletions images/themes/default/mGeoPackage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 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 Expand Up @@ -517,6 +525,7 @@ Check if the given path is hidden from the browser model
:rtype: bool
%End


public slots:
virtual void childrenCreated();
void directoryChanged();
Expand Down
10 changes: 10 additions & 0 deletions python/core/qgsproject.sip
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,14 @@ Returns the number of registered layers.
.. seealso:: QgsMapLayer.reload()
%End

QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
%Docstring
Returns the default CRS for new layers based on the settings and
the current project CRS
:rtype: QgsCoordinateReferenceSystem
%End


signals:
void readProject( const QDomDocument & );
%Docstring
Expand Down Expand Up @@ -1010,6 +1018,8 @@ emitted whenever the configuration for snapping has changed
\param layers List of QgsMapLayer which were added to the legend.
%End



public slots:

void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
Expand Down
32 changes: 6 additions & 26 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1740,27 +1740,6 @@ void QgisApp::applyDefaultSettingsToCanvas( QgsMapCanvas *canvas )
canvas->setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType( settings.value( QStringLiteral( "qgis/segmentationToleranceType" ), "0" ).toInt() ) );
}

QgsCoordinateReferenceSystem QgisApp::defaultCrsForNewLayers() const
{
QgsSettings settings;
QgsCoordinateReferenceSystem defaultCrs;
if ( settings.value( QStringLiteral( "/Projections/defaultBehavior" ), QStringLiteral( "prompt" ) ).toString() == QStringLiteral( "useProject" )
|| settings.value( QStringLiteral( "/Projections/defaultBehavior" ), QStringLiteral( "prompt" ) ).toString() == QStringLiteral( "prompt" ) )
{
// for new layers if the new layer crs method is set to either prompt or use project, then we use the project crs
// (since "prompt" has no meaning here - the prompt will always be shown, it's just deciding on the default choice in the prompt!)
defaultCrs = QgsProject::instance()->crs();
}
else
{
// global crs
QString layerDefaultCrs = settings.value( QStringLiteral( "/Projections/layerDefaultCrs" ), GEO_EPSG_CRS_AUTHID ).toString();
defaultCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( layerDefaultCrs );
}

return defaultCrs;
}

int QgisApp::chooseReasonableDefaultIconSize() const
{
QScreen *screen = QApplication::screens().at( 0 );
Expand Down Expand Up @@ -4488,6 +4467,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 @@ -5098,7 +5078,7 @@ void QgisApp::fileNewFromTemplateAction( QAction *qAction )
void QgisApp::newVectorLayer()
{
QString enc;
QString fileName = QgsNewVectorLayerDialog::runAndCreateLayer( this, &enc, defaultCrsForNewLayers() );
QString fileName = QgsNewVectorLayerDialog::runAndCreateLayer( this, &enc, QgsProject::instance()->defaultCrsForNewLayers() );

if ( !fileName.isEmpty() )
{
Expand All @@ -5120,7 +5100,7 @@ void QgisApp::newVectorLayer()

void QgisApp::newMemoryLayer()
{
QgsVectorLayer *newLayer = QgsNewMemoryLayerDialog::runAndCreateLayer( this, defaultCrsForNewLayers() );
QgsVectorLayer *newLayer = QgsNewMemoryLayerDialog::runAndCreateLayer( this, QgsProject::instance()->defaultCrsForNewLayers() );

if ( newLayer )
{
Expand All @@ -5135,14 +5115,14 @@ void QgisApp::newMemoryLayer()

void QgisApp::newSpatialiteLayer()
{
QgsNewSpatialiteLayerDialog spatialiteDialog( this, QgsGuiUtils::ModalDialogFlags, defaultCrsForNewLayers() );
QgsNewSpatialiteLayerDialog spatialiteDialog( this, QgsGuiUtils::ModalDialogFlags, QgsProject::instance()->defaultCrsForNewLayers() );
spatialiteDialog.exec();
}

void QgisApp::newGeoPackageLayer()
{
QgsNewGeoPackageLayerDialog dialog( this );
dialog.setCrs( defaultCrsForNewLayers() );
dialog.setCrs( QgsProject::instance()->defaultCrsForNewLayers() );
dialog.exec();
}

Expand Down Expand Up @@ -9807,7 +9787,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
24 changes: 22 additions & 2 deletions src/core/qgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ void QgsDataItem::populate( bool foreground )
{
mFutureWatcher = new QFutureWatcher< QVector <QgsDataItem *> >( this );
}

connect( mFutureWatcher, &QFutureWatcherBase::finished, this, &QgsDataItem::childrenCreated );
mFutureWatcher->setFuture( QtConcurrent::run( runCreateChildren, this ) );
}
Expand Down Expand Up @@ -581,6 +582,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 Expand Up @@ -785,12 +792,22 @@ void QgsDirectoryItem::directoryChanged()
{
if ( state() == Populating )
{
// schedule to refresh later, because refres() simply returns if Populating
// schedule to refresh later, because refresh() simply returns if Populating
mRefreshLater = true;
}
else
{
refresh();
// We definintely don't want the temporary files created by sqlite
// to re-trigger a refresh in an infinite loop.
disconnect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
// QFileSystemWhatcher::directoryChanged is emitted when a
// file is created and not when it is closed/flushed.
//
// Delay to give to OS the time to complete writing the file
// this happens when a new file appears in the directory and
// the item's children thread will try to open the file with
// GDAL or OGR even if it is still being written.
QTimer::singleShot( 100, this, SLOT( refresh() ) );
}
}

Expand All @@ -803,6 +820,7 @@ bool QgsDirectoryItem::hiddenPath( const QString &path )
return ( idx > -1 );
}


void QgsDirectoryItem::childrenCreated()
{
QgsDebugMsgLevel( QString( "mRefreshLater = %1" ).arg( mRefreshLater ), 3 );
Expand All @@ -818,6 +836,8 @@ void QgsDirectoryItem::childrenCreated()
{
QgsDataCollectionItem::childrenCreated();
}
// Re-connect the file watcher after all children have been created
connect( mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &QgsDirectoryItem::directoryChanged );
}

bool QgsDirectoryItem::equal( const QgsDataItem *other )
Expand Down
9 changes: 9 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 Expand Up @@ -460,6 +468,7 @@ class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
//! Check if the given path is hidden from the browser model
static bool hiddenPath( const QString &path );


public slots:
virtual void childrenCreated() override;
void directoryChanged();
Expand Down
20 changes: 20 additions & 0 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2241,3 +2241,23 @@ QMap<QString, QgsMapLayer *> QgsProject::mapLayers() const
}


QgsCoordinateReferenceSystem QgsProject::defaultCrsForNewLayers() const
{
QgsSettings settings;
QgsCoordinateReferenceSystem defaultCrs;
if ( settings.value( QStringLiteral( "/Projections/defaultBehavior" ), QStringLiteral( "prompt" ) ).toString() == QStringLiteral( "useProject" )
|| settings.value( QStringLiteral( "/Projections/defaultBehavior" ), QStringLiteral( "prompt" ) ).toString() == QStringLiteral( "prompt" ) )
{
// for new layers if the new layer crs method is set to either prompt or use project, then we use the project crs
// (since "prompt" has no meaning here - the prompt will always be shown, it's just deciding on the default choice in the prompt!)
defaultCrs = crs();
}
else
{
// global crs
QString layerDefaultCrs = settings.value( QStringLiteral( "/Projections/layerDefaultCrs" ), GEO_EPSG_CRS_AUTHID ).toString();
defaultCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( layerDefaultCrs );
}

return defaultCrs;
}
8 changes: 8 additions & 0 deletions src/core/qgsproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,12 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
void reloadAllLayers();

/** Returns the default CRS for new layers based on the settings and
* the current project CRS
*/
QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;


signals:
//! emitted when project is being read
void readProject( const QDomDocument & );
Expand Down Expand Up @@ -967,6 +973,8 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
void legendLayersAdded( const QList<QgsMapLayer *> &layers );



public slots:

/**
Expand Down
Loading

0 comments on commit d9a2492

Please sign in to comment.