void QgsAuthConfigSelect::populateConfigSelector() { loadAvailableConfigs(); validateConfig(); cmbConfigSelect->blockSignals( true ); cmbConfigSelect->clear(); cmbConfigSelect->addItem( tr( "No authentication" ), "0" ); QgsStringMap sortmap; QgsAuthMethodConfigsMap::const_iterator cit = mConfigs.constBegin(); for ( cit = mConfigs.constBegin(); cit != mConfigs.constEnd(); ++cit ) { QgsAuthMethodConfig config = cit.value(); sortmap.insert( config.name(), cit.key() ); } QgsStringMap::const_iterator sm = sortmap.constBegin(); for ( sm = sortmap.constBegin(); sm != sortmap.constEnd(); ++sm ) { cmbConfigSelect->addItem( sm.key(), sm.value() ); } cmbConfigSelect->blockSignals( false ); int indx = 0; if ( !mAuthCfg.isEmpty() ) { indx = cmbConfigSelect->findData( mAuthCfg ); } cmbConfigSelect->setCurrentIndex( indx > 0 ? indx : 0 ); }
void QgsSymbolLayerV2::restoreDataDefinedProperties( const QgsStringMap &stringMap ) { QgsStringMap::const_iterator propIt = stringMap.constBegin(); for ( ; propIt != stringMap.constEnd(); ++propIt ) { if ( propIt.key().endsWith( "_dd_expression" ) ) { //found a data defined property //get data defined property name by stripping "_dd_expression" from property key QString propertyName = propIt.key().left( propIt.key().length() - 14 ); QgsDataDefined* dd = QgsDataDefined::fromMap( stringMap, propertyName ); if ( dd ) setDataDefinedProperty( propertyName, dd ); } else if ( propIt.key().endsWith( "_expression" ) ) { //old style data defined property, upgrade //get data defined property name by stripping "_expression" from property key QString propertyName = propIt.key().left( propIt.key().length() - 11 ); setDataDefinedProperty( propertyName, new QgsDataDefined( propIt.value() ) ); } } }
QgsExpressionContextScope* QgsExpressionContextUtils::projectScope() { QgsProject* project = QgsProject::instance(); QgsExpressionContextScope* scope = new QgsExpressionContextScope( QObject::tr( "Project" ) ); const QgsStringMap vars = QgsProject::instance()->variables(); QgsStringMap::const_iterator it = vars.constBegin(); for ( ; it != vars.constEnd(); ++it ) { scope->setVariable( it.key(), it.value() ); } //add other known project variables scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_title" ), project->title(), true ) ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_path" ), project->fileInfo().filePath(), true ) ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_folder" ), project->fileInfo().dir().path(), true ) ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_filename" ), project->fileInfo().fileName(), true ) ); QgsCoordinateReferenceSystem projectCrs = project->crs(); scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs" ), projectCrs.authid(), true ) ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs_definition" ), projectCrs.toProj4(), true ) ); scope->addFunction( QStringLiteral( "project_color" ), new GetNamedProjectColor() ); return scope; }
QStringList QgsProcessingModelChildAlgorithm::asPythonCode( const QgsProcessing::PythonOutputType outputType, const QgsStringMap &extraParameters, int currentIndent, int indentSize ) const { QStringList lines; const QString baseIndent = QString( ' ' ).repeated( currentIndent ); const QString lineIndent = QString( ' ' ).repeated( indentSize ); if ( !algorithm() ) return QStringList(); QStringList paramParts; for ( auto paramIt = mParams.constBegin(); paramIt != mParams.constEnd(); ++paramIt ) { QStringList sourceParts; const QgsProcessingParameterDefinition *def = algorithm() ? algorithm()->parameterDefinition( paramIt.key() ) : nullptr; const auto parts = paramIt.value(); for ( const QgsProcessingModelChildParameterSource &source : parts ) { QString part = source.asPythonCode( outputType, def ); if ( !part.isEmpty() ) sourceParts << part; } if ( sourceParts.count() == 1 ) paramParts << QStringLiteral( "'%1': %2" ).arg( paramIt.key(), sourceParts.at( 0 ) ); else paramParts << QStringLiteral( "'%1': [%2]" ).arg( paramIt.key(), sourceParts.join( ',' ) ); } lines << baseIndent + QStringLiteral( "alg_params = {" ); lines.reserve( lines.size() + paramParts.size() ); for ( const QString &p : qgis::as_const( paramParts ) ) { lines << baseIndent + lineIndent + p + ','; } for ( auto it = extraParameters.constBegin(); it != extraParameters.constEnd(); ++it ) { lines << baseIndent + lineIndent + QStringLiteral( "%1: %2," ).arg( QgsProcessingUtils::stringToPythonLiteral( it.key() ), it.value() ); } if ( lines.constLast().endsWith( ',' ) ) { lines[ lines.count() - 1 ].truncate( lines.constLast().length() - 1 ); } lines << baseIndent + QStringLiteral( "}" ); lines << baseIndent + QStringLiteral( "outputs['%1'] = processing.run('%2', alg_params, context=context, feedback=feedback, is_child_algorithm=True)" ).arg( mId, mAlgorithmId ); for ( auto outputIt = mModelOutputs.constBegin(); outputIt != mModelOutputs.constEnd(); ++outputIt ) { lines << baseIndent + QStringLiteral( "results['%1:%2'] = outputs['%1']['%3']" ).arg( mId, outputIt.key(), outputIt.value().childOutputName() ); } return lines; }
void QgsExpressionContextUtils::setGlobalVariables( const QgsStringMap &variables ) { QSettings settings; QList< QVariant > customVariableVariants; QList< QVariant > customVariableNames; QMap< QString, QString >::const_iterator it = variables.constBegin(); for ( ; it != variables.constEnd(); ++it ) { customVariableNames << it.key(); customVariableVariants << it.value(); } settings.setValue( QString( "/variables/names" ), customVariableNames ); settings.setValue( QString( "/variables/values" ), customVariableVariants ); }
void QgsExpressionContextUtils::setComposerItemVariables( QgsComposerItem* composerItem, const QgsStringMap& variables ) { if ( !composerItem ) return; QStringList variableNames; QStringList variableValues; QMap< QString, QString >::const_iterator it = variables.constBegin(); for ( ; it != variables.constEnd(); ++it ) { variableNames << it.key(); variableValues << it.value(); } composerItem->setCustomProperty( "variableNames", variableNames ); composerItem->setCustomProperty( "variableValues", variableValues ); }
void QgsExpressionContextUtils::setLayerVariables( QgsMapLayer* layer, const QgsStringMap& variables ) { if ( !layer ) return; QStringList variableNames; QStringList variableValues; QMap< QString, QString >::const_iterator it = variables.constBegin(); for ( ; it != variables.constEnd(); ++it ) { variableNames << it.key(); variableValues << it.value(); } layer->setCustomProperty( "variableNames", variableNames ); layer->setCustomProperty( "variableValues", variableValues ); }
void QgsExpressionContextUtils::setProjectVariables( const QgsStringMap &variables ) { QgsProject* project = QgsProject::instance(); //write variable to project QStringList variableNames; QStringList variableValues; QMap< QString, QString >::const_iterator it = variables.constBegin(); for ( ; it != variables.constEnd(); ++it ) { variableNames << it.key(); variableValues << it.value(); } project->writeEntry( "Variables", "/variableNames", variableNames ); project->writeEntry( "Variables", "/variableValues", variableValues ); }
void QgsSymbolLayer::restoreOldDataDefinedProperties( const QgsStringMap &stringMap ) { QgsStringMap::const_iterator propIt = stringMap.constBegin(); for ( ; propIt != stringMap.constEnd(); ++propIt ) { QgsProperty prop; QString propertyName; if ( propIt.key().endsWith( QLatin1String( "_dd_expression" ) ) ) { //found a data defined property //get data defined property name by stripping "_dd_expression" from property key propertyName = propIt.key().left( propIt.key().length() - 14 ); prop = propertyFromMap( stringMap, propertyName ); } else if ( propIt.key().endsWith( QLatin1String( "_expression" ) ) ) { //old style data defined property, upgrade //get data defined property name by stripping "_expression" from property key propertyName = propIt.key().left( propIt.key().length() - 11 ); prop = QgsProperty::fromExpression( propIt.value() ); } if ( !prop || !OLD_PROPS.contains( propertyName ) ) continue; QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( OLD_PROPS.value( propertyName ) ); if ( type() == QgsSymbol::Line ) { //these keys had different meaning for line symbol layers if ( propertyName == QLatin1String( "width" ) ) key = QgsSymbolLayer::PropertyStrokeWidth; else if ( propertyName == QLatin1String( "color" ) ) key = QgsSymbolLayer::PropertyStrokeColor; } setDataDefinedProperty( key, prop ); } }
QVector<QgsDataItem *> QgsXyzTileDataItemProvider::createDataItems( const QString &path, QgsDataItem *parentItem ) { QVector<QgsDataItem *> items; if ( path.startsWith( QLatin1String( "geonode:/" ) ) ) { QString connectionName = path.split( '/' ).last(); if ( QgsGeoNodeConnectionUtils::connectionList().contains( connectionName ) ) { QgsGeoNodeConnection connection( connectionName ); QString url = connection.uri().param( QStringLiteral( "url" ) ); QgsGeoNodeRequest geonodeRequest( url, true ); const QgsStringMap urlData( geonodeRequest.fetchServiceUrlDataBlocking( QStringLiteral( "XYZ" ) ) ); if ( !urlData.isEmpty() ) { auto urlDataIt = urlData.constBegin(); for ( ; urlDataIt != urlData.constEnd(); ++urlDataIt ) { const QString layerName = urlDataIt.key(); QgsDebugMsg( urlDataIt.value() ); QgsDataSourceUri uri; uri.setParam( QStringLiteral( "type" ), QStringLiteral( "xyz" ) ); uri.setParam( QStringLiteral( "url" ), urlDataIt.value() ); QgsDataItem *item = new QgsXyzLayerItem( parentItem, layerName, path, uri.encodedUri() ); if ( item ) { items.append( item ); } } } } } return items; }
void QgsGradientColorRampDialog::on_btnInformation_pressed() { if ( mRamp.info().isEmpty() ) return; QgsDialog *dlg = new QgsDialog( this ); QLabel *label = nullptr; // information table QTableWidget *tableInfo = new QTableWidget( dlg ); tableInfo->verticalHeader()->hide(); tableInfo->horizontalHeader()->hide(); tableInfo->setRowCount( mRamp.info().count() ); tableInfo->setColumnCount( 2 ); int i = 0; QgsStringMap rampInfo = mRamp.info(); for ( QgsStringMap::const_iterator it = rampInfo.constBegin(); it != rampInfo.constEnd(); ++it ) { if ( it.key().startsWith( QLatin1String( "cpt-city" ) ) ) continue; tableInfo->setItem( i, 0, new QTableWidgetItem( it.key() ) ); tableInfo->setItem( i, 1, new QTableWidgetItem( it.value() ) ); tableInfo->resizeRowToContents( i ); i++; } tableInfo->resizeColumnToContents( 0 ); tableInfo->horizontalHeader()->setStretchLastSection( true ); tableInfo->setRowCount( i ); tableInfo->setFixedHeight( tableInfo->rowHeight( 0 ) * i + 5 ); dlg->layout()->addWidget( tableInfo ); dlg->resize( 600, 250 ); dlg->layout()->addSpacing( 5 ); // gradient file QString gradientFile = mRamp.info().value( QStringLiteral( "cpt-city-gradient" ) ); if ( ! gradientFile.isNull() ) { QString fileName = gradientFile; fileName.replace( QLatin1String( "<cpt-city>" ), QgsCptCityArchive::defaultBaseDir() ); if ( ! QFile::exists( fileName ) ) { fileName = gradientFile; fileName.replace( QLatin1String( "<cpt-city>" ), QLatin1String( "http://soliton.vm.bytemark.co.uk/pub/cpt-city" ) ); } label = new QLabel( tr( "Gradient file : %1" ).arg( fileName ), dlg ); label->setTextInteractionFlags( Qt::TextBrowserInteraction ); dlg->layout()->addSpacing( 5 ); dlg->layout()->addWidget( label ); } // license file QString licenseFile = mRamp.info().value( QStringLiteral( "cpt-city-license" ) ); if ( !licenseFile.isNull() ) { QString fileName = licenseFile; fileName.replace( QLatin1String( "<cpt-city>" ), QgsCptCityArchive::defaultBaseDir() ); if ( ! QFile::exists( fileName ) ) { fileName = licenseFile; fileName.replace( QLatin1String( "<cpt-city>" ), QLatin1String( "http://soliton.vm.bytemark.co.uk/pub/cpt-city" ) ); } label = new QLabel( tr( "License file : %1" ).arg( fileName ), dlg ); label->setTextInteractionFlags( Qt::TextBrowserInteraction ); dlg->layout()->addSpacing( 5 ); dlg->layout()->addWidget( label ); if ( QFile::exists( fileName ) ) { QTextEdit *textEdit = new QTextEdit( dlg ); textEdit->setReadOnly( true ); QFile file( fileName ); if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) ) { textEdit->setText( file.readAll() ); file.close(); dlg->layout()->addSpacing( 5 ); dlg->layout()->addWidget( textEdit ); dlg->resize( 600, 500 ); } } } dlg->show(); //non modal }