Skip to content
Permalink
Browse files

Add a new composer item to draw basic shapes (atm ellipse, rectangle,…

… triangle), fix some composer related bugs and bring rotation to composer item level

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12183 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 19, 2009
1 parent c9c6ffc commit 701ba52c79ef276c8eacb8a049fa0bf7c48abff4
Binary file not shown.
@@ -1,7 +1,7 @@
/** \ingroup MapComposer
* A item that forms part of a map composition.
*/
class QgsComposerItem: QGraphicsRectItem
class QgsComposerItem: public QObject, public QGraphicsRectItem
{
%TypeHeaderCode
#include <qgscomposeritem.h>
@@ -130,6 +130,23 @@ class QgsComposerItem: QGraphicsRectItem
/**Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE*/
QFont scaledFontPixelSize( const QFont& font ) const;

/**Locks / unlocks the item position for mouse drags
@note this method was added in version 1.2*/
void setPositionLock( bool lock );

/**Returns position lock for mouse drags (true means locked)
@note this method was added in version 1.2*/
bool positionLock() const;

/**Update mouse cursor at (item) position
@note this method was added in version 1.2*/
void updateCursor( const QPointF& itemPos );

double rotation() const;

public slots:
void setRotation( double r);

protected:

//event handlers
@@ -163,4 +180,28 @@ class QgsComposerItem: QGraphicsRectItem

/**Draw background*/
virtual void drawBackground( QPainter* p );
};

/**Returns the current (zoom level dependent) tolerance to decide if mouse position is close enough to the \
item border for resizing*/
double rectHandlerBorderTolerance() const;

/**Returns the size of the lock symbol depending on the composer zoom level and the item size
@note: this function was introduced in version 1.2*/
double lockSymbolSize() const;

/**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;

/**Calculates width and hight of the picture (in mm) such that it fits into the item frame with the given rotation*/
bool imageSizeConsideringRotation( double& width, double& height ) const;
/**Calculates corner point after rotation and scaling*/
bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
/**Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point*/
QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance ) const;

signals:
/**Is emitted on rotation change to notify north arrow pictures*/
void rotationChanged( double newRotation );
};
@@ -1,7 +1,7 @@
/** \ingroup MapComposer
* A legend that can be placed onto a map composition
*/
class QgsComposerLegend: QObject, QgsComposerItem
class QgsComposerLegend: QgsComposerItem
{
%TypeHeaderCode
#include <qgscomposerlegend.h>
@@ -3,7 +3,7 @@
* \brief Object representing map window.
*/
// NOTE: QgsComposerMapBase must be first, otherwise does not compile
class QgsComposerMap : QObject, QgsComposerItem
class QgsComposerMap : QgsComposerItem
{
%TypeHeaderCode
#include <qgscomposermap.h>
@@ -211,11 +211,6 @@ class QgsComposerMap : QObject, QgsComposerItem
@note this function was added in version 1.4*/
void updateBoundingRect();

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

/**Sets length of the cros segments (if grid style is cross)
@note this function was added in version 1.4*/
void setCrossLength(double l);
@@ -231,6 +226,4 @@ class QgsComposerMap : QObject, QgsComposerItem
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 );
};
@@ -1,7 +1,7 @@
/** \ingroup MapComposer
* A composer class that displays svg files or raster format (jpg, png, ...)
* */
class QgsComposerPicture: QObject, QgsComposerItem
class QgsComposerPicture: QgsComposerItem
{

%TypeHeaderCode
@@ -23,10 +23,6 @@ class QgsComposerPicture: QObject, QgsComposerItem
corresponds to 1 scene size unit*/
void setSceneRect( const QRectF& rectangle );

void setRotation( double rotation );

double rotation() const;

/** stores state in Dom node
* @param node is Dom node corresponding to 'Composer' tag
* @param temp write template file
@@ -2,7 +2,7 @@
* A scale bar item that can be added to a map composition.
*/

class QgsComposerScaleBar: QObject, QgsComposerItem
class QgsComposerScaleBar: QgsComposerItem
{
%TypeHeaderCode
#include "qgscomposerscalebar.h"
@@ -0,0 +1,43 @@
/**A composer items that draws common shapes (ellipse, triangle, rectangle)*/
class QgsComposerShape: public QgsComposerItem
{
%TypeHeaderCode
#include "qgscomposershape.h"
%End
public:

enum Shape
{
Ellipse,
Rectangle,
Triangle
};

QgsComposerShape( QgsComposition* composition /TransferThis/);
QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition );
~QgsComposerShape();

/** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

/** stores state in Dom node
* @param node is Dom node corresponding to 'Composer' tag
* @param temp write template file
*/
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;

/** sets state from Dom document
* @param itemElem is Dom node corresponding to item tag
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

//setters and getters
void setLineWidth( double width );
double lineWidth() const;
void setOutlineColor( const QColor& color );
QColor outlineColor() const;
void setFillColor( const QColor& color );
QColor fillColor() const;
QgsComposerShape::Shape shapeType() const;
void setShapeType( QgsComposerShape::Shape s );
};
@@ -80,6 +80,7 @@ SET(QGIS_APP_SRCS
composer/qgscomposermanager.cpp
composer/qgscomposermapwidget.cpp
composer/qgscomposerscalebarwidget.cpp
composer/qgscomposershapewidget.cpp
composer/qgscomposerlegenditemdialog.cpp
composer/qgscomposerlegendwidget.cpp
composer/qgscompositionwidget.cpp
@@ -179,6 +180,7 @@ SET (QGIS_APP_MOC_HDRS
composer/qgscomposermapwidget.h
composer/qgscomposerpicturewidget.h
composer/qgscomposerscalebarwidget.h
composer/qgscomposershapewidget.h
composer/qgscompositionwidget.h
composer/qgsitempositiondialog.h

@@ -31,6 +31,8 @@
#include "qgscomposerpicturewidget.h"
#include "qgscomposerscalebar.h"
#include "qgscomposerscalebarwidget.h"
#include "qgscomposershape.h"
#include "qgscomposershapewidget.h"
#include "qgsexception.h"
#include "qgsproject.h"
#include "qgsmapcanvas.h"
@@ -106,6 +108,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
toggleActionGroup->addAction( mActionAddNewScalebar );
toggleActionGroup->addAction( mActionAddImage );
toggleActionGroup->addAction( mActionSelectMoveItem );
toggleActionGroup->addAction( mActionAddBasicShape );
toggleActionGroup->setExclusive( true );

mActionAddNewMap->setCheckable( true );
@@ -115,6 +118,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
mActionAddNewScalebar->setCheckable( true );
mActionAddImage->setCheckable( true );
mActionMoveItemContent->setCheckable( true );
mActionAddBasicShape->setCheckable( true );

#ifdef Q_WS_MAC
QMenu *appMenu = menuBar()->addMenu( tr( "QGIS" ) );
@@ -150,6 +154,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
layoutMenu->addAction( mActionAddImage );
layoutMenu->addAction( mActionSelectMoveItem );
layoutMenu->addAction( mActionMoveItemContent );
layoutMenu->addAction( mActionAddBasicShape );
layoutMenu->addSeparator();
layoutMenu->addAction( mActionGroupItems );
layoutMenu->addAction( mActionUngroupItems );
@@ -243,6 +248,7 @@ void QgsComposer::setupTheme()
mActionAddNewLabel->setIcon( QgisApp::getThemeIcon( "/mActionLabel.png" ) );
mActionAddNewLegend->setIcon( QgisApp::getThemeIcon( "/mActionAddLegend.png" ) );
mActionAddNewScalebar->setIcon( QgisApp::getThemeIcon( "/mActionScaleBar.png" ) );
mActionAddBasicShape->setIcon( QgisApp::getThemeIcon( "/mActionAddBasicShape.png" ) );
mActionSelectMoveItem->setIcon( QgisApp::getThemeIcon( "/mActionSelectPan.png" ) );
mActionMoveItemContent->setIcon( QgisApp::getThemeIcon( "/mActionMoveItemContent.png" ) );
mActionGroupItems->setIcon( QgisApp::getThemeIcon( "/mActionGroupItems.png" ) );
@@ -268,6 +274,7 @@ void QgsComposer::connectSlots()
connect( mView, SIGNAL( composerScaleBarAdded( QgsComposerScaleBar* ) ), this, SLOT( addComposerScaleBar( QgsComposerScaleBar* ) ) );
connect( mView, SIGNAL( composerLegendAdded( QgsComposerLegend* ) ), this, SLOT( addComposerLegend( QgsComposerLegend* ) ) );
connect( mView, SIGNAL( composerPictureAdded( QgsComposerPicture* ) ), this, SLOT( addComposerPicture( QgsComposerPicture* ) ) );
connect( mView, SIGNAL( composerShapeAdded( QgsComposerShape* ) ), this, SLOT( addComposerShape( QgsComposerShape* ) ) );
connect( mView, SIGNAL( actionFinished() ), this, SLOT( setSelectionTool() ) );
}

@@ -330,6 +337,10 @@ void QgsComposer::setTitle( const QString& title )
{
mTitle = title;
setWindowTitle( mTitle );
if ( mWindowAction )
{
mWindowAction->setText( title );
}
}

void QgsComposer::showCompositionOptions( QWidget *w )
@@ -786,6 +797,14 @@ void QgsComposer::on_mActionAddImage_triggered()
}
}

void QgsComposer::on_mActionAddBasicShape_triggered()
{
if ( mView )
{
mView->setCurrentTool( QgsComposerView::AddShape );
}
}

void QgsComposer::on_mActionSaveAsTemplate_triggered()
{
//show file dialog
@@ -1015,6 +1034,16 @@ void QgsComposer::writeXML( QDomNode& parentNode, QDomDocument& doc )
{
QDomElement composerElem = doc.createElement( "Composer" );
composerElem.setAttribute( "title", mTitle );

//store if composer is open or closed
if ( isVisible() )
{
composerElem.setAttribute( "visible", 1 );
}
else
{
composerElem.setAttribute( "visible", 0 );
}
parentNode.appendChild( composerElem );

//store composer items:
@@ -1173,6 +1202,21 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
showItemOptions( newPicture );
}

//composer shapes
QDomNodeList composerShapeList = composerElem.elementsByTagName( "ComposerShape" );
for ( int i = 0; i < composerShapeList.size(); ++i )
{
QDomElement currentShapeElem = composerShapeList.at( i ).toElement();
QgsComposerShape* newShape = new QgsComposerShape( mComposition );
newShape->readXML( currentShapeElem, doc );
addComposerShape( newShape );
mComposition->addItem( newShape );
mComposition->update();
mComposition->clearSelection();
newShape->setSelected( true );
showItemOptions( newShape );
}

mComposition->sortZList();
mView->setComposition( mComposition );

@@ -1247,6 +1291,16 @@ void QgsComposer::addComposerPicture( QgsComposerPicture* picture )
mItemWidgetMap.insert( picture, pWidget );
}

void QgsComposer::addComposerShape( QgsComposerShape* shape )
{
if ( !shape )
{
return;
}
QgsComposerShapeWidget* sWidget = new QgsComposerShapeWidget( shape );
mItemWidgetMap.insert( shape, sWidget );
}

void QgsComposer::deleteItem( QgsComposerItem* item )
{
QMap<QgsComposerItem*, QWidget*>::iterator it = mItemWidgetMap.find( item );
@@ -27,6 +27,7 @@ class QgsComposerLegend;
class QgsComposerMap;
class QgsComposerPicture;
class QgsComposerScaleBar;
class QgsComposerShape;
class QgsComposerView;
class QgsComposition;
class QgsMapCanvas;
@@ -142,6 +143,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Add new picture
void on_mActionAddImage_triggered();

//! Add ellipse shape item
void on_mActionAddBasicShape_triggered();

//! Save composer as template
void on_mActionSaveAsTemplate_triggered();

@@ -204,6 +208,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
/**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*/
void addComposerShape( QgsComposerShape* shape );

/**Removes item from the item/widget map and deletes the configuration widget*/
void deleteItem( QgsComposerItem* item );

@@ -162,7 +162,7 @@ void QgsComposerMapWidget::on_mRotationSpinBox_valueChanged( int value )
return;
}

mComposerMap->setRotation( value );
mComposerMap->setMapRotation( value );
mComposerMap->cache();
mComposerMap->update();
}
@@ -46,6 +46,7 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture
//add preview icons
addStandardDirectoriesToPreview();
connect( mPicture, SIGNAL( settingsChanged() ), this, SLOT( setGuiElementValues() ) );
connect( mPicture, SIGNAL( rotationChanged( double ) ), this, SLOT( setGuiElementValues() ) );
}

QgsComposerPictureWidget::~QgsComposerPictureWidget()

0 comments on commit 701ba52

Please sign in to comment.