Skip to content

Commit f71a357

Browse files
author
mhugent
committed
[FEATURE]: Improve the rotation of composer pictures and added the possibility to synchronize composer map rotation and composer picture rotation (e.g. usefull for north arrows)
git-svn-id: http://svn.osgeo.org/qgis/trunk@11894 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent ed8b487 commit f71a357

File tree

7 files changed

+521
-166
lines changed

7 files changed

+521
-166
lines changed

src/app/composer/qgscomposerpicturewidget.cpp

Lines changed: 143 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgscomposerpicturewidget.h"
1919
#include "qgsapplication.h"
20+
#include "qgscomposermap.h"
2021
#include "qgscomposerpicture.h"
2122
#include "qgscomposeritemwidget.h"
2223
#include <QDoubleValidator>
@@ -34,18 +35,16 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture
3435

3536
//add widget for general composer item properties
3637
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, picture );
37-
gridLayout->addWidget( itemPropertiesWidget, 6, 0, 1, 4 );
38+
gridLayout->addWidget( itemPropertiesWidget, 8, 0, 1, 4 );
3839

3940
mWidthLineEdit->setValidator( new QDoubleValidator( this ) );
4041
mHeightLineEdit->setValidator( new QDoubleValidator( this ) );
41-
4242
setGuiElementValues();
4343

4444
mPreviewListWidget->setIconSize( QSize( 30, 30 ) );
4545

4646
//add preview icons
4747
addStandardDirectoriesToPreview();
48-
4948
connect( mPicture, SIGNAL( settingsChanged() ), this, SLOT( setGuiElementValues() ) );
5049
}
5150

@@ -198,6 +197,118 @@ void QgsComposerPictureWidget::on_mRemoveDirectoryButton_clicked()
198197
}
199198
}
200199

200+
void QgsComposerPictureWidget::on_mRotationFromComposerMapCheckBox_stateChanged( int state )
201+
{
202+
if ( !mPicture )
203+
{
204+
return;
205+
}
206+
207+
if ( state == Qt::Unchecked )
208+
{
209+
mPicture->setRotationMap( -1 );
210+
mRotationSpinBox->setEnabled( true );
211+
mComposerMapComboBox->setEnabled( false );
212+
}
213+
else
214+
{
215+
int currentItemIndex = mComposerMapComboBox->currentIndex();
216+
if ( currentItemIndex == -1 )
217+
{
218+
return;
219+
}
220+
int composerId = mComposerMapComboBox->itemData( currentItemIndex, Qt::UserRole ).toInt();
221+
mPicture->setRotationMap( composerId );
222+
mRotationSpinBox->setEnabled( false );
223+
mComposerMapComboBox->setEnabled( true );
224+
}
225+
}
226+
227+
void QgsComposerPictureWidget::showEvent( QShowEvent * event )
228+
{
229+
refreshMapComboBox();
230+
QWidget::showEvent( event );
231+
}
232+
233+
void QgsComposerPictureWidget::on_mComposerMapComboBox_activated( const QString & text )
234+
{
235+
if ( !mPicture || text.isEmpty() || !mPicture->useRotationMap() )
236+
{
237+
return;
238+
}
239+
240+
//get composition
241+
const QgsComposition* composition = mPicture->composition();
242+
if ( !composition )
243+
{
244+
return;
245+
}
246+
247+
//extract id
248+
int id;
249+
bool conversionOk;
250+
QStringList textSplit = text.split( " " );
251+
if ( textSplit.size() < 1 )
252+
{
253+
return;
254+
}
255+
256+
QString idString = textSplit.at( textSplit.size() - 1 );
257+
id = idString.toInt( &conversionOk );
258+
259+
if ( !conversionOk )
260+
{
261+
return;
262+
}
263+
264+
const QgsComposerMap* composerMap = composition->getComposerMapById( id );
265+
if ( !composerMap )
266+
{
267+
return;
268+
}
269+
mPicture->setRotationMap( id );
270+
mPicture->update();
271+
}
272+
273+
void QgsComposerPictureWidget::refreshMapComboBox()
274+
{
275+
mComposerMapComboBox->blockSignals( true );
276+
//save the current entry in case it is still present after refresh
277+
QString saveCurrentComboText = mComposerMapComboBox->currentText();
278+
279+
mComposerMapComboBox->clear();
280+
281+
if ( mPicture )
282+
{
283+
//insert available maps into mMapComboBox
284+
const QgsComposition* composition = mPicture->composition();
285+
if ( composition )
286+
{
287+
QList<const QgsComposerMap*> availableMaps = composition->composerMapItems();
288+
QList<const QgsComposerMap*>::const_iterator mapItemIt = availableMaps.constBegin();
289+
for ( ; mapItemIt != availableMaps.constEnd(); ++mapItemIt )
290+
{
291+
mComposerMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ), ( *mapItemIt )->id() );
292+
}
293+
}
294+
}
295+
296+
if ( !saveCurrentComboText.isEmpty() )
297+
{
298+
if ( mComposerMapComboBox->findText( saveCurrentComboText ) == -1 )
299+
{
300+
//the former entry is no longer present. Inform the scalebar about the changed composer map
301+
on_mComposerMapComboBox_activated( mComposerMapComboBox->currentText() );
302+
}
303+
else
304+
{
305+
//the former entry is still present. Make it the current entry again
306+
mComposerMapComboBox->setCurrentIndex( mComposerMapComboBox->findText( saveCurrentComboText ) );
307+
}
308+
}
309+
mComposerMapComboBox->blockSignals( false );
310+
}
311+
201312
void QgsComposerPictureWidget::setGuiElementValues()
202313
{
203314
//set initial gui values
@@ -207,17 +318,43 @@ void QgsComposerPictureWidget::setGuiElementValues()
207318
mHeightLineEdit->blockSignals( true );
208319
mRotationSpinBox->blockSignals( true );
209320
mPictureLineEdit->blockSignals( true );
321+
mComposerMapComboBox->blockSignals( true );
322+
mRotationFromComposerMapCheckBox->blockSignals( true );
210323

211324
mPictureLineEdit->setText( mPicture->pictureFile() );
212325
QRectF pictureRect = mPicture->rect();
213326
mWidthLineEdit->setText( QString::number( pictureRect.width() ) );
214327
mHeightLineEdit->setText( QString::number( pictureRect.height() ) );
215328
mRotationSpinBox->setValue( mPicture->rotation() );
216329

330+
refreshMapComboBox();
331+
332+
if ( mPicture->useRotationMap() )
333+
{
334+
mRotationFromComposerMapCheckBox->setCheckState( Qt::Checked );
335+
mRotationSpinBox->setEnabled( false );
336+
mComposerMapComboBox->setEnabled( true );
337+
QString mapText = tr( "Map %1" ).arg( mPicture->rotationMap() );
338+
int itemId = mComposerMapComboBox->findText( mapText );
339+
if ( itemId >= 0 )
340+
{
341+
mComposerMapComboBox->setCurrentIndex( itemId );
342+
}
343+
}
344+
else
345+
{
346+
mRotationFromComposerMapCheckBox->setCheckState( Qt::Unchecked );
347+
mRotationSpinBox->setEnabled( true );
348+
mComposerMapComboBox->setEnabled( false );
349+
}
350+
351+
352+
mRotationFromComposerMapCheckBox->blockSignals( false );
217353
mWidthLineEdit->blockSignals( false );
218354
mHeightLineEdit->blockSignals( false );
219355
mRotationSpinBox->blockSignals( false );
220356
mPictureLineEdit->blockSignals( false );
357+
mComposerMapComboBox->blockSignals( false );
221358
}
222359
}
223360

@@ -302,7 +439,8 @@ void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
302439
{
303440
//list all directories in $prefix/share/qgis/svg
304441
QStringList svgPaths = QgsApplication::svgPaths();
305-
for(int i=0; i<svgPaths.size(); i++) {
442+
for ( int i = 0; i < svgPaths.size(); i++ )
443+
{
306444
QDir svgDirectory( svgPaths[i] );
307445
if ( !svgDirectory.exists() || !svgDirectory.isReadable() )
308446
{
@@ -315,7 +453,7 @@ void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
315453
{
316454
if ( addDirectoryToPreview( dirIt->absoluteFilePath() ) == 0 )
317455
{
318-
mSearchDirectoriesComboBox->addItem( dirIt->absoluteFilePath() );
456+
mSearchDirectoriesComboBox->addItem( dirIt->absoluteFilePath() );
319457
}
320458
}
321459
}

src/app/composer/qgscomposerpicturewidget.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
4242
void on_mPreviewListWidget_currentItemChanged( QListWidgetItem* current, QListWidgetItem* previous );
4343
void on_mAddDirectoryButton_clicked();
4444
void on_mRemoveDirectoryButton_clicked();
45+
void on_mRotationFromComposerMapCheckBox_stateChanged( int state );
46+
void on_mComposerMapComboBox_activated( const QString & text );
47+
4548
/**Sets the GUI elements to the values of mPicture*/
4649
void setGuiElementValues();
4750

51+
protected:
52+
void showEvent( QShowEvent * event );
53+
4854
private:
4955
QgsComposerPicture* mPicture;
5056
/**Add the icons of a directory to the preview. Returns 0 in case of success*/
@@ -55,6 +61,8 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
5561
bool testSvgFile( const QString& filename ) const;
5662
/**Tests if a file is a valid pixel format*/
5763
bool testImageFile( const QString& filename ) const;
64+
/**Updates the map combo box with the current composer map ids*/
65+
void refreshMapComboBox();
5866
};
5967

6068
#endif

src/core/composer/qgscomposermap.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,12 @@ void QgsComposerMap::setOffset( double xOffset, double yOffset )
505505
mYOffset = yOffset;
506506
}
507507

508+
void QgsComposerMap::setRotation( double r )
509+
{
510+
mRotation = r;
511+
emit rotationChanged( r );
512+
}
513+
508514
bool QgsComposerMap::containsWMSLayer() const
509515
{
510516
if ( !mMapRenderer )

src/core/composer/qgscomposermap.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB
241241

242242
/**Sets the rotation of the map content
243243
@note this function was added in version 1.4*/
244-
void setRotation( double r ) { mRotation = r; }
244+
void setRotation( double r );
245245
double rotation() const { return mRotation; }
246246

247247
/**Sets length of the cros segments (if grid style is cross)
@@ -259,6 +259,8 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB
259259
signals:
260260
/**Is emitted when width/height is changed as a result of user interaction*/
261261
void extentChanged();
262+
/**Is emitted on rotation change to notify north arrow pictures*/
263+
void rotationChanged( double newRotation );
262264

263265
private:
264266

0 commit comments

Comments
 (0)