-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python bindings for composer classes
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10244 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
mhugent
committed
Feb 27, 2009
1 parent
040a039
commit 9bd34cc
Showing
19 changed files
with
1,025 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/** \ingroup MapComposer | ||
* A item that forms part of a map composition. | ||
*/ | ||
class QgsComposerItem: QGraphicsRectItem | ||
{ | ||
%TypeHeaderCode | ||
#include <qgscomposeritem.h> | ||
%End | ||
|
||
public: | ||
|
||
/**Describes the action (move or resize in different directon) to be done during mouse move*/ | ||
enum MouseMoveAction | ||
{ | ||
MoveItem, | ||
ResizeUp, | ||
ResizeDown, | ||
ResizeLeft, | ||
ResizeRight, | ||
ResizeLeftUp, | ||
ResizeRightUp, | ||
ResizeLeftDown, | ||
ResizeRightDown | ||
}; | ||
|
||
enum ItemPositionMode | ||
{ | ||
UpperLeft, | ||
UpperMiddle, | ||
UpperRight, | ||
MiddleLeft, | ||
Middle, | ||
MiddleRight, | ||
LowerLeft, | ||
LowerMiddle, | ||
LowerRight | ||
}; | ||
|
||
/**Constructor | ||
@param manageZValue true if the z-Value of this object should be managed by mComposition*/ | ||
QgsComposerItem( QgsComposition* composition, bool manageZValue = true ); | ||
/**Constructor with box position and composer object | ||
@param manageZValue true if the z-Value of this object should be managed by mComposition*/ | ||
QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue = true ); | ||
virtual ~QgsComposerItem(); | ||
|
||
/** \brief Set selected, selected item should be highlighted */ | ||
virtual void setSelected( bool s ); | ||
|
||
/** \brief Is selected */ | ||
virtual bool selected(); | ||
|
||
/** stores state in project */ | ||
virtual bool writeSettings(); | ||
|
||
/** read state from project */ | ||
virtual bool readSettings(); | ||
|
||
/** delete settings from project file */ | ||
virtual bool removeSettings(); | ||
|
||
/**Moves item in canvas coordinates*/ | ||
void move( double dx, double dy ); | ||
|
||
/**Move Content of item. Does nothing per default (but implemented in composer map) | ||
@param dx move in x-direction (canvas coordinates) | ||
@param dy move in y-direction(canvas coordinates)*/ | ||
virtual void moveContent( double dx, double dy ); | ||
|
||
/**Zoom content of item. Does nothing per default (but implemented in composer map) | ||
@param delta value from wheel event that describes magnitude and direction (positive /negative number) | ||
@param x x-position of mouse cursor (in item coordinates) | ||
@param y y-position of mouse cursor (in item coordinates)*/ | ||
virtual void zoomContent( int delta, double x, double y ); | ||
|
||
/**Moves the item to a new position (in canvas coordinates)*/ | ||
void setItemPosition( double x, double y, ItemPositionMode itemPoint = UpperLeft ); | ||
|
||
/**Sets this items bound in scene coordinates such that 1 item size units | ||
corresponds to 1 scene size unit*/ | ||
virtual void setSceneRect( const QRectF& rectangle ); | ||
|
||
/** stores state in Dom node | ||
* @param node is Dom node corresponding to 'Composer' tag | ||
* @param temp write template file | ||
*/ | ||
virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const = 0; | ||
|
||
/**Writes parameter that are not subclass specific in document. Usually called from writeXML methods of subclasses*/ | ||
bool _writeXML( QDomElement& itemElem, QDomDocument& doc ) const; | ||
|
||
/** sets state from Dom document | ||
* @param itemElem is Dom node corresponding to item tag | ||
*/ | ||
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) = 0; | ||
|
||
/**Reads parameter that are not subclass specific in document. Usually called from readXML methods of subclasses*/ | ||
bool _readXML( const QDomElement& itemElem, const QDomDocument& doc ); | ||
|
||
|
||
|
||
bool frame() const; | ||
void setFrame( bool drawFrame ); | ||
|
||
/**Composite operations for item groups do nothing per default*/ | ||
virtual void addItem( QgsComposerItem* item ); | ||
virtual void removeItems(); | ||
|
||
const QgsComposition* composition() const; | ||
|
||
//functions that encapsulate the workaround for the Qt font bug (that is to scale the font size up and then scale the | ||
//painter down by the same factor for drawing | ||
|
||
/**Draws Text. Takes care about all the composer specific issues (calculation to pixel, scaling of font and painter | ||
to work arount the Qt font bug)*/ | ||
void drawText( QPainter* p, int x, int y, const QString& text, const QFont& font ) const; | ||
|
||
/**Like the above, but with a rectangle for multiline text*/ | ||
void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font ) const; | ||
|
||
/**Returns the font width in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/ | ||
double textWidthMillimeters( const QFont& font, const QString& text ) const; | ||
|
||
/**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/ | ||
double fontAscentMillimeters( const QFont& font ) const; | ||
|
||
/**Calculates font to from point size to pixel size*/ | ||
double pixelFontSize( double pointSize ) const; | ||
|
||
/**Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE*/ | ||
QFont scaledFontPixelSize( const QFont& font ) const; | ||
|
||
protected: | ||
|
||
//event handlers | ||
virtual void mouseMoveEvent( QGraphicsSceneMouseEvent * event ); | ||
virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ); | ||
virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent * event ); | ||
|
||
virtual void hoverMoveEvent( QGraphicsSceneHoverEvent * event ); | ||
|
||
/**Finds out the appropriate cursor for the current mouse position in the widget (e.g. move in the middle, resize at border)*/ | ||
Qt::CursorShape cursorForPosition( const QPointF& itemCoordPos ); | ||
|
||
/**Finds out which mouse move action to choose depending on the cursor position inside the widget*/ | ||
QgsComposerItem::MouseMoveAction mouseMoveActionForPosition( const QPointF& itemCoordPos ); | ||
|
||
/**Changes the rectangle of an item depending on current mouse action (resize or move) | ||
@param currentPosition current position of mouse cursor | ||
@param mouseMoveStartPos cursor position at the start of the current mouse action | ||
@param originalItem Item position at the start of the mouse action | ||
@param dx x-Change of mouse cursor | ||
@param dy y-Change of mouse cursor | ||
@param changeItem Item to change size (can be the same as originalItem or a differen one) | ||
*/ | ||
void changeItemRectangle( const QPointF& currentPosition, const QPointF& mouseMoveStartPos, const QGraphicsRectItem* originalItem, double dx, double dy, QGraphicsRectItem* changeItem ); | ||
|
||
/**Draw selection boxes around item*/ | ||
virtual void drawSelectionBoxes( QPainter* p ); | ||
|
||
/**Draw black frame around item*/ | ||
virtual void drawFrame( QPainter* p ); | ||
|
||
/**Draw background*/ | ||
virtual void drawBackground( QPainter* p ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** \ingroup MapComposer | ||
* A label that can be placed onto a map composition. | ||
*/ | ||
class QgsComposerLabel: QgsComposerItem | ||
{ | ||
%TypeHeaderCode | ||
#include "qgscomposerlabel.h" | ||
%End | ||
public: | ||
QgsComposerLabel( QgsComposition *composition ); | ||
~QgsComposerLabel(); | ||
|
||
/** \brief Reimplementation of QCanvasItem::paint*/ | ||
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ); | ||
|
||
/**resizes the widget such that the text fits to the item. Keeps top left point*/ | ||
void adjustSizeToText(); | ||
|
||
QString text(); | ||
void setText( const QString& text ); | ||
QFont font() const; | ||
void setFont( const QFont& f ); | ||
double margin(); | ||
void setMargin( double m ); | ||
|
||
/** 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 node is Dom node corresponding to 'ComposerLabel' tag | ||
*/ | ||
bool readXML( const QDomElement& itemElem, const QDomDocument& doc ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** \ingroup MapComposer | ||
* A legend that can be placed onto a map composition | ||
*/ | ||
class QgsComposerLegend: QObject, QgsComposerItem | ||
{ | ||
%TypeHeaderCode | ||
#include <qgscomposerlegend.h> | ||
%End | ||
|
||
public: | ||
QgsComposerLegend( QgsComposition* composition ); | ||
~QgsComposerLegend(); | ||
|
||
/** \brief Reimplementation of QCanvasItem::paint*/ | ||
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ); | ||
|
||
/**Paints the legend and calculates its size. If painter is 0, only size is calculated*/ | ||
QSizeF paintAndDetermineSize( QPainter* painter ); | ||
|
||
/**Sets item box to the whole content*/ | ||
void adjustBoxSize(); | ||
|
||
/**Returns pointer to the legend model*/ | ||
QgsLegendModel* model(); | ||
|
||
//setters and getters | ||
void setTitle( const QString& t ); | ||
QString title() const; | ||
|
||
QFont titleFont() const; | ||
void setTitleFont( const QFont& f ); | ||
|
||
QFont layerFont() const; | ||
void setLayerFont( const QFont& f ); | ||
|
||
QFont itemFont() const; | ||
void setItemFont( const QFont& f ); | ||
|
||
double boxSpace() const; | ||
void setBoxSpace( double s ); | ||
|
||
double layerSpace() const; | ||
void setLayerSpace( double s ); | ||
|
||
double symbolSpace() const; | ||
void setSymbolSpace( double s ); | ||
|
||
double iconLabelSpace() const; | ||
void setIconLabelSpace( double s ); | ||
|
||
double symbolWidth() const; | ||
void setSymbolWidth( double w ); | ||
|
||
double symbolHeight() const; | ||
void setSymbolHeight( double h ); | ||
|
||
/**Updates the model and all legend entries*/ | ||
void updateLegend(); | ||
|
||
/** stores state in Dom node | ||
* @param elem is Dom element 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 ); | ||
|
||
public slots: | ||
/**Data changed*/ | ||
void synchronizeWithModel(); | ||
|
||
protected: | ||
|
||
|
||
private: | ||
QgsComposerLegend(); //forbidden | ||
|
||
/**Draws child items of a layer item | ||
@param layerItem parent model item (layer) | ||
@param currentYCoord in/out: current y position of legend item | ||
@param maxXCoord in/out: maximum x-coordinate of the whole legend | ||
*/ | ||
void drawLayerChildItems( QPainter* p, QStandardItem* layerItem, double& currentYCoord, double& maxXCoord ); | ||
|
||
/**Draws a symbol at the current y position and returns the new x position. Returns real symbol height, because for points, | ||
it is possible that it differs from mSymbolHeight*/ | ||
void drawSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight ) const; | ||
void drawPointSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight ) const; | ||
void drawLineSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition ) const; | ||
void drawPolygonSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition ) const; | ||
|
||
/**Helper function that lists ids of layers contained in map canvas*/ | ||
QStringList layerIdList() const; | ||
}; |
Oops, something went wrong.