Skip to content

Commit

Permalink
More minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 8, 2018
1 parent fabc2c1 commit ad25261
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 7 deletions.
37 changes: 37 additions & 0 deletions src/providers/mssql/qgsmssqlconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "qgsmssqlconnection.h"
#include "qgslogger.h"
#include "qgssettings.h"
#include <QSqlDatabase>
#include <QThread>

Expand Down Expand Up @@ -105,6 +106,42 @@ bool QgsMssqlConnection::openDatabase( QSqlDatabase &db )
return true;
}

bool QgsMssqlConnection::geometryColumnsOnly( const QString &name )
{
QgsSettings settings;
return settings.value( "/MSSQL/connections/" + name + "/geometryColumnsOnly", false ).toBool();
}

void QgsMssqlConnection::setGeometryColumnsOnly( const QString &name, bool enabled )
{
QgsSettings settings;
settings.setValue( "/MSSQL/connections/" + name + "/geometryColumnsOnly", enabled );
}

bool QgsMssqlConnection::allowGeometrylessTables( const QString &name )
{
QgsSettings settings;
return settings.value( "/MSSQL/connections/" + name + "/allowGeometrylessTables", false ).toBool();
}

void QgsMssqlConnection::setAllowGeometrylessTables( const QString &name, bool enabled )
{
QgsSettings settings;
settings.setValue( "/MSSQL/connections/" + name + "/allowGeometrylessTables", enabled );
}

bool QgsMssqlConnection::useEstimatedMetadata( const QString &name )
{
QgsSettings settings;
return settings.value( "/MSSQL/connections/" + name + "/estimatedMetadata", false ).toBool();
}

void QgsMssqlConnection::setUseEstimatedMetadata( const QString &name, bool enabled )
{
QgsSettings settings;
settings.setValue( "/MSSQL/connections/" + name + "/estimatedMetadata", enabled );
}

QString QgsMssqlConnection::dbConnectionName( const QString &name )
{
// Starting with Qt 5.11, sharing the same connection between threads is not allowed.
Expand Down
40 changes: 40 additions & 0 deletions src/providers/mssql/qgsmssqlconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,46 @@ class QgsMssqlConnection

static bool openDatabase( QSqlDatabase &db );

/**
* Returns true if the connection with matching \a name should
* only look in the geometry_columns metadata table when scanning for tables.
*
* \see setGeometryColumnsOnly()
*/
static bool geometryColumnsOnly( const QString &name );

/**
* Sets whether the connection with matching \a name should
* only look in the geometry_columns metadata table when scanning for tables.
*
* \see geometryColumnsOnly()
*/
static void setGeometryColumnsOnly( const QString &name, bool enabled );

/**
* Returns true if the connection with matching \a name should
* show geometryless tables when scanning for tables.
*/
static bool allowGeometrylessTables( const QString &name );

/**
* Sets whether the connection with matching \a name should
* show geometryless tables when scanning for tables.
*/
static void setAllowGeometrylessTables( const QString &name, bool enabled );

/**
* Returns true if the connection with matching \a name should
* use estimated table parameters.
*/
static bool useEstimatedMetadata( const QString &name );

/**
* Sets whether the connection with matching \a name should
* use estimated table parameters.
*/
static void setUseEstimatedMetadata( const QString &name, bool enabled );

private:

/**
Expand Down
15 changes: 8 additions & 7 deletions src/providers/mssql/qgsmssqlnewconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ QgsMssqlNewConnection::QgsMssqlNewConnection( QWidget *parent, const QString &co
txtHost->setText( settings.value( key + "/host" ).toString() );
listDatabase->addItem( settings.value( key + "/database" ).toString() );
listDatabase->setCurrentRow( 0 );
cb_geometryColumns->setChecked( settings.value( key + "/geometryColumns", true ).toBool() );
cb_allowGeometrylessTables->setChecked( settings.value( key + "/allowGeometrylessTables", true ).toBool() );
cb_useEstimatedMetadata->setChecked( settings.value( key + "/estimatedMetadata", false ).toBool() );
cb_geometryColumns->setChecked( QgsMssqlConnection::geometryColumnsOnly( connName ) );
cb_allowGeometrylessTables->setChecked( QgsMssqlConnection::geometryColumnsOnly( connName ) );
cb_useEstimatedMetadata->setChecked( QgsMssqlConnection::useEstimatedMetadata( connName ) );

if ( settings.value( key + "/saveUsername" ).toString() == QLatin1String( "true" ) )
{
Expand Down Expand Up @@ -97,7 +97,8 @@ void QgsMssqlNewConnection::accept()
settings.sync();
}

baseKey += txtName->text();
const QString connName = txtName->text();
baseKey += connName;
QString database;
QListWidgetItem *item = listDatabase->currentItem();
if ( item && item->text() != QLatin1String( "(from service)" ) )
Expand All @@ -112,9 +113,9 @@ void QgsMssqlNewConnection::accept()
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : QString() );
settings.setValue( baseKey + "/saveUsername", chkStoreUsername->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/savePassword", chkStorePassword->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/geometryColumns", cb_geometryColumns->isChecked() );
settings.setValue( baseKey + "/allowGeometrylessTables", cb_allowGeometrylessTables->isChecked() );
settings.setValue( baseKey + "/estimatedMetadata", cb_useEstimatedMetadata->isChecked() );
QgsMssqlConnection::setGeometryColumnsOnly( connName, cb_geometryColumns->isChecked() );
QgsMssqlConnection::setAllowGeometrylessTables( connName, cb_allowGeometrylessTables->isChecked() );
QgsMssqlConnection::setUseEstimatedMetadata( connName, cb_useEstimatedMetadata->isChecked() );

QDialog::accept();
}
Expand Down

0 comments on commit ad25261

Please sign in to comment.