31using namespace Qt::StringLiterals;
33QString
QgsGdalGuiUtils::createDatabaseURI(
const QString &connectionType,
const QString &host,
const QString &database, QString port,
const QString &configId, QString username, QString password,
bool expandAuthConfig )
39 if ( !configId.isEmpty() )
48 if ( connectionType ==
"ESRI Personal GeoDatabase"_L1 )
50 uri =
"PGeo:" + database;
52 else if ( connectionType ==
"ESRI ArcSDE"_L1 )
57 uri =
"SDE:" + host +
",PORT:" + port +
',' + database +
',' + username +
',' + password;
59 else if ( connectionType ==
"Informix DataBlade"_L1 )
62 uri =
"IDB:dbname=" + database;
64 if ( !host.isEmpty() )
65 uri += u
" server=%1"_s.arg( host );
67 if ( !username.isEmpty() )
69 uri += u
" user=%1"_s.arg( username );
71 if ( !password.isEmpty() )
72 uri += u
" pass=%1"_s.arg( password );
75 else if ( connectionType ==
"Ingres"_L1 )
78 uri =
"@driver=ingres,dbname=" + database;
79 if ( !username.isEmpty() )
81 uri += u
",userid=%1"_s.arg( username );
83 if ( !password.isEmpty() )
84 uri += u
",password=%1"_s.arg( password );
87 else if ( connectionType ==
"MySQL"_L1 )
89 uri =
"MySQL:" + database;
91 if ( !host.isEmpty() )
93 uri += u
",host=%1"_s.arg( host );
95 if ( !port.isEmpty() )
96 uri += u
",port=%1"_s.arg( port );
99 if ( !username.isEmpty() )
101 uri += u
",user=%1"_s.arg( username );
103 if ( !password.isEmpty() )
104 uri += u
",password=%1"_s.arg( password );
107 else if ( connectionType ==
"MSSQL"_L1 )
111 if ( !host.isEmpty() )
113 uri += u
";server=%1"_s.arg( host );
115 if ( !port.isEmpty() )
116 uri += u
",%1"_s.arg( port );
119 if ( !username.isEmpty() )
121 uri += u
";uid=%1"_s.arg( username );
123 if ( !password.isEmpty() )
124 uri += u
";pwd=%1"_s.arg( password );
127 uri +=
";trusted_connection=yes"_L1;
129 if ( !database.isEmpty() )
130 uri += u
";database=%1"_s.arg( database );
132 else if ( connectionType ==
"Oracle Spatial"_L1 )
134 uri =
"OCI:" + username;
136 if ( ( !username.isEmpty() && !password.isEmpty() ) || ( username.isEmpty() && password.isEmpty() ) )
139 if ( !password.isEmpty() )
143 if ( !host.isEmpty() || !database.isEmpty() )
147 if ( !host.isEmpty() )
150 if ( !port.isEmpty() )
154 if ( !database.isEmpty() )
156 if ( !host.isEmpty() )
162 else if ( connectionType ==
"ODBC"_L1 )
164 if ( !username.isEmpty() )
166 if ( password.isEmpty() )
168 uri =
"ODBC:" + username +
'@' + database;
172 uri =
"ODBC:" + username +
'/' + password +
'@' + database;
177 uri =
"ODBC:" + database;
180 else if ( connectionType ==
"OGDI Vectors"_L1 )
183 else if ( connectionType ==
"PostgreSQL"_L1 )
185 uri =
"PG:dbname='" + database +
'\'';
187 if ( !host.isEmpty() )
189 uri += u
" host='%1'"_s.arg( host );
191 if ( !port.isEmpty() )
192 uri += u
" port='%1'"_s.arg( port );
195 if ( !username.isEmpty() )
197 uri += u
" user='%1'"_s.arg( username );
199 if ( !password.isEmpty() )
200 uri += u
" password='%1'"_s.arg( password );
206 if ( !( configId.isEmpty() ) )
208 if ( !expandAuthConfig )
210 uri += u
" authcfg='%1'"_s.arg( configId );
214 QStringList connectionItems;
215 connectionItems << uri;
218 uri = connectionItems.join( QString() );
222 QgsDebugMsgLevel(
"Connection type is=" + connectionType +
" and uri=" + uri, 2 );
227QString
QgsGdalGuiUtils::createProtocolURI(
const QString &type,
const QString &url,
const QString &configId,
const QString &username,
const QString &password,
bool expandAuthConfig )
231 if ( type ==
"vsicurl"_L1 )
233 prefix = u
"/vsicurl/"_s;
234 if ( !uri.startsWith( prefix ) )
237 if ( !uri.startsWith(
"http://"_L1 ) && !uri.startsWith(
"https://"_L1 ) && !uri.startsWith(
"ftp://"_L1 ) )
239 uri.prepend( u
"http://"_s );
241 uri.prepend( prefix );
244 else if ( type ==
"vsis3"_L1
245 || type ==
"vsigs"_L1
246 || type ==
"vsiaz"_L1
247 || type ==
"vsiadls"_L1
248 || type ==
"vsioss"_L1
249 || type ==
"vsiswift"_L1
250 || type ==
"vsihdfs"_L1 )
252 prefix = u
"/%1/"_s.arg( type );
253 if ( !uri.startsWith( prefix ) )
255 uri.prepend( prefix );
259 else if ( type.startsWith(
"GeoJSON"_L1 ) )
263 else if ( type ==
"CouchDB"_L1 )
265 prefix = u
"couchdb:"_s;
266 if ( !uri.startsWith( prefix ) )
268 uri.prepend( prefix );
271 else if ( type ==
"DODS/OPeNDAP"_L1 )
274 if ( !uri.startsWith( prefix ) )
276 uri.prepend( prefix );
279 else if ( type ==
"WFS3"_L1 )
282 if ( !uri.startsWith( prefix ) )
284 uri.prepend( prefix );
289 if ( !configId.isEmpty() )
291 if ( expandAuthConfig )
293 QStringList connectionItems;
294 connectionItems << uri;
297 uri = connectionItems.join( QString() );
302 uri += u
" authcfg='%1'"_s.arg( configId );
305 else if ( !( username.isEmpty() || password.isEmpty() ) )
307 uri.replace(
"://"_L1, u
"://%1:%2@"_s.arg( username, password ) );
314 switch ( option.
type )
318 QComboBox *cb =
new QComboBox( parent );
319 if ( includeDefaultChoices )
323 for (
const QString &val : std::as_const( option.
options ) )
325 cb->addItem( val, val );
327 cb->setCurrentIndex( 0 );
334 QComboBox *cb =
new QComboBox( parent );
335 if ( includeDefaultChoices )
339 cb->addItem( QObject::tr(
"Yes" ),
"YES" );
340 cb->addItem( QObject::tr(
"No" ),
"NO" );
341 cb->setCurrentIndex( 0 );
351 if ( includeDefaultChoices )
353 res->setPlaceholderText( QObject::tr(
"Default" ) );
362 if ( option.
minimum.isValid() )
363 res->setMinimum( option.
minimum.toInt() );
365 res->setMinimum( 0 );
366 if ( option.
maximum.isValid() )
367 res->setMaximum( option.
maximum.toInt() );
369 res->setMaximum( std::numeric_limits<int>::max() - 1 );
370 if ( includeDefaultChoices )
372 res->setMinimum( res->minimum() - 1 );
387 if ( option.
minimum.isValid() )
388 res->setMinimum( option.
minimum.toDouble() );
390 res->setMinimum( 0 );
391 if ( option.
maximum.isValid() )
392 res->setMaximum( option.
maximum.toDouble() );
394 res->setMaximum( std::numeric_limits<double>::max() - 1 );
397 if ( includeDefaultChoices )
399 res->setMinimum( res->minimum() - 1 );
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
void setClearValueMode(ClearValueMode mode, const QString &clearValueText=QString())
Defines if the clear value should be the minimum or maximum values of the widget or a custom value.
void clear() override
Sets the current value to the value defined by the clear value.
@ MinimumValue
Reset value to minimum().
void setClearValue(double customValue, const QString &clearValueText=QString())
Defines the clear value as a custom value and will automatically set the clear value mode to CustomVa...
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
void setShowClearButton(bool visible)
Sets whether the widget's clear button is visible.
static QString createProtocolURI(const QString &type, const QString &url, const QString &configId, const QString &username, const QString &password, bool expandAuthConfig=false)
Create protocol uri from connection parameters.
static QString createDatabaseURI(const QString &connectionType, const QString &host, const QString &database, QString port, const QString &configId, QString username, QString password, bool expandAuthConfig=false)
Create database uri from connection parameters.
static QWidget * createWidgetForOption(const QgsGdalOption &option, QWidget *parent=nullptr, bool includeDefaultChoices=false)
Creates a new widget for configuration a GDAL option.
Encapsulates the definition of a GDAL configuration option.
QVariant defaultValue
Default value.
QVariant maximum
Maximum acceptable value.
QStringList options
Available choices, for Select options.
QVariant minimum
Minimum acceptable value.
@ Select
Selection option.
QString description
Option description.
A spin box with a clear button that will set the value to the defined clear value.
@ MinimumValue
Reset value to minimum().
void setClearValueMode(ClearValueMode mode, const QString &clearValueText=QString())
Defines if the clear value should be the minimum or maximum values of the widget or a custom value.
void setClearValue(int customValue, const QString &clearValueText=QString())
Defines the clear value as a custom value and will automatically set the clear value mode to CustomVa...
void clear() override
Sets the current value to the value defined by the clear value.
static QVariant createNullVariant(QMetaType::Type metaType)
Helper method to properly create a null QVariant from a metaType Returns the created QVariant.
#define QgsDebugMsgLevel(str, level)