Skip to content
Permalink
Browse files
[FEATURE][composer] Add page number combo box to atlas toolbar
(fix #13136)
  • Loading branch information
nyalldawson committed Jul 23, 2015
1 parent b431187 commit d07dadf3336590d85b4bdef41391eb8b7224974f
@@ -216,6 +216,11 @@ public:

/** Returns the current atlas feature. Must be called after prepareForFeature( i ). */
QgsFeature* currentFeature();

/** Returns the current feature number.
* @note added in QGIS 2.12
*/
int currentFeatureNumber() const;

/** Recalculates the bounds of an atlas driven map */
void prepareMap( QgsComposerMap* map );
@@ -253,5 +258,9 @@ public:

/**Is emitted when the current atlas feature changes*/
void featureChanged( QgsFeature* feature );


/** Is emitted when the number of features for the atlas changes.
* @note added in QGIS 2.12
*/
void numberFeaturesChanged( int numFeatures );
};
@@ -407,6 +407,17 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
atlasExportToolButton->addAction( mActionExportAtlasAsPDF );
atlasExportToolButton->setDefaultAction( mActionExportAtlasAsImage );
mAtlasToolbar->insertWidget( mActionAtlasSettings, atlasExportToolButton );
mAtlasPageComboBox = new QComboBox();
mAtlasPageComboBox->setEditable( true );
mAtlasPageComboBox->addItem( QString::number( 1 ) );
mAtlasPageComboBox->setCurrentIndex( 0 );
mAtlasPageComboBox->setMinimumHeight( mAtlasToolbar->height() );
mAtlasPageComboBox->setMinimumContentsLength( 6 );
mAtlasPageComboBox->setMaxVisibleItems( 20 );
mAtlasPageComboBox->setInsertPolicy( QComboBox::NoInsert );
connect( mAtlasPageComboBox->lineEdit(), SIGNAL( editingFinished() ), this, SLOT( atlasPageComboEditingFinished() ) );
connect( mAtlasPageComboBox, SIGNAL( currentIndexChanged( QString ) ), this, SLOT( atlasPageComboEditingFinished() ) );
mAtlasToolbar->insertWidget( mActionAtlasNext, mAtlasPageComboBox );

QMenu *settingsMenu = menuBar()->addMenu( tr( "&Settings" ) );
settingsMenu->addAction( mActionOptions );
@@ -613,12 +624,14 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mActionAtlasNext->setEnabled( false );
mActionAtlasPrev->setEnabled( false );
mActionPrintAtlas->setEnabled( false );
mAtlasPageComboBox->setEnabled( false );
mActionExportAtlasAsImage->setEnabled( false );
mActionExportAtlasAsSVG->setEnabled( false );
mActionExportAtlasAsPDF->setEnabled( false );
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );
connect( atlasMap, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( updateAtlasMapLayerAction( QgsVectorLayer * ) ) );
connect( atlasMap, SIGNAL( numberFeaturesChanged( int ) ), this, SLOT( updateAtlasPageComboBox( int ) ) );

//default printer page setup
setPrinterPageDefaults();
@@ -968,6 +981,7 @@ void QgsComposer::toggleAtlasControls( bool atlasEnabled )
mActionAtlasLast->setEnabled( false );
mActionAtlasNext->setEnabled( false );
mActionAtlasPrev->setEnabled( false );
mAtlasPageComboBox->setEnabled( false );
mActionAtlasPreview->blockSignals( false );
mActionAtlasPreview->setEnabled( atlasEnabled );
mActionPrintAtlas->setEnabled( atlasEnabled );
@@ -978,6 +992,20 @@ void QgsComposer::toggleAtlasControls( bool atlasEnabled )
updateAtlasMapLayerAction( atlasEnabled );
}

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

mAtlasPageComboBox->blockSignals( true );
mAtlasPageComboBox->clear();
for ( int i = 1; i <= pageCount && i < 500; ++i )
{
mAtlasPageComboBox->addItem( QString::number( i ), i );
}
mAtlasPageComboBox->blockSignals( false );
}

void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -1002,6 +1030,7 @@ void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
mActionAtlasLast->setEnabled( checked );
mActionAtlasNext->setEnabled( checked );
mActionAtlasPrev->setEnabled( checked );
mAtlasPageComboBox->setEnabled( checked );

if ( checked )
{
@@ -1022,6 +1051,7 @@ void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
mActionAtlasLast->setEnabled( false );
mActionAtlasNext->setEnabled( false );
mActionAtlasPrev->setEnabled( false );
mAtlasPageComboBox->setEnabled( false );
mActionAtlasPreview->blockSignals( false );
mStatusAtlasLabel->setText( QString() );
return;
@@ -1036,10 +1066,8 @@ void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
{
mStatusAtlasLabel->setText( QString() );
}

}


void QgsComposer::on_mActionAtlasNext_triggered()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -1100,6 +1128,23 @@ void QgsComposer::on_mActionAtlasLast_triggered()
emit atlasPreviewFeatureChanged();
}

void QgsComposer::atlasPageComboEditingFinished()
{
QString text = mAtlasPageComboBox->lineEdit()->text();
bool ok = false;
int page = text.toInt( &ok );
if ( !ok || page >= mComposition->atlasComposition().numFeatures() )
{
mAtlasPageComboBox->blockSignals( true );
mAtlasPageComboBox->setCurrentIndex( mComposition->atlasComposition().currentFeatureNumber() );
mAtlasPageComboBox->blockSignals( false );
}
else if ( page != mComposition->atlasComposition().currentFeatureNumber() + 1 )
{
mComposition->atlasComposition().prepareForFeature( page - 1 );
}
}

QgsMapCanvas *QgsComposer::mapCanvas( void )
{
return mQgis->mapCanvas();
@@ -1415,6 +1460,7 @@ void QgsComposer::setComposition( QgsComposition* composition )
toggleAtlasControls( atlasMap->enabled() );
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );
connect( atlasMap, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( updateAtlasMapLayerAction( QgsVectorLayer * ) ) );
connect( atlasMap, SIGNAL( numberFeaturesChanged( int ) ), this, SLOT( updateAtlasPageComboBox( int ) ) );

//default printer page setup
setPrinterPageDefaults();
@@ -3233,6 +3279,7 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
toggleAtlasControls( atlasMap->enabled() );
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );
connect( atlasMap, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( updateAtlasMapLayerAction( QgsVectorLayer * ) ) );
connect( atlasMap, SIGNAL( numberFeaturesChanged( int ) ), this, SLOT( updateAtlasPageComboBox( int ) ) );

//default printer page setup
setPrinterPageDefaults();
@@ -3716,6 +3763,7 @@ void QgsComposer::setAtlasFeature( QgsMapLayer* layer, const QgsFeature& feat )
mActionAtlasLast->setEnabled( true );
mActionAtlasNext->setEnabled( true );
mActionAtlasPrev->setEnabled( true );
mAtlasPageComboBox->setEnabled( true );
}

//bring composer window to foreground
@@ -343,6 +343,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//!Last atlas feature
void on_mActionAtlasLast_triggered();

//!Jump to a specific atlas page
void atlasPageComboEditingFinished();

//! Print the atlas
void on_mActionPrintAtlas_triggered();

@@ -367,40 +370,40 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Save window state
void saveWindowState();

/**Add a composer arrow to the item/widget map and creates a configuration widget for it*/
/** Add a composer arrow to the item/widget map and creates a configuration widget for it*/
void addComposerArrow( QgsComposerArrow* arrow );

/**Add a composer map to the item/widget map and creates a configuration widget for it*/
/** Add a composer map to the item/widget map and creates a configuration widget for it*/
void addComposerMap( QgsComposerMap* map );

/**Adds a composer label to the item/widget map and creates a configuration widget for it*/
/** Adds a composer label to the item/widget map and creates a configuration widget for it*/
void addComposerLabel( QgsComposerLabel* label );

/**Adds a composer scale bar to the item/widget map and creates a configuration widget for it*/
/** Adds a composer scale bar to the item/widget map and creates a configuration widget for it*/
void addComposerScaleBar( QgsComposerScaleBar* scalebar );

/**Adds a composer legend to the item/widget map and creates a configuration widget for it*/
/** Adds a composer legend to the item/widget map and creates a configuration widget for it*/
void addComposerLegend( QgsComposerLegend* legend );

/**Adds a composer picture to the item/widget map and creates a configuration widget*/
/** Adds a composer picture to the item/widget map and creates a configuration widget*/
void addComposerPicture( QgsComposerPicture* picture );

/**Adds a composer shape to the item/widget map and creates a configuration widget*/
/** Adds a composer shape to the item/widget map and creates a configuration widget*/
void addComposerShape( QgsComposerShape* shape );

/**Adds a composer table to the item/widget map and creates a configuration widget*/
/** Adds a composer table to the item/widget map and creates a configuration widget*/
void addComposerTable( QgsComposerAttributeTable* table );

/**Adds a composer table v2 to the item/widget map and creates a configuration widget*/
/** Adds a composer table v2 to the item/widget map and creates a configuration widget*/
void addComposerTableV2( QgsComposerAttributeTableV2* table, QgsComposerFrame* frame );

/**Adds composer html and creates a configuration widget*/
/** Adds composer html and creates a configuration widget*/
void addComposerHtmlFrame( QgsComposerHtml* html, QgsComposerFrame* frame );

/**Removes item from the item/widget map and deletes the configuration widget. Does not delete the item itself*/
/** Removes item from the item/widget map and deletes the configuration widget. Does not delete the item itself*/
void deleteItem( QgsComposerItem* item );

/**Shows the configuration widget for a composer item*/
/** Shows the configuration widget for a composer item*/
void showItemOptions( QgsComposerItem* i );

//XML, usually connected with QgsProject::readProject and QgsProject::writeProject
@@ -438,19 +441,19 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

private:

/**Establishes the signal slot connections from the QgsComposerView to the composer*/
/** Establishes the signal slot connections from the QgsComposerView to the composer*/
void connectViewSlots();

/**Establishes the signal slot connections from the QgsComposition to the composer*/
/** Establishes the signal slot connections from the QgsComposition to the composer*/
void connectCompositionSlots();

/**Establishes other signal slot connections for the composer*/
/** Establishes other signal slot connections for the composer*/
void connectOtherSlots();

/**Creates the composition widget*/
/** Creates the composition widget*/
void createCompositionWidget();

/**Sets up the compositions undo/redo connections*/
/** Sets up the compositions undo/redo connections*/
void setupUndoView();

//! True if a composer map contains a WMS layer
@@ -510,19 +513,19 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

QPrinter* printer();

/**Composer title*/
/** Composer title*/
QString mTitle;

/**Labels in status bar which shows current mouse position*/
/** Labels in status bar which shows current mouse position*/
QLabel* mStatusCursorXLabel;
QLabel* mStatusCursorYLabel;
QLabel* mStatusCursorPageLabel;
/**Combobox in status bar which shows/adjusts current zoom level*/
/** Combobox in status bar which shows/adjusts current zoom level*/
QComboBox* mStatusZoomCombo;
QList<double> mStatusZoomLevelsList;
/**Label in status bar which shows messages from the composition*/
/** Label in status bar which shows messages from the composition*/
QLabel* mStatusCompositionLabel;
/**Label in status bar which shows atlas details*/
/** Label in status bar which shows atlas details*/
QLabel* mStatusAtlasLabel;

//! Pointer to composer view
@@ -570,6 +573,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
QAction *mActionPreviewProtanope;
QAction *mActionPreviewDeuteranope;

QComboBox* mAtlasPageComboBox;

//! We load composer map content from project xml only on demand. Therefore we need to store the real preview mode type
QMap< QgsComposerMap*, int > mMapsToRestore;

@@ -649,6 +654,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

void dockVisibilityChanged( bool visible );

/** Repopulates the atlas page combo box with valid items.
*/
void updateAtlasPageComboBox( int pageCount );
};

#endif
@@ -263,6 +263,7 @@ int QgsAtlasComposition::updateFeatures()
}

QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )mFeatureIds.size() ) );
emit numberFeaturesChanged( mFeatureIds.size() );

//jump to first feature if currently using an atlas preview
//need to do this in case filtering/layer change has altered matching features
@@ -396,6 +397,11 @@ bool QgsAtlasComposition::prepareForFeature( const int featureI, const bool upda
return false;
}

if ( featureI >= mFeatureIds.size() )
{
return false;
}

mCurrentFeatureNo = featureI;

// retrieve the next feature, based on its id

0 comments on commit d07dadf

Please sign in to comment.