29QString
QgsGdalGuiUtils::createDatabaseURI(
const QString &connectionType,
const QString &host,
const QString &database, QString port,
const QString &configId, QString username, QString password,
bool expandAuthConfig )
35 if ( !configId.isEmpty() )
44 if ( connectionType == QLatin1String(
"ESRI Personal GeoDatabase" ) )
46 uri =
"PGeo:" + database;
48 else if ( connectionType == QLatin1String(
"ESRI ArcSDE" ) )
51 port = QStringLiteral(
"5151" );
53 uri =
"SDE:" + host +
",PORT:" + port +
',' + database +
',' + username +
',' + password;
55 else if ( connectionType == QLatin1String(
"Informix DataBlade" ) )
58 uri =
"IDB:dbname=" + database;
60 if ( !host.isEmpty() )
61 uri += QStringLiteral(
" server=%1" ).arg( host );
63 if ( !username.isEmpty() )
65 uri += QStringLiteral(
" user=%1" ).arg( username );
67 if ( !password.isEmpty() )
68 uri += QStringLiteral(
" pass=%1" ).arg( password );
71 else if ( connectionType == QLatin1String(
"Ingres" ) )
74 uri =
"@driver=ingres,dbname=" + database;
75 if ( !username.isEmpty() )
77 uri += QStringLiteral(
",userid=%1" ).arg( username );
79 if ( !password.isEmpty() )
80 uri += QStringLiteral(
",password=%1" ).arg( password );
83 else if ( connectionType == QLatin1String(
"MySQL" ) )
85 uri =
"MySQL:" + database;
87 if ( !host.isEmpty() )
89 uri += QStringLiteral(
",host=%1" ).arg( host );
91 if ( !port.isEmpty() )
92 uri += QStringLiteral(
",port=%1" ).arg( port );
95 if ( !username.isEmpty() )
97 uri += QStringLiteral(
",user=%1" ).arg( username );
99 if ( !password.isEmpty() )
100 uri += QStringLiteral(
",password=%1" ).arg( password );
103 else if ( connectionType == QLatin1String(
"MSSQL" ) )
105 uri = QStringLiteral(
"MSSQL:" );
107 if ( !host.isEmpty() )
109 uri += QStringLiteral(
";server=%1" ).arg( host );
111 if ( !port.isEmpty() )
112 uri += QStringLiteral(
",%1" ).arg( port );
115 if ( !username.isEmpty() )
117 uri += QStringLiteral(
";uid=%1" ).arg( username );
119 if ( !password.isEmpty() )
120 uri += QStringLiteral(
";pwd=%1" ).arg( password );
123 uri += QLatin1String(
";trusted_connection=yes" );
125 if ( !database.isEmpty() )
126 uri += QStringLiteral(
";database=%1" ).arg( database );
128 else if ( connectionType == QLatin1String(
"Oracle Spatial" ) )
130 uri =
"OCI:" + username;
132 if ( ( !username.isEmpty() && !password.isEmpty() ) || ( username.isEmpty() && password.isEmpty() ) )
135 if ( !password.isEmpty() )
139 if ( !host.isEmpty() || !database.isEmpty() )
143 if ( !host.isEmpty() )
146 if ( !port.isEmpty() )
150 if ( !database.isEmpty() )
152 if ( !host.isEmpty() )
158 else if ( connectionType == QLatin1String(
"ODBC" ) )
160 if ( !username.isEmpty() )
162 if ( password.isEmpty() )
164 uri =
"ODBC:" + username +
'@' + database;
168 uri =
"ODBC:" + username +
'/' + password +
'@' + database;
173 uri =
"ODBC:" + database;
176 else if ( connectionType == QLatin1String(
"OGDI Vectors" ) )
179 else if ( connectionType == QLatin1String(
"PostgreSQL" ) )
181 uri =
"PG:dbname='" + database +
'\'';
183 if ( !host.isEmpty() )
185 uri += QStringLiteral(
" host='%1'" ).arg( host );
187 if ( !port.isEmpty() )
188 uri += QStringLiteral(
" port='%1'" ).arg( port );
191 if ( !username.isEmpty() )
193 uri += QStringLiteral(
" user='%1'" ).arg( username );
195 if ( !password.isEmpty() )
196 uri += QStringLiteral(
" password='%1'" ).arg( password );
202 if ( !( configId.isEmpty() ) )
204 if ( !expandAuthConfig )
206 uri += QStringLiteral(
" authcfg='%1'" ).arg( configId );
210 QStringList connectionItems;
211 connectionItems << uri;
214 uri = connectionItems.join( QString() );
218 QgsDebugMsgLevel(
"Connection type is=" + connectionType +
" and uri=" + uri, 2 );
223QString
QgsGdalGuiUtils::createProtocolURI(
const QString &type,
const QString &url,
const QString &configId,
const QString &username,
const QString &password,
bool expandAuthConfig )
226 if ( type == QLatin1String(
"vsicurl" ) )
230 if ( !uri.startsWith(
"http://" ) && !uri.startsWith(
"https://" ) && !uri.startsWith(
"ftp://" ) )
232 uri.prepend( QStringLiteral(
"http://" ) );
234 uri.prepend( QStringLiteral(
"/vsicurl/" ) );
236 else if ( type == QLatin1String(
"vsis3" )
237 || type == QLatin1String(
"vsigs" )
238 || type == QLatin1String(
"vsiaz" )
239 || type == QLatin1String(
"vsiadls" )
240 || type == QLatin1String(
"vsioss" )
241 || type == QLatin1String(
"vsiswift" )
242 || type == QLatin1String(
"vsihdfs" ) )
245 uri.prepend( QStringLiteral(
"/%1/" ).arg( type ) );
248 else if ( type.startsWith( QLatin1String(
"GeoJSON" ) ) )
252 else if ( type == QLatin1String(
"CouchDB" ) )
254 uri = QStringLiteral(
"couchdb:%1" ).arg( url );
256 else if ( type == QLatin1String(
"DODS/OPeNDAP" ) )
258 uri = QStringLiteral(
"DODS:%1" ).arg( url );
260 else if ( type == QLatin1String(
"WFS3" ) )
262 uri = QStringLiteral(
"WFS3:%1" ).arg( url );
266 if ( !configId.isEmpty() )
268 if ( expandAuthConfig )
270 QStringList connectionItems;
271 connectionItems << uri;
274 uri = connectionItems.join( QString() );
279 uri += QStringLiteral(
" authcfg='%1'" ).arg( configId );
282 else if ( !( username.isEmpty() || password.isEmpty() ) )
284 uri.replace( QLatin1String(
"://" ), QStringLiteral(
"://%1:%2@" ).arg( username, password ) );
291 switch ( option.
type )
295 QComboBox *cb =
new QComboBox( parent );
296 if ( includeDefaultChoices )
300 for (
const QString &val : std::as_const( option.
options ) )
302 cb->addItem( val, val );
304 cb->setCurrentIndex( 0 );
311 QComboBox *cb =
new QComboBox( parent );
312 if ( includeDefaultChoices )
316 cb->addItem( QObject::tr(
"Yes" ),
"YES" );
317 cb->addItem( QObject::tr(
"No" ),
"NO" );
318 cb->setCurrentIndex( 0 );
328 if ( includeDefaultChoices )
330 res->setPlaceholderText( QObject::tr(
"Default" ) );
339 if ( option.
minimum.isValid() )
340 res->setMinimum( option.
minimum.toInt() );
342 res->setMinimum( 0 );
343 if ( option.
maximum.isValid() )
344 res->setMaximum( option.
maximum.toInt() );
346 res->setMaximum( std::numeric_limits<int>::max() - 1 );
347 if ( includeDefaultChoices )
349 res->setMinimum( res->minimum() - 1 );
364 if ( option.
minimum.isValid() )
365 res->setMinimum( option.
minimum.toDouble() );
367 res->setMinimum( 0 );
368 if ( option.
maximum.isValid() )
369 res->setMaximum( option.
maximum.toDouble() );
371 res->setMaximum( std::numeric_limits<double>::max() - 1 );
374 if ( includeDefaultChoices )
376 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.
The QgsSpinBox is 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)