17
17
18
18
#include " qgspaperitem.h"
19
19
#include " qgscomposition.h"
20
+ #include " qgslogger.h"
21
+ #include < QGraphicsRectItem>
20
22
#include < QPainter>
21
23
22
- QgsPaperItem::QgsPaperItem ( QgsComposition* c ): QgsComposerItem( c, false )
23
- {
24
- initialize ();
25
- }
26
-
27
- QgsPaperItem::QgsPaperItem ( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition ): QgsComposerItem( x, y, width, height, composition, false )
28
- {
29
- initialize ();
30
- }
24
+ // QgsPaperGrid
31
25
32
- QgsPaperItem::QgsPaperItem ( ): QgsComposerItem ( 0 , false )
26
+ QgsPaperGrid::QgsPaperGrid ( double x, double y, double width, double height, QgsComposition* composition ): QGraphicsRectItem ( 0 , 0 , width, height ), mComposition( composition )
33
27
{
34
- initialize ();
28
+ setFlag ( QGraphicsItem::ItemIsSelectable, false );
29
+ setFlag ( QGraphicsItem::ItemIsMovable, false );
30
+ setZValue ( 1000 );
31
+ setPos ( x, y );
35
32
}
36
33
37
- QgsPaperItem ::~QgsPaperItem ()
34
+ QgsPaperGrid ::~QgsPaperGrid ()
38
35
{
39
-
40
36
}
41
37
42
- void QgsPaperItem ::paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
38
+ void QgsPaperGrid ::paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
43
39
{
44
40
Q_UNUSED ( itemStyle );
45
41
Q_UNUSED ( pWidget );
46
- if ( !painter )
47
- {
48
- return ;
49
- }
50
-
51
- drawBackground ( painter );
52
42
53
43
// draw grid
54
44
if ( mComposition )
@@ -127,6 +117,44 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
127
117
}
128
118
}
129
119
120
+
121
+ // QgsPaperItem
122
+
123
+ QgsPaperItem::QgsPaperItem ( QgsComposition* c ): QgsComposerItem( c, false ),
124
+ mPageGrid( 0 )
125
+ {
126
+ initialize ();
127
+ }
128
+
129
+ QgsPaperItem::QgsPaperItem ( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition ): QgsComposerItem( x, y, width, height, composition, false ),
130
+ mPageGrid( 0 )
131
+ {
132
+ initialize ();
133
+ }
134
+
135
+ QgsPaperItem::QgsPaperItem (): QgsComposerItem( 0 , false ),
136
+ mPageGrid( 0 )
137
+ {
138
+ initialize ();
139
+ }
140
+
141
+ QgsPaperItem::~QgsPaperItem ()
142
+ {
143
+ delete mPageGrid ;
144
+ }
145
+
146
+ void QgsPaperItem::paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
147
+ {
148
+ Q_UNUSED ( itemStyle );
149
+ Q_UNUSED ( pWidget );
150
+ if ( !painter )
151
+ {
152
+ return ;
153
+ }
154
+
155
+ drawBackground ( painter );
156
+ }
157
+
130
158
bool QgsPaperItem::writeXML ( QDomElement& elem, QDomDocument & doc ) const
131
159
{
132
160
Q_UNUSED ( elem );
@@ -141,9 +169,21 @@ bool QgsPaperItem::readXML( const QDomElement& itemElem, const QDomDocument& doc
141
169
return true ;
142
170
}
143
171
172
+ void QgsPaperItem::setSceneRect ( const QRectF& rectangle )
173
+ {
174
+ QgsComposerItem::setSceneRect ( rectangle );
175
+ // update size and position of attached QgsPaperGrid to reflect new page size and position
176
+ mPageGrid ->setRect ( 0 , 0 , rect ().width (), rect ().height () );
177
+ mPageGrid ->setPos ( transform ().dx (), transform ().dy () );
178
+ }
179
+
144
180
void QgsPaperItem::initialize ()
145
181
{
146
182
setFlag ( QGraphicsItem::ItemIsSelectable, false );
147
183
setFlag ( QGraphicsItem::ItemIsMovable, false );
148
184
setZValue ( 0 );
185
+
186
+ // create a new QgsPaperGrid for this page, and add it to the composition
187
+ mPageGrid = new QgsPaperGrid ( transform ().dx (), transform ().dy (), rect ().width (), rect ().height (), mComposition );
188
+ mComposition ->addItem ( mPageGrid );
149
189
}
0 commit comments