void QgsAfsSourceSelect::buildQuery( const QgsOwsConnection &connection, const QModelIndex& index ) { if ( !index.isValid() ) { return; } QModelIndex filterIndex = index.sibling( index.row(), 4 ); QString id = index.sibling( index.row(), 0 ).data().toString(); // Query available fields QgsDataSourceUri ds = connection.uri(); QString url = ds.param( "url" ) + "/" + id; ds.removeParam( "url" ); ds.setParam( "url", url ); QgsAfsProvider provider( ds.uri() ); if ( !provider.isValid() ) { return; } //show expression builder QgsExpressionBuilderDialog d( 0, filterIndex.data().toString() ); //add available attributes to expression builder QgsExpressionBuilderWidget* w = d.expressionBuilder(); w->loadFieldNames( provider.fields() ); if ( d.exec() == QDialog::Accepted ) { QgsDebugMsg( "Expression text = " + w->expressionText() ); mModelProxy->setData( filterIndex, QVariant( w->expressionText() ) ); } }
void QgsDualView::modifySort() { if ( !mLayer ) return; QgsAttributeTableConfig config = mConfig; QDialog orderByDlg; orderByDlg.setWindowTitle( tr( "Configure Attribute Table Sort Order" ) ); QDialogButtonBox *dialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel ); QGridLayout *layout = new QGridLayout(); connect( dialogButtonBox, &QDialogButtonBox::accepted, &orderByDlg, &QDialog::accept ); connect( dialogButtonBox, &QDialogButtonBox::rejected, &orderByDlg, &QDialog::reject ); orderByDlg.setLayout( layout ); QGroupBox *sortingGroupBox = new QGroupBox(); sortingGroupBox->setTitle( tr( "Defined sort order in attribute table" ) ); sortingGroupBox->setCheckable( true ); sortingGroupBox->setChecked( !sortExpression().isEmpty() ); layout->addWidget( sortingGroupBox ); sortingGroupBox->setLayout( new QGridLayout() ); QgsExpressionBuilderWidget *expressionBuilder = new QgsExpressionBuilderWidget(); QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) ); expressionBuilder->setExpressionContext( context ); expressionBuilder->setLayer( mLayer ); expressionBuilder->loadFieldNames(); expressionBuilder->loadRecent( QStringLiteral( "generic" ) ); expressionBuilder->setExpressionText( sortExpression().isEmpty() ? mLayer->displayExpression() : sortExpression() ); sortingGroupBox->layout()->addWidget( expressionBuilder ); QCheckBox *cbxSortAscending = new QCheckBox( tr( "Sort ascending" ) ); cbxSortAscending->setChecked( config.sortOrder() == Qt::AscendingOrder ); sortingGroupBox->layout()->addWidget( cbxSortAscending ); layout->addWidget( dialogButtonBox ); if ( orderByDlg.exec() ) { Qt::SortOrder sortOrder = cbxSortAscending->isChecked() ? Qt::AscendingOrder : Qt::DescendingOrder; if ( sortingGroupBox->isChecked() ) { setSortExpression( expressionBuilder->expressionText(), sortOrder ); config.setSortExpression( expressionBuilder->expressionText() ); config.setSortOrder( sortOrder ); } else { setSortExpression( QString(), sortOrder ); config.setSortExpression( QString() ); } setAttributeTableConfig( config ); } }
void QgsWFSSourceSelect::buildQuery( const QModelIndex& index ) { if ( !index.isValid() ) { return; } QModelIndex filterIndex = index.sibling( index.row(), MODEL_IDX_FILTER ); QString typeName = index.sibling( index.row(), MODEL_IDX_NAME ).data().toString(); //get available fields for wfs layer QgsWFSConnection connection( cmbConnections->currentText() ); QgsWFSDataSourceURI uri( connection.uri().uri() ); uri.setTypeName( typeName ); QgsWFSProvider p( uri.uri() ); if ( !p.isValid() ) { return; } QgsFields fields( p.fields() ); //show expression builder QgsExpressionBuilderDialog d( nullptr, filterIndex.data().toString() ); //add available attributes to expression builder QgsExpressionBuilderWidget* w = d.expressionBuilder(); if ( !w ) { return; } w->loadFieldNames( fields ); if ( d.exec() == QDialog::Accepted ) { QgsDebugMsg( "Expression text = " + w->expressionText() ); mModelProxy->setData( filterIndex, QVariant( w->expressionText() ) ); } }