Skip to content

Commit

Permalink
Merge pull request #9451 from elpaso/geopackage-project-storage-followup
Browse files Browse the repository at this point in the history
Added option to load/store from/to the filesystem
  • Loading branch information
elpaso committed Mar 10, 2019
2 parents 6c79fff + 2537296 commit d5de1d9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/providers/ogr/qgsgeopackagedataitems.h
Expand Up @@ -95,6 +95,7 @@ class QgsGeoPackageVectorLayerItem : public QgsGeoPackageAbstractLayerItem
/**
* \brief The QgsGeoPackageCollectionItem class is the base class for
* GeoPackage container
*
*/
class QgsGeoPackageCollectionItem : public QgsDataCollectionItem
{
Expand Down
30 changes: 25 additions & 5 deletions src/providers/ogr/qgsgeopackageprojectstoragedialog.cpp
Expand Up @@ -18,11 +18,14 @@
#include "qgsprojectstorage.h"
#include "qgsprojectstorageregistry.h"
#include "qgsogrdbconnection.h"
#include "qgsvectorfilewriter.h"
#include "qgis.h"

#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QFileInfo>
#include <QFile>

QgsGeoPackageProjectStorageDialog::QgsGeoPackageProjectStorageDialog( bool saving, QWidget *parent )
: QDialog( parent )
Expand All @@ -38,6 +41,19 @@ QgsGeoPackageProjectStorageDialog::QgsGeoPackageProjectStorageDialog( bool savin
connect( mActionRemoveProject, &QAction::triggered, this, &QgsGeoPackageProjectStorageDialog::removeProject );
btnManageProjects->setMenu( menuManageProjects );
buttonBox->addButton( btnManageProjects, QDialogButtonBox::ActionRole );
mFileWidget->lineEdit()->hide();
mFileWidget->setFilter( QgsVectorFileWriter::filterForDriver( QStringLiteral( "GPKG" ) ) );

connect( mFileWidget, &QgsFileWidget::fileChanged, [ = ]( const QString & path )
{
const QString fileName{QFileInfo( path ).fileName()};
if ( mCboConnection->findData( path ) == -1 )
{
mCboConnection->addItem( QFileInfo( path ).fileName(), path );
mCboConnection->setItemData( mCboConnection->findText( fileName ), path, Qt::ItemDataRole::ToolTipRole );
}
mCboConnection->setCurrentIndex( mCboConnection->findText( fileName ) );
} );

if ( saving )
{
Expand All @@ -50,7 +66,13 @@ QgsGeoPackageProjectStorageDialog::QgsGeoPackageProjectStorageDialog( bool savin
}

// populate connections
mCboConnection->addItems( QgsOgrDbConnection::connectionList( QStringLiteral( "GPKG" ) ) );
const auto &connList { QgsOgrDbConnection::connectionList( QStringLiteral( "GPKG" ) ) };
for ( const auto &connName : connList )
{
QgsOgrDbConnection conn { connName, QStringLiteral( "GPKG" ) };
mCboConnection->addItem( connName, conn.path() );
mCboConnection->setItemData( mCboConnection->findText( connName ), conn.path(), Qt::ItemDataRole::ToolTipRole );
}

connect( mCboProject, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsGeoPackageProjectStorageDialog::projectChanged );
connect( mCboConnection, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsGeoPackageProjectStorageDialog::populateProjects );
Expand Down Expand Up @@ -124,7 +146,7 @@ void QgsGeoPackageProjectStorageDialog::removeProject()
if ( res != QMessageBox::Yes )
return;

QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromType( QStringLiteral( "GeoPackage" ) );
QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromType( QStringLiteral( "geopackage" ) );
Q_ASSERT( storage );
storage->removeProject( currentProjectUri() );
populateProjects();
Expand All @@ -133,9 +155,7 @@ void QgsGeoPackageProjectStorageDialog::removeProject()
QString QgsGeoPackageProjectStorageDialog::currentProjectUri( )
{
QgsGeoPackageProjectUri gpkgUri;
// find path in connections
QgsOgrDbConnection conn( mCboConnection->currentText(), QStringLiteral( "GPKG" ) );
gpkgUri.database = conn.path();
gpkgUri.database = mCboConnection->currentData().toString();
gpkgUri.projectName = mCboProject->currentText();
return QgsGeoPackageProjectStorage::encodeUri( gpkgUri );
}
20 changes: 15 additions & 5 deletions src/ui/qgsgeopackageprojectstoragedialog.ui
Expand Up @@ -13,25 +13,28 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QComboBox" name="mCboProject"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Connection</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mCboConnection"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Project</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mCboConnection"/>
<item row="0" column="2">
<widget class="QgsFileWidget" name="mFileWidget" native="true"/>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="mCboProject"/>
</item>
</layout>
</item>
Expand Down Expand Up @@ -60,6 +63,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
Expand Down
Binary file modified tests/testdata/polys_overlapping_with_id.dbf
Binary file not shown.

0 comments on commit d5de1d9

Please sign in to comment.