Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Store every parameters and expose operations in a new QgsAtlasComposition class * Restructure the GUI part. The atlas configuration panel is now independant
- Loading branch information
Hugo Mercier
committed
Oct 5, 2012
1 parent
a588e1b
commit e4371d8
Showing
18 changed files
with
1,100 additions
and
861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
/*************************************************************************** | ||
qgsatlascompositionwidget.cpp | ||
----------------------------- | ||
begin : October 2012 | ||
copyright : (C) 2012 Hugo Mercier | ||
email : hugo dot mercier at oslandia dot com | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsatlascompositionwidget.h" | ||
#include "qgsatlascomposition.h" | ||
#include "qgscomposition.h" | ||
#include "qgsmaplayerregistry.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsexpressionbuilderdialog.h" | ||
#include "qgscomposermap.h" | ||
|
||
QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsAtlasComposition* atlas, QgsComposition* c ): | ||
QWidget( parent ), mAtlas( atlas ), mComposition( c ) | ||
{ | ||
setupUi( this ); | ||
|
||
// populate the layer list | ||
mAtlasCoverageLayerComboBox->clear(); | ||
QMap< QString, QgsMapLayer * >& layers = QgsMapLayerRegistry::instance()->mapLayers(); | ||
int idx = 0; | ||
for ( QMap<QString, QgsMapLayer*>::const_iterator it = layers.begin(); it != layers.end(); ++it ) | ||
{ | ||
// Only consider vector layers | ||
if ( dynamic_cast<QgsVectorLayer*>(it.value()) ) | ||
{ | ||
mAtlasCoverageLayerComboBox->insertItem( idx++, it.key(), /* userdata */ qVariantFromValue( (void*)it.value() ) ); | ||
} | ||
} | ||
|
||
// Connect to addition / removal of layers | ||
QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance(); | ||
if ( layerRegistry ) | ||
{ | ||
connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( onLayerRemoved( QString ) ) ); | ||
connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( onLayerAdded( QgsMapLayer* ) ) ); | ||
} | ||
|
||
// update the composer map combo box | ||
// populate the map list | ||
mComposerMapComboBox->clear(); | ||
QList<const QgsComposerMap*> availableMaps = mComposition->composerMapItems(); | ||
QList<const QgsComposerMap*>::const_iterator mapItemIt = availableMaps.constBegin(); | ||
for ( ; mapItemIt != availableMaps.constEnd(); ++mapItemIt ) | ||
{ | ||
mComposerMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ), qVariantFromValue( (void*)*mapItemIt ) ); | ||
} | ||
|
||
// Connect to addition / removal of maps | ||
connect( mComposition, SIGNAL( composerMapAdded( QgsComposerMap* ) ), this, SLOT( onComposerMapAdded( QgsComposerMap* ) ) ); | ||
connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( onItemRemoved( QgsComposerItem* ) ) ); | ||
|
||
// connect to updates | ||
connect( mAtlas, SIGNAL( parameterChanged() ), this, SLOT( updateGuiElements() ) ); | ||
|
||
updateGuiElements(); | ||
} | ||
|
||
QgsAtlasCompositionWidget::~QgsAtlasCompositionWidget() | ||
{ | ||
} | ||
|
||
void QgsAtlasCompositionWidget::on_mUseAtlasCheckBox_stateChanged( int state ) | ||
{ | ||
QgsAtlasComposition* atlasMap = mAtlas; | ||
if ( state == Qt::Checked ) | ||
{ | ||
atlasMap->setEnabled( true ); | ||
mAtlasFrame->setEnabled( true ); | ||
} | ||
else | ||
{ | ||
atlasMap->setEnabled( false ); | ||
mAtlasFrame->setEnabled( false ); | ||
} | ||
} | ||
|
||
void QgsAtlasCompositionWidget::onLayerRemoved( QString layerName ) | ||
{ | ||
// update the atlas coverage layer combo box | ||
for ( int i = 0; i < mAtlasCoverageLayerComboBox->count(); ++i ) | ||
{ | ||
if ( mAtlasCoverageLayerComboBox->itemText( i ) == layerName ) | ||
{ | ||
mAtlasCoverageLayerComboBox->removeItem( i ); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void QgsAtlasCompositionWidget::onLayerAdded( QgsMapLayer* map ) | ||
{ | ||
// update the atlas coverage layer combo box | ||
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( map ); | ||
if ( vectorLayer ) | ||
{ | ||
mAtlasCoverageLayerComboBox->addItem( map->id(), qVariantFromValue( (void*)map ) ); | ||
} | ||
} | ||
|
||
void QgsAtlasCompositionWidget::onComposerMapAdded( QgsComposerMap* map ) | ||
{ | ||
mComposerMapComboBox->addItem( tr( "Map %1" ).arg( map->id() ), map->id() ); | ||
} | ||
|
||
void QgsAtlasCompositionWidget::onItemRemoved( QgsComposerItem* item ) | ||
{ | ||
QgsComposerMap* map = dynamic_cast<QgsComposerMap*>( item ); | ||
if ( map ) | ||
{ | ||
int idx = mComposerMapComboBox->findData( map->id() ); | ||
if ( idx != -1 ) | ||
{ | ||
mComposerMapComboBox->removeItem( idx ); | ||
} | ||
} | ||
} | ||
|
||
void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChanged( int index ) | ||
{ | ||
QgsAtlasComposition* atlasMap = mAtlas; | ||
if ( !atlasMap ) | ||
{ | ||
return; | ||
} | ||
QgsVectorLayer* layer = reinterpret_cast<QgsVectorLayer*>(mAtlasCoverageLayerComboBox->itemData( index ).value<void*>()); | ||
atlasMap->setCoverageLayer( layer ); | ||
} | ||
|
||
void QgsAtlasCompositionWidget::on_mComposerMapComboBox_currentIndexChanged( int index ) | ||
{ | ||
QgsAtlasComposition* atlasMap = mAtlas; | ||
if ( !atlasMap ) | ||
{ | ||
return; | ||
} | ||
QgsComposerMap* map = reinterpret_cast<QgsComposerMap*>(mComposerMapComboBox->itemData( index ).value<void*>()); | ||
atlasMap->setComposerMap( map ); | ||
} | ||
|
||
void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_textChanged( const QString& text ) | ||
{ | ||
QgsAtlasComposition* atlasMap = mAtlas; | ||
if ( !atlasMap ) | ||
{ | ||
return; | ||
} | ||
|
||
atlasMap->setFilenamePattern( text ); | ||
} | ||
|
||
void QgsAtlasCompositionWidget::on_mAtlasFilenameExpressionButton_clicked() | ||
{ | ||
QgsAtlasComposition* atlasMap = mAtlas; | ||
if ( !atlasMap || !atlasMap->coverageLayer() ) | ||
{ | ||
return; | ||
} | ||
|
||
QgsExpressionBuilderDialog exprDlg( atlasMap->coverageLayer(), mAtlasFilenamePatternEdit->text(), this ); | ||
exprDlg.setWindowTitle( tr( "Expression based filename" ) ); | ||
if ( exprDlg.exec() == QDialog::Accepted ) | ||
{ | ||
QString expression = exprDlg.expressionText(); | ||
if ( !expression.isEmpty() ) | ||
{ | ||
// will emit a textChanged signal | ||
mAtlasFilenamePatternEdit->setText( expression ); | ||
} | ||
} | ||
} | ||
|
||
void QgsAtlasCompositionWidget::on_mAtlasHideCoverageCheckBox_stateChanged( int state ) | ||
{ | ||
QgsAtlasComposition* atlasMap = mAtlas; | ||
if ( !atlasMap ) | ||
{ | ||
return; | ||
} | ||
atlasMap->setHideCoverage( state == Qt::Checked ); | ||
} | ||
|
||
void QgsAtlasCompositionWidget::on_mAtlasFixedScaleCheckBox_stateChanged( int state ) | ||
{ | ||
QgsAtlasComposition* atlasMap = mAtlas; | ||
if ( !atlasMap ) | ||
{ | ||
return; | ||
} | ||
atlasMap->setFixedScale( state == Qt::Checked ); | ||
|
||
// in fixed scale mode, the margin is meaningless | ||
if ( state == Qt::Checked ) | ||
{ | ||
mAtlasMarginSpinBox->setEnabled( false ); | ||
} | ||
else | ||
{ | ||
mAtlasMarginSpinBox->setEnabled( true ); | ||
} | ||
} | ||
|
||
void QgsAtlasCompositionWidget::on_mAtlasSingleFileCheckBox_stateChanged( int state ) | ||
{ | ||
QgsAtlasComposition* atlasMap = mAtlas; | ||
if ( !atlasMap ) | ||
{ | ||
return; | ||
} | ||
atlasMap->setSingleFile( state == Qt::Checked ); | ||
} | ||
|
||
void QgsAtlasCompositionWidget::updateGuiElements() | ||
{ | ||
if ( mAtlas->enabled() ) | ||
{ | ||
mUseAtlasCheckBox->setCheckState( Qt::Checked ); | ||
} | ||
else | ||
{ | ||
mUseAtlasCheckBox->setCheckState( Qt::Unchecked ); | ||
} | ||
|
||
int idx = mAtlasCoverageLayerComboBox->findData( qVariantFromValue( (void*)mAtlas->coverageLayer() )); | ||
if ( idx != -1 ) | ||
{ | ||
mAtlasCoverageLayerComboBox->setCurrentIndex( idx ); | ||
} | ||
idx = mComposerMapComboBox->findData( qVariantFromValue( (void*)mAtlas->composerMap() )); | ||
if ( idx != -1 ) | ||
{ | ||
mComposerMapComboBox->setCurrentIndex( idx ); | ||
} | ||
|
||
mAtlasMarginSpinBox->setValue( static_cast<int>(mAtlas->margin() * 100) ); | ||
mAtlasFilenamePatternEdit->setText( mAtlas->filenamePattern() ); | ||
mAtlasFixedScaleCheckBox->setCheckState( mAtlas->fixedScale() ? Qt::Checked : Qt::Unchecked ); | ||
mAtlasHideCoverageCheckBox->setCheckState( mAtlas->hideCoverage() ? Qt::Checked : Qt::Unchecked ); | ||
mAtlasSingleFileCheckBox->setCheckState( mAtlas->singleFile() ? Qt::Checked : Qt::Unchecked ); | ||
} | ||
|
||
void QgsAtlasCompositionWidget::blockAllSignals( bool b ) | ||
{ | ||
mUseAtlasCheckBox->blockSignals( b ); | ||
mAtlasFrame->blockSignals( b ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*************************************************************************** | ||
qgsatlascompositionwidget.h | ||
--------------------------- | ||
begin : October 2012 | ||
copyright : (C) 2012 Hugo Mercier | ||
email : hugo dot mercier at oslandia dot com | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "ui_qgsatlascompositionwidgetbase.h" | ||
|
||
class QgsComposition; | ||
class QgsAtlasComposition; | ||
class QgsMapLayer; | ||
class QgsComposerMap; | ||
class QgsComposerItem; | ||
|
||
/** \ingroup MapComposer | ||
* Input widget for QgsAtlasComposition | ||
*/ | ||
class QgsAtlasCompositionWidget: | ||
public QWidget, | ||
private Ui::QgsAtlasCompositionWidgetBase | ||
{ | ||
Q_OBJECT | ||
public: | ||
QgsAtlasCompositionWidget( QWidget* parent, QgsAtlasComposition* atlas, QgsComposition* c ); | ||
~QgsAtlasCompositionWidget(); | ||
|
||
public slots: | ||
void on_mUseAtlasCheckBox_stateChanged( int state ); | ||
void on_mComposerMapComboBox_currentIndexChanged( int index ); | ||
void on_mAtlasCoverageLayerComboBox_currentIndexChanged( int index ); | ||
void on_mAtlasFilenamePatternEdit_textChanged( const QString& text ); | ||
void on_mAtlasFilenameExpressionButton_clicked(); | ||
void on_mAtlasHideCoverageCheckBox_stateChanged( int state ); | ||
void on_mAtlasFixedScaleCheckBox_stateChanged( int state ); | ||
void on_mAtlasSingleFileCheckBox_stateChanged( int state ); | ||
|
||
private slots: | ||
void onLayerRemoved( QString ); | ||
void onLayerAdded( QgsMapLayer* ); | ||
void onComposerMapAdded( QgsComposerMap* ); | ||
void onItemRemoved( QgsComposerItem* ); | ||
|
||
void updateGuiElements(); | ||
|
||
private: | ||
QgsAtlasComposition* mAtlas; | ||
QgsComposition* mComposition; | ||
|
||
void blockAllSignals( bool b ); | ||
}; |
Oops, something went wrong.