Skip to content

Commit

Permalink
Don't list join fields to facilitate 'save as' function (fixes #3857)…
Browse files Browse the repository at this point in the history
…. Don't display the query builder if a layer has joins (#3858)
  • Loading branch information
Marco Hugentobler committed Jun 3, 2011
1 parent 107df1f commit 3ac604f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ void QgsVectorLayerProperties::toggleEditing()
{
emit toggleEditing( layer );

pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() && !layer->isEditable() );
pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
!layer->isEditable() && layer->vectorJoins().size() < 1 );
if ( layer->isEditable() )
{
pbnQueryBuilder->setToolTip( tr( "Stop editing mode to enable this." ) );
Expand Down Expand Up @@ -474,7 +475,8 @@ void QgsVectorLayerProperties::reset( void )
// on the builder. If the ability to enter a query directly into the box is required,
// a mechanism to check it must be implemented.
txtSubsetSQL->setEnabled( false );
pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() && !layer->isEditable() );
pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
!layer->isEditable() && layer->vectorJoins().size() < 1 );
if ( layer->isEditable() )
{
pbnQueryBuilder->setToolTip( tr( "Stop editing mode to enable this." ) );
Expand Down Expand Up @@ -1079,6 +1081,8 @@ void QgsVectorLayerProperties::on_mButtonAddJoin_clicked()
layer->addJoin( info );
loadRows(); //update attribute tab
addJoinToTreeWidget( info );
pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
!layer->isEditable() && layer->vectorJoins().size() < 1 );
}
}
}
Expand Down Expand Up @@ -1116,6 +1120,8 @@ void QgsVectorLayerProperties::on_mButtonRemoveJoin_clicked()
layer->removeJoin( currentJoinItem->data( 0, Qt::UserRole ).toString() );
loadRows();
mJoinTreeWidget->takeTopLevelItem( mJoinTreeWidget->indexOfTopLevelItem( currentJoinItem ) );
pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
!layer->isEditable() && layer->vectorJoins().size() < 1 );
}

void QgsVectorLayerProperties::handleDiagramItemDoubleClick( QTreeWidgetItem * item, int column )
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2693,6 +2693,7 @@ bool QgsVectorLayer::readXml( QDomNode & layer_node )
mJoinBuffer->readXml( layer_node );

updateFieldMap();
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( checkJoinLayerRemove( QString ) ) );

QString errorMsg;
if ( !readSymbology( layer_node, errorMsg ) )
Expand Down
12 changes: 11 additions & 1 deletion src/core/qgsvectorlayerjoinbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ void QgsVectorLayerJoinBuffer::updateFieldMap( QgsFieldMap& fields, int& maxInde
QgsFieldMap::const_iterator fieldIt = joinFields.constBegin();
for ( ; fieldIt != joinFields.constEnd(); ++fieldIt )
{
fields.insert( maxIndex + 1 + fieldIt.key(), fieldIt.value() );
//skip the join field to avoid double field names (fields often have the same name)
if ( fieldIt.key() != joinIt->joinField )
{
fields.insert( maxIndex + 1 + fieldIt.key(), fieldIt.value() );
}
}

if ( maximumIndex( joinFields, currentMaxIndex ) )
Expand Down Expand Up @@ -217,6 +221,12 @@ void QgsVectorLayerJoinBuffer::addJoinedFeatureAttributes( QgsFeature& f, const
QgsAttributeList::const_iterator attIt = attributes.constBegin();
for ( ; attIt != attributes.constEnd(); ++attIt )
{
//skip the join field to avoid double field names (fields often have the same name)
if ( *attIt == joinInfo.joinField )
{
continue;
}

if ( found )
{
f.addAttribute( *attIt + attributeIndexOffset, featureAttributes.value( *attIt ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayerjoinbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <QHash>
#include <QString>

/**Manages joined field for a vector layer*/
/**Manages joined fields for a vector layer*/
class CORE_EXPORT QgsVectorLayerJoinBuffer
{
public:
Expand Down

0 comments on commit 3ac604f

Please sign in to comment.