Skip to content

Commit

Permalink
Merge pull request #473 from Oslandia/atlas
Browse files Browse the repository at this point in the history
Atlas: fix #7408
  • Loading branch information
jef-n committed Mar 26, 2013
2 parents 250cc4e + a482c42 commit 53c47dd
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
22 changes: 22 additions & 0 deletions src/app/composer/qgsatlascompositionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,27 @@ void QgsAtlasCompositionWidget::on_mAtlasSortFeatureKeyComboBox_currentIndexChan
}
}

void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterCheckBox_stateChanged( int state )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
}

if ( state == Qt::Checked )
{
mAtlasFeatureFilterEdit->setEnabled( true );
mAtlasFeatureFilterButton->setEnabled( true );
}
else
{
mAtlasFeatureFilterEdit->setEnabled( false );
mAtlasFeatureFilterButton->setEnabled( false );
}
atlasMap->setFilterFeatures( state == Qt::Checked );
}

void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterEdit_textChanged( const QString& text )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
Expand Down Expand Up @@ -421,6 +442,7 @@ void QgsAtlasCompositionWidget::updateGuiElements()
mAtlasSortFeatureKeyComboBox->setCurrentIndex( atlasMap->sortKeyAttributeIndex() );
mAtlasSortFeatureDirectionButton->setArrowType( atlasMap->sortAscending() ? Qt::UpArrow : Qt::DownArrow );
mAtlasFeatureFilterEdit->setText( atlasMap->featureFilter() );
mAtlasFeatureFilterCheckBox->setCheckState( atlasMap->filterFeatures() ? Qt::Checked : Qt::Unchecked );
}

void QgsAtlasCompositionWidget::blockAllSignals( bool b )
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgsatlascompositionwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class QgsAtlasCompositionWidget:
void on_mAtlasSortFeatureDirectionButton_clicked();
void on_mAtlasFeatureFilterEdit_textChanged( const QString& text );
void on_mAtlasFeatureFilterButton_clicked();
void on_mAtlasFeatureFilterCheckBox_stateChanged( int state );

// extract fields from the current coverage layer and populate the corresponding combo box
void fillSortColumns();
Expand Down
18 changes: 13 additions & 5 deletions src/core/composer/qgsatlascomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void QgsAtlasComposition::beginRender()
QgsFeatureIterator fit = mCoverageLayer->getFeatures();

std::auto_ptr<QgsExpression> filterExpression;
if ( mFeatureFilter.size() > 0 )
if ( mFilterFeatures )
{
filterExpression = std::auto_ptr<QgsExpression>( new QgsExpression( mFeatureFilter ) );
if ( filterExpression->hasParserError() )
Expand All @@ -134,7 +134,7 @@ void QgsAtlasComposition::beginRender()
mFeatureKeys.clear();
while ( fit.nextFeature( feat ) )
{
if ( mFeatureFilter.size() > 0 )
if ( mFilterFeatures )
{
QVariant result = filterExpression->evaluate( &feat, mCoverageLayer->pendingFields() );
if ( filterExpression->hasEvalError() )
Expand Down Expand Up @@ -228,7 +228,7 @@ void QgsAtlasComposition::prepareForFeature( size_t featureI )
if ( !mSingleFile && mFilenamePattern.size() > 0 )
{
QgsExpression::setSpecialColumn( "$feature", QVariant(( int )featureI + 1 ) );
QVariant filenameRes = mFilenameExpr->evaluate( &mCurrentFeature );
QVariant filenameRes = mFilenameExpr->evaluate( &mCurrentFeature, mCoverageLayer->pendingFields() );
if ( mFilenameExpr->hasEvalError() )
{
throw std::runtime_error( tr( "Filename eval error: %1" ).arg( mFilenameExpr->evalErrorString() ).toLocal8Bit().data() );
Expand Down Expand Up @@ -360,7 +360,11 @@ void QgsAtlasComposition::writeXML( QDomElement& elem, QDomDocument& doc ) const
atlasElem.setAttribute( "sortKey", QString::number( mSortKeyAttributeIdx ) );
atlasElem.setAttribute( "sortAscending", mSortAscending ? "true" : "false" );
}
atlasElem.setAttribute( "featureFilter", mFeatureFilter );
atlasElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
if ( mFilterFeatures )
{
atlasElem.setAttribute( "featureFilter", mFeatureFilter );
}

elem.appendChild( atlasElem );
}
Expand Down Expand Up @@ -408,7 +412,11 @@ void QgsAtlasComposition::readXML( const QDomElement& atlasElem, const QDomDocum
mSortKeyAttributeIdx = atlasElem.attribute( "sortKey", "0" ).toInt();
mSortAscending = atlasElem.attribute( "sortAscending", "true" ) == "true" ? true : false;
}
mFeatureFilter = atlasElem.attribute( "featureFilter", "" );
mFilterFeatures = atlasElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
if ( mFilterFeatures )
{
mFeatureFilter = atlasElem.attribute( "featureFilter", "" );
}

emit parameterChanged();
}
7 changes: 6 additions & 1 deletion src/core/composer/qgsatlascomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
bool sortAscending() const { return mSortAscending; }
void setSortAscending( bool ascending ) { mSortAscending = ascending; }

bool filterFeatures() const { return mFilterFeatures; }
void setFilterFeatures( bool doFilter ) { mFilterFeatures = doFilter; }

QString featureFilter() const { return mFeatureFilter; }
void setFeatureFilter( const QString& expression ) { mFeatureFilter = expression; }

Expand Down Expand Up @@ -127,7 +130,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
// key (attribute index) used for ordering
size_t mSortKeyAttributeIdx;

// feature expression filter (or empty)
// feature filtering
bool mFilterFeatures;
// feature expression filter
QString mFeatureFilter;

// id of each iterated feature (after filtering and sorting)
Expand Down
18 changes: 9 additions & 9 deletions src/ui/qgsatlascompositionwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<x>0</x>
<y>0</y>
<width>431</width>
<height>566</height>
<height>567</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
Expand Down Expand Up @@ -256,8 +256,15 @@
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="1">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="mAtlasFeatureFilterCheckBox">
<property name="text">
<string>Filter with</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mAtlasFeatureFilterEdit"/>
</item>
Expand All @@ -270,13 +277,6 @@
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Filter with</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 53c47dd

Please sign in to comment.