Skip to content
Permalink
Browse files

[FEATURE][composer] Option for current atlas feature as source for

attribute tables. Sponsored by City of Uster, Switzerland.
  • Loading branch information
nyalldawson committed Sep 22, 2014
1 parent 1704866 commit f58768c550ecd1ec0d5a41557d80c972043cee77
@@ -32,6 +32,15 @@ class QgsComposerAttributeTableV2 : QgsComposerTableV2
%End

public:

/*! Specifies the content source for the attribute table
*/
enum ContentSource
{
LayerAttributes = 0, /*!< table shows attributes from features in a vector layer */
AtlasFeature, /*!< table shows attributes from the current atlas feature */
RelationChildren /*!< table shows attributes from related child features */
};

QgsComposerAttributeTableV2( QgsComposition* composition /TransferThis/, bool createUndoCommands );
~QgsComposerAttributeTableV2();
@@ -52,6 +61,18 @@ class QgsComposerAttributeTableV2 : QgsComposerTableV2

virtual void addFrame( QgsComposerFrame* frame /Transfer/, bool recalcFrameSizes = true );

/**Sets the source for attributes to show in table body.
* @param source content source
* @see source
*/
void setSource( const ContentSource source );

/**Returns the source for attributes shown in the table body.
* @returns content source
* @see setSource
*/
ContentSource source() const;

/**Sets the vector layer from which to display feature attributes
* @param layer Vector layer for attribute table
* @see vectorLayer
@@ -222,6 +222,11 @@ class QgsComposerTableV2: QgsComposerMultiFrame
* @note not available in python bindings
*/
virtual bool getTableContents( QgsComposerTableContents &contents ) = 0;

/**Returns the current contents of the table. Excludes header cells.
* @returns table contents
*/
QgsComposerTableContents* contents();

//reimplemented to return fixed table width
virtual QSizeF fixedFrameSize( const int frameIndex = -1 ) const;
@@ -45,6 +45,13 @@ QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAtt
mResizeModeComboBox->addItem( tr( "Extend to next page" ), QgsComposerMultiFrame::ExtendToNextPage );
mResizeModeComboBox->addItem( tr( "Repeat until finished" ), QgsComposerMultiFrame::RepeatUntilFinished );

bool atlasEnabled = atlasComposition() && atlasComposition()->enabled();
mSourceComboBox->addItem( tr( "Layer features" ), QgsComposerAttributeTableV2::LayerAttributes );
if ( atlasEnabled )
{
mSourceComboBox->addItem( tr( "Current atlas feature" ), QgsComposerAttributeTableV2::AtlasFeature );
}

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

@@ -66,6 +73,15 @@ QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAtt
if ( mComposerTable )
{
QObject::connect( mComposerTable, SIGNAL( changed() ), this, SLOT( updateGuiElements() ) );

QgsAtlasComposition* atlas = atlasComposition();
if ( atlas )
{
// repopulate table source combo box if atlas properties change
// connect( atlas, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ),
// this, SLOT( populateDataDefinedButtons() ) );
connect( atlas, SIGNAL( toggled( bool ) ), this, SLOT( atlasToggled() ) );
}
}
}

@@ -202,7 +218,7 @@ void QgsComposerAttributeTableWidget::on_mComposerMapComboBox_activated( int ind
}
}

void QgsComposerAttributeTableWidget::on_mMaximumColumnsSpinBox_valueChanged( int i )
void QgsComposerAttributeTableWidget::on_mMaximumRowsSpinBox_valueChanged( int i )
{
if ( !mComposerTable )
{
@@ -410,6 +426,8 @@ void QgsComposerAttributeTableWidget::updateGuiElements()

blockAllSignals( true );

mSourceComboBox->setCurrentIndex( mSourceComboBox->findData( mComposerTable->source() ) );

//layer combo box
if ( mComposerTable->vectorLayer() )
{
@@ -436,7 +454,7 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
mComposerMapComboBox->setCurrentIndex( mapIndex );
}
}
mMaximumColumnsSpinBox->setValue( mComposerTable->maximumNumberOfFeatures() );
mMaximumRowsSpinBox->setValue( mComposerTable->maximumNumberOfFeatures() );
mMarginSpinBox->setValue( mComposerTable->cellMargin() );
mGridStrokeWidthSpinBox->setValue( mComposerTable->gridStrokeWidth() );
mGridColorButton->setColor( mComposerTable->gridColor() );
@@ -476,14 +494,42 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mComposerTable->resizeMode() ) );
mAddFramePushButton->setEnabled( mComposerTable->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );

toggleSourceControls();

blockAllSignals( false );
}

void QgsComposerAttributeTableWidget::atlasToggled()
{
//display/hide atlas options in source combobox depending on atlas status
bool atlasEnabled = atlasComposition() && atlasComposition()->enabled();
if ( !atlasEnabled )
{
if ( mComposerTable->source() == QgsComposerAttributeTableV2::AtlasFeature )
{
mComposerTable->setSource( QgsComposerAttributeTableV2::LayerAttributes );
}
mSourceComboBox->removeItem( mSourceComboBox->findData( QgsComposerAttributeTableV2::AtlasFeature ) );
}
else
{
if ( mSourceComboBox->findData( QgsComposerAttributeTableV2::AtlasFeature ) == -1 )
{
//add missing atlasfeature option to combobox
mSourceComboBox->addItem( tr( "Current atlas feature" ), QgsComposerAttributeTableV2::AtlasFeature );
}
}
mSourceComboBox->blockSignals( true );
mSourceComboBox->setCurrentIndex( mSourceComboBox->findData( mComposerTable->source() ) );
mSourceComboBox->blockSignals( false );
}

void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
{
mSourceComboBox->blockSignals( b );
mLayerComboBox->blockSignals( b );
mComposerMapComboBox->blockSignals( b );
mMaximumColumnsSpinBox->blockSignals( b );
mMaximumRowsSpinBox->blockSignals( b );
mMarginSpinBox->blockSignals( b );
mGridColorButton->blockSignals( b );
mGridStrokeWidthSpinBox->blockSignals( b );
@@ -500,9 +546,9 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )

void QgsComposerAttributeTableWidget::setMaximumNumberOfFeatures( int n )
{
mMaximumColumnsSpinBox->blockSignals( true );
mMaximumColumnsSpinBox->setValue( n );
mMaximumColumnsSpinBox->blockSignals( false );
mMaximumRowsSpinBox->blockSignals( true );
mMaximumRowsSpinBox->setValue( n );
mMaximumRowsSpinBox->blockSignals( false );
}

void QgsComposerAttributeTableWidget::on_mShowOnlyVisibleFeaturesCheckBox_stateChanged( int state )
@@ -726,3 +772,46 @@ void QgsComposerAttributeTableWidget::on_mResizeModeComboBox_currentIndexChanged

mAddFramePushButton->setEnabled( mComposerTable->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );
}

void QgsComposerAttributeTableWidget::on_mSourceComboBox_currentIndexChanged( int index )
{
if ( !mComposerTable )
{
return;
}

QgsComposition* composition = mComposerTable->composition();
if ( composition )
{
composition->beginMultiFrameCommand( mComposerTable, tr( "Change table source" ) );
mComposerTable->setSource(( QgsComposerAttributeTableV2::ContentSource )mSourceComboBox->itemData( index ).toInt() );
composition->endMultiFrameCommand();
}

toggleSourceControls();
}

void QgsComposerAttributeTableWidget::toggleSourceControls()
{
switch ( mComposerTable->source() )
{
case QgsComposerAttributeTableV2::LayerAttributes:
mLayerComboBox->setEnabled( true );
mMaximumRowsSpinBox->setEnabled( true );
mMaxNumFeaturesLabel->setEnabled( true );
mShowOnlyVisibleFeaturesCheckBox->setEnabled( true );
mComposerMapComboBox->setEnabled( mComposerTable->displayOnlyVisibleFeatures() );
mComposerMapLabel->setEnabled( mComposerTable->displayOnlyVisibleFeatures() );
break;
case QgsComposerAttributeTableV2::AtlasFeature:
mLayerComboBox->setEnabled( false );
mMaximumRowsSpinBox->setEnabled( false );
mMaxNumFeaturesLabel->setEnabled( false );
mShowOnlyVisibleFeaturesCheckBox->setEnabled( false );
mComposerMapComboBox->setEnabled( false );
mComposerMapLabel->setEnabled( false );
break;
default:
break;
}
}
@@ -42,11 +42,13 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void blockAllSignals( bool b );
void refreshMapComboBox();

void toggleSourceControls();

private slots:
void on_mRefreshPushButton_clicked();
void on_mAttributesPushButton_clicked();
void on_mComposerMapComboBox_activated( int index );
void on_mMaximumColumnsSpinBox_valueChanged( int i );
void on_mMaximumRowsSpinBox_valueChanged( int i );
void on_mMarginSpinBox_valueChanged( double d );
void on_mGridStrokeWidthSpinBox_valueChanged( double d );
void on_mGridColorButton_colorChanged( const QColor& newColor );
@@ -64,13 +66,16 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void changeLayer( QgsMapLayer* layer );
void on_mAddFramePushButton_clicked();
void on_mResizeModeComboBox_currentIndexChanged( int index );
void on_mSourceComboBox_currentIndexChanged( int index );

/**Inserts a new maximum number of features into the spin box (without the spinbox emitting a signal)*/
void setMaximumNumberOfFeatures( int n );

/**Sets the GUI elements to the values of mComposerTable*/
void updateGuiElements();

void atlasToggled();

};

#endif // QGSCOMPOSERATTRIBUTETABLEWIDGET_H

0 comments on commit f58768c

Please sign in to comment.
You can’t perform that action at this time.