Skip to content
Permalink
Browse files

Added option to load/store from/to the filesystem

+ Added tooltips with full path to the gpkg file
+ Fixed a crash when removing a stored project
  • Loading branch information
elpaso committed Mar 9, 2019
1 parent 4f1dd95 commit 06678ebda392c0e2c2d512c14062b5447c64a3e1
@@ -95,6 +95,7 @@ class QgsGeoPackageVectorLayerItem : public QgsGeoPackageAbstractLayerItem
/**
* \brief The QgsGeoPackageCollectionItem class is the base class for
* GeoPackage container
*
*/
class QgsGeoPackageCollectionItem : public QgsDataCollectionItem
{
@@ -23,6 +23,8 @@
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QFileInfo>
#include <QFile>

QgsGeoPackageProjectStorageDialog::QgsGeoPackageProjectStorageDialog( bool saving, QWidget *parent )
: QDialog( parent )
@@ -38,6 +40,18 @@ QgsGeoPackageProjectStorageDialog::QgsGeoPackageProjectStorageDialog( bool savin
connect( mActionRemoveProject, &QAction::triggered, this, &QgsGeoPackageProjectStorageDialog::removeProject );
btnManageProjects->setMenu( menuManageProjects );
buttonBox->addButton( btnManageProjects, QDialogButtonBox::ActionRole );
mFileWidget->lineEdit()->hide();

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 +64,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 +144,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 +153,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 06678eb

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