31using namespace Qt::StringLiterals;
34 const QString &connectionType,
const QString &host,
const QString &database, QString port,
const QString &configId, QString username, QString password,
bool expandAuthConfig
41 if ( !configId.isEmpty() )
50 if ( connectionType ==
"ESRI Personal GeoDatabase"_L1 )
52 uri =
"PGeo:" + database;
54 else if ( connectionType ==
"ESRI ArcSDE"_L1 )
59 uri =
"SDE:" + host +
",PORT:" + port +
',' + database +
',' + username +
',' + password;
61 else if ( connectionType ==
"Informix DataBlade"_L1 )
64 uri =
"IDB:dbname=" + database;
66 if ( !host.isEmpty() )
67 uri += u
" server=%1"_s.arg( host );
69 if ( !username.isEmpty() )
71 uri += u
" user=%1"_s.arg( username );
73 if ( !password.isEmpty() )
74 uri += u
" pass=%1"_s.arg( password );
77 else if ( connectionType ==
"Ingres"_L1 )
80 uri =
"@driver=ingres,dbname=" + database;
81 if ( !username.isEmpty() )
83 uri += u
",userid=%1"_s.arg( username );
85 if ( !password.isEmpty() )
86 uri += u
",password=%1"_s.arg( password );
89 else if ( connectionType ==
"MySQL"_L1 )
91 uri =
"MySQL:" + database;
93 if ( !host.isEmpty() )
95 uri += u
",host=%1"_s.arg( host );
97 if ( !port.isEmpty() )
98 uri += u
",port=%1"_s.arg( port );
101 if ( !username.isEmpty() )
103 uri += u
",user=%1"_s.arg( username );
105 if ( !password.isEmpty() )
106 uri += u
",password=%1"_s.arg( password );
109 else if ( connectionType ==
"MSSQL"_L1 )
113 if ( !host.isEmpty() )
115 uri += u
";server=%1"_s.arg( host );
117 if ( !port.isEmpty() )
118 uri += u
",%1"_s.arg( port );
121 if ( !username.isEmpty() )
123 uri += u
";uid=%1"_s.arg( username );
125 if ( !password.isEmpty() )
126 uri += u
";pwd=%1"_s.arg( password );
129 uri +=
";trusted_connection=yes"_L1;
131 if ( !database.isEmpty() )
132 uri += u
";database=%1"_s.arg( database );
134 else if ( connectionType ==
"Oracle Spatial"_L1 )
136 uri =
"OCI:" + username;
138 if ( ( !username.isEmpty() && !password.isEmpty() ) || ( username.isEmpty() && password.isEmpty() ) )
141 if ( !password.isEmpty() )
145 if ( !host.isEmpty() || !database.isEmpty() )
149 if ( !host.isEmpty() )
152 if ( !port.isEmpty() )
156 if ( !database.isEmpty() )
158 if ( !host.isEmpty() )
164 else if ( connectionType ==
"ODBC"_L1 )
166 if ( !username.isEmpty() )
168 if ( password.isEmpty() )
170 uri =
"ODBC:" + username +
'@' + database;
174 uri =
"ODBC:" + username +
'/' + password +
'@' + database;
179 uri =
"ODBC:" + database;
182 else if ( connectionType ==
"OGDI Vectors"_L1 )
185 else if ( connectionType ==
"PostgreSQL"_L1 )
187 uri =
"PG:dbname='" + database +
'\'';
189 if ( !host.isEmpty() )
191 uri += u
" host='%1'"_s.arg( host );
193 if ( !port.isEmpty() )
194 uri += u
" port='%1'"_s.arg( port );
197 if ( !username.isEmpty() )
199 uri += u
" user='%1'"_s.arg( username );
201 if ( !password.isEmpty() )
202 uri += u
" password='%1'"_s.arg( password );
208 if ( !( configId.isEmpty() ) )
210 if ( !expandAuthConfig )
212 uri += u
" authcfg='%1'"_s.arg( configId );
216 QStringList connectionItems;
217 connectionItems << uri;
220 uri = connectionItems.join( QString() );
224 QgsDebugMsgLevel(
"Connection type is=" + connectionType +
" and uri=" + uri, 2 );
229QString
QgsGdalGuiUtils::createProtocolURI(
const QString &type,
const QString &url,
const QString &configId,
const QString &username,
const QString &password,
bool expandAuthConfig )
233 if ( type ==
"vsicurl"_L1 )
235 prefix = u
"/vsicurl/"_s;
236 if ( !uri.startsWith( prefix ) )
239 if ( !uri.startsWith(
"http://"_L1 ) && !uri.startsWith(
"https://"_L1 ) && !uri.startsWith(
"ftp://"_L1 ) )
241 uri.prepend( u
"http://"_s );
243 uri.prepend( prefix );
246 else if ( type ==
"vsis3"_L1 || type ==
"vsigs"_L1 || type ==
"vsiaz"_L1 || type ==
"vsiadls"_L1 || type ==
"vsioss"_L1 || type ==
"vsiswift"_L1 || type ==
"vsihdfs"_L1 )
248 prefix = u
"/%1/"_s.arg( type );
249 if ( !uri.startsWith( prefix ) )
251 uri.prepend( prefix );
255 else if ( type.startsWith(
"GeoJSON"_L1 ) )
259 else if ( type ==
"CouchDB"_L1 )
261 prefix = u
"couchdb:"_s;
262 if ( !uri.startsWith( prefix ) )
264 uri.prepend( prefix );
267 else if ( type ==
"DODS/OPeNDAP"_L1 )
270 if ( !uri.startsWith( prefix ) )
272 uri.prepend( prefix );
275 else if ( type ==
"WFS3"_L1 )
278 if ( !uri.startsWith( prefix ) )
280 uri.prepend( prefix );
285 if ( !configId.isEmpty() )
287 if ( expandAuthConfig )
289 QStringList connectionItems;
290 connectionItems << uri;
293 uri = connectionItems.join( QString() );
298 uri += u
" authcfg='%1'"_s.arg( configId );
301 else if ( !( username.isEmpty() || password.isEmpty() ) )
303 uri.replace(
"://"_L1, u
"://%1:%2@"_s.arg( username, password ) );
310 switch ( option.
type )
314 QComboBox *cb =
new QComboBox( parent );
315 if ( includeDefaultChoices )
319 for (
const QString &val : std::as_const( option.
options ) )
321 cb->addItem( val, val );
323 cb->setCurrentIndex( 0 );
330 QComboBox *cb =
new QComboBox( parent );
331 if ( includeDefaultChoices )
335 cb->addItem( QObject::tr(
"Yes" ),
"YES" );
336 cb->addItem( QObject::tr(
"No" ),
"NO" );
337 cb->setCurrentIndex( 0 );
347 if ( includeDefaultChoices )
349 res->setPlaceholderText( QObject::tr(
"Default" ) );
358 if ( option.
minimum.isValid() )
359 res->setMinimum( option.
minimum.toInt() );
361 res->setMinimum( 0 );
362 if ( option.
maximum.isValid() )
363 res->setMaximum( option.
maximum.toInt() );
365 res->setMaximum( std::numeric_limits<int>::max() - 1 );
366 if ( includeDefaultChoices )
368 res->setMinimum( res->minimum() - 1 );
383 if ( option.
minimum.isValid() )
384 res->setMinimum( option.
minimum.toDouble() );
386 res->setMinimum( 0 );
387 if ( option.
maximum.isValid() )
388 res->setMaximum( option.
maximum.toDouble() );
390 res->setMaximum( std::numeric_limits<double>::max() - 1 );
393 if ( includeDefaultChoices )
395 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)