Skip to content
Permalink
Browse files
[Atlas] Add UI management for feature sorting and filtering
  • Loading branch information
Hugo Mercier committed Feb 6, 2013
1 parent b477179 commit 866dce84d9b532f49ff22e98ecaba0f29b170976
Showing with 158 additions and 8 deletions.
  1. +112 −0 src/app/composer/qgsatlascompositionwidget.cpp
  2. +8 −0 src/app/composer/qgsatlascompositionwidget.h
  3. +38 −8 src/ui/qgsatlascompositionwidgetbase.ui
@@ -39,6 +39,8 @@ QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsCompos
mAtlasCoverageLayerComboBox->insertItem( idx++, it.value()->name(), /* userdata */ qVariantFromValue(( void* )it.value() ) );
}
}
// update sort columns
fillSortColumns();

// Connect to addition / removal of layers
QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();
@@ -58,6 +60,13 @@ QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsCompos
mComposerMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ), qVariantFromValue(( void* )*mapItemIt ) );
}

// Sort direction
mAtlasSortFeatureDirectionComboBox->insertItem( 0, tr("Ascending") );
mAtlasSortFeatureDirectionComboBox->insertItem( 1, tr("Descending") );
mAtlasSortFeatureDirectionComboBox->setEnabled( false );

mAtlasSortFeatureKeyComboBox->setEnabled( false );

// Connect to addition / removal of maps
connect( mComposition, SIGNAL( composerMapAdded( QgsComposerMap* ) ), this, SLOT( onComposerMapAdded( QgsComposerMap* ) ) );
connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( onItemRemoved( QgsComposerItem* ) ) );
@@ -159,11 +168,17 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang
if ( index == -1 )
{
atlasMap->setCoverageLayer( 0 );

// clean up the sorting columns
mAtlasSortFeatureKeyComboBox->clear();
}
else
{
QgsVectorLayer* layer = reinterpret_cast<QgsVectorLayer*>( mAtlasCoverageLayerComboBox->itemData( index ).value<void*>() );
atlasMap->setCoverageLayer( layer );

// update sorting columns
fillSortColumns();
}
}

@@ -257,6 +272,99 @@ void QgsAtlasCompositionWidget::on_mAtlasSingleFileCheckBox_stateChanged( int st
atlasMap->setSingleFile( state == Qt::Checked );
}

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

if ( state == Qt::Checked ) {
mAtlasSortFeatureDirectionComboBox->setEnabled( true );
mAtlasSortFeatureKeyComboBox->setEnabled( true );
}
else {
mAtlasSortFeatureDirectionComboBox->setEnabled( false );
mAtlasSortFeatureKeyComboBox->setEnabled( false );
}
atlasMap->setSortFeatures( state == Qt::Checked );
}

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

if ( index != -1 ) {
atlasMap->setSortKeyAttributeIndex( index );
}
}

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

if ( index != -1 ) {
atlasMap->setSortAscending( index == 0 ? true : false );
}
}

void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterEdit_textChanged( const QString& text )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
}

atlasMap->setFeatureFilter( text );
}

void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterButton_clicked()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap || !atlasMap->coverageLayer() )
{
return;
}

QgsExpressionBuilderDialog exprDlg( atlasMap->coverageLayer(), mAtlasFeatureFilterEdit->text(), this );
exprDlg.setWindowTitle( tr( "Expression based filter" ) );
if ( exprDlg.exec() == QDialog::Accepted )
{
QString expression = exprDlg.expressionText();
if ( !expression.isEmpty() )
{
// will emit a textChanged signal
mAtlasFeatureFilterEdit->setText( expression );
}
}
}

void QgsAtlasCompositionWidget::fillSortColumns()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap || !atlasMap->coverageLayer() )
{
return;
}

mAtlasSortFeatureKeyComboBox->clear();
// Get fields of the selected coverage layer
const QgsFields& fields = atlasMap->coverageLayer()->pendingFields();
for ( int i = 0; i < fields.count(); ++i ) {
mAtlasSortFeatureKeyComboBox->insertItem( i, fields.at(i).name() );
}
}

void QgsAtlasCompositionWidget::updateGuiElements()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -285,6 +393,10 @@ void QgsAtlasCompositionWidget::updateGuiElements()
mAtlasFixedScaleCheckBox->setCheckState( atlasMap->fixedScale() ? Qt::Checked : Qt::Unchecked );
mAtlasHideCoverageCheckBox->setCheckState( atlasMap->hideCoverage() ? Qt::Checked : Qt::Unchecked );
mAtlasSingleFileCheckBox->setCheckState( atlasMap->singleFile() ? Qt::Checked : Qt::Unchecked );
mAtlasSortFeatureCheckBox->setCheckState( atlasMap->sortFeatures() ? Qt::Checked : Qt::Unchecked );
mAtlasSortFeatureKeyComboBox->setCurrentIndex( atlasMap->sortKeyAttributeIndex() );
mAtlasSortFeatureDirectionComboBox->setCurrentIndex( atlasMap->sortAscending() ? 0 : 1 );
mAtlasFeatureFilterEdit->setText( atlasMap->featureFilter() );
}

void QgsAtlasCompositionWidget::blockAllSignals( bool b )
@@ -43,6 +43,14 @@ class QgsAtlasCompositionWidget:
void on_mAtlasFixedScaleCheckBox_stateChanged( int state );
void on_mAtlasSingleFileCheckBox_stateChanged( int state );

void on_mAtlasSortFeatureCheckBox_stateChanged( int state );
void on_mAtlasSortFeatureKeyComboBox_currentIndexChanged( int index );
void on_mAtlasSortFeatureDirectionComboBox_currentIndexChanged( int index );
void on_mAtlasFeatureFilterEdit_textChanged( const QString& text );
void on_mAtlasFeatureFilterButton_clicked();

// extract fields from the current coverage layer and populate the corresponding combo box
void fillSortColumns();
private slots:
void onLayerRemoved( QString );
void onLayerAdded( QgsMapLayer* );
@@ -75,7 +75,14 @@
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout_7" rowstretch="0,0,0,0,0,0,0,0,0" columnstretch="0,0,0">
<layout class="QGridLayout" name="gridLayout_7" rowstretch="0,0,0,0,0,0,0,0,0,0,0" columnstretch="0,0,0">
<item row="5" column="0">
<widget class="QLabel" name="mAtlasFeatureFilterLabel">
<property name="text">
<string>Feature filter</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="mAtlasHideCoverageCheckBox">
<property name="toolTip">
@@ -86,21 +93,21 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Margin around coverage</string>
</property>
</widget>
</item>
<item row="7" column="0">
<item row="9" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Output filename expression</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="6" column="1">
<widget class="QSpinBox" name="mAtlasMarginSpinBox">
<property name="suffix">
<string> %</string>
@@ -113,14 +120,14 @@
</property>
</widget>
</item>
<item row="7" column="2">
<item row="9" column="2">
<widget class="QToolButton" name="mAtlasFilenameExpressionButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="9" column="1">
<widget class="QLineEdit" name="mAtlasFilenamePatternEdit"/>
</item>
<item row="1" column="0">
@@ -137,14 +144,14 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="mAtlasFixedScaleCheckBox">
<property name="text">
<string>Fixed scale</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<item row="10" column="0" colspan="2">
<widget class="QCheckBox" name="mAtlasSingleFileCheckBox">
<property name="text">
<string>Single file export when possible</string>
@@ -161,6 +168,29 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="mAtlasSortFeatureKeyComboBox"/>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="mAtlasSortFeatureCheckBox">
<property name="text">
<string>Sort features</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QToolButton" name="mAtlasFeatureFilterButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="mAtlasFeatureFilterEdit"/>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="mAtlasSortFeatureDirectionComboBox"/>
</item>
</layout>
</item>
</layout>

0 comments on commit 866dce8

Please sign in to comment.