Skip to content
Permalink
Browse files

Added removal of projects

  • Loading branch information
wonder-sk committed Apr 7, 2018
1 parent 0c701fb commit fe686d316af61ae97b1cd38efa235fd69876f473
@@ -52,7 +52,7 @@ QStringList QgsPostgresProjectStorage::listProjects( const QString &uri )
{
QStringList lst;

QgsPostgresProjectUri projectUri = parseUri( uri );
QgsPostgresProjectUri projectUri = decodeUri( uri );
if ( !projectUri.valid )
return lst;

@@ -81,7 +81,7 @@ QStringList QgsPostgresProjectStorage::listProjects( const QString &uri )

bool QgsPostgresProjectStorage::readProject( const QString &uri, QIODevice *device, QgsReadWriteContext &context )
{
QgsPostgresProjectUri projectUri = parseUri( uri );
QgsPostgresProjectUri projectUri = decodeUri( uri );
if ( !projectUri.valid )
{
context.pushMessage( "Invalid URI for PostgreSQL provider: " + uri, Qgis::Critical );
@@ -121,7 +121,7 @@ bool QgsPostgresProjectStorage::readProject( const QString &uri, QIODevice *devi

bool QgsPostgresProjectStorage::writeProject( const QString &uri, QIODevice *device, QgsReadWriteContext &context )
{
QgsPostgresProjectUri projectUri = parseUri( uri );
QgsPostgresProjectUri projectUri = decodeUri( uri );
if ( !projectUri.valid )
{
context.pushMessage( "Invalid URI for PostgreSQL provider: " + uri, Qgis::Critical );
@@ -173,7 +173,7 @@ bool QgsPostgresProjectStorage::writeProject( const QString &uri, QIODevice *dev

bool QgsPostgresProjectStorage::removeProject( const QString &uri )
{
QgsPostgresProjectUri projectUri = parseUri( uri );
QgsPostgresProjectUri projectUri = decodeUri( uri );
if ( !projectUri.valid )
return false;

@@ -195,7 +195,7 @@ bool QgsPostgresProjectStorage::removeProject( const QString &uri )

bool QgsPostgresProjectStorage::readProjectMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata )
{
QgsPostgresProjectUri projectUri = parseUri( uri );
QgsPostgresProjectUri projectUri = decodeUri( uri );
if ( !projectUri.valid )
return false;

@@ -235,11 +235,7 @@ QString QgsPostgresProjectStorage::showLoadGui()
if ( !dlg.exec() )
return QString();

QgsPostgresProjectUri postUri;
postUri.connInfo = QgsPostgresConn::connUri( dlg.connectionName() );
postUri.schemaName = dlg.schemaName();
postUri.projectName = dlg.projectName();
return makeUri( postUri );
return dlg.currentProjectUri();
}

QString QgsPostgresProjectStorage::showSaveGui()
@@ -248,17 +244,13 @@ QString QgsPostgresProjectStorage::showSaveGui()
if ( !dlg.exec() )
return QString();

QgsPostgresProjectUri postUri;
postUri.connInfo = QgsPostgresConn::connUri( dlg.connectionName() );
postUri.schemaName = dlg.schemaName();
postUri.projectName = dlg.projectName();
return makeUri( postUri );
return dlg.currentProjectUri();
}

#endif


QString QgsPostgresProjectStorage::makeUri( const QgsPostgresProjectUri &postUri )
QString QgsPostgresProjectStorage::encodeUri( const QgsPostgresProjectUri &postUri )
{
QUrl u;
QUrlQuery urlQuery;
@@ -283,7 +275,7 @@ QString QgsPostgresProjectStorage::makeUri( const QgsPostgresProjectUri &postUri
}


QgsPostgresProjectUri QgsPostgresProjectStorage::parseUri( const QString &uri )
QgsPostgresProjectUri QgsPostgresProjectStorage::decodeUri( const QString &uri )
{
QUrl u = QUrl::fromEncoded( uri.toUtf8() );
QUrlQuery urlQuery( u.query() );
@@ -44,8 +44,8 @@ class QgsPostgresProjectStorage : public QgsProjectStorage
virtual QString showSaveGui() override;
#endif

static QString makeUri( const QgsPostgresProjectUri &postUri );
static QgsPostgresProjectUri parseUri( const QString &uri );
static QString encodeUri( const QgsPostgresProjectUri &postUri );
static QgsPostgresProjectUri decodeUri( const QString &uri );
};

#endif // QGSPOSTGRESPROJECTSTORAGE_H
@@ -8,7 +8,9 @@
#include "qgsprojectstorage.h"
#include "qgsprojectstorageregistry.h"

#include <QMenu>
#include <QMessageBox>
#include <QPushButton>

QgsPostgresProjectStorageDialog::QgsPostgresProjectStorageDialog( bool saving, QWidget *parent )
: QDialog( parent )
@@ -18,6 +20,12 @@ QgsPostgresProjectStorageDialog::QgsPostgresProjectStorageDialog( bool saving, Q

connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsPostgresProjectStorageDialog::onOK );

QPushButton *btnManageProjects = new QPushButton( tr( "Manage Projects" ), this );
QMenu *menuManageProjects = new QMenu( btnManageProjects );
mActionRemoveProject = menuManageProjects->addAction( tr( "Remove Project" ), this, &QgsPostgresProjectStorageDialog::removeProject );
btnManageProjects->setMenu( menuManageProjects );
buttonBox->addButton( btnManageProjects, QDialogButtonBox::ActionRole );

if ( saving )
{
setWindowTitle( tr( "Save project to PostgreSQL" ) );
@@ -38,6 +46,9 @@ QgsPostgresProjectStorageDialog::QgsPostgresProjectStorageDialog( bool saving, Q
mCboConnection->setCurrentIndex( mCboConnection->findText( toSelect ) );

connect( mCboSchema, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPostgresProjectStorageDialog::populateProjects );
connect( mCboProject, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPostgresProjectStorageDialog::projectChanged );

projectChanged();
}

QString QgsPostgresProjectStorageDialog::connectionName() const
@@ -89,20 +100,19 @@ void QgsPostgresProjectStorageDialog::populateSchemas()
{
mCboSchema->addItem( schema.name );
}

projectChanged();
}

void QgsPostgresProjectStorageDialog::populateProjects()
{
mCboProject->clear();

QgsPostgresProjectUri postUri;
postUri.connInfo = QgsPostgresConn::connUri( mCboConnection->currentText() );
postUri.schemaName = mCboSchema->currentText();
QString uri = QgsPostgresProjectStorage::makeUri( postUri );

QString uri = currentProjectUri();
QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromType( "postgresql" );
Q_ASSERT( storage );
mCboProject->addItems( storage->listProjects( uri ) );
projectChanged();
}

void QgsPostgresProjectStorageDialog::onOK()
@@ -125,3 +135,32 @@ void QgsPostgresProjectStorageDialog::onOK()

accept();
}

void QgsPostgresProjectStorageDialog::projectChanged()
{
mActionRemoveProject->setEnabled( mCboProject->count() != 0 && mCboProject->findText( mCboProject->currentText() ) != -1 );
}

void QgsPostgresProjectStorageDialog::removeProject()
{
int res = QMessageBox::question( this, tr( "Remove project" ),
tr( "Do you really want to remove the project \"%1\"?" ).arg( mCboProject->currentText() ),
QMessageBox::Yes | QMessageBox::No );
if ( res != QMessageBox::Yes )
return;

QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromType( "postgresql" );
Q_ASSERT( storage );
storage->removeProject( currentProjectUri() );
populateProjects();
}

QString QgsPostgresProjectStorageDialog::currentProjectUri( bool schemaOnly )
{
QgsPostgresProjectUri postUri;
postUri.connInfo = QgsPostgresConn::connUri( mCboConnection->currentText() );
postUri.schemaName = mCboSchema->currentText();
if ( !schemaOnly )
postUri.projectName = mCboProject->currentText();
return QgsPostgresProjectStorage::encodeUri( postUri );
}
@@ -16,15 +16,21 @@ class QgsPostgresProjectStorageDialog : public QDialog, private Ui::QgsPostgresP
QString schemaName() const;
QString projectName() const;

QString currentProjectUri( bool schemaOnly = false );

signals:

private slots:
void populateSchemas();
void populateProjects();
void onOK();
void projectChanged();
void removeProject();

private:

bool mSaving; //!< Whether using this dialog for loading or saving a project
QAction *mActionRemoveProject = nullptr;
};

#endif // QGSPOSTGRESPROJECTSTORAGEDIALOG_H

0 comments on commit fe686d3

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