Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[composer] Add an apply button for atlas settings, prevents
numerous refetching/redrawing when tweaking atlas configuration
  • Loading branch information
nyalldawson committed Aug 3, 2015
1 parent 8088e35 commit 7934a92
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 106 deletions.
109 changes: 23 additions & 86 deletions src/app/composer/qgsatlascompositionwidget.cpp
Expand Up @@ -33,9 +33,7 @@ QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsCompos
mAtlasCoverageLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer );

connect( mAtlasCoverageLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), mAtlasSortFeatureKeyComboBox, SLOT( setLayer( QgsMapLayer* ) ) );
connect( mAtlasCoverageLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( changeCoverageLayer( QgsMapLayer* ) ) );
connect( mAtlasSortFeatureKeyComboBox, SIGNAL( fieldChanged( QString ) ), this, SLOT( changesSortFeatureField( QString ) ) );
connect( mPageNameWidget, SIGNAL( fieldChanged( QString, bool ) ), this, SLOT( pageNameExpressionChanged( QString, bool ) ) );
connect( mAtlasCoverageLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), mPageNameWidget, SLOT( setLayer( QgsMapLayer* ) ) );

// Sort direction
mAtlasSortFeatureDirectionButton->setEnabled( false );
Expand Down Expand Up @@ -68,27 +66,6 @@ void QgsAtlasCompositionWidget::on_mUseAtlasCheckBox_stateChanged( int state )
}
}

void QgsAtlasCompositionWidget::changeCoverageLayer( QgsMapLayer *layer )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
}

QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer );

if ( !vl )
{
atlasMap->setCoverageLayer( 0 );
}
else
{
atlasMap->setCoverageLayer( vl );
updateAtlasFeatures();
}
}

void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_editingFinished()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
Expand Down Expand Up @@ -140,16 +117,6 @@ void QgsAtlasCompositionWidget::on_mAtlasFilenameExpressionButton_clicked()
}
}

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

void QgsAtlasCompositionWidget::on_mAtlasSingleFileCheckBox_stateChanged( int state )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
Expand All @@ -172,12 +139,6 @@ void QgsAtlasCompositionWidget::on_mAtlasSingleFileCheckBox_stateChanged( int st

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

if ( state == Qt::Checked )
{
mAtlasSortFeatureDirectionButton->setEnabled( true );
Expand All @@ -188,8 +149,6 @@ void QgsAtlasCompositionWidget::on_mAtlasSortFeatureCheckBox_stateChanged( int s
mAtlasSortFeatureDirectionButton->setEnabled( false );
mAtlasSortFeatureKeyComboBox->setEnabled( false );
}
atlasMap->setSortFeatures( state == Qt::Checked );
updateAtlasFeatures();
}

void QgsAtlasCompositionWidget::updateAtlasFeatures()
Expand All @@ -215,31 +174,12 @@ void QgsAtlasCompositionWidget::updateAtlasFeatures()
QMessageBox::Ok,
QMessageBox::Ok );

//Perhaps atlas preview should be disabled now? If so, it may get annoying if user is editing
//the filter expression and it keeps disabling itself.
return;
}
}

void QgsAtlasCompositionWidget::changesSortFeatureField( QString fieldName )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
}
atlasMap->setSortKeyAttributeName( fieldName );
updateAtlasFeatures();
}

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

if ( state == Qt::Checked )
{
mAtlasFeatureFilterEdit->setEnabled( true );
Expand All @@ -250,51 +190,57 @@ void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterCheckBox_stateChanged( int
mAtlasFeatureFilterEdit->setEnabled( false );
mAtlasFeatureFilterButton->setEnabled( false );
}
atlasMap->setFilterFeatures( state == Qt::Checked );
updateAtlasFeatures();
}

void QgsAtlasCompositionWidget::pageNameExpressionChanged( QString expression, bool valid )
void QgsAtlasCompositionWidget::on_mApplyConfigButton_clicked()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap || ( !valid && !expression.isEmpty() ) )
if ( !atlasMap )
{
return;
}

atlasMap->setPageNameExpression( expression );
}

void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterEdit_editingFinished()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( mAtlasCoverageLayerComboBox->currentLayer() );
if ( !vl )
{
return;
atlasMap->setCoverageLayer( 0 );
}
else
{
atlasMap->setCoverageLayer( vl );
}

atlasMap->setSortFeatures( mAtlasSortFeatureCheckBox->isChecked() );
atlasMap->setSortKeyAttributeName( mAtlasSortFeatureKeyComboBox->currentField() );
Qt::ArrowType at = mAtlasSortFeatureDirectionButton->arrowType();
at = ( at == Qt::UpArrow ) ? Qt::DownArrow : Qt::UpArrow;
atlasMap->setSortAscending( at == Qt::UpArrow );
atlasMap->setFilterFeatures( mAtlasFeatureFilterCheckBox->isChecked() );
atlasMap->setFeatureFilter( mAtlasFeatureFilterEdit->text() );
atlasMap->setPageNameExpression( mPageNameWidget->currentField() );
atlasMap->setHideCoverage( mAtlasHideCoverageCheckBox->isChecked() );

updateAtlasFeatures();
}

void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterButton_clicked()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap || !atlasMap->coverageLayer() )
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( mAtlasCoverageLayerComboBox->currentLayer() );

if ( !atlasMap || !vl )
{
return;
}

QgsExpressionBuilderDialog exprDlg( atlasMap->coverageLayer(), mAtlasFeatureFilterEdit->text(), this );
QgsExpressionBuilderDialog exprDlg( vl, mAtlasFeatureFilterEdit->text(), this );
exprDlg.setWindowTitle( tr( "Expression based filter" ) );
if ( exprDlg.exec() == QDialog::Accepted )
{
QString expression = exprDlg.expressionText();
if ( !expression.isEmpty() )
{
mAtlasFeatureFilterEdit->setText( expression );
atlasMap->setFeatureFilter( mAtlasFeatureFilterEdit->text() );
updateAtlasFeatures();
}
}
}
Expand All @@ -304,15 +250,6 @@ void QgsAtlasCompositionWidget::on_mAtlasSortFeatureDirectionButton_clicked()
Qt::ArrowType at = mAtlasSortFeatureDirectionButton->arrowType();
at = ( at == Qt::UpArrow ) ? Qt::DownArrow : Qt::UpArrow;
mAtlasSortFeatureDirectionButton->setArrowType( at );

QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
}

atlasMap->setSortAscending( at == Qt::UpArrow );
updateAtlasFeatures();
}

void QgsAtlasCompositionWidget::updateGuiElements()
Expand Down
6 changes: 1 addition & 5 deletions src/app/composer/qgsatlascompositionwidget.h
Expand Up @@ -36,19 +36,15 @@ class QgsAtlasCompositionWidget:

public slots:
void on_mUseAtlasCheckBox_stateChanged( int state );
void changeCoverageLayer( QgsMapLayer* layer );
void on_mAtlasFilenamePatternEdit_editingFinished();
void on_mAtlasFilenameExpressionButton_clicked();
void on_mAtlasHideCoverageCheckBox_stateChanged( int state );
void on_mAtlasSingleFileCheckBox_stateChanged( int state );

void on_mAtlasSortFeatureCheckBox_stateChanged( int state );
void changesSortFeatureField( QString fieldName );
void on_mAtlasSortFeatureDirectionButton_clicked();
void on_mAtlasFeatureFilterEdit_editingFinished();
void on_mAtlasFeatureFilterButton_clicked();
void on_mAtlasFeatureFilterCheckBox_stateChanged( int state );
void pageNameExpressionChanged( QString expression, bool valid );
void on_mApplyConfigButton_clicked();

private slots:
void updateGuiElements();
Expand Down
3 changes: 0 additions & 3 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -997,9 +997,6 @@ void QgsComposer::toggleAtlasControls( bool atlasEnabled )

void QgsComposer::updateAtlasPageComboBox( int pageCount )
{
if ( pageCount == mAtlasPageComboBox->count() )
return;

if ( !mComposition )
return;

Expand Down
46 changes: 34 additions & 12 deletions src/ui/qgsatlascompositionwidgetbase.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>435</width>
<height>596</height>
<width>310</width>
<height>381</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -93,8 +93,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>431</width>
<height>567</height>
<width>306</width>
<height>352</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
Expand All @@ -121,7 +121,7 @@
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,1,0">
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,0">
<item row="4" column="2">
<widget class="QToolButton" name="mAtlasSortFeatureDirectionButton">
<property name="toolTip">
Expand Down Expand Up @@ -219,6 +219,30 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="mApplyConfigButton">
<property name="text">
<string>Apply configuration</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -274,13 +298,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>GroupBox</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -328,12 +345,17 @@
</customwidgets>
<tabstops>
<tabstop>mUseAtlasCheckBox</tabstop>
<tabstop>scrollArea</tabstop>
<tabstop>mConfigurationGroup</tabstop>
<tabstop>mAtlasCoverageLayerComboBox</tabstop>
<tabstop>mAtlasHideCoverageCheckBox</tabstop>
<tabstop>mAtlasFeatureFilterCheckBox</tabstop>
<tabstop>mAtlasFeatureFilterEdit</tabstop>
<tabstop>mAtlasFeatureFilterButton</tabstop>
<tabstop>mAtlasSortFeatureCheckBox</tabstop>
<tabstop>mAtlasSortFeatureKeyComboBox</tabstop>
<tabstop>mAtlasSortFeatureDirectionButton</tabstop>
<tabstop>mApplyConfigButton</tabstop>
<tabstop>mOutputGroup</tabstop>
<tabstop>mAtlasFilenamePatternEdit</tabstop>
<tabstop>mAtlasFilenameExpressionButton</tabstop>
Expand Down

0 comments on commit 7934a92

Please sign in to comment.