Skip to content

Commit

Permalink
[joins] editing keeps the same order and selection in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Mar 12, 2015
1 parent 1810cdd commit a9e58e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -1099,11 +1099,11 @@ void QgsVectorLayerProperties::on_mButtonEditJoin_clicked()

// remove old join
layer->removeJoin( joinLayerId );
mJoinTreeWidget->takeTopLevelItem( mJoinTreeWidget->indexOfTopLevelItem( currentJoinItem ) );
int idx = mJoinTreeWidget->indexOfTopLevelItem( currentJoinItem );
mJoinTreeWidget->takeTopLevelItem( idx );

// add the new edited


//create attribute index if possible
if ( d.createAttributeIndex() )
{
Expand All @@ -1114,15 +1114,15 @@ void QgsVectorLayerProperties::on_mButtonEditJoin_clicked()
}
}
layer->addJoin( info );
addJoinToTreeWidget( info );
addJoinToTreeWidget( info, idx );

pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
!layer->isEditable() && layer->vectorJoins().size() < 1 );
mFieldsPropertiesDialog->init();
}
}

void QgsVectorLayerProperties::addJoinToTreeWidget( const QgsVectorJoinInfo& join )
void QgsVectorLayerProperties::addJoinToTreeWidget( const QgsVectorJoinInfo& join, const int insertIndex )
{
QTreeWidgetItem* joinItem = new QTreeWidgetItem();

Expand Down Expand Up @@ -1170,11 +1170,19 @@ void QgsVectorLayerProperties::addJoinToTreeWidget( const QgsVectorJoinInfo& joi
joinItem->setText( 5, tr( "all" ) );
}

mJoinTreeWidget->addTopLevelItem( joinItem );
if ( insertIndex >= 0 )
{
mJoinTreeWidget->insertTopLevelItem( insertIndex, joinItem );
}
else
{
mJoinTreeWidget->addTopLevelItem( joinItem );
}
for ( int c = 0; c < 5; c++ )
{
mJoinTreeWidget->resizeColumnToContents( c );
}
mJoinTreeWidget->setCurrentItem( joinItem );
}

void QgsVectorLayerProperties::on_mButtonRemoveJoin_clicked()
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsvectorlayerproperties.h
Expand Up @@ -181,7 +181,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
//QPixmap bufferPixmap;

/**Adds a new join to mJoinTreeWidget*/
void addJoinToTreeWidget( const QgsVectorJoinInfo& join );
void addJoinToTreeWidget( const QgsVectorJoinInfo& join , const int insertIndex = -1 );
};

inline QString QgsVectorLayerProperties::displayName()
Expand Down

0 comments on commit a9e58e6

Please sign in to comment.