Skip to content
Permalink
Browse files

More minor refactoring

  • Loading branch information
nyalldawson committed Oct 8, 2018
1 parent fabc2c1 commit ad25261708a8ff75e4e03ebb4b40ca6029d44e9d
@@ -17,6 +17,7 @@

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

@@ -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.
@@ -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:

/**
@@ -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" ) )
{
@@ -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)" ) )
@@ -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();
}

0 comments on commit ad25261

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