Skip to content

Commit

Permalink
Fix taking attribute values in merge attributes dialog (fix #13971)
Browse files Browse the repository at this point in the history
Also fix handling of long feature ids in tool.
  • Loading branch information
nyalldawson committed Dec 10, 2015
1 parent f93fce7 commit b23ddfe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions src/app/qgsmergeattributesdialog.cpp
Expand Up @@ -170,7 +170,7 @@ QComboBox *QgsMergeAttributesDialog::createMergeComboBox( QVariant::Type columnT
QgsFeatureList::const_iterator f_it = mFeatureList.constBegin();
for ( ; f_it != mFeatureList.constEnd(); ++f_it )
{
newComboBox->addItem( tr( "Feature %1" ).arg( f_it->id() ), QString( "f%1" ).arg( f_it->id() ) );
newComboBox->addItem( tr( "Feature %1" ).arg( f_it->id() ), QString( "f%1" ).arg( FID_TO_STRING( f_it->id() ) ) );
}

if ( columnType == QVariant::Double || columnType == QVariant::Int )
Expand Down Expand Up @@ -223,7 +223,7 @@ void QgsMergeAttributesDialog::selectedRowChanged()
{
//find out selected row
QList<QTableWidgetItem *> selectionList = mTableWidget->selectedItems();
if ( selectionList.size() < 1 )
if ( selectionList.isEmpty() )
{
delete mSelectionRubberBand;
mSelectionRubberBand = 0;
Expand All @@ -245,7 +245,7 @@ void QgsMergeAttributesDialog::selectedRowChanged()
}

bool conversionSuccess = false;
int featureIdToSelect = idItem->text().toInt( &conversionSuccess );
QgsFeatureId featureIdToSelect = idItem->text().toLongLong( &conversionSuccess );
if ( !conversionSuccess )
{
//the merge result row was selected
Expand Down Expand Up @@ -275,10 +275,10 @@ void QgsMergeAttributesDialog::refreshMergedValue( int col )
{
mergeResult = tr( "Skipped" );
}
else if ( mergeBehaviourString.startsWith( "f" ) )
else if ( mergeBehaviourString.startsWith( 'f' ) )
{
//an existing feature value - TODO should be QgsFeatureId, not int
int featureId = mergeBehaviourString.mid( 1 ).toInt();
//an existing feature value
QgsFeatureId featureId = STRING_TO_FID( mergeBehaviourString.mid( 1 ) );
mergeResult = featureAttribute( featureId, col );
}
else
Expand All @@ -295,7 +295,7 @@ void QgsMergeAttributesDialog::refreshMergedValue( int col )
mTableWidget->setItem( mTableWidget->rowCount() - 1, col, newTotalItem );
}

QVariant QgsMergeAttributesDialog::featureAttribute( int featureId, int col )
QVariant QgsMergeAttributesDialog::featureAttribute( QgsFeatureId featureId, int col )
{
int idx = mTableWidget->horizontalHeaderItem( col )->data( Qt::UserRole ).toInt();

Expand Down Expand Up @@ -362,7 +362,7 @@ void QgsMergeAttributesDialog::on_mFromSelectedPushButton_clicked()

//find out feature id of selected row
QList<QTableWidgetItem *> selectionList = mTableWidget->selectedItems();
if ( selectionList.size() < 1 )
if ( selectionList.isEmpty() )
{
return;
}
Expand All @@ -377,7 +377,7 @@ void QgsMergeAttributesDialog::on_mFromSelectedPushButton_clicked()
}

bool conversionSuccess;
int featureId = selectedHeaderItem->text().toInt( &conversionSuccess );
QgsFeatureId featureId = selectedHeaderItem->text().toLongLong( &conversionSuccess );
if ( !conversionSuccess )
{
return;
Expand All @@ -393,7 +393,7 @@ void QgsMergeAttributesDialog::on_mFromSelectedPushButton_clicked()
QComboBox* currentComboBox = qobject_cast<QComboBox *>( mTableWidget->cellWidget( 0, i ) );
if ( currentComboBox )
{
currentComboBox->setCurrentIndex( currentComboBox->findData( QString::number( featureId ) ) );
currentComboBox->setCurrentIndex( currentComboBox->findData( QString( "f%1" ).arg( FID_TO_STRING( featureId ) ) ) );
}
}
}
Expand All @@ -407,7 +407,7 @@ void QgsMergeAttributesDialog::on_mRemoveFeatureFromSelectionButton_clicked()

//find out feature id of selected row
QList<QTableWidgetItem *> selectionList = mTableWidget->selectedItems();
if ( selectionList.size() < 1 )
if ( selectionList.isEmpty() )
{
return;
}
Expand All @@ -422,7 +422,7 @@ void QgsMergeAttributesDialog::on_mRemoveFeatureFromSelectionButton_clicked()
}

bool conversionSuccess;
int featureId = selectedHeaderItem->text().toInt( &conversionSuccess );
QgsFeatureId featureId = selectedHeaderItem->text().toLongLong( &conversionSuccess );
if ( !conversionSuccess )
{
selectedRowChanged();
Expand All @@ -446,7 +446,7 @@ void QgsMergeAttributesDialog::on_mRemoveFeatureFromSelectionButton_clicked()
continue;

currentComboBox->blockSignals( true );
currentComboBox->removeItem( currentComboBox->findData( QString::number( featureId ) ) );
currentComboBox->removeItem( currentComboBox->findData( QString( "f%1" ).arg( FID_TO_STRING( featureId ) ) ) );
currentComboBox->blockSignals( false );
}

Expand All @@ -463,7 +463,7 @@ void QgsMergeAttributesDialog::on_mRemoveFeatureFromSelectionButton_clicked()
}
}

void QgsMergeAttributesDialog::createRubberBandForFeature( int featureId )
void QgsMergeAttributesDialog::createRubberBandForFeature( QgsFeatureId featureId )
{
//create rubber band to highlight the feature
delete mSelectionRubberBand;
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmergeattributesdialog.h
Expand Up @@ -67,7 +67,7 @@ class APP_EXPORT QgsMergeAttributesDialog: public QDialog, private Ui::QgsMergeA
/** Calculates the merged value of a column (depending on the selected merge behaviour) and inserts the value in the corresponding cell*/
void refreshMergedValue( int col );
/** Inserts the attribute value of a specific feature into the row of merged attributes*/
QVariant featureAttribute( int featureId, int col );
QVariant featureAttribute( QgsFeatureId featureId, int col );
/** Appends the values of the features for the final value*/
QVariant concatenationAttribute( int col );

Expand All @@ -77,7 +77,7 @@ class APP_EXPORT QgsMergeAttributesDialog: public QDialog, private Ui::QgsMergeA
QVariant calcStatistic( int col, QgsStatisticalSummary::Statistic stat );

/** Sets mSelectionRubberBand to a new feature*/
void createRubberBandForFeature( int featureId );
void createRubberBandForFeature( QgsFeatureId featureId );

QgsFeatureList mFeatureList;
QgsVectorLayer* mVectorLayer;
Expand Down

0 comments on commit b23ddfe

Please sign in to comment.