Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GUI implementation to load/save projects in PostgreSQL
- Loading branch information
Showing
9 changed files
with
378 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/providers/postgres/qgspostgresprojectstoragedialog.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,127 @@ | |||
#include "qgspostgresprojectstoragedialog.h" | |||
|
|||
#include "qgspostgresconn.h" | |||
#include "qgspostgresconnpool.h" | |||
#include "qgspostgresprojectstorage.h" | |||
|
|||
#include "qgsapplication.h" | |||
#include "qgsprojectstorage.h" | |||
#include "qgsprojectstorageregistry.h" | |||
|
|||
#include <QMessageBox> | |||
|
|||
QgsPostgresProjectStorageDialog::QgsPostgresProjectStorageDialog( bool saving, QWidget *parent ) | |||
: QDialog( parent ) | |||
, mSaving( saving ) | |||
{ | |||
setupUi( this ); | |||
|
|||
connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsPostgresProjectStorageDialog::onOK ); | |||
|
|||
if ( saving ) | |||
{ | |||
setWindowTitle( tr( "Save project to PostgreSQL" ) ); | |||
mCboProject->setEditable( true ); | |||
} | |||
else | |||
{ | |||
setWindowTitle( tr( "Load project from PostgreSQL" ) ); | |||
} | |||
|
|||
connect( mCboConnection, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPostgresProjectStorageDialog::populateSchemas ); | |||
|
|||
// populate connections | |||
mCboConnection->addItems( QgsPostgresConn::connectionList() ); | |||
|
|||
// If possible, set the item currently displayed database | |||
QString toSelect = QgsPostgresConn::selectedConnection(); | |||
mCboConnection->setCurrentIndex( mCboConnection->findText( toSelect ) ); | |||
|
|||
connect( mCboSchema, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPostgresProjectStorageDialog::populateProjects ); | |||
} | |||
|
|||
QString QgsPostgresProjectStorageDialog::connectionName() const | |||
{ | |||
return mCboConnection->currentText(); | |||
} | |||
|
|||
QString QgsPostgresProjectStorageDialog::schemaName() const | |||
{ | |||
return mCboSchema->currentText(); | |||
} | |||
|
|||
QString QgsPostgresProjectStorageDialog::projectName() const | |||
{ | |||
return mCboProject->currentText(); | |||
} | |||
|
|||
void QgsPostgresProjectStorageDialog::populateSchemas() | |||
{ | |||
mCboSchema->clear(); | |||
mCboProject->clear(); | |||
|
|||
QString name = mCboConnection->currentText(); | |||
QgsDataSourceUri uri = QgsPostgresConn::connUri( name ); | |||
|
|||
QApplication::setOverrideCursor( Qt::WaitCursor ); | |||
|
|||
QgsPostgresConn *conn = QgsPostgresConnPool::instance()->acquireConnection( uri.connectionInfo( false ) ); | |||
if ( !conn ) | |||
{ | |||
QApplication::restoreOverrideCursor(); | |||
QMessageBox::critical( this, tr( "Error" ), tr( "Connection failed" ) + "\n" + uri.connectionInfo( false ) ); | |||
return; | |||
} | |||
|
|||
QList<QgsPostgresSchemaProperty> schemas; | |||
bool ok = conn->getSchemas( schemas ); | |||
QgsPostgresConnPool::instance()->releaseConnection( conn ); | |||
|
|||
QApplication::restoreOverrideCursor(); | |||
|
|||
if ( !ok ) | |||
{ | |||
QMessageBox::critical( this, tr( "Error" ), tr( "Failed to get schemas" ) ); | |||
return; | |||
} | |||
|
|||
for ( const QgsPostgresSchemaProperty &schema : qAsConst( schemas ) ) | |||
{ | |||
mCboSchema->addItem( schema.name ); | |||
} | |||
} | |||
|
|||
void QgsPostgresProjectStorageDialog::populateProjects() | |||
{ | |||
mCboProject->clear(); | |||
|
|||
QgsPostgresProjectUri postUri; | |||
postUri.connInfo = QgsPostgresConn::connUri( mCboConnection->currentText() ); | |||
postUri.schemaName = mCboSchema->currentText(); | |||
QString uri = QgsPostgresProjectStorage::makeUri( postUri ); | |||
|
|||
QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromType( "postgresql" ); | |||
Q_ASSERT( storage ); | |||
mCboProject->addItems( storage->listProjects( uri ) ); | |||
} | |||
|
|||
void QgsPostgresProjectStorageDialog::onOK() | |||
{ | |||
// check that the fields are filled in | |||
if ( mCboProject->currentText().isEmpty() ) | |||
return; | |||
|
|||
if ( mSaving ) | |||
{ | |||
if ( mCboProject->findText( mCboProject->currentText() ) != -1 ) | |||
{ | |||
int res = QMessageBox::question( this, tr( "Overwrite project" ), | |||
tr( "A project with the same name already exists. Would you like to overwrite it?" ), | |||
QMessageBox::Yes | QMessageBox::No ); | |||
if ( res != QMessageBox::Yes ) | |||
return; | |||
} | |||
} | |||
|
|||
accept(); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
#ifndef QGSPOSTGRESPROJECTSTORAGEDIALOG_H | |||
#define QGSPOSTGRESPROJECTSTORAGEDIALOG_H | |||
|
|||
#include <QDialog> | |||
|
|||
#include "ui_qgspostgresprojectstoragedialog.h" | |||
|
|||
|
|||
class QgsPostgresProjectStorageDialog : public QDialog, private Ui::QgsPostgresProjectStorageDialog | |||
{ | |||
Q_OBJECT | |||
public: | |||
explicit QgsPostgresProjectStorageDialog( bool saving, QWidget *parent = nullptr ); | |||
|
|||
QString connectionName() const; | |||
QString schemaName() const; | |||
QString projectName() const; | |||
|
|||
signals: | |||
|
|||
private slots: | |||
void populateSchemas(); | |||
void populateProjects(); | |||
void onOK(); | |||
|
|||
private: | |||
bool mSaving; //!< Whether using this dialog for loading or saving a project | |||
}; | |||
|
|||
#endif // QGSPOSTGRESPROJECTSTORAGEDIALOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.