Skip to content

Commit

Permalink
[composer] Allow choice of non-geometry vector layers for attribute t…
Browse files Browse the repository at this point in the history
…able, but disable controls which have no meaning for geometryless tables (fix #9944)
  • Loading branch information
nyalldawson committed Apr 14, 2014
1 parent 85b6b0b commit 31c3b0d
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions src/app/composer/qgscomposertablewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ QgsComposerTableWidget::QgsComposerTableWidget( QgsComposerAttributeTable* table
mainLayout->addWidget( itemPropertiesWidget );

blockAllSignals( true );
mLayerComboBox->setFilters( QgsMapLayerProxyModel::HasGeometry );
mLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer );
connect( mLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( changeLayer( QgsMapLayer* ) ) );

refreshMapComboBox();
Expand Down Expand Up @@ -263,7 +263,20 @@ void QgsComposerTableWidget::updateGuiElements()
blockAllSignals( true );

//layer combo box
mLayerComboBox->setLayer( mComposerTable->vectorLayer() );
if ( mComposerTable->vectorLayer() )
{
mLayerComboBox->setLayer( mComposerTable->vectorLayer() );
if ( mComposerTable->vectorLayer()->geometryType() == QGis::NoGeometry )
{
//layer has no geometry, so uncheck & disable controls which require geometry
mShowOnlyVisibleFeaturesCheckBox->setChecked( false );
mShowOnlyVisibleFeaturesCheckBox->setEnabled( false );
}
else
{
mShowOnlyVisibleFeaturesCheckBox->setEnabled( true );
}
}

//map combo box
const QgsComposerMap* cm = mComposerTable->composerMap();
Expand All @@ -290,13 +303,17 @@ void QgsComposerTableWidget::updateGuiElements()
mShowGridGroupCheckBox->setChecked( false );
}

if ( mComposerTable->displayOnlyVisibleFeatures() )
if ( mComposerTable->displayOnlyVisibleFeatures() && mShowOnlyVisibleFeaturesCheckBox->isEnabled() )
{
mShowOnlyVisibleFeaturesCheckBox->setCheckState( Qt::Checked );
mComposerMapComboBox->setEnabled( true );
mComposerMapLabel->setEnabled( true );
}
else
{
mShowOnlyVisibleFeaturesCheckBox->setCheckState( Qt::Unchecked );
mComposerMapComboBox->setEnabled( false );
mComposerMapLabel->setEnabled( false );
}

mFeatureFilterEdit->setText( mComposerTable->featureFilter() );
Expand Down Expand Up @@ -339,6 +356,10 @@ void QgsComposerTableWidget::on_mShowOnlyVisibleFeaturesCheckBox_stateChanged( i
mComposerTable->setDisplayOnlyVisibleFeatures( showOnlyVisibleFeatures );
mComposerTable->update();
mComposerTable->endCommand();

//enable/disable map combobox based on state of checkbox
mComposerMapComboBox->setEnabled( state == Qt::Checked );
mComposerMapLabel->setEnabled( state == Qt::Checked );
}

void QgsComposerTableWidget::on_mFeatureFilterCheckBox_stateChanged( int state )
Expand Down Expand Up @@ -408,11 +429,24 @@ void QgsComposerTableWidget::changeLayer( QgsMapLayer *layer )
}

QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer );
if ( vl )
if ( !vl )
{
mComposerTable->beginCommand( tr( "Table layer changed" ) );
mComposerTable->setVectorLayer( vl );
mComposerTable->update();
mComposerTable->endCommand();
return;
}

mComposerTable->beginCommand( tr( "Table layer changed" ) );
mComposerTable->setVectorLayer( vl );
mComposerTable->update();
mComposerTable->endCommand();

if ( vl->geometryType() == QGis::NoGeometry )
{
//layer has no geometry, so uncheck & disable controls which require geometry
mShowOnlyVisibleFeaturesCheckBox->setChecked( false );
mShowOnlyVisibleFeaturesCheckBox->setEnabled( false );
}
else
{
mShowOnlyVisibleFeaturesCheckBox->setEnabled( true );
}
}

0 comments on commit 31c3b0d

Please sign in to comment.