Skip to content
Permalink
Browse files

[oracle] Fix clazy warnings in new connection dialog

  • Loading branch information
nyalldawson committed Apr 22, 2018
1 parent 9242d2f commit 529173f3fad04f5434886bdab18fa17372747c94
Showing with 54 additions and 58 deletions.
  1. +49 −54 src/providers/oracle/qgsoraclenewconnection.cpp
  2. +5 −4 src/providers/oracle/qgsoraclenewconnection.h
@@ -26,69 +26,71 @@
#include "qgsoracleconnpool.h"

QgsOracleNewConnection::QgsOracleNewConnection( QWidget *parent, const QString &connName, Qt::WindowFlags fl )
: QDialog( parent, fl ), mOriginalConnName( connName )
: QDialog( parent, fl )
, mOriginalConnName( connName )
{
setupUi( this );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsOracleNewConnection::showHelp );
connect( btnConnect, &QPushButton::clicked, this, &QgsOracleNewConnection::testConnection );

if ( !connName.isEmpty() )
{
// populate the dialog with the information stored for the connection
// populate the fields with the stored setting parameters
QgsSettings settings;

QString key = "/Oracle/connections/" + connName;
txtDatabase->setText( settings.value( key + "/database" ).toString() );
txtHost->setText( settings.value( key + "/host" ).toString() );
QString port = settings.value( key + "/port" ).toString();
QString key = QStringLiteral( "/Oracle/connections/" ) + connName;
txtDatabase->setText( settings.value( key + QStringLiteral( "/database" ) ).toString() );
txtHost->setText( settings.value( key + QStringLiteral( "/host" ) ).toString() );
QString port = settings.value( key + QStringLiteral( "/port" ) ).toString();
if ( port.length() == 0 )
{
port = "1521";
port = QStringLiteral( "1521" );
}
txtPort->setText( port );
txtOptions->setText( settings.value( key + "/dboptions" ).toString() );
txtWorkspace->setText( settings.value( key + "/dbworkspace" ).toString() );
cb_userTablesOnly->setChecked( settings.value( key + "/userTablesOnly", false ).toBool() );
cb_geometryColumnsOnly->setChecked( settings.value( key + "/geometryColumnsOnly", true ).toBool() );
cb_allowGeometrylessTables->setChecked( settings.value( key + "/allowGeometrylessTables", false ).toBool() );
cb_useEstimatedMetadata->setChecked( settings.value( key + "/estimatedMetadata", false ).toBool() );
cb_onlyExistingTypes->setChecked( settings.value( key + "/onlyExistingTypes", true ).toBool() );
cb_includeGeoAttributes->setChecked( settings.value( key + "/includeGeoAttributes", false ).toBool() );

if ( settings.value( key + "/saveUsername" ).toString() == "true" )
txtOptions->setText( settings.value( key + QStringLiteral( "/dboptions" ) ).toString() );
txtWorkspace->setText( settings.value( key + QStringLiteral( "/dbworkspace" ) ).toString() );
cb_userTablesOnly->setChecked( settings.value( key + QStringLiteral( "/userTablesOnly" ), false ).toBool() );
cb_geometryColumnsOnly->setChecked( settings.value( key + QStringLiteral( "/geometryColumnsOnly" ), true ).toBool() );
cb_allowGeometrylessTables->setChecked( settings.value( key + QStringLiteral( "/allowGeometrylessTables" ), false ).toBool() );
cb_useEstimatedMetadata->setChecked( settings.value( key + QStringLiteral( "/estimatedMetadata" ), false ).toBool() );
cb_onlyExistingTypes->setChecked( settings.value( key + QStringLiteral( "/onlyExistingTypes" ), true ).toBool() );
cb_includeGeoAttributes->setChecked( settings.value( key + QStringLiteral( "/includeGeoAttributes" ), false ).toBool() );

if ( settings.value( key + QStringLiteral( "/saveUsername" ) ).toString() == QLatin1String( "true" ) )
{
txtUsername->setText( settings.value( key + "/username" ).toString() );
txtUsername->setText( settings.value( key + QStringLiteral( "/username" ) ).toString() );
chkStoreUsername->setChecked( true );
}

if ( settings.value( key + "/savePassword" ).toString() == "true" )
if ( settings.value( key + QStringLiteral( "/savePassword" ) ).toString() == QLatin1String( "true" ) )
{
txtPassword->setText( settings.value( key + "/password" ).toString() );
txtPassword->setText( settings.value( key + QStringLiteral( "/password" ) ).toString() );
chkStorePassword->setChecked( true );
}

// Old save setting
if ( settings.contains( key + "/save" ) )
if ( settings.contains( key + QStringLiteral( "/save" ) ) )
{
txtUsername->setText( settings.value( key + "/username" ).toString() );
txtUsername->setText( settings.value( key + QStringLiteral( "/username" ) ).toString() );
chkStoreUsername->setChecked( !txtUsername->text().isEmpty() );

if ( settings.value( key + "/save" ).toString() == "true" )
txtPassword->setText( settings.value( key + "/password" ).toString() );
if ( settings.value( key + QStringLiteral( "/save" ) ).toString() == QLatin1String( "true" ) )
txtPassword->setText( settings.value( key + QStringLiteral( "/password" ) ).toString() );

chkStorePassword->setChecked( true );
}

txtName->setText( connName );
}
txtName->setValidator( new QRegExpValidator( QRegExp( "[^\\/]+" ), txtName ) );
txtName->setValidator( new QRegExpValidator( QRegExp( QStringLiteral( "[^\\/]+" ) ), txtName ) );
}
//! Autoconnected SLOTS *

void QgsOracleNewConnection::accept()
{
QgsSettings settings;
QString baseKey = "/Oracle/connections/";
settings.setValue( baseKey + "selected", txtName->text() );
QString baseKey = QStringLiteral( "/Oracle/connections/" );
settings.setValue( baseKey + QStringLiteral( "selected" ), txtName->text() );

if ( chkStorePassword->isChecked() &&
QMessageBox::question( this,
@@ -101,8 +103,8 @@ void QgsOracleNewConnection::accept()

// warn if entry was renamed to an existing connection
if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( txtName->text(), Qt::CaseInsensitive ) != 0 ) &&
( settings.contains( baseKey + txtName->text() + "/service" ) ||
settings.contains( baseKey + txtName->text() + "/host" ) ) &&
( settings.contains( baseKey + txtName->text() + QStringLiteral( "/service" ) ) ||
settings.contains( baseKey + txtName->text() + QStringLiteral( "/host" ) ) ) &&
QMessageBox::question( this,
tr( "Save Connection" ),
tr( "Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
@@ -119,33 +121,33 @@ void QgsOracleNewConnection::accept()
}

baseKey += txtName->text();
settings.setValue( baseKey + "/database", txtDatabase->text() );
settings.setValue( baseKey + "/host", txtHost->text() );
settings.setValue( baseKey + "/port", txtPort->text() );
settings.setValue( baseKey + "/username", chkStoreUsername->isChecked() ? txtUsername->text() : "" );
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" );
settings.setValue( baseKey + "/userTablesOnly", cb_userTablesOnly->isChecked() );
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
settings.setValue( baseKey + "/allowGeometrylessTables", cb_allowGeometrylessTables->isChecked() );
settings.setValue( baseKey + "/estimatedMetadata", cb_useEstimatedMetadata->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/onlyExistingTypes", cb_onlyExistingTypes->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/includeGeoAttributes", cb_includeGeoAttributes->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/saveUsername", chkStoreUsername->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/savePassword", chkStorePassword->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/dboptions", txtOptions->text() );
settings.setValue( baseKey + "/dbworkspace", txtWorkspace->text() );
settings.setValue( baseKey + QStringLiteral( "/database" ), txtDatabase->text() );
settings.setValue( baseKey + QStringLiteral( "/host" ), txtHost->text() );
settings.setValue( baseKey + QStringLiteral( "/port" ), txtPort->text() );
settings.setValue( baseKey + QStringLiteral( "/username" ), chkStoreUsername->isChecked() ? txtUsername->text() : QString() );
settings.setValue( baseKey + QStringLiteral( "/password" ), chkStorePassword->isChecked() ? txtPassword->text() : QString() );
settings.setValue( baseKey + QStringLiteral( "/userTablesOnly" ), cb_userTablesOnly->isChecked() );
settings.setValue( baseKey + QStringLiteral( "/geometryColumnsOnly" ), cb_geometryColumnsOnly->isChecked() );
settings.setValue( baseKey + QStringLiteral( "/allowGeometrylessTables" ), cb_allowGeometrylessTables->isChecked() );
settings.setValue( baseKey + QStringLiteral( "/estimatedMetadata" ), cb_useEstimatedMetadata->isChecked() ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
settings.setValue( baseKey + QStringLiteral( "/onlyExistingTypes" ), cb_onlyExistingTypes->isChecked() ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
settings.setValue( baseKey + QStringLiteral( "/includeGeoAttributes" ), cb_includeGeoAttributes->isChecked() ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
settings.setValue( baseKey + QStringLiteral( "/saveUsername" ), chkStoreUsername->isChecked() ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
settings.setValue( baseKey + QStringLiteral( "/savePassword" ), chkStorePassword->isChecked() ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
settings.setValue( baseKey + QStringLiteral( "/dboptions" ), txtOptions->text() );
settings.setValue( baseKey + QStringLiteral( "/dbworkspace" ), txtWorkspace->text() );

QDialog::accept();
}

void QgsOracleNewConnection::on_btnConnect_clicked()
void QgsOracleNewConnection::testConnection()
{
QgsDataSourceUri uri;
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text() );
if ( !txtOptions->text().isEmpty() )
uri.setParam( "dboptions", txtOptions->text() );
uri.setParam( QStringLiteral( "dboptions" ), txtOptions->text() );
if ( !txtWorkspace->text().isEmpty() )
uri.setParam( "dbworkspace", txtWorkspace->text() );
uri.setParam( QStringLiteral( "dbworkspace" ), txtWorkspace->text() );

QgsOracleConn *conn = QgsOracleConnPool::instance()->acquireConnection( QgsOracleConn::toPoolName( uri ) );

@@ -164,13 +166,6 @@ void QgsOracleNewConnection::on_btnConnect_clicked()
}
}

//! End Autoconnected SLOTS *

QgsOracleNewConnection::~QgsOracleNewConnection()
{
}


void QgsOracleNewConnection::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#connecting-to-oracle-spatial" ) );
@@ -31,15 +31,16 @@ class QgsOracleNewConnection : public QDialog, private Ui::QgsOracleNewConnectio
public:
//! Constructor
QgsOracleNewConnection( QWidget *parent = nullptr, const QString &connName = QString(), Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
//! Destructor
~QgsOracleNewConnection();

QString originalConnName() const { return mOriginalConnName; }
QString connName() const { return txtName->text(); }

public slots:
void accept();
void on_btnConnect_clicked();
void accept() override;

private slots:
void testConnection();

private:
QString mOriginalConnName; //store initial name to delete entry in case of rename
void showHelp();

0 comments on commit 529173f

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