22 #include <QGraphicsRectItem> 23 #include <QGraphicsView> 30 setFlag( QGraphicsItem::ItemIsSelectable,
false );
31 setFlag( QGraphicsItem::ItemIsMovable,
false );
40 void QgsPaperGrid::paint( QPainter* painter,
const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
42 Q_UNUSED( itemStyle );
59 painter->setRenderHint( QPainter::Antialiasing,
false );
63 painter->setPen( mComposition->
gridPen() );
66 for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->
snapGridResolution() )
68 painter->drawLine( QPointF( currentXCoord, 0 ), QPointF( currentXCoord, rect().height() ) );
72 currentYCoord = minYCoord;
73 for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->
snapGridResolution() )
75 painter->drawLine( QPointF( 0, currentYCoord ), QPointF( rect().width(), currentYCoord ) );
80 QPen gridPen = mComposition->
gridPen();
81 painter->setPen( gridPen );
82 painter->setBrush( QBrush( gridPen.color() ) );
83 double halfCrossLength = 1;
90 QList<QGraphicsView*> viewList = scene()->views();
91 if ( viewList.size() > 0 )
93 QGraphicsView* currentView = viewList.at( 0 );
94 if ( currentView->isVisible() )
97 halfCrossLength = 1 / currentView->transform().m11();
107 for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->
snapGridResolution() )
109 currentYCoord = minYCoord;
110 for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->
snapGridResolution() )
112 painter->drawLine( QPointF( currentXCoord - halfCrossLength, currentYCoord ), QPointF( currentXCoord + halfCrossLength, currentYCoord ) );
113 painter->drawLine( QPointF( currentXCoord, currentYCoord - halfCrossLength ), QPointF( currentXCoord, currentYCoord + halfCrossLength ) );
131 QgsPaperItem::QgsPaperItem( qreal x, qreal y, qreal width, qreal height,
QgsComposition*
composition ):
QgsComposerItem( x, y, width, height, composition, false ),
132 mPageGrid( 0 ), mPageMargin( 0 )
138 mPageGrid( 0 ), mPageMargin( 0 )
148 void QgsPaperItem::paint( QPainter* painter,
const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
150 Q_UNUSED( itemStyle );
158 double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
174 painter->setRenderHint( QPainter::Antialiasing,
false );
177 painter->setBrush( QBrush( QColor( 150, 150, 150 ) ) );
178 painter->setPen( Qt::NoPen );
179 painter->drawRect( QRectF( 1, 1, rect().width() + 1, rect().height() + 1 ) );
182 painter->setBrush( QColor( 215, 215, 215 ) );
183 painter->setPen( QPen( QColor( 100, 100, 100 ) ) );
184 painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
187 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
189 painter->setRenderHint( QPainter::Antialiasing );
192 calculatePageMargin();
193 QPolygonF pagePolygon = QPolygonF( QRectF( mPageMargin * dotsPerMM, mPageMargin * dotsPerMM,
194 ( rect().width() - 2 * mPageMargin ) * dotsPerMM, ( rect().height() - 2 * mPageMargin ) * dotsPerMM ) );
195 QList<QPolygonF> rings;
213 void QgsPaperItem::calculatePageMargin()
233 Q_UNUSED( itemElem );
242 mPageGrid->setRect( 0, 0, rect().width(), rect().height() );
243 mPageGrid->setPos( pos().x(), pos().y() );
246 void QgsPaperItem::initialize()
248 setFlag( QGraphicsItem::ItemIsSelectable,
false );
249 setFlag( QGraphicsItem::ItemIsMovable,
false );
255 setPen( QPen( QBrush( Qt::NoBrush ), 4 ) );
void setForceVectorOutput(bool force)
QgsComposition::AtlasMode atlasMode() const
Returns the current atlas mode of the composition.
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
QgsFillSymbolV2 * pageStyleSymbol()
Note: added in version 2.1.
bool writeXML(QDomElement &elem, QDomDocument &doc) const override
stores state in Dom element
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
const QPen & gridPen() const
A item that forms part of a map composition.
QgsPaperGrid(double x, double y, double width, double height, QgsComposition *composition)
bool enabled() const
Returns whether the atlas generation is enabled.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
The QgsMapSettings class contains configuration for rendering of the map.
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
int printResolution() const
const QgsComposition * composition() const
Returns the composition the item is attached to.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
sets state from Dom document
Item representing a grid.
void setPainter(QPainter *p)
QgsPaperItem(QgsComposition *c)
static double estimateMaxSymbolBleed(QgsSymbolV2 *symbol)
Returns the maximum estimated bleed for the symbol.
Graphics scene for map printing.
QgsFeature * currentFeature()
Returns the current atlas feature.
GridStyle gridStyle() const
QgsComposition * mComposition
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint.
double snapGridOffsetY() const
Contains information about the context of a rendering operation.
double snapGridOffsetX() const
void stopRender(QgsRenderContext &context)
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
double snapGridResolution() const
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
virtual void setSceneRect(const QRectF &rectangle) override
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
QgsAtlasComposition & atlasComposition()
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint.
QgsComposerItem(QgsComposition *composition, bool manageZValue=true)
Constructor.
QgsComposition::PlotStyle plotStyle() const