Skip to content

Commit

Permalink
[FEATURE]: Improve the rotation of composer pictures and added the po…
Browse files Browse the repository at this point in the history
…ssibility 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
  • Loading branch information
mhugent committed Nov 2, 2009
1 parent ed8b487 commit f71a357
Show file tree
Hide file tree
Showing 7 changed files with 521 additions and 166 deletions.
148 changes: 143 additions & 5 deletions src/app/composer/qgscomposerpicturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "qgscomposerpicturewidget.h"
#include "qgsapplication.h"
#include "qgscomposermap.h"
#include "qgscomposerpicture.h"
#include "qgscomposeritemwidget.h"
#include <QDoubleValidator>
Expand All @@ -34,18 +35,16 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture

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

mWidthLineEdit->setValidator( new QDoubleValidator( this ) );
mHeightLineEdit->setValidator( new QDoubleValidator( this ) );

setGuiElementValues();

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

//add preview icons
addStandardDirectoriesToPreview();

connect( mPicture, SIGNAL( settingsChanged() ), this, SLOT( setGuiElementValues() ) );
}

Expand Down Expand Up @@ -198,6 +197,118 @@ void QgsComposerPictureWidget::on_mRemoveDirectoryButton_clicked()
}
}

void QgsComposerPictureWidget::on_mRotationFromComposerMapCheckBox_stateChanged( int state )
{
if ( !mPicture )
{
return;
}

if ( state == Qt::Unchecked )
{
mPicture->setRotationMap( -1 );
mRotationSpinBox->setEnabled( true );
mComposerMapComboBox->setEnabled( false );
}
else
{
int currentItemIndex = mComposerMapComboBox->currentIndex();
if ( currentItemIndex == -1 )
{
return;
}
int composerId = mComposerMapComboBox->itemData( currentItemIndex, Qt::UserRole ).toInt();
mPicture->setRotationMap( composerId );
mRotationSpinBox->setEnabled( false );
mComposerMapComboBox->setEnabled( true );
}
}

void QgsComposerPictureWidget::showEvent( QShowEvent * event )
{
refreshMapComboBox();
QWidget::showEvent( event );
}

void QgsComposerPictureWidget::on_mComposerMapComboBox_activated( const QString & text )
{
if ( !mPicture || text.isEmpty() || !mPicture->useRotationMap() )
{
return;
}

//get composition
const QgsComposition* composition = mPicture->composition();
if ( !composition )
{
return;
}

//extract id
int id;
bool conversionOk;
QStringList textSplit = text.split( " " );
if ( textSplit.size() < 1 )
{
return;
}

QString idString = textSplit.at( textSplit.size() - 1 );
id = idString.toInt( &conversionOk );

if ( !conversionOk )
{
return;
}

const QgsComposerMap* composerMap = composition->getComposerMapById( id );
if ( !composerMap )
{
return;
}
mPicture->setRotationMap( id );
mPicture->update();
}

void QgsComposerPictureWidget::refreshMapComboBox()
{
mComposerMapComboBox->blockSignals( true );
//save the current entry in case it is still present after refresh
QString saveCurrentComboText = mComposerMapComboBox->currentText();

mComposerMapComboBox->clear();

if ( mPicture )
{
//insert available maps into mMapComboBox
const QgsComposition* composition = mPicture->composition();
if ( composition )
{
QList<const QgsComposerMap*> availableMaps = composition->composerMapItems();
QList<const QgsComposerMap*>::const_iterator mapItemIt = availableMaps.constBegin();
for ( ; mapItemIt != availableMaps.constEnd(); ++mapItemIt )
{
mComposerMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ), ( *mapItemIt )->id() );
}
}
}

if ( !saveCurrentComboText.isEmpty() )
{
if ( mComposerMapComboBox->findText( saveCurrentComboText ) == -1 )
{
//the former entry is no longer present. Inform the scalebar about the changed composer map
on_mComposerMapComboBox_activated( mComposerMapComboBox->currentText() );
}
else
{
//the former entry is still present. Make it the current entry again
mComposerMapComboBox->setCurrentIndex( mComposerMapComboBox->findText( saveCurrentComboText ) );
}
}
mComposerMapComboBox->blockSignals( false );
}

void QgsComposerPictureWidget::setGuiElementValues()
{
//set initial gui values
Expand All @@ -207,17 +318,43 @@ void QgsComposerPictureWidget::setGuiElementValues()
mHeightLineEdit->blockSignals( true );
mRotationSpinBox->blockSignals( true );
mPictureLineEdit->blockSignals( true );
mComposerMapComboBox->blockSignals( true );
mRotationFromComposerMapCheckBox->blockSignals( true );

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

refreshMapComboBox();

if ( mPicture->useRotationMap() )
{
mRotationFromComposerMapCheckBox->setCheckState( Qt::Checked );
mRotationSpinBox->setEnabled( false );
mComposerMapComboBox->setEnabled( true );
QString mapText = tr( "Map %1" ).arg( mPicture->rotationMap() );
int itemId = mComposerMapComboBox->findText( mapText );
if ( itemId >= 0 )
{
mComposerMapComboBox->setCurrentIndex( itemId );
}
}
else
{
mRotationFromComposerMapCheckBox->setCheckState( Qt::Unchecked );
mRotationSpinBox->setEnabled( true );
mComposerMapComboBox->setEnabled( false );
}


mRotationFromComposerMapCheckBox->blockSignals( false );
mWidthLineEdit->blockSignals( false );
mHeightLineEdit->blockSignals( false );
mRotationSpinBox->blockSignals( false );
mPictureLineEdit->blockSignals( false );
mComposerMapComboBox->blockSignals( false );
}
}

Expand Down Expand Up @@ -302,7 +439,8 @@ void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
{
//list all directories in $prefix/share/qgis/svg
QStringList svgPaths = QgsApplication::svgPaths();
for(int i=0; i<svgPaths.size(); i++) {
for ( int i = 0; i < svgPaths.size(); i++ )
{
QDir svgDirectory( svgPaths[i] );
if ( !svgDirectory.exists() || !svgDirectory.isReadable() )
{
Expand All @@ -315,7 +453,7 @@ void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
{
if ( addDirectoryToPreview( dirIt->absoluteFilePath() ) == 0 )
{
mSearchDirectoriesComboBox->addItem( dirIt->absoluteFilePath() );
mSearchDirectoriesComboBox->addItem( dirIt->absoluteFilePath() );
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/app/composer/qgscomposerpicturewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
void on_mPreviewListWidget_currentItemChanged( QListWidgetItem* current, QListWidgetItem* previous );
void on_mAddDirectoryButton_clicked();
void on_mRemoveDirectoryButton_clicked();
void on_mRotationFromComposerMapCheckBox_stateChanged( int state );
void on_mComposerMapComboBox_activated( const QString & text );

/**Sets the GUI elements to the values of mPicture*/
void setGuiElementValues();

protected:
void showEvent( QShowEvent * event );

private:
QgsComposerPicture* mPicture;
/**Add the icons of a directory to the preview. Returns 0 in case of success*/
Expand All @@ -55,6 +61,8 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
bool testSvgFile( const QString& filename ) const;
/**Tests if a file is a valid pixel format*/
bool testImageFile( const QString& filename ) const;
/**Updates the map combo box with the current composer map ids*/
void refreshMapComboBox();
};

#endif
6 changes: 6 additions & 0 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ void QgsComposerMap::setOffset( double xOffset, double yOffset )
mYOffset = yOffset;
}

void QgsComposerMap::setRotation( double r )
{
mRotation = r;
emit rotationChanged( r );
}

bool QgsComposerMap::containsWMSLayer() const
{
if ( !mMapRenderer )
Expand Down
4 changes: 3 additions & 1 deletion src/core/composer/qgscomposermap.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB

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

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

private:

Expand Down
Loading

0 comments on commit f71a357

Please sign in to comment.