Skip to content

Commit ad25261

Browse files
committedOct 8, 2018
More minor refactoring
1 parent fabc2c1 commit ad25261

File tree

3 files changed

+85
-7
lines changed

3 files changed

+85
-7
lines changed
 

‎src/providers/mssql/qgsmssqlconnection.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgsmssqlconnection.h"
1919
#include "qgslogger.h"
20+
#include "qgssettings.h"
2021
#include <QSqlDatabase>
2122
#include <QThread>
2223

@@ -105,6 +106,42 @@ bool QgsMssqlConnection::openDatabase( QSqlDatabase &db )
105106
return true;
106107
}
107108

109+
bool QgsMssqlConnection::geometryColumnsOnly( const QString &name )
110+
{
111+
QgsSettings settings;
112+
return settings.value( "/MSSQL/connections/" + name + "/geometryColumnsOnly", false ).toBool();
113+
}
114+
115+
void QgsMssqlConnection::setGeometryColumnsOnly( const QString &name, bool enabled )
116+
{
117+
QgsSettings settings;
118+
settings.setValue( "/MSSQL/connections/" + name + "/geometryColumnsOnly", enabled );
119+
}
120+
121+
bool QgsMssqlConnection::allowGeometrylessTables( const QString &name )
122+
{
123+
QgsSettings settings;
124+
return settings.value( "/MSSQL/connections/" + name + "/allowGeometrylessTables", false ).toBool();
125+
}
126+
127+
void QgsMssqlConnection::setAllowGeometrylessTables( const QString &name, bool enabled )
128+
{
129+
QgsSettings settings;
130+
settings.setValue( "/MSSQL/connections/" + name + "/allowGeometrylessTables", enabled );
131+
}
132+
133+
bool QgsMssqlConnection::useEstimatedMetadata( const QString &name )
134+
{
135+
QgsSettings settings;
136+
return settings.value( "/MSSQL/connections/" + name + "/estimatedMetadata", false ).toBool();
137+
}
138+
139+
void QgsMssqlConnection::setUseEstimatedMetadata( const QString &name, bool enabled )
140+
{
141+
QgsSettings settings;
142+
settings.setValue( "/MSSQL/connections/" + name + "/estimatedMetadata", enabled );
143+
}
144+
108145
QString QgsMssqlConnection::dbConnectionName( const QString &name )
109146
{
110147
// Starting with Qt 5.11, sharing the same connection between threads is not allowed.

‎src/providers/mssql/qgsmssqlconnection.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,46 @@ class QgsMssqlConnection
4242

4343
static bool openDatabase( QSqlDatabase &db );
4444

45+
/**
46+
* Returns true if the connection with matching \a name should
47+
* only look in the geometry_columns metadata table when scanning for tables.
48+
*
49+
* \see setGeometryColumnsOnly()
50+
*/
51+
static bool geometryColumnsOnly( const QString &name );
52+
53+
/**
54+
* Sets whether the connection with matching \a name should
55+
* only look in the geometry_columns metadata table when scanning for tables.
56+
*
57+
* \see geometryColumnsOnly()
58+
*/
59+
static void setGeometryColumnsOnly( const QString &name, bool enabled );
60+
61+
/**
62+
* Returns true if the connection with matching \a name should
63+
* show geometryless tables when scanning for tables.
64+
*/
65+
static bool allowGeometrylessTables( const QString &name );
66+
67+
/**
68+
* Sets whether the connection with matching \a name should
69+
* show geometryless tables when scanning for tables.
70+
*/
71+
static void setAllowGeometrylessTables( const QString &name, bool enabled );
72+
73+
/**
74+
* Returns true if the connection with matching \a name should
75+
* use estimated table parameters.
76+
*/
77+
static bool useEstimatedMetadata( const QString &name );
78+
79+
/**
80+
* Sets whether the connection with matching \a name should
81+
* use estimated table parameters.
82+
*/
83+
static void setUseEstimatedMetadata( const QString &name, bool enabled );
84+
4585
private:
4686

4787
/**

‎src/providers/mssql/qgsmssqlnewconnection.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ QgsMssqlNewConnection::QgsMssqlNewConnection( QWidget *parent, const QString &co
4949
txtHost->setText( settings.value( key + "/host" ).toString() );
5050
listDatabase->addItem( settings.value( key + "/database" ).toString() );
5151
listDatabase->setCurrentRow( 0 );
52-
cb_geometryColumns->setChecked( settings.value( key + "/geometryColumns", true ).toBool() );
53-
cb_allowGeometrylessTables->setChecked( settings.value( key + "/allowGeometrylessTables", true ).toBool() );
54-
cb_useEstimatedMetadata->setChecked( settings.value( key + "/estimatedMetadata", false ).toBool() );
52+
cb_geometryColumns->setChecked( QgsMssqlConnection::geometryColumnsOnly( connName ) );
53+
cb_allowGeometrylessTables->setChecked( QgsMssqlConnection::geometryColumnsOnly( connName ) );
54+
cb_useEstimatedMetadata->setChecked( QgsMssqlConnection::useEstimatedMetadata( connName ) );
5555

5656
if ( settings.value( key + "/saveUsername" ).toString() == QLatin1String( "true" ) )
5757
{
@@ -97,7 +97,8 @@ void QgsMssqlNewConnection::accept()
9797
settings.sync();
9898
}
9999

100-
baseKey += txtName->text();
100+
const QString connName = txtName->text();
101+
baseKey += connName;
101102
QString database;
102103
QListWidgetItem *item = listDatabase->currentItem();
103104
if ( item && item->text() != QLatin1String( "(from service)" ) )
@@ -112,9 +113,9 @@ void QgsMssqlNewConnection::accept()
112113
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : QString() );
113114
settings.setValue( baseKey + "/saveUsername", chkStoreUsername->isChecked() ? "true" : "false" );
114115
settings.setValue( baseKey + "/savePassword", chkStorePassword->isChecked() ? "true" : "false" );
115-
settings.setValue( baseKey + "/geometryColumns", cb_geometryColumns->isChecked() );
116-
settings.setValue( baseKey + "/allowGeometrylessTables", cb_allowGeometrylessTables->isChecked() );
117-
settings.setValue( baseKey + "/estimatedMetadata", cb_useEstimatedMetadata->isChecked() );
116+
QgsMssqlConnection::setGeometryColumnsOnly( connName, cb_geometryColumns->isChecked() );
117+
QgsMssqlConnection::setAllowGeometrylessTables( connName, cb_allowGeometrylessTables->isChecked() );
118+
QgsMssqlConnection::setUseEstimatedMetadata( connName, cb_useEstimatedMetadata->isChecked() );
118119

119120
QDialog::accept();
120121
}

0 commit comments

Comments
 (0)
Please sign in to comment.