void QgsMergeAttributesDialog::refreshMergedValue( int col ) { QComboBox* comboBox = qobject_cast<QComboBox *>( mTableWidget->cellWidget( 0, col ) ); if ( !comboBox ) { return; } //evaluate behaviour (feature value or min / max / mean ) QString mergeBehaviourString = comboBox->currentText(); QVariant mergeResult; // result to show in the merge result field if ( mergeBehaviourString == tr( "Minimum" ) ) { mergeResult = minimumAttribute( col ); } else if ( mergeBehaviourString == tr( "Maximum" ) ) { mergeResult = maximumAttribute( col ); } else if ( mergeBehaviourString == tr( "Mean" ) ) { mergeResult = meanAttribute( col ); } else if ( mergeBehaviourString == tr( "Median" ) ) { mergeResult = medianAttribute( col ); } else if ( mergeBehaviourString == tr( "Sum" ) ) { mergeResult = sumAttribute( col ); } else if ( mergeBehaviourString == tr( "Concatenation" ) ) { mergeResult = concatenationAttribute( col ); } else if ( mergeBehaviourString == tr( "Skip attribute" ) ) { mergeResult = tr( "Skipped" ); } else //an existing feature value { int featureId = mergeBehaviourString.split( " " ).at( 1 ).toInt(); //probably not very robust for translations... mergeResult = featureAttribute( featureId, col ); } //insert string into table widget QTableWidgetItem* newTotalItem = new QTableWidgetItem(); newTotalItem->setData( Qt::DisplayRole, mergeResult ); newTotalItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable ); mTableWidget->setItem( mTableWidget->rowCount() - 1, col, newTotalItem ); }
void QgsMergeAttributesDialog::refreshMergedValue( int col ) { QComboBox *comboBox = qobject_cast<QComboBox *>( mTableWidget->cellWidget( 0, col ) ); if ( !comboBox ) { return; } int fieldIdx = mTableWidget->horizontalHeaderItem( col )->data( FieldIndex ).toInt(); //evaluate behavior (feature value or min / max / mean ) QString mergeBehaviorString = comboBox->currentData().toString(); QVariant mergeResult; // result to show in the merge result field if ( mergeBehaviorString == QLatin1String( "concat" ) ) { mergeResult = concatenationAttribute( col ); } else if ( mergeBehaviorString == QLatin1String( "skip" ) ) { mergeResult = tr( "Skipped" ); } else if ( mergeBehaviorString == QLatin1String( "manual" ) ) { return; //nothing to do } else if ( mergeBehaviorString.startsWith( 'f' ) ) { //an existing feature value QgsFeatureId featureId = STRING_TO_FID( mergeBehaviorString.mid( 1 ) ); mergeResult = featureAttribute( featureId, fieldIdx ); } else { //numerical statistic QgsStatisticalSummary::Statistic stat = ( QgsStatisticalSummary::Statistic )( comboBox->currentData().toInt() ); mergeResult = calcStatistic( fieldIdx, stat ); } //insert string into table widget mUpdating = true; // prevent combobox changing to "manual" value QTableWidgetItem *item = mTableWidget->item( mTableWidget->rowCount() - 1, col ); item->setData( Qt::DisplayRole, mergeResult ); mUpdating = false; }