30QString
QgsGdalGuiUtils::createDatabaseURI(
const QString &connectionType,
const QString &host,
const QString &database, QString port,
const QString &configId, QString username, QString password,
bool expandAuthConfig )
36 if ( !configId.isEmpty() )
45 if ( connectionType == QLatin1String(
"ESRI Personal GeoDatabase" ) )
47 uri =
"PGeo:" + database;
49 else if ( connectionType == QLatin1String(
"ESRI ArcSDE" ) )
52 port = QStringLiteral(
"5151" );
54 uri =
"SDE:" + host +
",PORT:" + port +
',' + database +
',' + username +
',' + password;
56 else if ( connectionType == QLatin1String(
"Informix DataBlade" ) )
59 uri =
"IDB:dbname=" + database;
61 if ( !host.isEmpty() )
62 uri += QStringLiteral(
" server=%1" ).arg( host );
64 if ( !username.isEmpty() )
66 uri += QStringLiteral(
" user=%1" ).arg( username );
68 if ( !password.isEmpty() )
69 uri += QStringLiteral(
" pass=%1" ).arg( password );
72 else if ( connectionType == QLatin1String(
"Ingres" ) )
75 uri =
"@driver=ingres,dbname=" + database;
76 if ( !username.isEmpty() )
78 uri += QStringLiteral(
",userid=%1" ).arg( username );
80 if ( !password.isEmpty() )
81 uri += QStringLiteral(
",password=%1" ).arg( password );
84 else if ( connectionType == QLatin1String(
"MySQL" ) )
86 uri =
"MySQL:" + database;
88 if ( !host.isEmpty() )
90 uri += QStringLiteral(
",host=%1" ).arg( host );
92 if ( !port.isEmpty() )
93 uri += QStringLiteral(
",port=%1" ).arg( port );
96 if ( !username.isEmpty() )
98 uri += QStringLiteral(
",user=%1" ).arg( username );
100 if ( !password.isEmpty() )
101 uri += QStringLiteral(
",password=%1" ).arg( password );
104 else if ( connectionType == QLatin1String(
"MSSQL" ) )
106 uri = QStringLiteral(
"MSSQL:" );
108 if ( !host.isEmpty() )
110 uri += QStringLiteral(
";server=%1" ).arg( host );
112 if ( !port.isEmpty() )
113 uri += QStringLiteral(
",%1" ).arg( port );
116 if ( !username.isEmpty() )
118 uri += QStringLiteral(
";uid=%1" ).arg( username );
120 if ( !password.isEmpty() )
121 uri += QStringLiteral(
";pwd=%1" ).arg( password );
124 uri += QLatin1String(
";trusted_connection=yes" );
126 if ( !database.isEmpty() )
127 uri += QStringLiteral(
";database=%1" ).arg( database );
129 else if ( connectionType == QLatin1String(
"Oracle Spatial" ) )
131 uri =
"OCI:" + username;
133 if ( ( !username.isEmpty() && !password.isEmpty() ) || ( username.isEmpty() && password.isEmpty() ) )
136 if ( !password.isEmpty() )
140 if ( !host.isEmpty() || !database.isEmpty() )
144 if ( !host.isEmpty() )
147 if ( !port.isEmpty() )
151 if ( !database.isEmpty() )
153 if ( !host.isEmpty() )
159 else if ( connectionType == QLatin1String(
"ODBC" ) )
161 if ( !username.isEmpty() )
163 if ( password.isEmpty() )
165 uri =
"ODBC:" + username +
'@' + database;
169 uri =
"ODBC:" + username +
'/' + password +
'@' + database;
174 uri =
"ODBC:" + database;
177 else if ( connectionType == QLatin1String(
"OGDI Vectors" ) )
180 else if ( connectionType == QLatin1String(
"PostgreSQL" ) )
182 uri =
"PG:dbname='" + database +
'\'';
184 if ( !host.isEmpty() )
186 uri += QStringLiteral(
" host='%1'" ).arg( host );
188 if ( !port.isEmpty() )
189 uri += QStringLiteral(
" port='%1'" ).arg( port );
192 if ( !username.isEmpty() )
194 uri += QStringLiteral(
" user='%1'" ).arg( username );
196 if ( !password.isEmpty() )
197 uri += QStringLiteral(
" password='%1'" ).arg( password );
203 if ( !( configId.isEmpty() ) )
205 if ( !expandAuthConfig )
207 uri += QStringLiteral(
" authcfg='%1'" ).arg( configId );
211 QStringList connectionItems;
212 connectionItems << uri;
215 uri = connectionItems.join( QString() );
219 QgsDebugMsgLevel(
"Connection type is=" + connectionType +
" and uri=" + uri, 2 );
224QString
QgsGdalGuiUtils::createProtocolURI(
const QString &type,
const QString &url,
const QString &configId,
const QString &username,
const QString &password,
bool expandAuthConfig )
228 if ( type == QLatin1String(
"vsicurl" ) )
230 prefix = QStringLiteral(
"/vsicurl/" );
231 if ( !uri.startsWith( prefix ) )
234 if ( !uri.startsWith( QLatin1String(
"http://" ) ) && !uri.startsWith( QLatin1String(
"https://" ) ) && !uri.startsWith( QLatin1String(
"ftp://" ) ) )
236 uri.prepend( QStringLiteral(
"http://" ) );
238 uri.prepend( prefix );
241 else if ( type == QLatin1String(
"vsis3" )
242 || type == QLatin1String(
"vsigs" )
243 || type == QLatin1String(
"vsiaz" )
244 || type == QLatin1String(
"vsiadls" )
245 || type == QLatin1String(
"vsioss" )
246 || type == QLatin1String(
"vsiswift" )
247 || type == QLatin1String(
"vsihdfs" ) )
249 prefix = QStringLiteral(
"/%1/" ).arg( type );
250 if ( !uri.startsWith( prefix ) )
252 uri.prepend( prefix );
256 else if ( type.startsWith( QLatin1String(
"GeoJSON" ) ) )
260 else if ( type == QLatin1String(
"CouchDB" ) )
262 prefix = QStringLiteral(
"couchdb:" );
263 if ( !uri.startsWith( prefix ) )
265 uri.prepend( prefix );
268 else if ( type == QLatin1String(
"DODS/OPeNDAP" ) )
270 prefix = QStringLiteral(
"DODS:" );
271 if ( !uri.startsWith( prefix ) )
273 uri.prepend( prefix );
276 else if ( type == QLatin1String(
"WFS3" ) )
278 prefix = QStringLiteral(
"WFS3:" );
279 if ( !uri.startsWith( prefix ) )
281 uri.prepend( prefix );
286 if ( !configId.isEmpty() )
288 if ( expandAuthConfig )
290 QStringList connectionItems;
291 connectionItems << uri;
294 uri = connectionItems.join( QString() );
299 uri += QStringLiteral(
" authcfg='%1'" ).arg( configId );
302 else if ( !( username.isEmpty() || password.isEmpty() ) )
304 uri.replace( QLatin1String(
"://" ), QStringLiteral(
"://%1:%2@" ).arg( username, password ) );
311 switch ( option.
type )
315 QComboBox *cb =
new QComboBox( parent );
316 if ( includeDefaultChoices )
320 for (
const QString &val : std::as_const( option.
options ) )
322 cb->addItem( val, val );
324 cb->setCurrentIndex( 0 );
331 QComboBox *cb =
new QComboBox( parent );
332 if ( includeDefaultChoices )
336 cb->addItem( QObject::tr(
"Yes" ),
"YES" );
337 cb->addItem( QObject::tr(
"No" ),
"NO" );
338 cb->setCurrentIndex( 0 );
348 if ( includeDefaultChoices )
350 res->setPlaceholderText( QObject::tr(
"Default" ) );
359 if ( option.
minimum.isValid() )
360 res->setMinimum( option.
minimum.toInt() );
362 res->setMinimum( 0 );
363 if ( option.
maximum.isValid() )
364 res->setMaximum( option.
maximum.toInt() );
366 res->setMaximum( std::numeric_limits<int>::max() - 1 );
367 if ( includeDefaultChoices )
369 res->setMinimum( res->minimum() - 1 );
384 if ( option.
minimum.isValid() )
385 res->setMinimum( option.
minimum.toDouble() );
387 res->setMinimum( 0 );
388 if ( option.
maximum.isValid() )
389 res->setMaximum( option.
maximum.toDouble() );
391 res->setMaximum( std::numeric_limits<double>::max() - 1 );
394 if ( includeDefaultChoices )
396 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)