Skip to content
Permalink
Browse files

[FEATURE][composer] Add a checkbox to filter attribute tables to

features which intersect the current atlas feature. Sponsored by City
of Uster, Switzerland.
  • Loading branch information
nyalldawson committed Sep 22, 2014
1 parent 14690d0 commit 30ada2833a7804f66077056f9fcd626952faccb1
@@ -139,7 +139,7 @@ class QgsComposerAttributeTableV2 : QgsComposerTableV2
* @param features maximum number of features to show in the table
* @see maximumNumberOfFeatures
*/
void setMaximumNumberOfFeatures( int features );
void setMaximumNumberOfFeatures( const int features );

/**Returns the maximum number of features to be shown by the table.
* @returns maximum number of features
@@ -154,7 +154,7 @@ class QgsComposerAttributeTableV2 : QgsComposerTableV2
* @see displayOnlyVisibleFeatures
* @see setComposerMap
*/
void setDisplayOnlyVisibleFeatures( bool visibleOnly );
void setDisplayOnlyVisibleFeatures( const bool visibleOnly );

/**Returns true if the table is set to show only features visible on a corresponding
* composer map item.
@@ -163,6 +163,21 @@ class QgsComposerAttributeTableV2 : QgsComposerTableV2
* @see setDisplayOnlyVisibleFeatures
*/
bool displayOnlyVisibleFeatures() const;

/**Sets attribute table to only show features which intersect the current atlas
* feature.
* @param filterToAtlas set to true to show only features which intersect
* the atlas feature
* @see filterToAtlasFeature
*/
void setFilterToAtlasFeature( const bool filterToAtlas );

/**Returns true if the table is set to only show features which intersect the current atlas
* feature.
* @returns true if table only shows features which intersect the atlas feature
* @see setFilterToAtlasFeature
*/
bool filterToAtlasFeature() const;

/**Returns true if a feature filter is active on the attribute table
* @returns bool state of the feature filter
@@ -178,7 +193,7 @@ class QgsComposerAttributeTableV2 : QgsComposerTableV2
* @see filterFeatures
* @see setFeatureFilter
*/
void setFilterFeatures( bool filter );
void setFilterFeatures( const bool filter );

/**Returns the current expression used to filter features for the table. The filter is only
* active if filterFeatures() is true.
@@ -491,6 +491,7 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
mComposerMapLabel->setEnabled( false );
}

mIntersectAtlasCheckBox->setChecked( mComposerTable->filterToAtlasFeature() );
mFeatureFilterEdit->setText( mComposerTable->featureFilter() );
mFeatureFilterCheckBox->setCheckState( mComposerTable->filterFeatures() ? Qt::Checked : Qt::Unchecked );
mFeatureFilterEdit->setEnabled( mComposerTable->filterFeatures() );
@@ -521,6 +522,11 @@ void QgsComposerAttributeTableWidget::atlasToggled()
mSourceComboBox->blockSignals( true );
mSourceComboBox->setCurrentIndex( mSourceComboBox->findData( mComposerTable->source() ) );
mSourceComboBox->blockSignals( false );

if ( !atlasEnabled && mComposerTable && mComposerTable->filterToAtlasFeature() )
{
mComposerTable->setFilterToAtlasFeature( false );
}
}

void QgsComposerAttributeTableWidget::updateRelationsCombo()
@@ -556,6 +562,7 @@ void QgsComposerAttributeTableWidget::toggleAtlasSpecificControls( const bool at
mRelationsComboBox->setEnabled( false );
mRelationsComboBox->clear();
mRelationsComboBox->blockSignals( false );
mIntersectAtlasCheckBox->setEnabled( false );
}
else
{
@@ -573,6 +580,7 @@ void QgsComposerAttributeTableWidget::toggleAtlasSpecificControls( const bool at
//add relations for coverage layer
updateRelationsCombo();
mRelationsComboBox->setEnabled( true );
mIntersectAtlasCheckBox->setEnabled( true );
}
}

@@ -587,6 +595,7 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
mGridStrokeWidthSpinBox->blockSignals( b );
mShowGridGroupCheckBox->blockSignals( b );
mShowOnlyVisibleFeaturesCheckBox->blockSignals( b );
mIntersectAtlasCheckBox->blockSignals( b );
mFeatureFilterEdit->blockSignals( b );
mFeatureFilterCheckBox->blockSignals( b );
mHeaderHAlignmentComboBox->blockSignals( b );
@@ -631,6 +640,27 @@ void QgsComposerAttributeTableWidget::on_mShowOnlyVisibleFeaturesCheckBox_stateC
mComposerMapLabel->setEnabled( state == Qt::Checked );
}

void QgsComposerAttributeTableWidget::on_mIntersectAtlasCheckBox_stateChanged( int state )
{
if ( !mComposerTable )
{
return;
}

QgsComposition* composition = mComposerTable->composition();
if ( composition )
{
composition->beginMultiFrameCommand( mComposerTable, tr( "Table filter to atlas changed" ) );
}
bool filterToAtlas = ( state == Qt::Checked );
mComposerTable->setFilterToAtlasFeature( filterToAtlas );
mComposerTable->update();
if ( composition )
{
composition->endMultiFrameCommand();
}
}

void QgsComposerAttributeTableWidget::on_mFeatureFilterCheckBox_stateChanged( int state )
{
if ( !mComposerTable )
@@ -72,6 +72,7 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void on_mRelationsComboBox_currentIndexChanged( int index );
void on_mEmptyModeComboBox_currentIndexChanged( int index );
void on_mEmptyMessageLineEdit_editingFinished();
void on_mIntersectAtlasCheckBox_stateChanged( int state );

/**Inserts a new maximum number of features into the spin box (without the spinbox emitting a signal)*/
void setMaximumNumberOfFeatures( int n );
@@ -82,6 +83,7 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void atlasToggled();

void updateRelationsCombo();

};

#endif // QGSCOMPOSERATTRIBUTETABLEWIDGET_H
@@ -25,6 +25,7 @@
#include "qgsatlascomposition.h"
#include "qgsproject.h"
#include "qgsrelationmanager.h"
#include "qgsgeometry.h"

//QgsComposerAttributeTableCompareV2

@@ -104,6 +105,7 @@ QgsComposerAttributeTableV2::QgsComposerAttributeTableV2( QgsComposition* compos
, mComposerMap( 0 )
, mMaximumNumberOfFeatures( 5 )
, mShowOnlyVisibleFeatures( false )
, mFilterToAtlasIntersection( false )
, mFilterFeatures( false )
, mFeatureFilter( "" )
{
@@ -279,7 +281,7 @@ void QgsComposerAttributeTableV2::setComposerMap( const QgsComposerMap* map )
emit changed();
}

void QgsComposerAttributeTableV2::setMaximumNumberOfFeatures( int features )
void QgsComposerAttributeTableV2::setMaximumNumberOfFeatures( const int features )
{
if ( features == mMaximumNumberOfFeatures )
{
@@ -291,7 +293,7 @@ void QgsComposerAttributeTableV2::setMaximumNumberOfFeatures( int features )
emit changed();
}

void QgsComposerAttributeTableV2::setDisplayOnlyVisibleFeatures( bool visibleOnly )
void QgsComposerAttributeTableV2::setDisplayOnlyVisibleFeatures( const bool visibleOnly )
{
if ( visibleOnly == mShowOnlyVisibleFeatures )
{
@@ -303,7 +305,19 @@ void QgsComposerAttributeTableV2::setDisplayOnlyVisibleFeatures( bool visibleOnl
emit changed();
}

void QgsComposerAttributeTableV2::setFilterFeatures( bool filter )
void QgsComposerAttributeTableV2::setFilterToAtlasFeature( const bool filterToAtlas )
{
if ( filterToAtlas == mFilterToAtlasIntersection )
{
return;
}

mFilterToAtlasIntersection = filterToAtlas;
refreshAttributes();
emit changed();
}

void QgsComposerAttributeTableV2::setFilterFeatures( const bool filter )
{
if ( filter == mFilterFeatures )
{
@@ -505,6 +519,21 @@ bool QgsComposerAttributeTableV2::getTableContents( QgsComposerTableContents &co
continue;
}
}
//check against atlas feature intersection
if ( mFilterToAtlasIntersection )
{
if ( !f.geometry() || ! mComposition->atlasComposition().enabled() )
{
continue;
}
QgsFeature* atlasFeature = mComposition->atlasComposition().currentFeature();
if ( !atlasFeature || !atlasFeature->geometry() ||
!f.geometry()->intersects( atlasFeature->geometry() ) )
{
//feature falls outside current atlas feature
continue;
}
}

QgsComposerTableRow currentRow;

@@ -616,6 +645,7 @@ bool QgsComposerAttributeTableV2::writeXML( QDomElement& elem, QDomDocument & do
composerTableElem.setAttribute( "source", QString::number(( int )mSource ) );
composerTableElem.setAttribute( "relationId", mRelationId );
composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
composerTableElem.setAttribute( "filterToAtlasIntersection", mFilterToAtlasIntersection );
composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
composerTableElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
composerTableElem.setAttribute( "featureFilter", mFeatureFilter );
@@ -669,6 +699,7 @@ bool QgsComposerAttributeTableV2::readXML( const QDomElement& itemElem, const QD
}

mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
mFilterToAtlasIntersection = itemElem.attribute( "filterToAtlasIntersection", "0" ).toInt();
mFilterFeatures = itemElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
mFeatureFilter = itemElem.attribute( "featureFilter", "" );
mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
@@ -162,7 +162,7 @@ class CORE_EXPORT QgsComposerAttributeTableV2: public QgsComposerTableV2
* @param features maximum number of features to show in the table
* @see maximumNumberOfFeatures
*/
void setMaximumNumberOfFeatures( int features );
void setMaximumNumberOfFeatures( const int features );

/**Returns the maximum number of features to be shown by the table.
* @returns maximum number of features
@@ -177,7 +177,7 @@ class CORE_EXPORT QgsComposerAttributeTableV2: public QgsComposerTableV2
* @see displayOnlyVisibleFeatures
* @see setComposerMap
*/
void setDisplayOnlyVisibleFeatures( bool visibleOnly );
void setDisplayOnlyVisibleFeatures( const bool visibleOnly );

/**Returns true if the table is set to show only features visible on a corresponding
* composer map item.
@@ -187,6 +187,21 @@ class CORE_EXPORT QgsComposerAttributeTableV2: public QgsComposerTableV2
*/
bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }

/**Sets attribute table to only show features which intersect the current atlas
* feature.
* @param filterToAtlas set to true to show only features which intersect
* the atlas feature
* @see filterToAtlasFeature
*/
void setFilterToAtlasFeature( const bool filterToAtlas );

/**Returns true if the table is set to only show features which intersect the current atlas
* feature.
* @returns true if table only shows features which intersect the atlas feature
* @see setFilterToAtlasFeature
*/
bool filterToAtlasFeature() const { return mFilterToAtlasIntersection; }

/**Returns true if a feature filter is active on the attribute table
* @returns bool state of the feature filter
* @see setFilterFeatures
@@ -201,7 +216,7 @@ class CORE_EXPORT QgsComposerAttributeTableV2: public QgsComposerTableV2
* @see filterFeatures
* @see setFeatureFilter
*/
void setFilterFeatures( bool filter );
void setFilterFeatures( const bool filter );

/**Returns the current expression used to filter features for the table. The filter is only
* active if filterFeatures() is true.
@@ -266,6 +281,9 @@ class CORE_EXPORT QgsComposerAttributeTableV2: public QgsComposerTableV2
/**Shows only the features that are visible in the associated composer map (true by default)*/
bool mShowOnlyVisibleFeatures;

/**Shows only the features that intersect the current atlas feature*/
bool mFilterToAtlasIntersection;

/**True if feature filtering enabled*/
bool mFilterFeatures;
/**Feature filter expression*/
@@ -45,9 +45,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-195</y>
<y>0</y>
<width>392</width>
<height>1020</height>
<height>1048</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
@@ -161,7 +161,7 @@
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="mShowOnlyVisibleFeaturesCheckBox">
<property name="text">
<string>Show only visible features</string>
<string>Show only features visible within a map</string>
</property>
</widget>
</item>
@@ -181,14 +181,14 @@
<item row="2" column="1">
<widget class="QComboBox" name="mComposerMapComboBox"/>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QCheckBox" name="mFeatureFilterCheckBox">
<property name="text">
<string>Filter with</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="mFeatureFilterEdit"/>
@@ -206,13 +206,21 @@
</item>
</layout>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mIntersectAtlasCheckBox">
<property name="text">
<string>Show only features intersecting atlas feature</string>
</property>
</widget>
</item>
</layout>
<zorder>mShowOnlyVisibleFeaturesCheckBox</zorder>
<zorder>mComposerMapLabel</zorder>
<zorder>mComposerMapComboBox</zorder>
<zorder>mFeatureFilterCheckBox</zorder>
<zorder>mMaximumRowsSpinBox</zorder>
<zorder>mMaxNumFeaturesLabel</zorder>
<zorder>mIntersectAtlasCheckBox</zorder>
</widget>
</item>
<item>

0 comments on commit 30ada28

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