Skip to content
Permalink
Browse files

Merge pull request #9451 from elpaso/geopackage-project-storage-followup

Added option to load/store from/to the filesystem
  • Loading branch information
elpaso committed Mar 10, 2019
2 parents 6c79fff + 2537296 commit d5de1d98b8cf238f3c506308cbba8e106389aa81
@@ -95,6 +95,7 @@ class QgsGeoPackageVectorLayerItem : public QgsGeoPackageAbstractLayerItem
/**
* \brief The QgsGeoPackageCollectionItem class is the base class for
* GeoPackage container
*
*/
class QgsGeoPackageCollectionItem : public QgsDataCollectionItem
{
@@ -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 )
@@ -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 )
{
@@ -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 );
@@ -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();
@@ -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 );
}
@@ -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>
@@ -60,6 +63,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
Binary file not shown.

0 comments on commit d5de1d9

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