Skip to content
Permalink
Browse files

[FEATURE]: Possibility to rotate composer map

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11847 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Oct 26, 2009
1 parent c74fde5 commit 9aa481e6e31bf24a394cdba6053878497f202915
@@ -24,6 +24,26 @@ class QgsComposerMap : QObject, QgsComposerItem
Rectangle // Display only rectangle
};

enum GridStyle
{
Solid = 0, //solid lines
Cross //only draw line crossings
};

enum GridAnnotationPosition
{
InsideMapFrame = 0,
OutsideMapFrame
};

enum GridAnnotationDirection
{
Horizontal = 0,
Vertical,
HorizontalAndVertical,
BoundaryDirection
};

/** \brief Draw to paint device
@param extent map extent
@param size size in scene coordinates
@@ -71,6 +91,22 @@ class QgsComposerMap : QObject, QgsComposerItem
PreviewMode previewMode();
void setPreviewMode( PreviewMode m );

/**Getter for flag that determines if the stored layer set should be used or the current layer set of the qgis mapcanvas
@note this function was added in version 1.2*/
bool keepLayerSet() const;
/**Setter for flag that determines if the stored layer set should be used or the current layer set of the qgis mapcanvas
@note this function was added in version 1.2*/
void setKeepLayerSet( bool enabled );

/**Getter for stored layer set that is used if mKeepLayerSet is true
@note this function was added in version 1.2*/
QStringList layerSet() const;
/**Setter for stored layer set that is used if mKeepLayerSet is true
@note this function was added in version 1.2*/
void setLayerSet( const QStringList& layerSet );
/**Stores the current layer set of the qgis mapcanvas in mLayerSet*/
void storeCurrentLayerSet();

// Set cache outdated
void setCacheUpdated( bool u = false );

@@ -95,6 +131,55 @@ class QgsComposerMap : QObject, QgsComposerItem
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

void setGridEnabled( bool enabled );
bool gridEnabled() const;

void setGridStyle( GridStyle style );
GridStyle gridStyle() const;

void setGridIntervalX( double interval );
double gridIntervalX() const;

void setGridIntervalY( double interval );
double gridIntervalY() const;

void setGridOffsetX( double offset );
double gridOffsetX() const;

void setGridOffsetY( double offset );
double gridOffsetY() const;

void setGridPen( const QPen& p );
QPen gridPen() const;
void setGridPenWidth( double w );
void setGridPenColor( const QColor& c );

void setGridAnnotationFont( const QFont& f );
QFont gridAnnotationFont() const;

void setShowGridAnnotation( bool show );
bool showGridAnnotation() const;

void setGridAnnotationPosition( GridAnnotationPosition p );
GridAnnotationPosition gridAnnotationPosition() const;

void setAnnotationFrameDistance( double d ) {mAnnotationFrameDistance = d;}
double annotationFrameDistance() const {return mAnnotationFrameDistance;}

void setGridAnnotationDirection( GridAnnotationDirection d );
GridAnnotationDirection gridAnnotationDirection() const;

/**In case of annotations, the bounding rectangle can be larger than the map item rectangle*/
QRectF boundingRect() const;
/**Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle*/
void updateBoundingRect();

void setRotation(double r);
double rotation() const;

void setCrossLength(double l);
double crossLength();

public slots:

/**Called if map canvas has changed*/
@@ -25,11 +25,13 @@
QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidget(), mComposerMap( composerMap )
{
setupUi( this );
mGridDockWidget->setVisible( false );
mGridWidget->setVisible( false );
mGridWidget->setParent( 0 ); //in order to save space, separate the grid widget
mGridWidget->setWindowFlags( Qt::CustomizeWindowHint | Qt::WindowTitleHint );

//add widget for general composer item properties
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, composerMap );
gridLayout_3->addWidget( itemPropertiesWidget, 7, 0, 1, 1 );
gridLayout_3->addWidget( itemPropertiesWidget, 6, 0, 1, 1 );
QDoubleValidator v( 0 );

mWidthLineEdit->setValidator( &v );
@@ -55,9 +57,8 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
mAnnotationDirectionComboBox->insertItem( 0, tr( "Horizontal" ) );
mAnnotationDirectionComboBox->insertItem( 1, tr( "Vertical" ) );
mAnnotationDirectionComboBox->insertItem( 2, tr( "Horizontal and Vertical" ) );
mAnnotationDirectionComboBox->insertItem( 2, tr( "Boundary direction" ) );

mAnnotationTypeComboBox->insertItem( 0, tr( "Coordinate" ) );
mAnnotationTypeComboBox->insertItem( 1, tr( "Sector" ) );
blockAllSignals( false );

if ( composerMap )
@@ -70,7 +71,7 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg

QgsComposerMapWidget::~QgsComposerMapWidget()
{

delete mGridWidget;
}

void QgsComposerMapWidget::on_mWidthLineEdit_editingFinished()
@@ -160,6 +161,18 @@ void QgsComposerMapWidget::on_mScaleLineEdit_editingFinished()
mComposerMap->setNewScale( scaleDenominator );
}

void QgsComposerMapWidget::on_mRotationSpinBox_valueChanged( int value )
{
if ( !mComposerMap )
{
return;
}

mComposerMap->setRotation( value );
mComposerMap->cache();
mComposerMap->update();
}

void QgsComposerMapWidget::on_mSetToMapCanvasExtentButton_clicked()
{
if ( mComposerMap )
@@ -274,6 +287,8 @@ void QgsComposerMapWidget::updateGuiElements()
mYMinLineEdit->setText( QString::number( composerMapExtent.yMinimum(), 'f', 3 ) );
mYMaxLineEdit->setText( QString::number( composerMapExtent.yMaximum(), 'f', 3 ) );

mRotationSpinBox->setValue( mComposerMap->rotation() );

//keep layer list check box
if ( mComposerMap->keepLayerSet() )
{
@@ -309,6 +324,8 @@ void QgsComposerMapWidget::updateGuiElements()
mGridTypeComboBox->setCurrentIndex( mGridTypeComboBox->findText( tr( "Solid" ) ) );
}

mCrossWidthSpinBox->setValue( mComposerMap->crossLength() );

QgsComposerMap::GridAnnotationPosition annotationPos = mComposerMap->gridAnnotationPosition();
if ( annotationPos == QgsComposerMap::InsideMapFrame )
{
@@ -339,19 +356,13 @@ void QgsComposerMapWidget::updateGuiElements()
{
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Vertical" ) ) );
}
else
else if ( dir == QgsComposerMap::HorizontalAndVertical )
{
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Horizontal and Vertical" ) ) );
}

QgsComposerMap::GridAnnotationType type = mComposerMap->gridAnnotationType();
if ( type == QgsComposerMap::Sector )
{
mAnnotationTypeComboBox->setCurrentIndex( mAnnotationTypeComboBox->findText( tr( "Sector" ) ) );
}
else
else //BoundaryDirection
{
mAnnotationTypeComboBox->setCurrentIndex( mAnnotationTypeComboBox->findText( tr( "Coordinate" ) ) );
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Boundary direction" ) ) );
}


@@ -400,6 +411,7 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
mOffsetXSpinBox->blockSignals( b );
mOffsetYSpinBox->blockSignals( b );
mGridTypeComboBox->blockSignals( b );
mCrossWidthSpinBox->blockSignals( b );
mPreviewModeComboBox->blockSignals( b );
mKeepLayerListCheckBox->blockSignals( b );
mSetToMapCanvasExtentButton->blockSignals( b );
@@ -411,7 +423,6 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
mAnnotationPositionComboBox->blockSignals( b );
mDistanceToMapFrameSpinBox->blockSignals( b );
mAnnotationDirectionComboBox->blockSignals( b );
mAnnotationTypeComboBox->blockSignals( b );
}

void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
@@ -561,6 +572,17 @@ void QgsComposerMapWidget::on_mGridTypeComboBox_currentIndexChanged( const QStri
mComposerMap->update();
}

void QgsComposerMapWidget::on_mCrossWidthSpinBox_valueChanged( double d )
{
if ( !mComposerMap )
{
return;
}

mComposerMap->setCrossLength( d );
mComposerMap->update();
}

void QgsComposerMapWidget::on_mAnnotationFontButton_clicked()
{
if ( !mComposerMap )
@@ -647,40 +669,26 @@ void QgsComposerMapWidget::on_mAnnotationDirectionComboBox_currentIndexChanged(
{
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Vertical );
}
else
else if ( text == tr( "Horizontal and Vertical" ) )
{
mComposerMap->setGridAnnotationDirection( QgsComposerMap::HorizontalAndVertical );
}
mComposerMap->updateBoundingRect();
mComposerMap->update();
}

void QgsComposerMapWidget::on_mAnnotationTypeComboBox_currentIndexChanged( const QString& text )
{
if ( !mComposerMap )
{
return;
}

if ( text == tr( "Sector" ) )
else //BoundaryDirection
{
mComposerMap->setGridAnnotationType( QgsComposerMap::Sector );
}
else
{
mComposerMap->setGridAnnotationType( QgsComposerMap::Coordinate );
mComposerMap->setGridAnnotationDirection( QgsComposerMap::BoundaryDirection );
}
mComposerMap->updateBoundingRect();
mComposerMap->update();
}

void QgsComposerMapWidget::on_mShowGridDialogCheckBox_stateChanged( int state )
{
if ( state == Qt::Checked )
{
mGridDockWidget->setVisible( true );
mGridWidget->setVisible( true );
}
else
{
mGridDockWidget->setVisible( false );
mGridWidget->setVisible( false );
}
}
@@ -39,6 +39,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
void on_mHeightLineEdit_editingFinished();
void on_mPreviewModeComboBox_activated( int i );
void on_mScaleLineEdit_editingFinished();
void on_mRotationSpinBox_valueChanged( int value );
void on_mSetToMapCanvasExtentButton_clicked();
void on_mUpdatePreviewButton_clicked();
void on_mKeepLayerListCheckBox_stateChanged( int state );
@@ -56,12 +57,12 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
void on_mLineWidthSpinBox_valueChanged( double d );
void on_mLineColorButton_clicked();
void on_mGridTypeComboBox_currentIndexChanged( const QString& text );
void on_mCrossWidthSpinBox_valueChanged( double d );
void on_mAnnotationFontButton_clicked();
void on_mDistanceToMapFrameSpinBox_valueChanged( double d );
void on_mAnnotationPositionComboBox_currentIndexChanged( const QString& text );
void on_mDrawAnnotationCheckBox_stateChanged( int state );
void on_mAnnotationDirectionComboBox_currentIndexChanged( const QString& text );
void on_mAnnotationTypeComboBox_currentIndexChanged( const QString& text );
void on_mShowGridDialogCheckBox_stateChanged( int state );

/**Updates width and height without notify the composer map (to avoid infinite recursion)*/
@@ -34,7 +34,7 @@
#define FONT_WORKAROUND_SCALE 10 //scale factor for upscaling fontsize and downscaling painter

QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue ): QGraphicsRectItem( 0 ), mComposition( composition ), mBoundingResizeRectangle( 0 ), \
mFrame( true ), mItemPositionLocked( false )
mFrame( true ), mItemPositionLocked( false ), mLastValidViewScaleFactor( -1 )
{
setFlag( QGraphicsItem::ItemIsSelectable, true );
setAcceptsHoverEvents( true );
@@ -53,7 +53,7 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
}

QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue ): \
QGraphicsRectItem( 0, 0, width, height, 0 ), mComposition( composition ), mBoundingResizeRectangle( 0 ), mFrame( true ), mItemPositionLocked( false )
QGraphicsRectItem( 0, 0, width, height, 0 ), mComposition( composition ), mBoundingResizeRectangle( 0 ), mFrame( true ), mItemPositionLocked( false ), mLastValidViewScaleFactor( -1 )
{
setFlag( QGraphicsItem::ItemIsSelectable, true );
setAcceptsHoverEvents( true );
@@ -135,6 +135,8 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
composerItemElem.setAttribute( "positionLock", "false" );
}

composerItemElem.setAttribute( "lastValidViewScaleFactor", mLastValidViewScaleFactor );


//frame color
QDomElement frameColorElem = doc.createElement( "FrameColor" );
@@ -205,6 +207,8 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
setSceneRect( QRectF( x, y, width, height ) );
setZValue( itemElem.attribute( "zValue" ).toDouble() );

mLastValidViewScaleFactor = itemElem.attribute( "lastValidViewScaleFactor", "-1" ).toDouble();

//pen
QDomNodeList frameColorList = itemElem.elementsByTagName( "FrameColor" );
if ( frameColorList.size() > 0 )
@@ -736,17 +740,18 @@ QFont QgsComposerItem::scaledFontPixelSize( const QFont& font ) const

double QgsComposerItem::horizontalViewScaleFactor() const
{
double result = 1;
double result = -1;
if ( scene() )
{
QList<QGraphicsView*> viewList = scene()->views();
if ( viewList.size() > 0 )
{
result = viewList.at( 0 )->transform().m11();
}
else
if ( viewList.size() > 0 ) //if not, probably this function was called from non-gui code
{
return 1; //probably called from non-gui code
QGraphicsView* currentView = viewList.at( 0 );
if ( currentView->isVisible() )
{
result = currentView->transform().m11();
mLastValidViewScaleFactor = result;
}
}
}
return result;
@@ -188,6 +188,9 @@ class CORE_EXPORT QgsComposerItem: public QGraphicsRectItem
@note: this member was added in version 1.2*/
bool mItemPositionLocked;

/**Backup to restore item appearance if no view scale factor is available*/
mutable double mLastValidViewScaleFactor;

//event handlers
virtual void mouseMoveEvent( QGraphicsSceneMouseEvent * event );
virtual void mousePressEvent( QGraphicsSceneMouseEvent * event );
@@ -228,8 +231,8 @@ class CORE_EXPORT QgsComposerItem: public QGraphicsRectItem
@note: this function was introduced in version 1.2*/
double lockSymbolSize() const;

/**Returns the zoom factor of the graphics view. If no
graphics view exists, the default 1 is returned
/**Returns the zoom factor of the graphics view.
@return the factor or -1 in case of error (e.g. graphic view does not exist)
@note: this function was introduced in version 1.2*/
double horizontalViewScaleFactor() const;
};

0 comments on commit 9aa481e

Please sign in to comment.
You can’t perform that action at this time.