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() ) ||
133 ( 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;
175 uri =
"ODBC:" + database;
178 else if ( connectionType == QLatin1String(
"OGDI Vectors" ) )
181 else if ( connectionType == QLatin1String(
"PostgreSQL" ) )
183 uri =
"PG:dbname='" + database +
'\'';
185 if ( !host.isEmpty() )
187 uri += QStringLiteral(
" host='%1'" ).arg( host );
189 if ( !port.isEmpty() )
190 uri += QStringLiteral(
" port='%1'" ).arg( port );
193 if ( !username.isEmpty() )
195 uri += QStringLiteral(
" user='%1'" ).arg( username );
197 if ( !password.isEmpty() )
198 uri += QStringLiteral(
" password='%1'" ).arg( password );
204 if ( !( configId.isEmpty() ) )
206 if ( ! expandAuthConfig )
208 uri += QStringLiteral(
" authcfg='%1'" ).arg( configId );
212 QStringList connectionItems;
213 connectionItems << uri;
216 uri = connectionItems.join( QString() );
220 QgsDebugMsgLevel(
"Connection type is=" + connectionType +
" and uri=" + uri, 2 );
225QString
QgsGdalGuiUtils::createProtocolURI(
const QString &type,
const QString &url,
const QString &configId,
const QString &username,
const QString &password,
bool expandAuthConfig )
228 if ( type == QLatin1String(
"vsicurl" ) )
232 if ( !uri.startsWith(
"http://" ) && !uri.startsWith(
"https://" ) && !uri.startsWith(
"ftp://" ) )
234 uri.prepend( QStringLiteral(
"http://" ) );
236 uri.prepend( QStringLiteral(
"/vsicurl/" ) );
238 else if ( type == QLatin1String(
"vsis3" )
239 || type == QLatin1String(
"vsigs" )
240 || type == QLatin1String(
"vsiaz" )
241 || type == QLatin1String(
"vsiadls" )
242 || type == QLatin1String(
"vsioss" )
243 || type == QLatin1String(
"vsiswift" )
244 || type == QLatin1String(
"vsihdfs" )
248 uri.prepend( QStringLiteral(
"/%1/" ).arg( type ) );
251 else if ( type.startsWith( QLatin1String(
"GeoJSON" ) ) )
255 else if ( type == QLatin1String(
"CouchDB" ) )
257 uri = QStringLiteral(
"couchdb:%1" ).arg( url );
259 else if ( type == QLatin1String(
"DODS/OPeNDAP" ) )
261 uri = QStringLiteral(
"DODS:%1" ).arg( url );
263 else if ( type == QLatin1String(
"WFS3" ) )
265 uri = QStringLiteral(
"WFS3:%1" ).arg( url );
269 if ( ! configId.isEmpty() )
271 if ( expandAuthConfig )
273 QStringList connectionItems;
274 connectionItems << uri;
277 uri = connectionItems.join( QString() );
282 uri += QStringLiteral(
" authcfg='%1'" ).arg( configId );
285 else if ( !( username.isEmpty() || password.isEmpty( ) ) )
287 uri.replace( QLatin1String(
"://" ), QStringLiteral(
"://%1:%2@" ).arg( username, password ) );
294 switch ( option.
type )
298 QComboBox *cb =
new QComboBox( parent );
299 if ( includeDefaultChoices )
303 for (
const QString &val : std::as_const( option.
options ) )
305 cb->addItem( val, val );
307 cb->setCurrentIndex( 0 );
314 QComboBox *cb =
new QComboBox( parent );
315 if ( includeDefaultChoices )
319 cb->addItem( QObject::tr(
"Yes" ),
"YES" );
320 cb->addItem( QObject::tr(
"No" ),
"NO" );
321 cb->setCurrentIndex( 0 );
331 if ( includeDefaultChoices )
333 res->setPlaceholderText( QObject::tr(
"Default" ) );
342 if ( option.
minimum.isValid() )
343 res->setMinimum( option.
minimum.toInt() );
345 res->setMinimum( 0 );
346 if ( option.
maximum.isValid() )
347 res->setMaximum( option.
maximum.toInt() );
349 res->setMaximum( std::numeric_limits< int>::max() - 1 );
350 if ( includeDefaultChoices )
352 res->setMinimum( res->minimum() - 1 );
354 QObject::tr(
"Default" ) );
368 if ( option.
minimum.isValid() )
369 res->setMinimum( option.
minimum.toDouble() );
371 res->setMinimum( 0 );
372 if ( option.
maximum.isValid() )
373 res->setMaximum( option.
maximum.toDouble() );
375 res->setMaximum( std::numeric_limits< double>::max() - 1 );
378 if ( includeDefaultChoices )
380 res->setMinimum( res->minimum() - 1 );
382 QObject::tr(
"Default" ) );
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)