Skip to content
Permalink
Browse files

refs #7408

[Atlas] Add a checkbox on "filter with"
  • Loading branch information
mhugo committed Mar 21, 2013
1 parent aa43c92 commit a482c42a7689d2afc3f94e00d9698abbf0537f98
@@ -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();
@@ -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 )
@@ -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();
@@ -117,7 +117,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() )
@@ -133,7 +133,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() )
@@ -359,7 +359,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 );
}
@@ -407,7 +411,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();
}
@@ -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; }

@@ -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)
@@ -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">
@@ -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>
@@ -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>

0 comments on commit a482c42

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