1
|
Index: src/app/composer/qgscomposerpicture.cpp
|
2
|
===================================================================
|
3
|
--- src/app/composer/qgscomposerpicture.cpp (revision 7070)
|
4
|
+++ src/app/composer/qgscomposerpicture.cpp (working copy)
|
5
|
@@ -24,16 +24,21 @@
|
6
|
#include <QPainter>
|
7
|
#include <QImageWriter>
|
8
|
#include <QSettings>
|
9
|
+#include <QPolygonF>
|
10
|
+#include <QAbstractGraphicsShapeItem>
|
11
|
+#include <QGraphicsScene>
|
12
|
|
13
|
#include <cmath>
|
14
|
#include <iostream>
|
15
|
|
16
|
#define PI 3.14159265358979323846
|
17
|
|
18
|
+#define QGISDEBUG 1
|
19
|
+
|
20
|
QgsComposerPicture::QgsComposerPicture ( QgsComposition *composition,
|
21
|
int id, QString file )
|
22
|
: QWidget(composition),
|
23
|
- Q3CanvasPolygonalItem(0),
|
24
|
+ QAbstractGraphicsShapeItem(0),
|
25
|
mPicturePath ( file ),
|
26
|
mPictureValid(false),
|
27
|
mCX(-10), mCY(-10),
|
28
|
@@ -54,18 +59,18 @@
|
29
|
init();
|
30
|
loadPicture();
|
31
|
|
32
|
- // Add to canvas
|
33
|
- setCanvas(mComposition->canvas());
|
34
|
+ // Add to scene
|
35
|
+ mComposition->canvas()->addItem(this);
|
36
|
|
37
|
- Q3CanvasPolygonalItem::show();
|
38
|
- Q3CanvasPolygonalItem::update();
|
39
|
+ QAbstractGraphicsShapeItem::show();
|
40
|
+ QAbstractGraphicsShapeItem::update();
|
41
|
|
42
|
writeSettings();
|
43
|
}
|
44
|
|
45
|
QgsComposerPicture::QgsComposerPicture ( QgsComposition *composition, int id ) :
|
46
|
QWidget(),
|
47
|
- Q3CanvasPolygonalItem(0),
|
48
|
+ QAbstractGraphicsShapeItem(0),
|
49
|
mFrame(false),
|
50
|
mAreaPoints(4),
|
51
|
mBoundingRect(0,0,0,0)
|
52
|
@@ -86,26 +91,25 @@
|
53
|
loadPicture();
|
54
|
adjustPictureSize();
|
55
|
|
56
|
- // Add to canvas
|
57
|
- setCanvas(mComposition->canvas());
|
58
|
+ // Add to scene
|
59
|
+ mComposition->canvas()->addItem(this);
|
60
|
|
61
|
recalculate();
|
62
|
|
63
|
- Q3CanvasPolygonalItem::show();
|
64
|
- Q3CanvasPolygonalItem::update();
|
65
|
+ QAbstractGraphicsShapeItem::show();
|
66
|
+ QAbstractGraphicsShapeItem::update();
|
67
|
}
|
68
|
|
69
|
void QgsComposerPicture::init ( void )
|
70
|
{
|
71
|
- mSelected = false;
|
72
|
- for ( int i = 0; i < 4; i++ )
|
73
|
- {
|
74
|
- mAreaPoints[i] = QPoint( 0, 0 );
|
75
|
- }
|
76
|
+ mSelected = false;
|
77
|
+ for ( int i = 0; i < 4; i++ )
|
78
|
+ {
|
79
|
+ mAreaPoints[i] = QPoint( 0, 0 );
|
80
|
+ }
|
81
|
|
82
|
- // Rectangle
|
83
|
- Q3CanvasPolygonalItem::setZ(60);
|
84
|
- setActive(true);
|
85
|
+ QAbstractGraphicsShapeItem::setZValue(60);
|
86
|
+
|
87
|
}
|
88
|
|
89
|
void QgsComposerPicture::loadPicture ( void )
|
90
|
@@ -113,71 +117,72 @@
|
91
|
#ifdef QGISDEBUG
|
92
|
std::cerr << "QgsComposerPicture::loadPicture() mPicturePath = " << mPicturePath.toLocal8Bit().data() << std::endl;
|
93
|
#endif
|
94
|
- mPicture = Q3Picture();
|
95
|
- mPictureValid = false;
|
96
|
|
97
|
- if ( !mPicturePath.isNull() )
|
98
|
- {
|
99
|
+ mPicture = QPicture();
|
100
|
+ mPictureValid = false;
|
101
|
+
|
102
|
+ if ( !mPicturePath.isNull() )
|
103
|
+ {
|
104
|
if ( mPicturePath.lower().right(3) == "svg" )
|
105
|
{
|
106
|
- if ( !mPicture.load ( mPicturePath, "svg" ) )
|
107
|
- {
|
108
|
+ if ( !mPicture.load ( mPicturePath, "svg" ) )
|
109
|
+ {
|
110
|
std::cerr << "Cannot load svg" << std::endl;
|
111
|
- }
|
112
|
- else
|
113
|
- {
|
114
|
+ }
|
115
|
+ else
|
116
|
+ {
|
117
|
mPictureValid = true;
|
118
|
- }
|
119
|
+ }
|
120
|
}
|
121
|
else
|
122
|
{
|
123
|
- QImage image;
|
124
|
- if ( !image.load(mPicturePath) )
|
125
|
- {
|
126
|
- std::cerr << "Cannot load raster" << std::endl;
|
127
|
- }
|
128
|
- else
|
129
|
- {
|
130
|
- QPainter p;
|
131
|
- p.begin( &mPicture );
|
132
|
- p.drawImage ( 0, 0, image );
|
133
|
- p.end();
|
134
|
- mPictureValid = true;
|
135
|
- }
|
136
|
+ QImage image;
|
137
|
+ if ( !image.load(mPicturePath) )
|
138
|
+ {
|
139
|
+ std::cerr << "Cannot load raster" << std::endl;
|
140
|
+ }
|
141
|
+ else
|
142
|
+ {
|
143
|
+ QPainter p;
|
144
|
+ p.begin( &mPicture );
|
145
|
+ p.drawImage ( 0, 0, image );
|
146
|
+ p.end();
|
147
|
+ mPictureValid = true;
|
148
|
+ }
|
149
|
}
|
150
|
- }
|
151
|
+ }
|
152
|
|
153
|
- if ( !mPictureValid )
|
154
|
- {
|
155
|
- // Dummy picture
|
156
|
- QPainter p;
|
157
|
+ if ( !mPictureValid )
|
158
|
+ {
|
159
|
+ // Dummy picture
|
160
|
+ QPainter p;
|
161
|
p.begin( &mPicture );
|
162
|
- QPen pen(QColor(0,0,0));
|
163
|
- pen.setWidthF(3.0);
|
164
|
- p.setPen( pen );
|
165
|
- p.setBrush( QBrush( QColor( 150, 150, 150) ) );
|
166
|
+ QPen pen(QColor(0,0,0));
|
167
|
+ pen.setWidthF(3.0);
|
168
|
+ p.setPen( pen );
|
169
|
+ p.setBrush( QBrush( QColor( 150, 150, 150) ) );
|
170
|
|
171
|
- int w, h;
|
172
|
- if ( mWidth > 0 && mHeight > 0
|
173
|
- && mWidth/mHeight > 0.001 && mWidth/mHeight < 1000 )
|
174
|
+ double w, h;
|
175
|
+ if ( mWidth > 0 && mHeight > 0
|
176
|
+ && mWidth/mHeight > 0.001 && mWidth/mHeight < 1000 )
|
177
|
{
|
178
|
- w = mWidth;
|
179
|
- h = mHeight;
|
180
|
- }
|
181
|
+ w = mWidth;
|
182
|
+ h = mHeight;
|
183
|
+ }
|
184
|
else
|
185
|
{
|
186
|
- w = 100;
|
187
|
- h = 100;
|
188
|
+ w = 100;
|
189
|
+ h = 100;
|
190
|
}
|
191
|
|
192
|
- p.drawRect ( 0, 0, w, h );
|
193
|
- p.drawLine ( 0, 0, w-1, h-1 );
|
194
|
- p.drawLine ( w-1, 0, 0, h-1 );
|
195
|
+ p.drawRect (QRectF(0, 0, w, h));
|
196
|
+ p.drawLine (QLineF(0, 0, w-1, h-1));
|
197
|
+ p.drawLine (QLineF(w-1, 0, 0, h-1));
|
198
|
|
199
|
p.end();
|
200
|
|
201
|
- mPicture.setBoundingRect ( QRect ( 0, 0, w, h ) );
|
202
|
- }
|
203
|
+ mPicture.setBoundingRect ( QRect( 0, 0, (int)w, (int)h ) );
|
204
|
+ }//END if(!mPictureValid)
|
205
|
}
|
206
|
|
207
|
bool QgsComposerPicture::pictureValid ( void )
|
208
|
@@ -190,111 +195,79 @@
|
209
|
#ifdef QGISDEBUG
|
210
|
std::cerr << "QgsComposerPicture::~QgsComposerPicture()" << std::endl;
|
211
|
#endif
|
212
|
- Q3CanvasItem::hide();
|
213
|
+ QGraphicsItem::hide();
|
214
|
}
|
215
|
|
216
|
-void QgsComposerPicture::draw ( QPainter & painter )
|
217
|
+void QgsComposerPicture::paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
|
218
|
{
|
219
|
#ifdef QGISDEBUG
|
220
|
- std::cerr << "QgsComposerPicture::draw()" << std::endl;
|
221
|
+ std::cerr << "QgsComposerPicture::paint()" << std::endl;
|
222
|
#endif
|
223
|
|
224
|
- QRect box = mPicture.boundingRect();
|
225
|
+ QRectF box = mPicture.boundingRect();
|
226
|
double scale = 1. * mWidth / box.width();
|
227
|
|
228
|
- painter.save();
|
229
|
+ painter->save();
|
230
|
|
231
|
- painter.translate ( mX, mY );
|
232
|
- painter.scale ( scale, scale );
|
233
|
- painter.rotate ( -mAngle );
|
234
|
+ painter->scale ( scale, scale );
|
235
|
+ painter->rotate ( -mAngle );
|
236
|
|
237
|
- painter.drawPicture ( -box.x(), -box.y(), mPicture );
|
238
|
+ painter->drawPicture (QPointF(-box.width()/2, -box.height()/2), mPicture );
|
239
|
|
240
|
- painter.restore();
|
241
|
+ painter->restore();
|
242
|
|
243
|
if ( mFrame ) {
|
244
|
- // TODO: rect is not correct, +/- 1 pixle - Qt3?
|
245
|
- painter.setPen( QPen(QColor(0,0,0), 1) );
|
246
|
- painter.setBrush( QBrush( Qt::NoBrush ) );
|
247
|
+ // TODO: rect is not correct, +/- 1 pixel - Qt3?
|
248
|
+ painter->setPen( QPen(QColor(0,0,0), .3) );
|
249
|
+ painter->setBrush( QBrush( Qt::NoBrush ) );
|
250
|
|
251
|
- painter.save();
|
252
|
- painter.translate ( mX, mY );
|
253
|
- painter.rotate ( -mAngle );
|
254
|
+ painter->save();
|
255
|
+ painter->rotate ( -mAngle );
|
256
|
|
257
|
- painter.drawRect ( 0, 0, mWidth, mHeight );
|
258
|
- painter.restore();
|
259
|
+ painter->drawRect (QRectF(-mWidth/2, -mHeight/2, mWidth, mHeight));
|
260
|
+
|
261
|
+ painter->restore();
|
262
|
}
|
263
|
|
264
|
// Show selected / Highlight
|
265
|
if ( mSelected && plotStyle() == QgsComposition::Preview ) {
|
266
|
- painter.setPen( mComposition->selectionPen() );
|
267
|
- painter.setBrush( mComposition->selectionBrush() );
|
268
|
+ painter->setPen( mComposition->selectionPen() );
|
269
|
+ painter->setBrush( mComposition->selectionBrush() );
|
270
|
|
271
|
- int s = mComposition->selectionBoxSize();
|
272
|
+ double s = mComposition->selectionBoxSize();
|
273
|
|
274
|
- for ( int i = 0; i < 4; i++ )
|
275
|
- {
|
276
|
- painter.save();
|
277
|
- painter.translate ( mAreaPoints.point(i).x(), mAreaPoints.point(i).y() );
|
278
|
- painter.rotate ( -mAngle + i * 90 );
|
279
|
-
|
280
|
- painter.drawRect ( 0, 0, s, s );
|
281
|
- painter.restore();
|
282
|
- }
|
283
|
- }
|
284
|
-}
|
285
|
+ for ( int i = 0; i < 4; i++ )
|
286
|
+ {
|
287
|
+ painter->save();
|
288
|
+ painter->translate ( mAreaPoints[i].x(), mAreaPoints[i].y() );
|
289
|
+ painter->rotate ( -mAngle + i * 90 );
|
290
|
+ painter->drawRect(QRectF(0, 0, s, s));
|
291
|
+ painter->restore();
|
292
|
+ }
|
293
|
+ }//END of drawing selected highlight
|
294
|
|
295
|
-void QgsComposerPicture::drawShape( QPainter & painter )
|
296
|
-{
|
297
|
-#ifdef QGISDEBUG
|
298
|
- std::cout << "QgsComposerPicture::drawShape" << std::endl;
|
299
|
-#endif
|
300
|
- draw ( painter );
|
301
|
}
|
302
|
|
303
|
-void QgsComposerPicture::setBox ( int x1, int y1, int x2, int y2 )
|
304
|
+void QgsComposerPicture::setSize(double width, double height )
|
305
|
{
|
306
|
- int tmp;
|
307
|
-
|
308
|
- if ( x1 > x2 ) { tmp = x1; x1 = x2; x2 = tmp; }
|
309
|
- if ( y1 > y2 ) { tmp = y1; y1 = y2; y2 = tmp; }
|
310
|
-
|
311
|
- // Center
|
312
|
- mCX = (x1 + x2) / 2;
|
313
|
- mCY = (y1 + y2) / 2;
|
314
|
-
|
315
|
- QRect box = mPicture.boundingRect();
|
316
|
- std::cout << "box.width() = " << box.width() << " box.height() = " << box.height() << std::endl;
|
317
|
-
|
318
|
- mWidth = x2-x1;
|
319
|
- mHeight = y2-y1;
|
320
|
+ mWidth = width;
|
321
|
+ mHeight = height;
|
322
|
adjustPictureSize();
|
323
|
|
324
|
recalculate();
|
325
|
}
|
326
|
|
327
|
-void QgsComposerPicture::moveBy( double x, double y )
|
328
|
-{
|
329
|
-#ifdef QGISDEBUG
|
330
|
- std::cout << "QgsComposerPicture::moveBy()" << std::endl;
|
331
|
-#endif
|
332
|
-
|
333
|
- mCX += (int) x;
|
334
|
- mCY += (int) y;
|
335
|
- recalculate();
|
336
|
-}
|
337
|
-
|
338
|
void QgsComposerPicture::recalculate()
|
339
|
{
|
340
|
#ifdef QGISDEBUG
|
341
|
std::cout << "QgsComposerPicture::recalculate" << std::endl;
|
342
|
#endif
|
343
|
|
344
|
- Q3CanvasPolygonalItem::invalidate();
|
345
|
+ QAbstractGraphicsShapeItem::prepareGeometryChange();
|
346
|
|
347
|
- QRect box = mPicture.boundingRect();
|
348
|
+ QRect box = mPicture.boundingRect(); //size of the image, in pixels
|
349
|
|
350
|
- double angle = PI * mAngle / 180;
|
351
|
+ double angle = PI * mAngle / 180; //convert angle to radians
|
352
|
|
353
|
// Angle between vertical in picture space and the vector
|
354
|
// from center to upper left corner of the picture
|
355
|
@@ -311,27 +284,24 @@
|
356
|
int dx = (int) ( r * cos ( anglePaper ) );
|
357
|
int dy = (int) ( r * sin ( anglePaper ) );
|
358
|
|
359
|
- mX = mCX - dx;
|
360
|
- mY = mCY - dy;
|
361
|
-
|
362
|
- // Area points
|
363
|
- mAreaPoints[0] = QPoint( mCX-dx, mCY-dy );
|
364
|
- mAreaPoints[2] = QPoint( mCX+dx, mCY+dy );
|
365
|
|
366
|
- anglePaper = angle + PI / 2 - anglePicture;
|
367
|
+ mAreaPoints[0] = QPointF( -dx, -dy ); //add the top-left point to the polygon
|
368
|
+ mAreaPoints[2] = QPointF( dx, dy ); //bottom-right
|
369
|
+
|
370
|
+ anglePaper = PI / 2 - anglePicture + angle;
|
371
|
dx = (int) ( r * cos ( anglePaper ) );
|
372
|
dy = (int) ( r * sin ( anglePaper ) );
|
373
|
- mAreaPoints[1] = QPoint( mCX+dx, mCY-dy );
|
374
|
- mAreaPoints[3] = QPoint( mCX-dx, mCY+dy );
|
375
|
|
376
|
+ mAreaPoints[1] = QPointF( dx, -dy ); //top right
|
377
|
+ mAreaPoints[3] = QPointF( -dx, dy ); //bottom left
|
378
|
+
|
379
|
mBoundingRect = mAreaPoints.boundingRect();
|
380
|
-
|
381
|
- Q3CanvasPolygonalItem::canvas()->setChanged(mBoundingRect);
|
382
|
- Q3CanvasPolygonalItem::update();
|
383
|
- Q3CanvasPolygonalItem::canvas()->update();
|
384
|
+
|
385
|
+ QAbstractGraphicsShapeItem::update();
|
386
|
+ QAbstractGraphicsShapeItem::scene()->update();
|
387
|
}
|
388
|
|
389
|
-QRect QgsComposerPicture::boundingRect ( void ) const
|
390
|
+QRectF QgsComposerPicture::boundingRect ( void ) const
|
391
|
{
|
392
|
#ifdef QGISDEBUG
|
393
|
std::cout << "QgsComposerPicture::boundingRect" << std::endl;
|
394
|
@@ -339,7 +309,7 @@
|
395
|
return mBoundingRect;
|
396
|
}
|
397
|
|
398
|
-Q3PointArray QgsComposerPicture::areaPoints() const
|
399
|
+QPolygonF QgsComposerPicture::areaPoints() const
|
400
|
{
|
401
|
#ifdef QGISDEBUG
|
402
|
std::cout << "QgsComposerPicture::areaPoints" << std::endl;
|
403
|
@@ -351,10 +321,14 @@
|
404
|
|
405
|
void QgsComposerPicture::on_mFrameCheckBox_stateChanged ( int )
|
406
|
{
|
407
|
+#ifdef QGISDEBUG
|
408
|
+ std::cout << "QgsComposerPicture::on_mFrameCheckBox_stateChanged" << std::endl;
|
409
|
+#endif
|
410
|
+
|
411
|
mFrame = mFrameCheckBox->isChecked();
|
412
|
|
413
|
- Q3CanvasPolygonalItem::update();
|
414
|
- Q3CanvasPolygonalItem::canvas()->update();
|
415
|
+ QAbstractGraphicsShapeItem::update();
|
416
|
+ QAbstractGraphicsShapeItem::scene()->update();
|
417
|
|
418
|
writeSettings();
|
419
|
}
|
420
|
@@ -364,12 +338,12 @@
|
421
|
#ifdef QGISDEBUG
|
422
|
std::cout << "QgsComposerPicture::on_mAngleLineEdit_returnPressed()" << std::endl;
|
423
|
#endif
|
424
|
-
|
425
|
mAngle = mAngleLineEdit->text().toDouble();
|
426
|
|
427
|
recalculate();
|
428
|
|
429
|
writeSettings();
|
430
|
+
|
431
|
}
|
432
|
|
433
|
void QgsComposerPicture::on_mWidthLineEdit_returnPressed ( )
|
434
|
@@ -416,7 +390,7 @@
|
435
|
loadPicture();
|
436
|
|
437
|
if ( !mPictureValid ) {
|
438
|
- QMessageBox::warning( this, tr("Warning"),
|
439
|
+ QMessageBox::warning( 0, tr("Warning"),
|
440
|
tr("Cannot load picture.") );
|
441
|
}
|
442
|
else
|
443
|
@@ -447,19 +421,19 @@
|
444
|
|
445
|
if ( 1.*box.width()/box.height() > 1.*mWidth/mHeight )
|
446
|
{
|
447
|
- mHeight = mWidth*box.height()/box.width();
|
448
|
+ mHeight = mWidth*box.height()/box.width();
|
449
|
}
|
450
|
else
|
451
|
{
|
452
|
- mWidth = mHeight*box.width()/box.height();
|
453
|
+ mWidth = mHeight*box.width()/box.height();
|
454
|
}
|
455
|
}
|
456
|
|
457
|
void QgsComposerPicture::setOptions ( void )
|
458
|
{
|
459
|
mPictureLineEdit->setText ( mPicturePath );
|
460
|
- mWidthLineEdit->setText ( QString("%1").arg( mComposition->toMM(mWidth), 0,'g') );
|
461
|
- mHeightLineEdit->setText ( QString("%1").arg( mComposition->toMM(mHeight), 0,'g') );
|
462
|
+ mWidthLineEdit->setText ( QString("%1").arg( mComposition->toMM((int)mWidth), 0,'g') );
|
463
|
+ mHeightLineEdit->setText ( QString("%1").arg( mComposition->toMM((int)mHeight), 0,'g') );
|
464
|
mAngleLineEdit->setText ( QString::number ( mAngle ) );
|
465
|
mFrameCheckBox->setChecked ( mFrame );
|
466
|
}
|
467
|
@@ -467,7 +441,7 @@
|
468
|
void QgsComposerPicture::setSelected ( bool s )
|
469
|
{
|
470
|
mSelected = s;
|
471
|
- Q3CanvasPolygonalItem::update(); // show highlight
|
472
|
+ QAbstractGraphicsShapeItem::update(); // show highlight
|
473
|
}
|
474
|
|
475
|
bool QgsComposerPicture::selected( void )
|
476
|
@@ -524,10 +498,10 @@
|
477
|
|
478
|
QgsProject::instance()->writeEntry( "Compositions", path+"picture", mPicturePath );
|
479
|
|
480
|
- QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM(mCX) );
|
481
|
- QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM(mCY) );
|
482
|
- QgsProject::instance()->writeEntry( "Compositions", path+"width", mComposition->toMM(mWidth) );
|
483
|
- QgsProject::instance()->writeEntry( "Compositions", path+"height", mComposition->toMM(mHeight) );
|
484
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QGraphicsItem::pos().x()) );
|
485
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QGraphicsItem::pos().y()) );
|
486
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"width", mComposition->toMM((int)mWidth) );
|
487
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"height", mComposition->toMM((int)mHeight) );
|
488
|
|
489
|
QgsProject::instance()->writeEntry( "Compositions", path+"angle", mAngle );
|
490
|
|
491
|
@@ -544,8 +518,10 @@
|
492
|
|
493
|
mPicturePath = QgsProject::instance()->readEntry( "Compositions", path+"picture", "", &ok) ;
|
494
|
|
495
|
- mCX = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok));
|
496
|
- mCY = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok));
|
497
|
+ double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok));
|
498
|
+ double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok));
|
499
|
+ setPos(x, y);
|
500
|
+
|
501
|
mWidth = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"width", 0, &ok));
|
502
|
mHeight = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"height", 0, &ok));
|
503
|
|
504
|
@@ -576,4 +552,3 @@
|
505
|
{
|
506
|
return true;
|
507
|
}
|
508
|
-
|
509
|
Index: src/app/composer/qgscomposerscalebar.cpp
|
510
|
===================================================================
|
511
|
--- src/app/composer/qgscomposerscalebar.cpp (revision 7070)
|
512
|
+++ src/app/composer/qgscomposerscalebar.cpp (working copy)
|
513
|
@@ -13,524 +13,549 @@
|
514
|
* (at your option) any later version. *
|
515
|
* *
|
516
|
***************************************************************************/
|
517
|
+
|
518
|
#include "qgscomposerscalebar.h"
|
519
|
#include "qgscomposermap.h"
|
520
|
#include "qgsproject.h"
|
521
|
|
522
|
#include <QFontDialog>
|
523
|
#include <QPainter>
|
524
|
+#include <QGraphicsScene>
|
525
|
|
526
|
#include <cmath>
|
527
|
#include <iostream>
|
528
|
|
529
|
+//can we/should we remove the x and y parameters?
|
530
|
QgsComposerScalebar::QgsComposerScalebar ( QgsComposition *composition, int id,
|
531
|
int x, int y )
|
532
|
: QWidget(composition),
|
533
|
- Q3CanvasPolygonalItem(0),
|
534
|
+ QAbstractGraphicsShapeItem(0),
|
535
|
mComposition(composition),
|
536
|
mMap(0),
|
537
|
mBrush(QColor(150,150,150))
|
538
|
{
|
539
|
- setupUi(this);
|
540
|
+ setupUi(this);
|
541
|
|
542
|
- std::cout << "QgsComposerScalebar::QgsComposerScalebar()" << std::endl;
|
543
|
- mId = id;
|
544
|
- mSelected = false;
|
545
|
+ std::cout << "QgsComposerScalebar::QgsComposerScalebar()" << std::endl;
|
546
|
+ mId = id;
|
547
|
+ mSelected = false;
|
548
|
|
549
|
- mMapCanvas = mComposition->mapCanvas();
|
550
|
+ mMapCanvas = mComposition->mapCanvas();
|
551
|
|
552
|
- Q3CanvasPolygonalItem::setX(x);
|
553
|
- Q3CanvasPolygonalItem::setY(y);
|
554
|
+ QAbstractGraphicsShapeItem::setPos(x, y);
|
555
|
|
556
|
- init();
|
557
|
+ init();
|
558
|
|
559
|
- // Set map to the first available if any
|
560
|
- std::vector<QgsComposerMap*> maps = mComposition->maps();
|
561
|
- if ( maps.size() > 0 ) {
|
562
|
- mMap = maps[0]->id();
|
563
|
+ // Set map to the first available if any
|
564
|
+ std::vector < QgsComposerMap * >maps = mComposition->maps();
|
565
|
+ if (maps.size() > 0)
|
566
|
+ {
|
567
|
+ mMap = maps[0]->id();
|
568
|
}
|
569
|
+ // Set default according to the map
|
570
|
+ QgsComposerMap *map = mComposition->map(mMap);
|
571
|
+ if (map)
|
572
|
+ {
|
573
|
+ mMapUnitsPerUnit = 1.;
|
574
|
+ mUnitLabel = "m";
|
575
|
|
576
|
- // Set default according to the map
|
577
|
- QgsComposerMap *map = mComposition->map ( mMap );
|
578
|
- if ( map ) {
|
579
|
- mMapUnitsPerUnit = 1.;
|
580
|
- mUnitLabel = "m";
|
581
|
+ // make one segment cca 1/10 of map width and it will be 1xxx, 2xxx or 5xxx
|
582
|
+ double mapwidth = 1. * map->QGraphicsRectItem::rect().width() / map->scale();
|
583
|
|
584
|
- // make one segment cca 1/10 of map width and it will be 1xxx, 2xxx or 5xxx
|
585
|
- double mapwidth = 1. * map->Q3CanvasRectangle::width() / map->scale();
|
586
|
+ mSegmentLength = mapwidth / 10;
|
587
|
|
588
|
- mSegmentLength = mapwidth / 10;
|
589
|
-
|
590
|
- int powerOf10 = int(pow(10.0, int(log(mSegmentLength) / log(10.0)))); // from scalebar plugin
|
591
|
+ int powerOf10 = int (pow(10.0, int (log(mSegmentLength) / log(10.0)))); // from scalebar plugin
|
592
|
|
593
|
- int isize = (int) ceil ( mSegmentLength / powerOf10 );
|
594
|
+ int isize = (int) ceil(mSegmentLength / powerOf10);
|
595
|
|
596
|
- if ( isize == 3 ) isize = 2;
|
597
|
- else if ( isize == 4 ) isize = 5;
|
598
|
- else if ( isize > 5 && isize < 8 ) isize = 5;
|
599
|
- else if ( isize > 7 ) isize = 10;
|
600
|
-
|
601
|
- mSegmentLength = isize * powerOf10 ;
|
602
|
-
|
603
|
- // the scale bar will take cca 1/4 of the map width
|
604
|
- mNumSegments = (int) ( mapwidth / 4 / mSegmentLength );
|
605
|
-
|
606
|
- int segsize = (int) ( mSegmentLength * map->scale() );
|
607
|
- mFont.setPointSize ( (int) ( segsize/10) );
|
608
|
- }
|
609
|
- else
|
610
|
+ if (isize == 3)
|
611
|
+ isize = 2;
|
612
|
+ else if (isize == 4)
|
613
|
+ isize = 5;
|
614
|
+ else if (isize > 5 && isize < 8)
|
615
|
+ isize = 5;
|
616
|
+ else if (isize > 7)
|
617
|
+ isize = 10;
|
618
|
+
|
619
|
+ mSegmentLength = isize * powerOf10;
|
620
|
+
|
621
|
+ // the scale bar will take cca 1/4 of the map width
|
622
|
+ mNumSegments = (int) (mapwidth / 4 / mSegmentLength);
|
623
|
+
|
624
|
+ int segsize = (int) (mSegmentLength * map->scale());
|
625
|
+
|
626
|
+ int fontsize = segsize / 3;
|
627
|
+
|
628
|
+ if(fontsize < 6)
|
629
|
+ {
|
630
|
+ fontsize = 6;
|
631
|
+ }
|
632
|
+
|
633
|
+ mFont.setPointSize(fontsize);
|
634
|
+ } else
|
635
|
{
|
636
|
- mMapUnitsPerUnit = 1.;
|
637
|
- mUnitLabel = "m";
|
638
|
- mSegmentLength = 1000.;
|
639
|
- mNumSegments = 5;
|
640
|
- mFont.setPointSize ( 8 );
|
641
|
+ mFont.setPointSize(6);
|
642
|
+ mMapUnitsPerUnit = 1.;
|
643
|
+ mUnitLabel = "m";
|
644
|
+ mSegmentLength = 1000.;
|
645
|
+ mNumSegments = 5;
|
646
|
}
|
647
|
-
|
648
|
- // Calc size
|
649
|
- recalculate();
|
650
|
|
651
|
- // Add to canvas
|
652
|
- setCanvas(mComposition->canvas());
|
653
|
+ // Calc size
|
654
|
+ recalculate();
|
655
|
|
656
|
- Q3CanvasPolygonalItem::show();
|
657
|
- Q3CanvasPolygonalItem::update();
|
658
|
-
|
659
|
- writeSettings();
|
660
|
+ // Add to scene
|
661
|
+ mComposition->canvas()->addItem(this);
|
662
|
+
|
663
|
+ QAbstractGraphicsShapeItem::show();
|
664
|
+ QAbstractGraphicsShapeItem::update();
|
665
|
+
|
666
|
+ writeSettings();
|
667
|
}
|
668
|
|
669
|
QgsComposerScalebar::QgsComposerScalebar ( QgsComposition *composition, int id )
|
670
|
- : Q3CanvasPolygonalItem(0),
|
671
|
+ : QAbstractGraphicsShapeItem(0),
|
672
|
mComposition(composition),
|
673
|
mMap(0),
|
674
|
mBrush(QColor(150,150,150))
|
675
|
{
|
676
|
- std::cout << "QgsComposerScalebar::QgsComposerScalebar()" << std::endl;
|
677
|
+ std::cout << "QgsComposerScalebar::QgsComposerScalebar()" << std::endl;
|
678
|
|
679
|
- setupUi(this);
|
680
|
+ setupUi(this);
|
681
|
|
682
|
- mId = id;
|
683
|
- mSelected = false;
|
684
|
+ mId = id;
|
685
|
+ mSelected = false;
|
686
|
|
687
|
- mMapCanvas = mComposition->mapCanvas();
|
688
|
+ mMapCanvas = mComposition->mapCanvas();
|
689
|
|
690
|
- init();
|
691
|
+ init();
|
692
|
|
693
|
- readSettings();
|
694
|
+ readSettings();
|
695
|
|
696
|
- // Calc size
|
697
|
- recalculate();
|
698
|
+ // Calc size
|
699
|
+ recalculate();
|
700
|
|
701
|
- // Add to canvas
|
702
|
- setCanvas(mComposition->canvas());
|
703
|
+ // Add to scene
|
704
|
+ mComposition->canvas()->addItem(this);
|
705
|
|
706
|
- Q3CanvasPolygonalItem::show();
|
707
|
- Q3CanvasPolygonalItem::update();
|
708
|
+ QAbstractGraphicsShapeItem::show();
|
709
|
+ QAbstractGraphicsShapeItem::update();
|
710
|
}
|
711
|
|
712
|
-void QgsComposerScalebar::init ( void )
|
713
|
+void QgsComposerScalebar::init(void)
|
714
|
{
|
715
|
- mUnitLabel = "m";
|
716
|
+ mUnitLabel = "m";
|
717
|
|
718
|
- // Rectangle
|
719
|
- Q3CanvasPolygonalItem::setZ(50);
|
720
|
- setActive(true);
|
721
|
+ // Rectangle
|
722
|
+ QAbstractGraphicsShapeItem::setZValue(50);
|
723
|
+// setActive(true);
|
724
|
|
725
|
- // Default value (map units?) for the scalebar border
|
726
|
- mPen.setWidthF(3.0);
|
727
|
+ // Default value (map units?) for the scalebar border
|
728
|
+ mPen.setWidthF(.5);
|
729
|
|
730
|
- // Plot style
|
731
|
- setPlotStyle ( QgsComposition::Preview );
|
732
|
-
|
733
|
- connect ( mComposition, SIGNAL(mapChanged(int)), this, SLOT(mapChanged(int)) );
|
734
|
+ // Plot style
|
735
|
+ setPlotStyle(QgsComposition::Preview);
|
736
|
+
|
737
|
+ connect(mComposition, SIGNAL(mapChanged(int)), this, SLOT(mapChanged(int)));
|
738
|
}
|
739
|
|
740
|
QgsComposerScalebar::~QgsComposerScalebar()
|
741
|
{
|
742
|
- std::cerr << "QgsComposerScalebar::~QgsComposerScalebar()" << std::endl;
|
743
|
- Q3CanvasItem::hide();
|
744
|
+ std::cerr << "QgsComposerScalebar::~QgsComposerScalebar()" << std::endl;
|
745
|
+ QGraphicsItem::hide();
|
746
|
}
|
747
|
|
748
|
-QRect QgsComposerScalebar::render ( QPainter *p )
|
749
|
+QRectF QgsComposerScalebar::render(QPainter * p)
|
750
|
{
|
751
|
- std::cout << "QgsComposerScalebar::render p = " << p << std::endl;
|
752
|
+ std::cout << "QgsComposerScalebar::render p = " << p << std::endl;
|
753
|
|
754
|
- // Painter can be 0, create dummy to avoid many if below
|
755
|
- QPainter *painter = NULL;
|
756
|
- QPixmap *pixmap = NULL;
|
757
|
- if ( p ) {
|
758
|
- painter = p;
|
759
|
- } else {
|
760
|
- pixmap = new QPixmap(1,1);
|
761
|
- painter = new QPainter( pixmap );
|
762
|
- }
|
763
|
+ // Painter can be 0, create dummy to avoid many if below
|
764
|
+ QPainter *painter;
|
765
|
+ QPixmap *pixmap;
|
766
|
+ if (p)
|
767
|
+ {
|
768
|
+ painter = p;
|
769
|
+ }else
|
770
|
+ {
|
771
|
+ pixmap = new QPixmap(1, 1);
|
772
|
+ painter = new QPainter(pixmap);
|
773
|
+ }
|
774
|
|
775
|
- std::cout << "mComposition->scale() = " << mComposition->scale() << std::endl;
|
776
|
+ std::cout << "mComposition->scale() = " << mComposition->scale() << std::endl;
|
777
|
|
778
|
- // Draw background rectangle
|
779
|
- painter->setPen( QPen(QColor(255,255,255), 1) );
|
780
|
- painter->setBrush( QBrush( QColor(255,255,255), Qt::SolidPattern) );
|
781
|
+ QgsComposerMap *map = mComposition->map(mMap); //Get the topmost map from the composition
|
782
|
|
783
|
- painter->drawRect ( mBoundingRect.x(), mBoundingRect.y(),
|
784
|
- mBoundingRect.width()+1, mBoundingRect.height()+1 ); // is it right?
|
785
|
-
|
786
|
+ double segwidth;
|
787
|
+ if(map)
|
788
|
+ {
|
789
|
+ segwidth = (mSegmentLength * map->scale()); //width of one segment
|
790
|
+ }
|
791
|
+ else //if there is no map, make up a segment width
|
792
|
+ {
|
793
|
+ segwidth = mSegmentLength/100;
|
794
|
+ }
|
795
|
+ double width = (segwidth * mNumSegments); //width of whole scalebar
|
796
|
+ double barLx = -width / 2; //x offset to the left
|
797
|
|
798
|
- // Font size in canvas units
|
799
|
- float size = 25.4 * mComposition->scale() * mFont.pointSizeFloat() / 72;
|
800
|
+ double barHeight = (25.4 * mComposition->scale() * mFont.pointSize() / 72);
|
801
|
|
802
|
- // Metrics
|
803
|
- QFont font ( mFont );
|
804
|
- font.setPointSizeFloat ( size );
|
805
|
- QFontMetrics metrics ( font );
|
806
|
-
|
807
|
- if ( plotStyle() == QgsComposition::Postscript )
|
808
|
- {
|
809
|
- font.setPointSizeF ( metrics.ascent() * 72.0 / mComposition->resolution() );
|
810
|
- }
|
811
|
+ double tickSize = barHeight * 1.5; //ticks go from the base of the bar to 1/2 the bar's height above it
|
812
|
|
813
|
- // Not sure about Style Strategy, QFont::PreferMatch?
|
814
|
- font.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
|
815
|
+ // Draw background rectangle
|
816
|
+ painter->setPen(QPen(QColor(255, 255, 255), 0));
|
817
|
+ painter->setBrush(QBrush(QColor(255, 255, 255), Qt::SolidPattern));
|
818
|
+ painter->drawRect(QRectF(barLx, -barHeight, width, barHeight));
|
819
|
|
820
|
- int xmin = 0; // min x
|
821
|
- int xmax = 0; // max x
|
822
|
- int ymin; // min y
|
823
|
- int ymax; // max y
|
824
|
+ // set the painter to have grey background and black border
|
825
|
+ painter->setPen(QPen(QColor(0, 0, 0), mPen.widthF()));
|
826
|
+ painter->setBrush(QBrush(QColor(127, 127, 127)));//default to solid brush
|
827
|
|
828
|
- int cx = (int) Q3CanvasPolygonalItem::x();
|
829
|
- int cy = (int) Q3CanvasPolygonalItem::y();
|
830
|
+ // fill every other segment with grey
|
831
|
+ for (int i = 0; i < mNumSegments; i += 2)
|
832
|
+ {
|
833
|
+ painter->drawRect(QRectF(barLx + ((double)i * segwidth), -barHeight, segwidth, barHeight));
|
834
|
+ }
|
835
|
|
836
|
- painter->setPen ( mPen );
|
837
|
- painter->setBrush ( mBrush );
|
838
|
- painter->setFont ( font );
|
839
|
+ // draw a box around the all of the segments
|
840
|
+ painter->setBrush(Qt::NoBrush);
|
841
|
+ painter->drawRect(QRectF(barLx, -barHeight, width, barHeight));
|
842
|
|
843
|
- QgsComposerMap *map = mComposition->map ( mMap );
|
844
|
- if ( map ) {
|
845
|
- // width of the whole scalebar in canvas points
|
846
|
- int segwidth = (int) ( mSegmentLength * map->scale() );
|
847
|
- int width = (int) ( segwidth * mNumSegments );
|
848
|
-
|
849
|
- int barLx = (int) ( cx - width/2 );
|
850
|
+ // set up the pen to draw the tick marks
|
851
|
+ painter->setPen(QPen(QColor(0, 0, 0), mPen.widthF()));
|
852
|
|
853
|
- int rectadd = 0;
|
854
|
- if ( plotStyle() == QgsComposition::Preview ) {
|
855
|
- rectadd = 1; // add 1 pixel in preview, must not be in PS
|
856
|
- }
|
857
|
+ // draw the tick marks
|
858
|
+ for (int i = 0; i <= mNumSegments; i++)
|
859
|
+ {
|
860
|
+ painter->drawLine(QLineF(barLx + ((double)i * segwidth), 0, barLx + (i * segwidth), -tickSize));
|
861
|
+ }
|
862
|
|
863
|
- // fill odd
|
864
|
- for ( int i = 0; i < mNumSegments; i += 2 ) {
|
865
|
- painter->drawRect( barLx+i*segwidth, cy, segwidth+rectadd, mHeight );
|
866
|
- }
|
867
|
|
868
|
- // ticks
|
869
|
- int ticksize = (int ) (3./4*mHeight);
|
870
|
- for ( int i = 0; i <= mNumSegments; i++ ) {
|
871
|
- painter->drawLine( barLx+i*segwidth, cy, barLx+i*segwidth, cy-ticksize );
|
872
|
- }
|
873
|
+ // labels
|
874
|
|
875
|
- painter->setBrush( Qt::NoBrush );
|
876
|
+ // Font size in canvas units
|
877
|
+ float size = 25.4 * mComposition->scale() * mFont.pointSizeFloat() / 72;
|
878
|
|
879
|
- painter->drawRect( barLx, cy, width+rectadd, mHeight );
|
880
|
-
|
881
|
- // labels
|
882
|
- int h = metrics.height();
|
883
|
- int offset = (int ) (1./2*ticksize);
|
884
|
- for ( int i = 0; i <= mNumSegments; i++ ) {
|
885
|
- int lab = (int) (1. * i * mSegmentLength / mMapUnitsPerUnit);
|
886
|
- QString txt = QString::number(lab);
|
887
|
- int w = metrics.width ( txt );
|
888
|
- int shift = (int) w/2;
|
889
|
-
|
890
|
- if ( i == 0 ) {
|
891
|
- xmin = (int) barLx - w/2;
|
892
|
- }
|
893
|
|
894
|
- if ( i == mNumSegments ) {
|
895
|
- txt.append ( " " + mUnitLabel );
|
896
|
- w = metrics.width ( txt );
|
897
|
+ // Create QFontMetrics so we can correctly place the text
|
898
|
+ QFont font(mFont);
|
899
|
+ font.setPointSizeFloat(size);
|
900
|
+ QFontMetrics metrics(font);
|
901
|
|
902
|
- xmax = (int) barLx + width - shift + w;
|
903
|
- }
|
904
|
-
|
905
|
- int x = barLx+i*segwidth-shift;
|
906
|
- int y = cy-ticksize-offset-metrics.descent();
|
907
|
+ if (plotStyle() == QgsComposition::Postscript)
|
908
|
+ {
|
909
|
+ font.setPointSizeF(metrics.ascent() * 72.0 / mComposition->resolution());
|
910
|
+std::cout << "scalebar using PS font size!" << std::endl;
|
911
|
+ }
|
912
|
|
913
|
- painter->drawText( x, y, txt );
|
914
|
- }
|
915
|
-
|
916
|
- ymin = cy - ticksize - offset - h;
|
917
|
- ymax = cy + mHeight;
|
918
|
- }
|
919
|
- else
|
920
|
- {
|
921
|
- int width = 50 * mComposition->scale();
|
922
|
+ painter->setFont(font);
|
923
|
|
924
|
- int barLx = (int) ( cx - width/2 );
|
925
|
- painter->drawRect( (int)barLx, (int)(cy-mHeight/2), width, mHeight );
|
926
|
+ // Not sure about Style Strategy, QFont::PreferMatch?
|
927
|
+ font.setStyleStrategy((QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias));
|
928
|
|
929
|
- xmin = barLx;
|
930
|
- xmax = barLx + width;
|
931
|
- ymin = cy - mHeight;
|
932
|
- ymax = cy + mHeight;
|
933
|
+ double offset = .5 * tickSize; //vertical offset above the top of the tick marks
|
934
|
+ double textRightOverhang;//amount the label text hangs over the right edge of the scalebar - used for the bounding box
|
935
|
+
|
936
|
+ for (int i = 0; i <= mNumSegments; i++)
|
937
|
+ {
|
938
|
+ int lab = (int) ((double)i * mSegmentLength / mMapUnitsPerUnit);
|
939
|
+
|
940
|
+ QString txt = QString::number(lab);
|
941
|
+ double shift = (double)metrics.width(txt) / 2;
|
942
|
+
|
943
|
+ if (i == mNumSegments) //on the last label, append the appropriate unit symbol
|
944
|
+ {
|
945
|
+ txt.append(" " + mUnitLabel);
|
946
|
+ textRightOverhang = (double)metrics.width(txt) - shift;
|
947
|
}
|
948
|
|
949
|
- if ( !p ) {
|
950
|
- delete painter;
|
951
|
- delete pixmap;
|
952
|
+ double x = barLx + (i * segwidth) - shift; //figure out the bottom left corner and draw the text
|
953
|
+ double y = -tickSize - offset - metrics.descent();
|
954
|
+ painter->drawText(QPointF(x, y), txt);
|
955
|
+
|
956
|
+ }//end of label drawing
|
957
|
+
|
958
|
+ double totalHeight = tickSize + offset + metrics.height();
|
959
|
+
|
960
|
+ if (!p)
|
961
|
+ {
|
962
|
+ delete painter;
|
963
|
+ delete pixmap;
|
964
|
}
|
965
|
|
966
|
- return QRect ( xmin-mMargin, ymin-mMargin, xmax-xmin+2*mMargin, ymax-ymin+2*mMargin);
|
967
|
+//Add the 1/2 the pen width to get the full bounding box
|
968
|
+return QRectF(barLx - (mPen.widthF()/2), -totalHeight, width + textRightOverhang, totalHeight + (mPen.widthF()/2));
|
969
|
}
|
970
|
|
971
|
-void QgsComposerScalebar::draw ( QPainter & painter )
|
972
|
+void QgsComposerScalebar::paint(QPainter * painter, const QStyleOptionGraphicsItem * itemStyle, QWidget * pWidget)
|
973
|
{
|
974
|
- std::cout << "draw mPlotStyle = " << plotStyle() << std::endl;
|
975
|
+ std::cout << "draw mPlotStyle = " << plotStyle() << std::endl;
|
976
|
|
977
|
- render( &painter );
|
978
|
+ mBoundingRect = render(painter);
|
979
|
|
980
|
- // Show selected / Highlight
|
981
|
- if ( mSelected && plotStyle() == QgsComposition::Preview ) {
|
982
|
- painter.setPen( mComposition->selectionPen() );
|
983
|
- painter.setBrush( mComposition->selectionBrush() );
|
984
|
-
|
985
|
- int s = mComposition->selectionBoxSize();
|
986
|
- QRect r = boundingRect();
|
987
|
+ // Show selected / Highlight
|
988
|
+ if (mSelected && plotStyle() == QgsComposition::Preview)
|
989
|
+ {
|
990
|
+ painter->setPen(mComposition->selectionPen());
|
991
|
+ painter->setBrush(mComposition->selectionBrush());
|
992
|
|
993
|
- painter.drawRect ( r.x(), r.y(), s, s );
|
994
|
- painter.drawRect ( r.x()+r.width()-s, r.y(), s, s );
|
995
|
- painter.drawRect ( r.x()+r.width()-s, r.y()+r.height()-s, s, s );
|
996
|
- painter.drawRect ( r.x(), r.y()+r.height()-s, s, s );
|
997
|
+ double s = mComposition->selectionBoxSize();
|
998
|
+ QRectF r = boundingRect();
|
999
|
+
|
1000
|
+ painter->drawRect(QRectF(r.x(), r.y(), s, s));
|
1001
|
+ painter->drawRect(QRectF(r.x() + r.width() - s, r.y(), s, s));
|
1002
|
+ painter->drawRect(QRectF(r.x() + r.width() - s, r.y() + r.height() - s, s, s));
|
1003
|
+ painter->drawRect(QRectF(r.x(), r.y() + r.height() - s, s, s));
|
1004
|
}
|
1005
|
}
|
1006
|
|
1007
|
+/*
|
1008
|
void QgsComposerScalebar::drawShape ( QPainter & painter )
|
1009
|
{
|
1010
|
- draw ( painter );
|
1011
|
+ paint ( painter );
|
1012
|
}
|
1013
|
-
|
1014
|
-void QgsComposerScalebar::on_mFontButton_clicked ( void )
|
1015
|
+*/
|
1016
|
+void QgsComposerScalebar::on_mFontButton_clicked(void)
|
1017
|
{
|
1018
|
- bool result;
|
1019
|
-
|
1020
|
- mFont = QFontDialog::getFont(&result, mFont, this );
|
1021
|
+ bool result;
|
1022
|
|
1023
|
- if ( result ) {
|
1024
|
- recalculate();
|
1025
|
- Q3CanvasPolygonalItem::update();
|
1026
|
- Q3CanvasPolygonalItem::canvas()->update();
|
1027
|
- writeSettings();
|
1028
|
+ mFont = QFontDialog::getFont(&result, mFont, this);
|
1029
|
+
|
1030
|
+ if (result)
|
1031
|
+ {
|
1032
|
+ recalculate();
|
1033
|
+ QAbstractGraphicsShapeItem::update();
|
1034
|
+ QAbstractGraphicsShapeItem::scene()->update();
|
1035
|
+ writeSettings();
|
1036
|
}
|
1037
|
}
|
1038
|
|
1039
|
-void QgsComposerScalebar::on_mUnitLabelLineEdit_returnPressed ( )
|
1040
|
+void QgsComposerScalebar::on_mUnitLabelLineEdit_returnPressed()
|
1041
|
{
|
1042
|
- mUnitLabel = mUnitLabelLineEdit->text();
|
1043
|
- recalculate();
|
1044
|
- Q3CanvasPolygonalItem::update();
|
1045
|
- Q3CanvasPolygonalItem::canvas()->update();
|
1046
|
- writeSettings();
|
1047
|
+ mUnitLabel = mUnitLabelLineEdit->text();
|
1048
|
+ recalculate();
|
1049
|
+ QAbstractGraphicsShapeItem::update();
|
1050
|
+ QAbstractGraphicsShapeItem::scene()->update();
|
1051
|
+ writeSettings();
|
1052
|
}
|
1053
|
|
1054
|
-void QgsComposerScalebar::on_mMapComboBox_activated ( int i )
|
1055
|
+void QgsComposerScalebar::on_mMapComboBox_activated(int i)
|
1056
|
{
|
1057
|
- mMap = mMaps[i];
|
1058
|
- recalculate();
|
1059
|
- Q3CanvasPolygonalItem::update();
|
1060
|
- Q3CanvasPolygonalItem::canvas()->update();
|
1061
|
- writeSettings();
|
1062
|
+ mMap = mMaps[i];
|
1063
|
+ recalculate();
|
1064
|
+ QAbstractGraphicsShapeItem::update();
|
1065
|
+ QAbstractGraphicsShapeItem::scene()->update();
|
1066
|
+ writeSettings();
|
1067
|
}
|
1068
|
|
1069
|
-void QgsComposerScalebar::mapChanged ( int id )
|
1070
|
+void QgsComposerScalebar::mapChanged(int id)
|
1071
|
{
|
1072
|
- if ( id != mMap ) return;
|
1073
|
- recalculate();
|
1074
|
- Q3CanvasPolygonalItem::update();
|
1075
|
- Q3CanvasPolygonalItem::canvas()->update();
|
1076
|
+ if (id != mMap)
|
1077
|
+ return;
|
1078
|
+ recalculate();
|
1079
|
+ QAbstractGraphicsShapeItem::update();
|
1080
|
+ QAbstractGraphicsShapeItem::scene()->update();
|
1081
|
}
|
1082
|
|
1083
|
-void QgsComposerScalebar::sizeChanged ( )
|
1084
|
+void QgsComposerScalebar::sizeChanged()
|
1085
|
{
|
1086
|
- mSegmentLength = mSegmentLengthLineEdit->text().toDouble();
|
1087
|
- mNumSegments = mNumSegmentsLineEdit->text().toInt();
|
1088
|
- mPen.setWidthF ( mLineWidthSpinBox->value() );
|
1089
|
- mMapUnitsPerUnit = mMapUnitsPerUnitLineEdit->text().toInt();
|
1090
|
- recalculate();
|
1091
|
- Q3CanvasPolygonalItem::update();
|
1092
|
- Q3CanvasPolygonalItem::canvas()->update();
|
1093
|
- writeSettings();
|
1094
|
+ mSegmentLength = mSegmentLengthLineEdit->text().toDouble();
|
1095
|
+ mNumSegments = mNumSegmentsLineEdit->text().toInt();
|
1096
|
+ mPen.setWidthF(mLineWidthSpinBox->value());
|
1097
|
+ mMapUnitsPerUnit = mMapUnitsPerUnitLineEdit->text().toInt();
|
1098
|
+ recalculate();
|
1099
|
+ QAbstractGraphicsShapeItem::update();
|
1100
|
+ QAbstractGraphicsShapeItem::scene()->update();
|
1101
|
+ writeSettings();
|
1102
|
}
|
1103
|
|
1104
|
-void QgsComposerScalebar::on_mLineWidthSpinBox_valueChanged() { sizeChanged(); }
|
1105
|
-void QgsComposerScalebar::on_mMapUnitsPerUnitLineEdit_returnPressed() { sizeChanged(); }
|
1106
|
-void QgsComposerScalebar::on_mNumSegmentsLineEdit_returnPressed() { sizeChanged(); }
|
1107
|
-void QgsComposerScalebar::on_mSegmentLengthLineEdit_returnPressed() { sizeChanged(); }
|
1108
|
+void QgsComposerScalebar::on_mLineWidthSpinBox_valueChanged()
|
1109
|
+{
|
1110
|
+ sizeChanged();
|
1111
|
+}
|
1112
|
|
1113
|
-void QgsComposerScalebar::moveBy(double x, double y )
|
1114
|
+void QgsComposerScalebar::on_mMapUnitsPerUnitLineEdit_returnPressed()
|
1115
|
{
|
1116
|
- std::cout << "QgsComposerScalebar::move" << std::endl;
|
1117
|
- Q3CanvasItem::moveBy ( x, y );
|
1118
|
+ sizeChanged();
|
1119
|
+}
|
1120
|
|
1121
|
- recalculate();
|
1122
|
- //writeSettings(); // not necessary called by composition
|
1123
|
+void QgsComposerScalebar::on_mNumSegmentsLineEdit_returnPressed()
|
1124
|
+{
|
1125
|
+ sizeChanged();
|
1126
|
}
|
1127
|
|
1128
|
-void QgsComposerScalebar::recalculate ( void )
|
1129
|
+void QgsComposerScalebar::on_mSegmentLengthLineEdit_returnPressed()
|
1130
|
{
|
1131
|
- std::cout << "QgsComposerScalebar::recalculate" << std::endl;
|
1132
|
-
|
1133
|
- mHeight = (int) ( 25.4 * mComposition->scale() * mFont.pointSize() / 72);
|
1134
|
- mMargin = (int) (3.*mHeight/2);
|
1135
|
-
|
1136
|
- // !!! invalidate() MUST BE called before the value returned by areaPoints() changes
|
1137
|
- Q3CanvasPolygonalItem::invalidate();
|
1138
|
-
|
1139
|
- mBoundingRect = render(0);
|
1140
|
-
|
1141
|
- Q3CanvasItem::update();
|
1142
|
+ sizeChanged();
|
1143
|
}
|
1144
|
+/*
|
1145
|
+void QgsComposerScalebar::moveBy(double x, double y)
|
1146
|
+{
|
1147
|
+ std::cout << "QgsComposerScalebar::move" << std::endl;
|
1148
|
+ QGraphicsItem::moveBy(x, y);
|
1149
|
|
1150
|
-QRect QgsComposerScalebar::boundingRect ( void ) const
|
1151
|
+ recalculate();
|
1152
|
+ //writeSettings(); // not necessary called by composition
|
1153
|
+}*/
|
1154
|
+
|
1155
|
+void QgsComposerScalebar::recalculate(void)
|
1156
|
{
|
1157
|
- std::cout << "QgsComposerScalebar::boundingRect" << std::endl;
|
1158
|
- return mBoundingRect;
|
1159
|
+ std::cout << "QgsComposerScalebar::recalculate" << std::endl;
|
1160
|
+
|
1161
|
+ // !!! prepareGeometryChange() MUST BE called before the value returned by areaPoints() changes
|
1162
|
+ //Is this still true after the port to GraphicsView?
|
1163
|
+ QAbstractGraphicsShapeItem::prepareGeometryChange();
|
1164
|
+
|
1165
|
+ mBoundingRect = render(0);
|
1166
|
+
|
1167
|
+ QGraphicsItem::update();
|
1168
|
}
|
1169
|
|
1170
|
-Q3PointArray QgsComposerScalebar::areaPoints() const
|
1171
|
+QRectF QgsComposerScalebar::boundingRect(void) const
|
1172
|
{
|
1173
|
- std::cout << "QgsComposerScalebar::areaPoints" << std::endl;
|
1174
|
+ std::cout << "QgsComposerScalebar::boundingRect" << std::endl;
|
1175
|
+ return mBoundingRect;
|
1176
|
+}
|
1177
|
|
1178
|
- QRect r = boundingRect();
|
1179
|
- Q3PointArray pa(4);
|
1180
|
- pa[0] = QPoint( r.x(), r.y() );
|
1181
|
- pa[1] = QPoint( r.x()+r.width(), r.y() );
|
1182
|
- pa[2] = QPoint( r.x()+r.width(), r.y()+r.height() );
|
1183
|
- pa[3] = QPoint( r.x(), r.y()+r.height() );
|
1184
|
- return pa ;
|
1185
|
+QPolygonF QgsComposerScalebar::areaPoints(void) const
|
1186
|
+{
|
1187
|
+ std::cout << "QgsComposerScalebar::areaPoints" << std::endl;
|
1188
|
+
|
1189
|
+ QRectF r = boundingRect();
|
1190
|
+ QPolygonF pa;
|
1191
|
+ pa << QPointF(r.x(), r.y());
|
1192
|
+ pa << QPointF(r.x() + r.width(), r.y());
|
1193
|
+ pa << QPointF(r.x() + r.width(), r.y() + r.height());
|
1194
|
+ pa << QPointF(r.x(), r.y() + r.height());
|
1195
|
+ return pa;
|
1196
|
}
|
1197
|
|
1198
|
-void QgsComposerScalebar::setOptions ( void )
|
1199
|
-{
|
1200
|
- mSegmentLengthLineEdit->setText( QString::number(mSegmentLength) );
|
1201
|
- mNumSegmentsLineEdit->setText( QString::number( mNumSegments ) );
|
1202
|
- mUnitLabelLineEdit->setText( mUnitLabel );
|
1203
|
- mMapUnitsPerUnitLineEdit->setText( QString::number(mMapUnitsPerUnit ) );
|
1204
|
+void QgsComposerScalebar::setOptions(void)
|
1205
|
+{
|
1206
|
+ mSegmentLengthLineEdit->setText(QString::number(mSegmentLength));
|
1207
|
+ mNumSegmentsLineEdit->setText(QString::number(mNumSegments));
|
1208
|
+ mUnitLabelLineEdit->setText(mUnitLabel);
|
1209
|
+ mMapUnitsPerUnitLineEdit->setText(QString::number(mMapUnitsPerUnit));
|
1210
|
|
1211
|
- mLineWidthSpinBox->setValue ( mPen.widthF() );
|
1212
|
-
|
1213
|
- // Maps
|
1214
|
- mMapComboBox->clear();
|
1215
|
- std::vector<QgsComposerMap*> maps = mComposition->maps();
|
1216
|
+ mLineWidthSpinBox->setValue(mPen.widthF());
|
1217
|
|
1218
|
- mMaps.clear();
|
1219
|
-
|
1220
|
- bool found = false;
|
1221
|
- mMapComboBox->insertItem ( "", 0 );
|
1222
|
- mMaps.push_back ( 0 );
|
1223
|
- for ( uint i = 0; i < maps.size(); i++ ) {
|
1224
|
- mMapComboBox->insertItem ( maps[i]->name(), i+1 );
|
1225
|
- mMaps.push_back ( maps[i]->id() );
|
1226
|
+ // Maps
|
1227
|
+ mMapComboBox->clear();
|
1228
|
+ std::vector < QgsComposerMap * >maps = mComposition->maps();
|
1229
|
|
1230
|
- if ( maps[i]->id() == mMap ) {
|
1231
|
- found = true;
|
1232
|
- mMapComboBox->setCurrentItem ( i+1 );
|
1233
|
- }
|
1234
|
+ mMaps.clear();
|
1235
|
+
|
1236
|
+ bool found = false;
|
1237
|
+ mMapComboBox->insertItem("", 0);
|
1238
|
+ mMaps.push_back(0);
|
1239
|
+ for (int i = 0; i < (int)maps.size(); i++)
|
1240
|
+ {
|
1241
|
+ mMapComboBox->insertItem(maps[i]->name(), i + 1);
|
1242
|
+ mMaps.push_back(maps[i]->id());
|
1243
|
+
|
1244
|
+ if (maps[i]->id() == mMap)
|
1245
|
+ {
|
1246
|
+ found = true;
|
1247
|
+ mMapComboBox->setCurrentItem(i + 1);
|
1248
|
+ }
|
1249
|
}
|
1250
|
|
1251
|
- if ( ! found ) {
|
1252
|
- mMap = 0;
|
1253
|
- mMapComboBox->setCurrentItem ( 0 );
|
1254
|
+ if (!found)
|
1255
|
+ {
|
1256
|
+ mMap = 0;
|
1257
|
+ mMapComboBox->setCurrentItem(0);
|
1258
|
}
|
1259
|
}
|
1260
|
|
1261
|
-void QgsComposerScalebar::setSelected ( bool s )
|
1262
|
+void QgsComposerScalebar::setSelected(bool s)
|
1263
|
{
|
1264
|
- mSelected = s;
|
1265
|
- Q3CanvasPolygonalItem::update(); // show highlight
|
1266
|
-}
|
1267
|
+ mSelected = s;
|
1268
|
+ QAbstractGraphicsShapeItem::update(); // show highlight
|
1269
|
+}
|
1270
|
|
1271
|
-bool QgsComposerScalebar::selected( void )
|
1272
|
+bool QgsComposerScalebar::selected(void)
|
1273
|
{
|
1274
|
- return mSelected;
|
1275
|
+ return mSelected;
|
1276
|
}
|
1277
|
|
1278
|
-QWidget *QgsComposerScalebar::options ( void )
|
1279
|
+QWidget *QgsComposerScalebar::options(void)
|
1280
|
{
|
1281
|
- setOptions ();
|
1282
|
- return ( dynamic_cast <QWidget *> (this) );
|
1283
|
+ setOptions();
|
1284
|
+ return (dynamic_cast < QWidget * >(this));
|
1285
|
}
|
1286
|
|
1287
|
-bool QgsComposerScalebar::writeSettings ( void )
|
1288
|
+bool QgsComposerScalebar::writeSettings(void)
|
1289
|
{
|
1290
|
- std::cout << "QgsComposerScalebar::writeSettings" << std::endl;
|
1291
|
- QString path;
|
1292
|
- path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId );
|
1293
|
+ std::cout << "QgsComposerScalebar::writeSettings" << std::endl;
|
1294
|
+ QString path;
|
1295
|
+ path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId);
|
1296
|
|
1297
|
- QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)Q3CanvasPolygonalItem::x()) );
|
1298
|
- QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)Q3CanvasPolygonalItem::y()) );
|
1299
|
+ QgsProject::instance()->writeEntry("Compositions", path + "x", mComposition->toMM((int) QAbstractGraphicsShapeItem::x()));
|
1300
|
+ QgsProject::instance()->writeEntry("Compositions", path + "y", mComposition->toMM((int) QAbstractGraphicsShapeItem::y()));
|
1301
|
|
1302
|
- QgsProject::instance()->writeEntry( "Compositions", path+"map", mMap );
|
1303
|
+ QgsProject::instance()->writeEntry("Compositions", path + "map", mMap);
|
1304
|
|
1305
|
- QgsProject::instance()->writeEntry( "Compositions", path+"unit/label", mUnitLabel );
|
1306
|
- QgsProject::instance()->writeEntry( "Compositions", path+"unit/mapunits", mMapUnitsPerUnit );
|
1307
|
+ QgsProject::instance()->writeEntry("Compositions", path + "unit/label", mUnitLabel);
|
1308
|
+ QgsProject::instance()->writeEntry("Compositions", path + "unit/mapunits", mMapUnitsPerUnit);
|
1309
|
|
1310
|
- QgsProject::instance()->writeEntry( "Compositions", path+"segmentsize", mSegmentLength );
|
1311
|
- QgsProject::instance()->writeEntry( "Compositions", path+"numsegments", mNumSegments );
|
1312
|
+ QgsProject::instance()->writeEntry("Compositions", path + "segmentsize", mSegmentLength);
|
1313
|
+ QgsProject::instance()->writeEntry("Compositions", path + "numsegments", mNumSegments);
|
1314
|
|
1315
|
- QgsProject::instance()->writeEntry( "Compositions", path+"font/size", mFont.pointSize() );
|
1316
|
- QgsProject::instance()->writeEntry( "Compositions", path+"font/family", mFont.family() );
|
1317
|
- QgsProject::instance()->writeEntry( "Compositions", path+"font/weight", mFont.weight() );
|
1318
|
- QgsProject::instance()->writeEntry( "Compositions", path+"font/underline", mFont.underline() );
|
1319
|
- QgsProject::instance()->writeEntry( "Compositions", path+"font/strikeout", mFont.strikeOut() );
|
1320
|
-
|
1321
|
- QgsProject::instance()->writeEntry( "Compositions", path+"pen/width", (double)mPen.widthF() );
|
1322
|
+ QgsProject::instance()->writeEntry("Compositions", path + "font/size", mFont.pointSize());
|
1323
|
+ QgsProject::instance()->writeEntry("Compositions", path + "font/family", mFont.family());
|
1324
|
+ QgsProject::instance()->writeEntry("Compositions", path + "font/weight", mFont.weight());
|
1325
|
+ QgsProject::instance()->writeEntry("Compositions", path + "font/underline", mFont.underline());
|
1326
|
+ QgsProject::instance()->writeEntry("Compositions", path + "font/strikeout", mFont.strikeOut());
|
1327
|
|
1328
|
- return true;
|
1329
|
+ QgsProject::instance()->writeEntry("Compositions", path + "pen/width", (double) mPen.widthF());
|
1330
|
+
|
1331
|
+ return true;
|
1332
|
}
|
1333
|
|
1334
|
-bool QgsComposerScalebar::readSettings ( void )
|
1335
|
+bool QgsComposerScalebar::readSettings(void)
|
1336
|
{
|
1337
|
- bool ok;
|
1338
|
- QString path;
|
1339
|
- path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId );
|
1340
|
+ bool ok;
|
1341
|
+ QString path;
|
1342
|
+ path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId);
|
1343
|
|
1344
|
- Q3CanvasPolygonalItem::setX( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok)) );
|
1345
|
- Q3CanvasPolygonalItem::setY( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok)) );
|
1346
|
-
|
1347
|
- mMap = QgsProject::instance()->readNumEntry("Compositions", path+"map", 0, &ok);
|
1348
|
- mUnitLabel = QgsProject::instance()->readEntry("Compositions", path+"unit/label", "???", &ok);
|
1349
|
- mMapUnitsPerUnit = QgsProject::instance()->readDoubleEntry("Compositions", path+"unit/mapunits", 1., &ok);
|
1350
|
+ double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry("Compositions", path + "x", 0, &ok));
|
1351
|
+ double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry("Compositions", path + "y", 0, &ok));
|
1352
|
+ QAbstractGraphicsShapeItem::setPos(x, y);
|
1353
|
|
1354
|
- mSegmentLength = QgsProject::instance()->readDoubleEntry("Compositions", path+"segmentsize", 1000., &ok);
|
1355
|
- mNumSegments = QgsProject::instance()->readNumEntry("Compositions", path+"numsegments", 5, &ok);
|
1356
|
-
|
1357
|
- mFont.setFamily ( QgsProject::instance()->readEntry("Compositions", path+"font/family", "", &ok) );
|
1358
|
- mFont.setPointSize ( QgsProject::instance()->readNumEntry("Compositions", path+"font/size", 10, &ok) );
|
1359
|
- mFont.setWeight( QgsProject::instance()->readNumEntry("Compositions", path+"font/weight", (int)QFont::Normal, &ok) );
|
1360
|
- mFont.setUnderline( QgsProject::instance()->readBoolEntry("Compositions", path+"font/underline", false, &ok) );
|
1361
|
- mFont.setStrikeOut( QgsProject::instance()->readBoolEntry("Compositions", path+"font/strikeout", false, &ok) );
|
1362
|
+ mMap = QgsProject::instance()->readNumEntry("Compositions", path + "map", 0, &ok);
|
1363
|
+ mUnitLabel = QgsProject::instance()->readEntry("Compositions", path + "unit/label", "???", &ok);
|
1364
|
+ mMapUnitsPerUnit = QgsProject::instance()->readDoubleEntry("Compositions", path + "unit/mapunits", 1., &ok);
|
1365
|
|
1366
|
- mPen.setWidthF( QgsProject::instance()->readDoubleEntry("Compositions", path+"pen/width", 1, &ok) );
|
1367
|
-
|
1368
|
- recalculate();
|
1369
|
-
|
1370
|
- return true;
|
1371
|
+ mSegmentLength = QgsProject::instance()->readDoubleEntry("Compositions", path + "segmentsize", 1000., &ok);
|
1372
|
+ mNumSegments = QgsProject::instance()->readNumEntry("Compositions", path + "numsegments", 5, &ok);
|
1373
|
+
|
1374
|
+ mFont.setFamily(QgsProject::instance()->readEntry("Compositions", path + "font/family", "", &ok));
|
1375
|
+ mFont.setPointSize(QgsProject::instance()->readNumEntry("Compositions", path + "font/size", 10, &ok));
|
1376
|
+ mFont.setWeight(QgsProject::instance()->readNumEntry("Compositions", path + "font/weight", (int) QFont::Normal, &ok));
|
1377
|
+ mFont.setUnderline(QgsProject::instance()->readBoolEntry("Compositions", path + "font/underline", false, &ok));
|
1378
|
+ mFont.setStrikeOut(QgsProject::instance()->readBoolEntry("Compositions", path + "font/strikeout", false, &ok));
|
1379
|
+
|
1380
|
+ mPen.setWidthF(QgsProject::instance()->readDoubleEntry("Compositions", path + "pen/width", 1, &ok));
|
1381
|
+
|
1382
|
+ recalculate();
|
1383
|
+
|
1384
|
+ return true;
|
1385
|
}
|
1386
|
|
1387
|
-bool QgsComposerScalebar::removeSettings( void )
|
1388
|
+bool QgsComposerScalebar::removeSettings(void)
|
1389
|
{
|
1390
|
- std::cerr << "QgsComposerScalebar::deleteSettings" << std::endl;
|
1391
|
+ std::cerr << "QgsComposerScalebar::deleteSettings" << std::endl;
|
1392
|
|
1393
|
- QString path;
|
1394
|
- path.sprintf("/composition_%d/scalebar_%d", mComposition->id(), mId );
|
1395
|
- return QgsProject::instance()->removeEntry ( "Compositions", path );
|
1396
|
+ QString path;
|
1397
|
+ path.sprintf("/composition_%d/scalebar_%d", mComposition->id(), mId);
|
1398
|
+ return QgsProject::instance()->removeEntry("Compositions", path);
|
1399
|
}
|
1400
|
|
1401
|
-bool QgsComposerScalebar::writeXML( QDomNode & node, QDomDocument & document, bool temp )
|
1402
|
+bool QgsComposerScalebar::writeXML(QDomNode & node, QDomDocument & document, bool temp)
|
1403
|
{
|
1404
|
- return true;
|
1405
|
+ return true;
|
1406
|
}
|
1407
|
|
1408
|
-bool QgsComposerScalebar::readXML( QDomNode & node )
|
1409
|
+bool QgsComposerScalebar::readXML(QDomNode & node)
|
1410
|
{
|
1411
|
- return true;
|
1412
|
+ return true;
|
1413
|
}
|
1414
|
-
|
1415
|
Index: src/app/composer/qgscomposermap.cpp
|
1416
|
===================================================================
|
1417
|
--- src/app/composer/qgscomposermap.cpp (revision 7070)
|
1418
|
+++ src/app/composer/qgscomposermap.cpp (working copy)
|
1419
|
@@ -14,7 +14,9 @@
|
1420
|
* (at your option) any later version. *
|
1421
|
* *
|
1422
|
***************************************************************************/
|
1423
|
+
|
1424
|
#include "qgscomposermap.h"
|
1425
|
+
|
1426
|
#include "qgscoordinatetransform.h"
|
1427
|
#include "qgsmapcanvas.h"
|
1428
|
#include "qgsmaplayer.h"
|
1429
|
@@ -22,12 +24,15 @@
|
1430
|
#include "qgsproject.h"
|
1431
|
#include "qgsmaprender.h"
|
1432
|
#include "qgsvectorlayer.h"
|
1433
|
+
|
1434
|
+#include <QGraphicsScene>
|
1435
|
+#include <QGraphicsRectItem>
|
1436
|
#include <QPainter>
|
1437
|
#include <iostream>
|
1438
|
#include <cmath>
|
1439
|
|
1440
|
QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int id, int x, int y, int width, int height )
|
1441
|
- : QWidget(), Q3CanvasRectangle(x,y,width,height,0)
|
1442
|
+ : QWidget(), QGraphicsRectItem(x,y,width,height,0)
|
1443
|
{
|
1444
|
setupUi(this);
|
1445
|
|
1446
|
@@ -39,15 +44,16 @@
|
1447
|
init();
|
1448
|
recalculate();
|
1449
|
|
1450
|
- // Add to canvas
|
1451
|
- setCanvas(mComposition->canvas());
|
1452
|
- Q3CanvasRectangle::show();
|
1453
|
+ // Add to scene
|
1454
|
+ mComposition->canvas()->addItem(this);
|
1455
|
|
1456
|
+ QGraphicsRectItem::show();
|
1457
|
+
|
1458
|
writeSettings();
|
1459
|
}
|
1460
|
|
1461
|
QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int id )
|
1462
|
- : Q3CanvasRectangle(0,0,10,10,0)
|
1463
|
+ : QGraphicsRectItem(0,0,10,10,0)
|
1464
|
{
|
1465
|
setupUi(this);
|
1466
|
|
1467
|
@@ -60,9 +66,9 @@
|
1468
|
readSettings();
|
1469
|
recalculate();
|
1470
|
|
1471
|
- // Add to canvas
|
1472
|
- setCanvas(mComposition->canvas());
|
1473
|
- Q3CanvasRectangle::show();
|
1474
|
+ // Add to scene
|
1475
|
+ mComposition->canvas()->addItem(this);
|
1476
|
+ QGraphicsRectItem::show();
|
1477
|
}
|
1478
|
|
1479
|
void QgsComposerMap::init ()
|
1480
|
@@ -95,8 +101,7 @@
|
1481
|
|
1482
|
mFrame = true;
|
1483
|
|
1484
|
- Q3CanvasRectangle::setZ(20);
|
1485
|
- setActive(true);
|
1486
|
+ QGraphicsRectItem::setZValue(20);
|
1487
|
|
1488
|
connect ( mMapCanvas, SIGNAL(layersChanged()), this, SLOT(mapCanvasChanged()) );
|
1489
|
}
|
1490
|
@@ -106,6 +111,8 @@
|
1491
|
std::cerr << "QgsComposerMap::~QgsComposerMap" << std::endl;
|
1492
|
}
|
1493
|
|
1494
|
+/* This function is called by paint() and cache() to render the map. It does not override any functions
|
1495
|
+from QGraphicsItem. */
|
1496
|
void QgsComposerMap::draw ( QPainter *painter, QgsRect &extent, QgsMapToPixel *transform)
|
1497
|
{
|
1498
|
mMapCanvas->freeze(true); // necessary ?
|
1499
|
@@ -114,7 +121,9 @@
|
1500
|
|
1501
|
for ( int i = nlayers - 1; i >= 0; i-- ) {
|
1502
|
QgsMapLayer *layer = mMapCanvas->getZpos(i);
|
1503
|
-
|
1504
|
+
|
1505
|
+ //if ( !layer->visible() ) continue;
|
1506
|
+
|
1507
|
if (mMapCanvas->projectionsEnabled())
|
1508
|
{
|
1509
|
ct = new QgsCoordinateTransform(layer->srs(), mMapCanvas->mapRender()->destinationSrs());
|
1510
|
@@ -143,25 +152,24 @@
|
1511
|
|
1512
|
vector->draw( painter, r1, transform, ct, FALSE, widthScale, symbolScale);
|
1513
|
|
1514
|
- if ( split )
|
1515
|
- {
|
1516
|
- vector->draw( painter, r2, transform, ct, FALSE, widthScale, symbolScale);
|
1517
|
- }
|
1518
|
+ if ( split )
|
1519
|
+ {
|
1520
|
+ vector->draw( painter, r2, transform, ct, FALSE, widthScale, symbolScale);
|
1521
|
+ }
|
1522
|
} else {
|
1523
|
// raster
|
1524
|
if ( plotStyle() == QgsComposition::Print || plotStyle() == QgsComposition::Postscript ) {
|
1525
|
// we have to rescale the raster to get requested resolution
|
1526
|
-
|
1527
|
+
|
1528
|
// calculate relation between composition point size and requested resolution (in mm)
|
1529
|
double multip = (1. / mComposition->scale()) / (25.4 / mComposition->resolution()) ;
|
1530
|
-
|
1531
|
- double sc = mExtent.width() / (multip*Q3CanvasRectangle::width());
|
1532
|
-
|
1533
|
- QgsMapToPixel trans ( sc, multip*Q3CanvasRectangle::height(), mExtent.yMin(), mExtent.xMin() );
|
1534
|
-
|
1535
|
+
|
1536
|
+ double sc = mExtent.width() / (multip*QGraphicsRectItem::rect().width());
|
1537
|
+
|
1538
|
+ QgsMapToPixel trans ( sc, multip*QGraphicsRectItem::rect().height(), mExtent.yMin(), mExtent.xMin() );
|
1539
|
+
|
1540
|
painter->save();
|
1541
|
painter->scale( 1./multip, 1./multip);
|
1542
|
-
|
1543
|
layer->draw( painter, extent, &trans, ct, FALSE);
|
1544
|
|
1545
|
painter->restore();
|
1546
|
@@ -187,7 +195,9 @@
|
1547
|
{
|
1548
|
ct = NULL;
|
1549
|
}
|
1550
|
-
|
1551
|
+
|
1552
|
+// if ( !layer->visible() ) continue; //this doesn't work with the newer map layer code
|
1553
|
+
|
1554
|
if ( layer->type() == QgsMapLayer::VECTOR ) {
|
1555
|
QgsVectorLayer *vector = dynamic_cast <QgsVectorLayer*> (layer);
|
1556
|
|
1557
|
@@ -219,9 +229,8 @@
|
1558
|
mUserExtent = rect;
|
1559
|
recalculate();
|
1560
|
|
1561
|
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
|
1562
|
- Q3CanvasRectangle::update();
|
1563
|
- Q3CanvasRectangle::canvas()->update();
|
1564
|
+ QGraphicsRectItem::update();
|
1565
|
+ QGraphicsRectItem::scene()->update();
|
1566
|
}
|
1567
|
|
1568
|
void QgsComposerMap::cache ( void )
|
1569
|
@@ -231,7 +240,7 @@
|
1570
|
// 1 pixel in cache should have ia similar size as 1 pixel in canvas
|
1571
|
// but it can result in big cache -> limit
|
1572
|
|
1573
|
- int w = static_cast<int>(round(Q3CanvasRectangle::width() * mComposition->viewScale()));
|
1574
|
+ int w = (int)(QGraphicsRectItem::rect().width() * mComposition->viewScale());
|
1575
|
w = w < 1000 ? w : 1000;
|
1576
|
int h = (int) ( mExtent.height() * w / mExtent.width() );
|
1577
|
// It can happen that extent is not initialised well -> check
|
1578
|
@@ -263,12 +272,12 @@
|
1579
|
mCacheUpdated = true;
|
1580
|
}
|
1581
|
|
1582
|
-void QgsComposerMap::draw ( QPainter & painter )
|
1583
|
+void QgsComposerMap::paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget)
|
1584
|
{
|
1585
|
if ( mDrawing ) return;
|
1586
|
mDrawing = true;
|
1587
|
|
1588
|
- std::cout << "draw mPlotStyle = " << plotStyle()
|
1589
|
+ std::cout << "QgsComposerMapt::paint mPlotStyle = " << plotStyle()
|
1590
|
<< " mPreviewMode = " << mPreviewMode << std::endl;
|
1591
|
|
1592
|
if ( plotStyle() == QgsComposition::Preview && mPreviewMode == Cache ) { // Draw from cache
|
1593
|
@@ -280,18 +289,18 @@
|
1594
|
}
|
1595
|
|
1596
|
// Scale so that the cache fills the map rectangle
|
1597
|
- double scale = 1.0 * Q3CanvasRectangle::width() / mCachePixmap.width();
|
1598
|
+ double scale = 1.0 * QGraphicsRectItem::rect().width() / mCachePixmap.width();
|
1599
|
|
1600
|
- painter.save();
|
1601
|
+ painter->save();
|
1602
|
|
1603
|
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
|
1604
|
- painter.scale(scale,scale);
|
1605
|
+ painter->translate(0, 0); //do we need this?
|
1606
|
+ painter->scale(scale,scale);
|
1607
|
std::cout << "scale = " << scale << std::endl;
|
1608
|
- std::cout << "translate: " << Q3CanvasRectangle::x() << ", " << Q3CanvasRectangle::y() << std::endl;
|
1609
|
+
|
1610
|
// Note: drawing only a visible part of the pixmap doesn't make it much faster
|
1611
|
- painter.drawPixmap(0,0, mCachePixmap);
|
1612
|
+ painter->drawPixmap(0,0, mCachePixmap);
|
1613
|
|
1614
|
- painter.restore();
|
1615
|
+ painter->restore();
|
1616
|
}
|
1617
|
else if ( (plotStyle() == QgsComposition::Preview && mPreviewMode == Render) ||
|
1618
|
plotStyle() == QgsComposition::Print ||
|
1619
|
@@ -299,46 +308,43 @@
|
1620
|
{
|
1621
|
std::cout << "render" << std::endl;
|
1622
|
|
1623
|
- double scale = mExtent.width() / Q3CanvasRectangle::width();
|
1624
|
- QgsMapToPixel transform(scale, Q3CanvasRectangle::height(), mExtent.yMin(), mExtent.xMin() );
|
1625
|
+ double scale = mExtent.width() / QGraphicsRectItem::rect().width();
|
1626
|
+ QgsMapToPixel transform(scale, QGraphicsRectItem::rect().height(), mExtent.yMin(), mExtent.xMin() );
|
1627
|
|
1628
|
- painter.save();
|
1629
|
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
|
1630
|
+ painter->save();
|
1631
|
+ painter->translate(0, 0); //do we need this?
|
1632
|
|
1633
|
// TODO: Qt4 appears to force QPainter::CoordDevice - need to check if this is actually valid.
|
1634
|
- painter.setClipRect ( 0, 0, Q3CanvasRectangle::width(), Q3CanvasRectangle::height() );
|
1635
|
+ painter->setClipRect (QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() ));
|
1636
|
|
1637
|
- draw( &painter, mExtent, &transform);
|
1638
|
- painter.restore();
|
1639
|
+ draw( painter, mExtent, &transform);
|
1640
|
+ painter->restore();
|
1641
|
}
|
1642
|
|
1643
|
// Draw frame around
|
1644
|
if ( mFrame ) {
|
1645
|
QPen pen(QColor(0,0,0));
|
1646
|
pen.setWidthF(0.6*mComposition->scale());
|
1647
|
- painter.setPen( pen );
|
1648
|
- painter.setBrush( Qt::NoBrush );
|
1649
|
- painter.save();
|
1650
|
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
|
1651
|
- painter.drawRect ( 0, 0, Q3CanvasRectangle::width(), Q3CanvasRectangle::height() );
|
1652
|
- painter.restore();
|
1653
|
+ painter->setPen( pen );
|
1654
|
+ painter->setBrush( Qt::NoBrush );
|
1655
|
+ painter->setRenderHint(QPainter::Antialiasing, true); //turn on antialiasing for drawing the box
|
1656
|
+ painter->save();
|
1657
|
+ painter->translate(0, 0);//do we need this?
|
1658
|
+ painter->drawRect (QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() ));
|
1659
|
+ painter->restore();
|
1660
|
}
|
1661
|
|
1662
|
// Show selected / Highlight
|
1663
|
if ( mSelected && plotStyle() == QgsComposition::Preview ) {
|
1664
|
- painter.setPen( mComposition->selectionPen() );
|
1665
|
- painter.setBrush( mComposition->selectionBrush() );
|
1666
|
- int x = (int) Q3CanvasRectangle::x();
|
1667
|
- int y = (int) Q3CanvasRectangle::y();
|
1668
|
- int s = mComposition->selectionBoxSize();
|
1669
|
+ painter->setPen( mComposition->selectionPen() );
|
1670
|
+ painter->setBrush( mComposition->selectionBrush() );
|
1671
|
|
1672
|
- painter.drawRect ( x, y, s, s );
|
1673
|
- x += Q3CanvasRectangle::width();
|
1674
|
- painter.drawRect ( x-s, y, s, s );
|
1675
|
- y += Q3CanvasRectangle::height();
|
1676
|
- painter.drawRect ( x-s, y-s, s, s );
|
1677
|
- x -= Q3CanvasRectangle::width();
|
1678
|
- painter.drawRect ( x, y-s, s, s );
|
1679
|
+ double s = mComposition->selectionBoxSize();
|
1680
|
+
|
1681
|
+ painter->drawRect (QRectF(0, 0, s, s));
|
1682
|
+ painter->drawRect (QRectF(QGraphicsRectItem::rect().width() -s, 0, s, s));
|
1683
|
+ painter->drawRect (QRectF(QGraphicsRectItem::rect().width() -s, QGraphicsRectItem::rect().height() -s, s, s));
|
1684
|
+ painter->drawRect (QRectF(0, QGraphicsRectItem::rect().height() -s, s, s));
|
1685
|
}
|
1686
|
|
1687
|
mDrawing = false;
|
1688
|
@@ -350,12 +356,11 @@
|
1689
|
w = mComposition->fromMM ( mWidthLineEdit->text().toDouble() );
|
1690
|
h = mComposition->fromMM ( mHeightLineEdit->text().toDouble() );
|
1691
|
|
1692
|
- Q3CanvasRectangle::setSize ( w, h);
|
1693
|
+ QGraphicsRectItem::setRect(0, 0, w, h);
|
1694
|
recalculate();
|
1695
|
|
1696
|
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
|
1697
|
- Q3CanvasRectangle::update();
|
1698
|
- Q3CanvasRectangle::canvas()->update();
|
1699
|
+ QGraphicsRectItem::update();
|
1700
|
+ QGraphicsRectItem::scene()->update();
|
1701
|
|
1702
|
writeSettings();
|
1703
|
}
|
1704
|
@@ -367,15 +372,12 @@
|
1705
|
{
|
1706
|
mCalculate = mCalculateComboBox->currentItem();
|
1707
|
|
1708
|
- if ( mCalculate == Scale ) { // return to extent defined by user
|
1709
|
- recalculate();
|
1710
|
-
|
1711
|
- mCacheUpdated = false;
|
1712
|
- //QCanvasRectangle::canvas()->setAllChanged(); // must be setAllChanged(), not sure why
|
1713
|
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
|
1714
|
- Q3CanvasRectangle::canvas()->update();
|
1715
|
-
|
1716
|
- mComposition->emitMapChanged ( mId );
|
1717
|
+ if ( mCalculate == Scale )
|
1718
|
+ {
|
1719
|
+ recalculate();
|
1720
|
+ mCacheUpdated = false;
|
1721
|
+ QGraphicsRectItem::scene()->update();
|
1722
|
+ mComposition->emitMapChanged ( mId );
|
1723
|
}
|
1724
|
setOptions();
|
1725
|
writeSettings();
|
1726
|
@@ -383,7 +385,7 @@
|
1727
|
|
1728
|
double QgsComposerMap::scaleFromUserScale ( double us )
|
1729
|
{
|
1730
|
- double s=0;
|
1731
|
+ double s;
|
1732
|
|
1733
|
switch ( mComposition->mapCanvas()->mapUnits() ) {
|
1734
|
case QGis::METERS :
|
1735
|
@@ -422,8 +424,9 @@
|
1736
|
|
1737
|
void QgsComposerMap::on_mScaleLineEdit_returnPressed()
|
1738
|
{
|
1739
|
+#ifdef QGISDEBUG
|
1740
|
std::cout << "QgsComposerMap::on_mScaleLineEdit_returnPressed" << std::endl;
|
1741
|
-
|
1742
|
+#endif
|
1743
|
mCalculate = mCalculateComboBox->currentItem();
|
1744
|
|
1745
|
mUserScale = mScaleLineEdit->text().toDouble();
|
1746
|
@@ -433,9 +436,8 @@
|
1747
|
recalculate();
|
1748
|
|
1749
|
mCacheUpdated = false;
|
1750
|
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
|
1751
|
- Q3CanvasRectangle::update();
|
1752
|
- Q3CanvasRectangle::canvas()->update();
|
1753
|
+ QGraphicsRectItem::update();
|
1754
|
+ QGraphicsRectItem::scene()->update();
|
1755
|
|
1756
|
writeSettings();
|
1757
|
mComposition->emitMapChanged ( mId );
|
1758
|
@@ -448,9 +450,8 @@
|
1759
|
mFontScale = mFontScaleLineEdit->text().toDouble();
|
1760
|
|
1761
|
mCacheUpdated = false;
|
1762
|
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
|
1763
|
- Q3CanvasRectangle::update();
|
1764
|
- Q3CanvasRectangle::canvas()->update();
|
1765
|
+ QGraphicsRectItem::update();
|
1766
|
+ QGraphicsRectItem::scene()->update();
|
1767
|
|
1768
|
writeSettings();
|
1769
|
mComposition->emitMapChanged ( mId );
|
1770
|
@@ -465,7 +466,7 @@
|
1771
|
std::cout << "QgsComposerMap::canvasChanged" << std::endl;
|
1772
|
|
1773
|
mCacheUpdated = false;
|
1774
|
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
|
1775
|
+ QGraphicsRectItem::update();
|
1776
|
}
|
1777
|
|
1778
|
void QgsComposerMap::on_mPreviewModeComboBox_activated ( int i )
|
1779
|
@@ -476,64 +477,65 @@
|
1780
|
|
1781
|
void QgsComposerMap::recalculate ( void )
|
1782
|
{
|
1783
|
- std::cout << "QgsComposerMap::recalculate mCalculate = " << mCalculate << std::endl;
|
1784
|
+#ifdef QGISDEBUG
|
1785
|
+ std::cout << "QgsComposerMap::recalculate mCalculate = " << mCalculate << std::endl;
|
1786
|
+#endif
|
1787
|
+ if ( mCalculate == Scale )
|
1788
|
+ {
|
1789
|
+ // Calculate scale from extent and rectangle
|
1790
|
+ double xscale = QGraphicsRectItem::rect().width() / mUserExtent.width();
|
1791
|
+ double yscale = QGraphicsRectItem::rect().height() / mUserExtent.height();
|
1792
|
|
1793
|
- if ( mCalculate == Scale )
|
1794
|
+ mExtent = mUserExtent;
|
1795
|
+
|
1796
|
+ if ( xscale < yscale )
|
1797
|
{
|
1798
|
- // Calculate scale from extent and rectangle
|
1799
|
- double xscale = Q3CanvasRectangle::width() / mUserExtent.width();
|
1800
|
- double yscale = Q3CanvasRectangle::height() / mUserExtent.height();
|
1801
|
-
|
1802
|
- mExtent = mUserExtent;
|
1803
|
-
|
1804
|
- if ( xscale < yscale ) {
|
1805
|
mScale = xscale;
|
1806
|
// extend y
|
1807
|
- double d = ( 1. * Q3CanvasRectangle::height() / mScale - mUserExtent.height() ) / 2 ;
|
1808
|
+ double d = ( 1. * QGraphicsRectItem::rect().height() / mScale - mUserExtent.height() ) / 2 ;
|
1809
|
mExtent.setYmin ( mUserExtent.yMin() - d );
|
1810
|
mExtent.setYmax ( mUserExtent.yMax() + d );
|
1811
|
- } else {
|
1812
|
+ }
|
1813
|
+ else
|
1814
|
+ {
|
1815
|
mScale = yscale;
|
1816
|
// extend x
|
1817
|
- double d = ( 1.* Q3CanvasRectangle::width() / mScale - mUserExtent.width() ) / 2 ;
|
1818
|
+ double d = ( 1.* QGraphicsRectItem::rect().width() / mScale - mUserExtent.width() ) / 2 ;
|
1819
|
mExtent.setXmin ( mUserExtent.xMin() - d );
|
1820
|
mExtent.setXmax ( mUserExtent.xMax() + d );
|
1821
|
- }
|
1822
|
+ }
|
1823
|
|
1824
|
- mUserScale = userScaleFromScale ( mScale );
|
1825
|
- }
|
1826
|
- else
|
1827
|
- {
|
1828
|
- // Calculate extent
|
1829
|
- double xc = ( mUserExtent.xMax() + mUserExtent.xMin() ) / 2;
|
1830
|
- double yc = ( mUserExtent.yMax() + mUserExtent.yMin() ) / 2;
|
1831
|
-
|
1832
|
- double width = Q3CanvasRectangle::width() / mScale;
|
1833
|
- double height = Q3CanvasRectangle::height() / mScale;
|
1834
|
+ mUserScale = userScaleFromScale ( mScale );
|
1835
|
+ }
|
1836
|
+ else
|
1837
|
+ {
|
1838
|
+ // Calculate extent
|
1839
|
+ double xc = ( mUserExtent.xMax() + mUserExtent.xMin() ) / 2;
|
1840
|
+ double yc = ( mUserExtent.yMax() + mUserExtent.yMin() ) / 2;
|
1841
|
|
1842
|
- mExtent.setXmin ( xc - width/2 );
|
1843
|
- mExtent.setXmax ( xc + width/2 );
|
1844
|
- mExtent.setYmin ( yc - height/2 );
|
1845
|
- mExtent.setYmax ( yc + height/2 );
|
1846
|
+ double width = QGraphicsRectItem::rect().width() / mScale;
|
1847
|
+ double height = QGraphicsRectItem::rect().height() / mScale;
|
1848
|
+
|
1849
|
+ mExtent.setXmin ( xc - width/2 );
|
1850
|
+ mExtent.setXmax ( xc + width/2 );
|
1851
|
+ mExtent.setYmin ( yc - height/2 );
|
1852
|
+ mExtent.setYmax ( yc + height/2 );
|
1853
|
+ }
|
1854
|
|
1855
|
- }
|
1856
|
+ std::cout << "mUserExtent = " << mUserExtent.stringRep().toLocal8Bit().data() << std::endl;
|
1857
|
+ std::cout << "mScale = " << mScale << std::endl;
|
1858
|
+ std::cout << "mExtent = " << mExtent.stringRep().toLocal8Bit().data() << std::endl;
|
1859
|
|
1860
|
- std::cout << "mUserExtent = " << mUserExtent.stringRep().toLocal8Bit().data() << std::endl;
|
1861
|
- std::cout << "mScale = " << mScale << std::endl;
|
1862
|
- std::cout << "mExtent = " << mExtent.stringRep().toLocal8Bit().data() << std::endl;
|
1863
|
-
|
1864
|
- setOptions();
|
1865
|
- mCacheUpdated = false;
|
1866
|
+ setOptions();
|
1867
|
+ mCacheUpdated = false;
|
1868
|
}
|
1869
|
|
1870
|
void QgsComposerMap::on_mFrameCheckBox_clicked ( )
|
1871
|
{
|
1872
|
mFrame = mFrameCheckBox->isChecked();
|
1873
|
+ QGraphicsRectItem::update();
|
1874
|
+ QGraphicsRectItem::scene()->update();
|
1875
|
|
1876
|
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
|
1877
|
- Q3CanvasRectangle::update();
|
1878
|
- Q3CanvasRectangle::canvas()->update();
|
1879
|
-
|
1880
|
writeSettings();
|
1881
|
}
|
1882
|
|
1883
|
@@ -546,8 +548,8 @@
|
1884
|
|
1885
|
mCalculateComboBox->setCurrentItem( mCalculate );
|
1886
|
|
1887
|
- mWidthLineEdit->setText ( QString("%1").arg( mComposition->toMM(Q3CanvasRectangle::width()), 0,'g') );
|
1888
|
- mHeightLineEdit->setText ( QString("%1").arg( mComposition->toMM(Q3CanvasRectangle::height()),0,'g') );
|
1889
|
+ mWidthLineEdit->setText ( QString("%1").arg( mComposition->toMM((int)QGraphicsRectItem::rect().width()), 0,'g') );
|
1890
|
+ mHeightLineEdit->setText ( QString("%1").arg( mComposition->toMM((int)QGraphicsRectItem::rect().height()),0,'g') );
|
1891
|
|
1892
|
// Scale
|
1893
|
switch ( mComposition->mapCanvas()->mapUnits() ) {
|
1894
|
@@ -579,9 +581,8 @@
|
1895
|
{
|
1896
|
mUserExtent = mMapCanvas->extent();
|
1897
|
recalculate();
|
1898
|
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
|
1899
|
- Q3CanvasRectangle::update();
|
1900
|
- Q3CanvasRectangle::canvas()->update();
|
1901
|
+ QGraphicsRectItem::update();
|
1902
|
+ QGraphicsRectItem::scene()->update();
|
1903
|
setOptions();
|
1904
|
writeSettings();
|
1905
|
mComposition->emitMapChanged ( mId );
|
1906
|
@@ -590,7 +591,7 @@
|
1907
|
void QgsComposerMap::setSelected ( bool s )
|
1908
|
{
|
1909
|
mSelected = s;
|
1910
|
- Q3CanvasRectangle::update(); // show highlight
|
1911
|
+ QGraphicsRectItem::update(); //re-paint, so we show the highlight boxes
|
1912
|
}
|
1913
|
|
1914
|
bool QgsComposerMap::selected( void )
|
1915
|
@@ -622,76 +623,81 @@
|
1916
|
|
1917
|
bool QgsComposerMap::writeSettings ( void )
|
1918
|
{
|
1919
|
- QString path;
|
1920
|
- path.sprintf("/composition_%d/map_%d/", mComposition->id(), mId );
|
1921
|
- QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)Q3CanvasRectangle::x()) );
|
1922
|
- QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)Q3CanvasRectangle::y()) );
|
1923
|
- QgsProject::instance()->writeEntry( "Compositions", path+"width", mComposition->toMM(Q3CanvasRectangle::width()) );
|
1924
|
- QgsProject::instance()->writeEntry( "Compositions", path+"height", mComposition->toMM(Q3CanvasRectangle::height()) );
|
1925
|
+ QString path;
|
1926
|
+ path.sprintf("/composition_%d/map_%d/", mComposition->id(), mId );
|
1927
|
|
1928
|
- if ( mCalculate == Scale ) {
|
1929
|
- QgsProject::instance()->writeEntry( "Compositions", path+"calculate", QString("scale") );
|
1930
|
- } else {
|
1931
|
- QgsProject::instance()->writeEntry( "Compositions", path+"calculate", QString("extent") );
|
1932
|
- }
|
1933
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QGraphicsRectItem::pos().x()) );
|
1934
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QGraphicsRectItem::pos().y()) );
|
1935
|
+
|
1936
|
+
|
1937
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"width", mComposition->toMM((int)QGraphicsRectItem::rect().width()) );
|
1938
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"height", mComposition->toMM((int)QGraphicsRectItem::rect().height()) );
|
1939
|
+
|
1940
|
+ if ( mCalculate == Scale ) {
|
1941
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"calculate", QString("scale") );
|
1942
|
+ } else {
|
1943
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"calculate", QString("extent") );
|
1944
|
+ }
|
1945
|
|
1946
|
- QgsProject::instance()->writeEntry( "Compositions", path+"north", mUserExtent.yMax() );
|
1947
|
- QgsProject::instance()->writeEntry( "Compositions", path+"south", mUserExtent.yMin() );
|
1948
|
- QgsProject::instance()->writeEntry( "Compositions", path+"east", mUserExtent.xMax() );
|
1949
|
- QgsProject::instance()->writeEntry( "Compositions", path+"west", mUserExtent.xMin() );
|
1950
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"north", mUserExtent.yMax() );
|
1951
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"south", mUserExtent.yMin() );
|
1952
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"east", mUserExtent.xMax() );
|
1953
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"west", mUserExtent.xMin() );
|
1954
|
|
1955
|
- QgsProject::instance()->writeEntry( "Compositions", path+"scale", mUserScale );
|
1956
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"scale", mUserScale );
|
1957
|
|
1958
|
- QgsProject::instance()->writeEntry( "Compositions", path+"widthscale", mWidthScale );
|
1959
|
- QgsProject::instance()->writeEntry( "Compositions", path+"symbolscale", mSymbolScale );
|
1960
|
- QgsProject::instance()->writeEntry( "Compositions", path+"fontscale", mFontScale );
|
1961
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"widthscale", mWidthScale );
|
1962
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"symbolscale", mSymbolScale );
|
1963
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"fontscale", mFontScale );
|
1964
|
|
1965
|
- QgsProject::instance()->writeEntry( "Compositions", path+"frame", mFrame );
|
1966
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"frame", mFrame );
|
1967
|
|
1968
|
- QgsProject::instance()->writeEntry( "Compositions", path+"previewmode", mPreviewMode );
|
1969
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"previewmode", mPreviewMode );
|
1970
|
|
1971
|
- return true;
|
1972
|
+ return true;
|
1973
|
}
|
1974
|
|
1975
|
bool QgsComposerMap::readSettings ( void )
|
1976
|
{
|
1977
|
- bool ok;
|
1978
|
- QString path;
|
1979
|
- path.sprintf("/composition_%d/map_%d/", mComposition->id(), mId );
|
1980
|
-
|
1981
|
+ bool ok;
|
1982
|
+ QString path;
|
1983
|
+ path.sprintf("/composition_%d/map_%d/", mComposition->id(), mId );
|
1984
|
|
1985
|
- Q3CanvasRectangle::setX( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok)) );
|
1986
|
- Q3CanvasRectangle::setY( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok)) );
|
1987
|
- int w = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"width", 100, &ok)) ;
|
1988
|
- int h = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"height", 100, &ok)) ;
|
1989
|
- Q3CanvasRectangle::setSize(w,h);
|
1990
|
+ double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok));
|
1991
|
+ double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok));
|
1992
|
+ int w = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"width", 100, &ok)) ;
|
1993
|
+ int h = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"height", 100, &ok)) ;
|
1994
|
+ QGraphicsRectItem::setRect(0, 0, w, h);
|
1995
|
+ QGraphicsRectItem::setPos(x, y);
|
1996
|
|
1997
|
- QString calculate = QgsProject::instance()->readEntry("Compositions", path+"calculate", "scale", &ok);
|
1998
|
- if ( calculate == "extent" ) {
|
1999
|
- mCalculate = Extent;
|
2000
|
- } else {
|
2001
|
- mCalculate = Scale;
|
2002
|
- }
|
2003
|
+ QString calculate = QgsProject::instance()->readEntry("Compositions", path+"calculate", "scale", &ok);
|
2004
|
+ if ( calculate == "extent" )
|
2005
|
+ {
|
2006
|
+ mCalculate = Extent;
|
2007
|
+ }else
|
2008
|
+ {
|
2009
|
+ mCalculate = Scale;
|
2010
|
+ }
|
2011
|
|
2012
|
- mUserExtent.setYmax ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"north", 100, &ok) );
|
2013
|
- mUserExtent.setYmin ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"south", 0, &ok) );
|
2014
|
- mUserExtent.setXmax ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"east", 100, &ok) );
|
2015
|
- mUserExtent.setXmin ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"west", 0, &ok) );
|
2016
|
+ mUserExtent.setYmax ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"north", 100, &ok) );
|
2017
|
+ mUserExtent.setYmin ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"south", 0, &ok) );
|
2018
|
+ mUserExtent.setXmax ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"east", 100, &ok) );
|
2019
|
+ mUserExtent.setXmin ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"west", 0, &ok) );
|
2020
|
|
2021
|
- mUserScale = QgsProject::instance()->readDoubleEntry( "Compositions", path+"scale", 1000., &ok);
|
2022
|
- mScale = scaleFromUserScale ( mUserScale );
|
2023
|
+ mUserScale = QgsProject::instance()->readDoubleEntry( "Compositions", path+"scale", 1000., &ok);
|
2024
|
+ mScale = scaleFromUserScale ( mUserScale );
|
2025
|
|
2026
|
- mWidthScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"widthscale", 1., &ok);
|
2027
|
- mSymbolScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"symbolscale", 1., &ok);
|
2028
|
- mFontScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"fontscale", 1., &ok);
|
2029
|
+ mWidthScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"widthscale", 1., &ok);
|
2030
|
+ mSymbolScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"symbolscale", 1., &ok);
|
2031
|
+ mFontScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"fontscale", 1., &ok);
|
2032
|
|
2033
|
- mFrame = QgsProject::instance()->readBoolEntry("Compositions", path+"frame", true, &ok);
|
2034
|
+ mFrame = QgsProject::instance()->readBoolEntry("Compositions", path+"frame", true, &ok);
|
2035
|
|
2036
|
- mPreviewMode = (PreviewMode) QgsProject::instance()->readNumEntry("Compositions", path+"previewmode", Cache, &ok);
|
2037
|
+ mPreviewMode = (PreviewMode) QgsProject::instance()->readNumEntry("Compositions", path+"previewmode", Cache, &ok);
|
2038
|
|
2039
|
- recalculate();
|
2040
|
+ recalculate();
|
2041
|
|
2042
|
- return true;
|
2043
|
+ return true;
|
2044
|
}
|
2045
|
|
2046
|
bool QgsComposerMap::removeSettings ( void )
|
2047
|
@@ -700,7 +706,7 @@
|
2048
|
path.sprintf("/composition_%d/map_%d", mComposition->id(), mId );
|
2049
|
return QgsProject::instance()->removeEntry ( "Compositions", path );
|
2050
|
}
|
2051
|
-
|
2052
|
+
|
2053
|
bool QgsComposerMap::writeXML( QDomNode & node, QDomDocument & document, bool temp )
|
2054
|
{
|
2055
|
return true;
|
2056
|
@@ -710,3 +716,4 @@
|
2057
|
{
|
2058
|
return true;
|
2059
|
}
|
2060
|
+
|
2061
|
Index: src/app/composer/qgscomposerlabel.cpp
|
2062
|
===================================================================
|
2063
|
--- src/app/composer/qgscomposerlabel.cpp (revision 7070)
|
2064
|
+++ src/app/composer/qgscomposerlabel.cpp (working copy)
|
2065
|
@@ -15,15 +15,19 @@
|
2066
|
* *
|
2067
|
***************************************************************************/
|
2068
|
#include "qgscomposerlabel.h"
|
2069
|
+#include "qgsproject.h"
|
2070
|
|
2071
|
-#include "qgsproject.h"
|
2072
|
+#include <QGraphicsScene>
|
2073
|
+#include <QAbstractGraphicsShapeItem>
|
2074
|
+#include <QPolygonF>
|
2075
|
#include <QFontDialog>
|
2076
|
#include <QPainter>
|
2077
|
+
|
2078
|
#include <iostream>
|
2079
|
|
2080
|
QgsComposerLabel::QgsComposerLabel ( QgsComposition *composition, int id,
|
2081
|
int x, int y, QString text, int fontSize )
|
2082
|
- : QWidget(composition), Q3CanvasPolygonalItem(0), mBox(false)
|
2083
|
+ : QWidget(composition), QAbstractGraphicsShapeItem(0), mBox(false)
|
2084
|
{
|
2085
|
setupUi(this);
|
2086
|
|
2087
|
@@ -37,28 +41,29 @@
|
2088
|
|
2089
|
// Font and pen
|
2090
|
mFont.setPointSize ( fontSize );
|
2091
|
+
|
2092
|
// Could make this user variable in the future
|
2093
|
mPen.setWidthF (0.5);
|
2094
|
|
2095
|
- Q3CanvasPolygonalItem::setX(x);
|
2096
|
- Q3CanvasPolygonalItem::setY(y);
|
2097
|
+ QAbstractGraphicsShapeItem::setPos(x, y);
|
2098
|
|
2099
|
mSelected = false;
|
2100
|
|
2101
|
setOptions();
|
2102
|
|
2103
|
// Add to canvas
|
2104
|
- setCanvas(mComposition->canvas());
|
2105
|
- Q3CanvasPolygonalItem::setZ(100);
|
2106
|
- setActive(true);
|
2107
|
- Q3CanvasPolygonalItem::show();
|
2108
|
- Q3CanvasPolygonalItem::update(); // ?
|
2109
|
+ mComposition->canvas()->addItem(this);
|
2110
|
|
2111
|
+ QAbstractGraphicsShapeItem::setZValue(100);
|
2112
|
+ //setActive(true); //no equivalent
|
2113
|
+ QAbstractGraphicsShapeItem::show();
|
2114
|
+ QAbstractGraphicsShapeItem::update();
|
2115
|
+
|
2116
|
writeSettings();
|
2117
|
}
|
2118
|
|
2119
|
QgsComposerLabel::QgsComposerLabel ( QgsComposition *composition, int id )
|
2120
|
- : Q3CanvasPolygonalItem(0)
|
2121
|
+ : QAbstractGraphicsShapeItem(0)
|
2122
|
{
|
2123
|
std::cout << "QgsComposerLabel::QgsComposerLabel()" << std::endl;
|
2124
|
|
2125
|
@@ -73,63 +78,64 @@
|
2126
|
setOptions();
|
2127
|
|
2128
|
// Add to canvas
|
2129
|
- setCanvas(mComposition->canvas());
|
2130
|
- Q3CanvasPolygonalItem::setZ(100);
|
2131
|
- setActive(true);
|
2132
|
- Q3CanvasPolygonalItem::show();
|
2133
|
- Q3CanvasPolygonalItem::update(); // ?
|
2134
|
+ mComposition->canvas()->addItem(this);
|
2135
|
+ QAbstractGraphicsShapeItem::setZValue(100);
|
2136
|
+ //setActive(true);//no equivalent
|
2137
|
+ QAbstractGraphicsShapeItem::show();
|
2138
|
+ QAbstractGraphicsShapeItem::update();
|
2139
|
|
2140
|
}
|
2141
|
|
2142
|
QgsComposerLabel::~QgsComposerLabel()
|
2143
|
{
|
2144
|
std::cout << "QgsComposerLabel::~QgsComposerLabel" << std::endl;
|
2145
|
- Q3CanvasItem::hide();
|
2146
|
+ QGraphicsItem::hide();
|
2147
|
}
|
2148
|
-
|
2149
|
-void QgsComposerLabel::drawShape ( QPainter & painter )
|
2150
|
+/*
|
2151
|
+void QgsComposerLabel::drawShape ( QPainter & painter, const QStyleOptionGraphicsItem* item, QWidget* pWidget)
|
2152
|
{
|
2153
|
std::cout << "QgsComposerLabel::drawShape" << std::endl;
|
2154
|
- draw ( painter );
|
2155
|
+ paint ( painter, item, pWidget );
|
2156
|
}
|
2157
|
+*/
|
2158
|
|
2159
|
-void QgsComposerLabel::draw ( QPainter & painter )
|
2160
|
+void QgsComposerLabel::paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
|
2161
|
{
|
2162
|
- std::cout << "QgsComposerLabel::render" << std::endl;
|
2163
|
+ std::cout << "QgsComposerLabel::paint" << std::endl;
|
2164
|
|
2165
|
float size = 25.4 * mComposition->scale() * mFont.pointSizeFloat() / 72;
|
2166
|
mBoxBuffer = (int) ( size / 10 * mComposition->scale() );
|
2167
|
+ mBoxBuffer = 1;
|
2168
|
|
2169
|
+
|
2170
|
QFont font ( mFont );
|
2171
|
font.setPointSizeFloat ( size );
|
2172
|
- QFontMetrics metrics ( font );
|
2173
|
+ QFontMetricsF metrics ( font );
|
2174
|
|
2175
|
// Not sure about Style Strategy, QFont::PreferMatch ?
|
2176
|
//font.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias ) );
|
2177
|
|
2178
|
- painter.setPen ( mPen );
|
2179
|
- painter.setFont ( font );
|
2180
|
+ painter->setPen ( mPen );
|
2181
|
+ painter->setFont ( font );
|
2182
|
|
2183
|
- int x = (int) Q3CanvasPolygonalItem::x();
|
2184
|
- int y = (int) Q3CanvasPolygonalItem::y();
|
2185
|
-
|
2186
|
- int w = metrics.width ( mText );
|
2187
|
- int h = metrics.height() ;
|
2188
|
+ double w = metrics.width ( mText );
|
2189
|
+ double h = metrics.height() - metrics.descent();
|
2190
|
|
2191
|
- QRect r ( (int)(x - w/2), (int) (y - h/2), w, h );
|
2192
|
+ QRectF r (0, -h, w, h); //used as the rectangle to draw the selection boxes on the corners of if there is no box
|
2193
|
|
2194
|
- QRect boxRect;
|
2195
|
+ QRectF boxRect;
|
2196
|
if ( mBox ) {
|
2197
|
- // I don't know why, but the box seems to be too short -> add 1 * mBoxBuffer to width
|
2198
|
- boxRect.setRect ( (int)(r.x()-1.5*mBoxBuffer), r.y()-mBoxBuffer, (int)(r.width()+3*mBoxBuffer), r.height()+2*mBoxBuffer );
|
2199
|
- QBrush brush ( QColor(255,255,255) );
|
2200
|
- painter.setBrush ( brush );
|
2201
|
- painter.drawRect ( boxRect );
|
2202
|
+ //I don't know why the top coordinate is -h rather than -(h+mBoxBuffer), but it seems to work better.
|
2203
|
+ boxRect.setRect(-mBoxBuffer, -h, w + (2 * mBoxBuffer), h + (2 * mBoxBuffer));
|
2204
|
+ QBrush brush ( QColor(255,255,255) );
|
2205
|
+ painter->setBrush ( brush );
|
2206
|
+ painter->setPen(QPen(QColor(0, 0, 0), .2));
|
2207
|
+ painter->drawRect ( boxRect );
|
2208
|
}
|
2209
|
- painter.setPen ( mPen );
|
2210
|
+ painter->setPen ( mPen );
|
2211
|
|
2212
|
// The width is not sufficient in postscript
|
2213
|
- QRect tr = r;
|
2214
|
+ QRectF tr = r;
|
2215
|
tr.setWidth ( r.width() );
|
2216
|
|
2217
|
if ( plotStyle() == QgsComposition::Postscript )
|
2218
|
@@ -137,26 +143,28 @@
|
2219
|
// This metrics.ascent() is empirical
|
2220
|
size = metrics.ascent() * 72.0 / mComposition->resolution();
|
2221
|
font.setPointSizeF ( size );
|
2222
|
- painter.setFont ( font );
|
2223
|
+ painter->setFont ( font );
|
2224
|
+std::cout << "label using PS render size" << std::endl;
|
2225
|
}
|
2226
|
- painter.drawText ( x-w/2,(int)(y+metrics.height()/2-metrics.descent()), mText );
|
2227
|
+ painter->drawText(0, 0, mText);
|
2228
|
|
2229
|
// Show selected / Highlight
|
2230
|
if ( mSelected && plotStyle() == QgsComposition::Preview ) {
|
2231
|
- QRect hr;
|
2232
|
- if ( mBox ) {
|
2233
|
- hr = boxRect;
|
2234
|
- } else {
|
2235
|
- hr = r;
|
2236
|
- }
|
2237
|
- painter.setPen( mComposition->selectionPen() );
|
2238
|
- painter.setBrush( mComposition->selectionBrush() );
|
2239
|
- int s = mComposition->selectionBoxSize();
|
2240
|
+ QRectF hr;
|
2241
|
+ if ( mBox ) {
|
2242
|
+ hr = boxRect;
|
2243
|
+ } else {
|
2244
|
+ hr = r;
|
2245
|
+ }
|
2246
|
+ painter->setPen( mComposition->selectionPen() );
|
2247
|
+ painter->setBrush( mComposition->selectionBrush() );
|
2248
|
+
|
2249
|
+ double s = mComposition->selectionBoxSize();
|
2250
|
|
2251
|
- painter.drawRect ( hr.x(), hr.y(), s, s );
|
2252
|
- painter.drawRect ( hr.x()+hr.width()-s, hr.y(), s, s );
|
2253
|
- painter.drawRect ( hr.x()+hr.width()-s, hr.y()+hr.height()-s, s, s );
|
2254
|
- painter.drawRect ( hr.x(), hr.y()+hr.height()-s, s, s );
|
2255
|
+ painter->drawRect (QRectF(hr.x(), hr.y(), s, s ));
|
2256
|
+ painter->drawRect (QRectF(hr.x()+hr.width()-s, hr.y(), s, s ));
|
2257
|
+ painter->drawRect (QRectF(hr.x()+hr.width()-s, hr.y()+hr.height()-s, s, s ));
|
2258
|
+ painter->drawRect (QRectF(hr.x(), hr.y()+hr.height()-s, s, s ));
|
2259
|
}
|
2260
|
}
|
2261
|
|
2262
|
@@ -164,70 +172,75 @@
|
2263
|
{
|
2264
|
bool result;
|
2265
|
|
2266
|
- QRect r = boundingRect();
|
2267
|
+ QRectF r = boundingRect();
|
2268
|
|
2269
|
mFont = QFontDialog::getFont(&result, mFont, this );
|
2270
|
|
2271
|
if ( result ) {
|
2272
|
- Q3CanvasPolygonalItem::invalidate();
|
2273
|
- Q3CanvasPolygonalItem::canvas()->setChanged(r);
|
2274
|
- Q3CanvasPolygonalItem::update();
|
2275
|
- Q3CanvasPolygonalItem::canvas()->update();
|
2276
|
+ QAbstractGraphicsShapeItem::prepareGeometryChange();
|
2277
|
+ QAbstractGraphicsShapeItem::update();
|
2278
|
}
|
2279
|
writeSettings();
|
2280
|
}
|
2281
|
|
2282
|
void QgsComposerLabel::on_mBoxCheckBox_clicked()
|
2283
|
{
|
2284
|
- QRect r = boundingRect();
|
2285
|
+ QRectF r = boundingRect();
|
2286
|
|
2287
|
mBox = mBoxCheckBox->isChecked();
|
2288
|
|
2289
|
- Q3CanvasPolygonalItem::invalidate();
|
2290
|
- Q3CanvasPolygonalItem::canvas()->setChanged(r);
|
2291
|
- Q3CanvasPolygonalItem::update();
|
2292
|
- Q3CanvasPolygonalItem::canvas()->update();
|
2293
|
-
|
2294
|
+ QAbstractGraphicsShapeItem::prepareGeometryChange();
|
2295
|
+ QAbstractGraphicsShapeItem::update();
|
2296
|
writeSettings();
|
2297
|
}
|
2298
|
|
2299
|
-QRect QgsComposerLabel::boundingRect ( void ) const
|
2300
|
+QRectF QgsComposerLabel::boundingRect ( void ) const
|
2301
|
{
|
2302
|
// Recalculate sizes according to current font size
|
2303
|
|
2304
|
- float size = 25.4 * mComposition->scale() * mFont.pointSize() / 72;
|
2305
|
-
|
2306
|
+ float size = 25.4 * mComposition->scale() * mFont.pointSizeFloat() / 72;
|
2307
|
+
|
2308
|
QFont font ( mFont );
|
2309
|
font.setPointSizeFloat ( size );
|
2310
|
-
|
2311
|
QFontMetrics metrics ( font );
|
2312
|
-
|
2313
|
- int x = (int) Q3CanvasPolygonalItem::x();
|
2314
|
- int y = (int) Q3CanvasPolygonalItem::y();
|
2315
|
+
|
2316
|
int w = metrics.width ( mText );
|
2317
|
- int h = metrics.height() ;
|
2318
|
-
|
2319
|
+ int h = metrics.height() - metrics.descent();
|
2320
|
+
|
2321
|
+/*
|
2322
|
int buf = 0;
|
2323
|
|
2324
|
if ( mBox ) {
|
2325
|
buf = (int) ( size / 10 * mComposition->scale() + 2 ); // 2 is for line width
|
2326
|
}
|
2327
|
|
2328
|
- QRect r ( (int)(x - w/2 - 1.5*buf), (int) (y - h/2 - buf), (int)(w+3*buf), h+2*buf );
|
2329
|
+ QRectF r ( (int)(x - w/2 - 1.5*buf), (int) (y - h/2 - buf), (int)(w+3*buf), h+2*buf );
|
2330
|
+*/
|
2331
|
|
2332
|
+QRectF r;
|
2333
|
+
|
2334
|
+ if(mBox){
|
2335
|
+ //what happens if we haven't called paint() first?
|
2336
|
+ r.setRect(-mBoxBuffer, -h, w + (2 * mBoxBuffer), h + (2 * mBoxBuffer));
|
2337
|
+ }
|
2338
|
+ else{
|
2339
|
+ r.setRect(0, -h, w, h);
|
2340
|
+ }
|
2341
|
+
|
2342
|
return r;
|
2343
|
+
|
2344
|
}
|
2345
|
|
2346
|
-Q3PointArray QgsComposerLabel::areaPoints() const
|
2347
|
+QPolygonF QgsComposerLabel::areaPoints() const
|
2348
|
{
|
2349
|
std::cout << "QgsComposerLabel::areaPoints" << std::endl;
|
2350
|
- QRect r = boundingRect();
|
2351
|
+ QRectF r = boundingRect();
|
2352
|
|
2353
|
- Q3PointArray pa(4);
|
2354
|
- pa[0] = QPoint( r.x(), r.y() );
|
2355
|
- pa[1] = QPoint( r.x()+r.width(), r.y() );
|
2356
|
- pa[2] = QPoint( r.x()+r.width(), r.y()+r.height() );
|
2357
|
- pa[3] = QPoint( r.x(), r.y()+r.height() );
|
2358
|
+ QPolygonF pa;
|
2359
|
+ pa << QPointF( r.x(), r.y() );
|
2360
|
+ pa << QPointF( r.x()+r.width(), r.y() );
|
2361
|
+ pa << QPointF( r.x()+r.width(), r.y()+r.height() );
|
2362
|
+ pa << QPointF( r.x(), r.y()+r.height() );
|
2363
|
|
2364
|
return pa ;
|
2365
|
}
|
2366
|
@@ -241,12 +254,10 @@
|
2367
|
|
2368
|
void QgsComposerLabel::on_mTextLineEdit_returnPressed()
|
2369
|
{
|
2370
|
- QRect r = boundingRect();
|
2371
|
+ QRectF r = boundingRect();
|
2372
|
mText = mTextLineEdit->text();
|
2373
|
- Q3CanvasPolygonalItem::invalidate();
|
2374
|
- Q3CanvasPolygonalItem::canvas()->setChanged(r);
|
2375
|
- Q3CanvasPolygonalItem::update();
|
2376
|
- Q3CanvasPolygonalItem::canvas()->update();
|
2377
|
+ QAbstractGraphicsShapeItem::prepareGeometryChange();
|
2378
|
+ QAbstractGraphicsShapeItem::update();
|
2379
|
writeSettings();
|
2380
|
}
|
2381
|
|
2382
|
@@ -254,7 +265,7 @@
|
2383
|
{
|
2384
|
std::cout << "QgsComposerLabel::setSelected" << std::endl;
|
2385
|
mSelected = s;
|
2386
|
- Q3CanvasPolygonalItem::update(); // show highlight
|
2387
|
+ QAbstractGraphicsShapeItem::update(); // show highlight
|
2388
|
|
2389
|
std::cout << "mSelected = " << mSelected << std::endl;
|
2390
|
}
|
2391
|
@@ -277,8 +288,8 @@
|
2392
|
|
2393
|
QgsProject::instance()->writeEntry( "Compositions", path+"text", mText );
|
2394
|
|
2395
|
- QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)Q3CanvasPolygonalItem::x()) );
|
2396
|
- QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)Q3CanvasPolygonalItem::y()) );
|
2397
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QAbstractGraphicsShapeItem::x()) );
|
2398
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QAbstractGraphicsShapeItem::y()) );
|
2399
|
|
2400
|
QgsProject::instance()->writeEntry( "Compositions", path+"font/size", mFont.pointSize() );
|
2401
|
QgsProject::instance()->writeEntry( "Compositions", path+"font/family", mFont.family() );
|
2402
|
@@ -302,9 +313,8 @@
|
2403
|
mText = QgsProject::instance()->readEntry("Compositions", path+"text", "???", &ok);
|
2404
|
|
2405
|
int x = mComposition->fromMM( QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok) );
|
2406
|
- Q3CanvasPolygonalItem::setX( x );
|
2407
|
int y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok) );
|
2408
|
- Q3CanvasPolygonalItem::setY( y );
|
2409
|
+ QAbstractGraphicsShapeItem::setPos(x,y);
|
2410
|
|
2411
|
mFont.setFamily ( QgsProject::instance()->readEntry("Compositions", path+"font/family", "", &ok) );
|
2412
|
mFont.setPointSize ( QgsProject::instance()->readNumEntry("Compositions", path+"font/size", 10, &ok) );
|
2413
|
@@ -314,7 +324,7 @@
|
2414
|
|
2415
|
mBox = QgsProject::instance()->readBoolEntry("Compositions", path+"box", false, &ok);
|
2416
|
|
2417
|
- Q3CanvasPolygonalItem::update();
|
2418
|
+ QAbstractGraphicsShapeItem::update();
|
2419
|
|
2420
|
return true;
|
2421
|
}
|
2422
|
Index: src/app/composer/qgscomposer.cpp
|
2423
|
===================================================================
|
2424
|
--- src/app/composer/qgscomposer.cpp (revision 7070)
|
2425
|
+++ src/app/composer/qgscomposer.cpp (working copy)
|
2426
|
@@ -31,18 +31,20 @@
|
2427
|
#include <QMatrix>
|
2428
|
#include <QMessageBox>
|
2429
|
#include <QPainter>
|
2430
|
-#include <Q3Picture>
|
2431
|
+
|
2432
|
#include <QPrinter>
|
2433
|
#include <QPrintDialog>
|
2434
|
#include <QSettings>
|
2435
|
#include <QIcon>
|
2436
|
#include <QPixmap>
|
2437
|
+#include <Q3Picture>
|
2438
|
#include <QToolBar>
|
2439
|
#include <QImageWriter>
|
2440
|
#include <QCheckBox>
|
2441
|
#include <QSizeGrip>
|
2442
|
#include <iostream>
|
2443
|
|
2444
|
+#include <Q3ValueList>
|
2445
|
|
2446
|
QgsComposer::QgsComposer( QgisApp *qgis): QMainWindow()
|
2447
|
{
|
2448
|
@@ -212,6 +214,8 @@
|
2449
|
|
2450
|
void QgsComposer::zoomFull(void)
|
2451
|
{
|
2452
|
+//can we just use QGraphicsView::fitInView with the "paper" rect?
|
2453
|
+
|
2454
|
QMatrix m;
|
2455
|
|
2456
|
// scale
|
2457
|
@@ -226,22 +230,24 @@
|
2458
|
m.translate ( dx, dy );
|
2459
|
m.scale( scale, scale );
|
2460
|
|
2461
|
- mView->setWorldMatrix( m );
|
2462
|
- mView->repaintContents();
|
2463
|
+ mView->setMatrix( m );
|
2464
|
+// mView->repaintContents(); //needed?
|
2465
|
+
|
2466
|
}
|
2467
|
|
2468
|
void QgsComposer::on_mActionZoomAll_activated(void)
|
2469
|
{
|
2470
|
zoomFull();
|
2471
|
}
|
2472
|
-
|
2473
|
+/*
|
2474
|
QMatrix QgsComposer::updateMatrix(double scaleChange)
|
2475
|
{
|
2476
|
- double scale = mView->worldMatrix().m11() * scaleChange; // get new scale
|
2477
|
|
2478
|
+ double scale = mView->matrix().m11() * scaleChange; // get new scale
|
2479
|
+
|
2480
|
double dx = ( mView->width() - scale * mComposition->canvas()->width() ) / 2;
|
2481
|
double dy = ( mView->height() - scale * mComposition->canvas()->height() ) / 2;
|
2482
|
-
|
2483
|
+
|
2484
|
// don't translate if composition is bigger than view
|
2485
|
if (dx < 0) dx = 0;
|
2486
|
if (dy < 0) dy = 0;
|
2487
|
@@ -251,26 +257,25 @@
|
2488
|
m.translate ( dx, dy );
|
2489
|
m.scale ( scale, scale );
|
2490
|
return m;
|
2491
|
+
|
2492
|
}
|
2493
|
-
|
2494
|
+*/
|
2495
|
void QgsComposer::on_mActionZoomIn_activated(void)
|
2496
|
{
|
2497
|
- QMatrix m = updateMatrix(2);
|
2498
|
- mView->setWorldMatrix( m );
|
2499
|
- mView->repaintContents();
|
2500
|
+ mView->scale(2, 2);
|
2501
|
+ mView->update();
|
2502
|
}
|
2503
|
|
2504
|
void QgsComposer::on_mActionZoomOut_activated(void)
|
2505
|
{
|
2506
|
- QMatrix m = updateMatrix(0.5);
|
2507
|
- mView->setWorldMatrix( m );
|
2508
|
- mView->repaintContents();
|
2509
|
+ mView->scale(.5, .5);
|
2510
|
+ mView->update();
|
2511
|
}
|
2512
|
|
2513
|
void QgsComposer::on_mActionRefreshView_activated(void)
|
2514
|
{
|
2515
|
mComposition->refresh();
|
2516
|
- mView->repaintContents();
|
2517
|
+ mView->update();
|
2518
|
}
|
2519
|
|
2520
|
void QgsComposer::on_mActionPrint_activated(void)
|
2521
|
@@ -289,15 +294,16 @@
|
2522
|
* important but bigger is better because it lefts enough space
|
2523
|
* in BoundingBox definition), then the file is reopened,
|
2524
|
* and the BoundingBox is redefined.
|
2525
|
- */
|
2526
|
+ */
|
2527
|
|
2528
|
// NOTE: QT 3.2 has QPrinter::setOptionEnabled but only for three options
|
2529
|
- if ( !mPrinter ) {
|
2530
|
+ if (!mPrinter)
|
2531
|
+ {
|
2532
|
|
2533
|
- mPrinter = new QPrinter ( QPrinter::PrinterResolution );
|
2534
|
+ mPrinter = new QPrinter(QPrinter::PrinterResolution);
|
2535
|
//mPrinter = new QPrinter ( QPrinter::HighResolution );
|
2536
|
//mPrinter = new QPrinter ( QPrinter::ScreenResolution );
|
2537
|
- mPrinter->setFullPage ( true );
|
2538
|
+ mPrinter->setFullPage(true);
|
2539
|
#ifndef Q_OS_MACX
|
2540
|
// For Qt/Mac 3, don't set outputToFile to true before calling setup
|
2541
|
// because it wiil suppress the Print dialog and output to file without
|
2542
|
@@ -305,287 +311,321 @@
|
2543
|
// The Mac Print dialog provides an option to create a pdf which is
|
2544
|
// intended to be invisible to the application. If an eps is desired,
|
2545
|
// a custom Mac Print dialog is needed.
|
2546
|
-
|
2547
|
+
|
2548
|
// There is a bug in Qt<=4.2.2 (dialog is not correct) if output is set to file
|
2549
|
// => disable until they fix it
|
2550
|
//mPrinter->setOutputToFile (true ) ;
|
2551
|
//mPrinter->setOutputFileName ( QDir::convertSeparators ( QDir::home().path() + "/" + "qgis.eps") );
|
2552
|
#endif
|
2553
|
+ mPrinter->setColorMode(QPrinter::Color);
|
2554
|
+ mPrinter->setPageSize(QPrinter::A4); //would be nice set this based on the composition paper size
|
2555
|
+ } else
|
2556
|
+ {
|
2557
|
+ // Because of bug in Qt<=4.2.2 (dialog is not correct) we have to reset always
|
2558
|
+ // to printer otherwise print to file is checked but printer combobox is in dialog
|
2559
|
+ mPrinter->setOutputToFile(false);
|
2560
|
+ }
|
2561
|
|
2562
|
- if ( mComposition->paperOrientation() == QgsComposition::Portrait ) {
|
2563
|
- mPrinter->setOrientation ( QPrinter::Portrait );
|
2564
|
- } else {
|
2565
|
- mPrinter->setOrientation ( QPrinter::Landscape );
|
2566
|
- }
|
2567
|
- mPrinter->setColorMode ( QPrinter::Color );
|
2568
|
- mPrinter->setPageSize ( QPrinter::A4 );
|
2569
|
- }
|
2570
|
- else
|
2571
|
+ //set the resolution and paper orientation each time we call up the dialog, not just the first time we run it
|
2572
|
+ mPrinter->setResolution(mComposition->resolution());
|
2573
|
+ if (mComposition->paperOrientation() == QgsComposition::Portrait)
|
2574
|
{
|
2575
|
- // Because of bug in Qt<=4.2.2 (dialog is not correct) we have to reset always
|
2576
|
- // to printer otherwise print to file is checked but printer combobox is in dialog
|
2577
|
- mPrinter->setOutputToFile (false) ;
|
2578
|
+ mPrinter->setOrientation(QPrinter::Portrait);
|
2579
|
+ } else
|
2580
|
+ {
|
2581
|
+ mPrinter->setOrientation(QPrinter::Landscape);
|
2582
|
}
|
2583
|
|
2584
|
- mPrinter->setResolution ( mComposition->resolution() );
|
2585
|
|
2586
|
//if ( mPrinter->setup(this) ) {
|
2587
|
- QPrintDialog printDialog ( mPrinter, this);
|
2588
|
- if ( printDialog.exec() == QDialog::Accepted )
|
2589
|
- {
|
2590
|
- // TODO: mPrinter->setup() moves the composer under Qgisapp, get it to foreground somehow
|
2591
|
- // raise() for now, is it something better?
|
2592
|
- raise ();
|
2593
|
+ QPrintDialog printDialog(mPrinter, this);
|
2594
|
+ if (printDialog.exec() == QDialog::Accepted)
|
2595
|
+ {
|
2596
|
+ // TODO: mPrinter->setup() moves the composer under Qgisapp, get it to foreground somehow
|
2597
|
+ // raise() for now, is it something better?
|
2598
|
+ raise();
|
2599
|
|
2600
|
- // TODO: Qt does not add pagesize to output file, it can cause problems if ps2pdf is used
|
2601
|
- // or if default page on printer is different.
|
2602
|
- // We should add somewhere in output file:
|
2603
|
- // << /PageSize [ %d %d ] >> setpagedevice
|
2604
|
- // %d %d is width and height in points
|
2605
|
-
|
2606
|
- // WARNING: If QCanvasView recieves repaint signal during the printing
|
2607
|
- // (e.g. covered by QPrinter::setup dialog) it breaks somehow drawing of QCanvas items
|
2608
|
- // (for example not all features in the map are drawn.
|
2609
|
- // I don't know how to stop temporarily updating, (I don't want to reimplement
|
2610
|
- // repaint in QCanvasView, so I unset the view, print and reset.
|
2611
|
- mView->setCanvas(0);
|
2612
|
+ // TODO: Qt does not add pagesize to output file, it can cause problems if ps2pdf is used
|
2613
|
+ // or if default page on printer is different.
|
2614
|
+ // We should add somewhere in output file:
|
2615
|
+ // << /PageSize [ %d %d ] >> setpagedevice
|
2616
|
+ // %d %d is width and height in points
|
2617
|
|
2618
|
- int resolution = mPrinter->resolution();
|
2619
|
+ // WARNING: If QCanvasView recieves repaint signal during the printing
|
2620
|
+ // (e.g. covered by QPrinter::setup dialog) it breaks somehow drawing of QCanvas items
|
2621
|
+ // (for example not all features in the map are drawn.
|
2622
|
+ // I don't know how to stop temporarily updating, (I don't want to reimplement
|
2623
|
+ // repaint in QCanvasView, so I unset the view, print and reset.
|
2624
|
+ mView->setScene(0);
|
2625
|
|
2626
|
- std::cout << "Resolution = " << resolution << std::endl;
|
2627
|
+ int resolution = mPrinter->resolution();
|
2628
|
|
2629
|
- double scale = resolution / 25.4 / mComposition->scale();
|
2630
|
+ std::cout << "Resolution = " << resolution << std::endl;
|
2631
|
|
2632
|
- mComposition->setPlotStyle ( QgsComposition::Postscript );
|
2633
|
+ double scale = resolution / 25.4 / mComposition->scale();
|
2634
|
|
2635
|
- if ( !mPrinter->outputFileName().isNull() ) {
|
2636
|
- try {
|
2637
|
- std::cout << "Print to file" << std::endl;
|
2638
|
+ mComposition->setPlotStyle(QgsComposition::Postscript);
|
2639
|
|
2640
|
- QPrinter::PageSize psize (QPrinter::A4); //default to A4
|
2641
|
-
|
2642
|
- // WARNING mPrinter->outputFormat() returns always 0 in Qt 4.2.2
|
2643
|
- // => we have to check extension
|
2644
|
- bool isPs = false;
|
2645
|
- if ( mPrinter->outputFileName().right(3).toLower() == ".ps"
|
2646
|
- || mPrinter->outputFileName().right(4).toLower() == ".eps" )
|
2647
|
- {
|
2648
|
- isPs = true;
|
2649
|
- }
|
2650
|
- //if ( mPrinter->outputFormat() == QPrinter::PostScriptFormat )
|
2651
|
- if ( isPs )
|
2652
|
- {
|
2653
|
- // NOTE: setPageSize after setup() works, but setOrientation does not
|
2654
|
- // -> the BoundingBox must follow the orientation
|
2655
|
+ if (!mPrinter->outputFileName().isNull())
|
2656
|
+ {
|
2657
|
+ try
|
2658
|
+ {
|
2659
|
+ std::cout << "Print to file" << std::endl;
|
2660
|
|
2661
|
- psize = mPrinter->pageSize();
|
2662
|
- // B0 ( 1000x1414mm = 2835x4008pt ) is the biggest defined in Qt, a map can be bigger
|
2663
|
- // but probably not bigger than 9999x9999pt = 3527x3527mm
|
2664
|
- mPrinter->setPageSize ( QPrinter::B0 );
|
2665
|
- }
|
2666
|
+ QPrinter::PageSize psize;
|
2667
|
|
2668
|
- QPainter p(mPrinter);
|
2669
|
- p.scale ( scale, scale);
|
2670
|
+ // WARNING mPrinter->outputFormat() returns always 0 in Qt 4.2.2
|
2671
|
+ // => we have to check extension
|
2672
|
+ bool isPs = false;
|
2673
|
+ if (mPrinter->outputFileName().right(3).toLower() == ".ps" || mPrinter->outputFileName().right(4).toLower() == ".eps")
|
2674
|
+ {
|
2675
|
+ isPs = true;
|
2676
|
+ }
|
2677
|
+ //if ( mPrinter->outputFormat() == QPrinter::PostScriptFormat )
|
2678
|
+ if (isPs)
|
2679
|
+ {
|
2680
|
+ // NOTE: setPageSize after setup() works, but setOrientation does not
|
2681
|
+ // -> the BoundingBox must follow the orientation
|
2682
|
|
2683
|
- mComposition->canvas()->drawArea ( QRect(0,0,
|
2684
|
- (int) (mComposition->paperWidth() * mComposition->scale()),
|
2685
|
- (int) (mComposition->paperHeight() * mComposition->scale()) ),
|
2686
|
- &p, FALSE );
|
2687
|
+ psize = mPrinter->pageSize();
|
2688
|
+ // B0 ( 1000x1414mm = 2835x4008pt ) is the biggest defined in Qt, a map can be bigger
|
2689
|
+ // but probably not bigger than 9999x9999pt = 3527x3527mm
|
2690
|
+ mPrinter->setPageSize(QPrinter::B0);
|
2691
|
+ }
|
2692
|
|
2693
|
- p.end();
|
2694
|
+ QPainter p(mPrinter);
|
2695
|
+ p.scale(scale, scale);
|
2696
|
|
2697
|
- std::cout << "mPrinter->outputFormat() = " << mPrinter->outputFormat() << std::endl;
|
2698
|
-
|
2699
|
-
|
2700
|
- //if ( mPrinter->outputFormat() == QPrinter::PostScriptFormat )
|
2701
|
- if ( isPs )
|
2702
|
- {
|
2703
|
- // reset the page
|
2704
|
- mPrinter->setPageSize ( psize );
|
2705
|
-
|
2706
|
- QFile f(mPrinter->outputFileName());
|
2707
|
-
|
2708
|
- // Overwrite the bounding box
|
2709
|
- std::cout << "Overwrite the bounding box" << std::endl;
|
2710
|
- if (!f.open( QIODevice::ReadWrite )) {
|
2711
|
- throw QgsIOException(tr("Couldn't open " + f.name() + tr(" for read/write")));
|
2712
|
- }
|
2713
|
- Q_LONG offset = 0;
|
2714
|
- Q_LONG size;
|
2715
|
- bool found = false;
|
2716
|
- QString s;
|
2717
|
- char buf[101];
|
2718
|
- while ( !f.atEnd() ) {
|
2719
|
- size = f.readLine ( buf, 100 );
|
2720
|
- s = QString(buf);
|
2721
|
- if ( s.find ("%%BoundingBox:") == 0 ) {
|
2722
|
- found = true;
|
2723
|
- break;
|
2724
|
- }
|
2725
|
- offset += size;
|
2726
|
- }
|
2727
|
-
|
2728
|
- if ( found ) {
|
2729
|
- int w,h;
|
2730
|
-
|
2731
|
- w = (int) ( 72 * mComposition->paperWidth() / 25.4 );
|
2732
|
- h = (int) ( 72 * mComposition->paperHeight() / 25.4 );
|
2733
|
- if ( mPrinter->orientation() == QPrinter::Landscape ) {
|
2734
|
- int tmp = w; w = h; h = tmp;
|
2735
|
- }
|
2736
|
- s.sprintf( "%%%%BoundingBox: 0 0 %d %d", w, h );
|
2737
|
-
|
2738
|
- if ( s.length() > size )
|
2739
|
- {
|
2740
|
- int shift = s.length() - size;
|
2741
|
- shiftFileContent ( &f, offset + size + 1, shift );
|
2742
|
- } else {
|
2743
|
- if ( ! f.at(offset) ) {
|
2744
|
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot seek"));
|
2745
|
- } else {
|
2746
|
- /* Write spaces (for case the size > s.length() ) */
|
2747
|
- QString es;
|
2748
|
- es.fill(' ', size-1 );
|
2749
|
- f.flush();
|
2750
|
- if ( f.writeBlock ( es.toLocal8Bit().data(), size-1 ) < size-1 ) {
|
2751
|
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite BoundingBox"));
|
2752
|
- }
|
2753
|
- f.flush();
|
2754
|
- f.at(offset);
|
2755
|
- f.flush();
|
2756
|
- if ( f.writeBlock ( s.toLocal8Bit().data(), s.length() ) < s.length()-1 ) {
|
2757
|
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite BoundingBox"));
|
2758
|
- }
|
2759
|
- f.flush();
|
2760
|
- }
|
2761
|
- }
|
2762
|
- } else {
|
2763
|
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot find BoundingBox"));
|
2764
|
- }
|
2765
|
- f.close();
|
2766
|
-
|
2767
|
- // Overwrite translate
|
2768
|
- if ( mPrinter->orientation() == QPrinter::Portrait ) {
|
2769
|
- std::cout << "Orientation portraint -> overwrite translate" << std::endl;
|
2770
|
- if (!f.open( QIODevice::ReadWrite )) {
|
2771
|
- throw QgsIOException(tr("Couldn't open ") + f.name() + tr(" for read/write"));
|
2772
|
- }
|
2773
|
- offset = 0;
|
2774
|
- found = false;
|
2775
|
-
|
2776
|
- //Example Qt3:
|
2777
|
- //0 4008 translate 1 -1 scale/defM ...
|
2778
|
- //QRegExp rx ( "^0 [^ ]+ translate ([^ ]+ [^ ]+) scale/defM matrix CM d \\} d" );
|
2779
|
- //Example Qt4:
|
2780
|
- //0 0 translate 0.239999 -0.239999 scale } def
|
2781
|
- QRegExp rx ( "^0 [^ ]+ translate ([^ ]+ [^ ]+) scale \\} def" );
|
2782
|
-
|
2783
|
- while ( !f.atEnd() ) {
|
2784
|
- size = f.readLine ( buf, 100 );
|
2785
|
- s = QString(buf);
|
2786
|
- if ( rx.search( s ) != -1 ) {
|
2787
|
- found = true;
|
2788
|
- break;
|
2789
|
- }
|
2790
|
- offset += size;
|
2791
|
- }
|
2792
|
-
|
2793
|
- if ( found ) {
|
2794
|
- int trans;
|
2795
|
-
|
2796
|
- trans = (int) ( 72 * mComposition->paperHeight() / 25.4 );
|
2797
|
- std::cout << "trans = " << trans << std::endl;
|
2798
|
- //Qt3:
|
2799
|
- //s.sprintf( "0 %d translate %s scale/defM matrix CM d } d", trans, (const char *)rx.cap(1).toLocal8Bit().data() );
|
2800
|
- //Qt4:
|
2801
|
- s.sprintf( "0 %d translate %s scale } def\n", trans, (const char *)rx.cap(1).toLocal8Bit().data() );
|
2802
|
-
|
2803
|
-
|
2804
|
- std::cout << "s.length() = " << s.length() << " size = " << size << std::endl;
|
2805
|
- if ( s.length() > size ) {
|
2806
|
- //QMessageBox::warning(this, tr("Error in Print"), tr("Cannot format translate"));
|
2807
|
- // Move the content up
|
2808
|
- int shift = s.length() - size;
|
2809
|
- /*
|
2810
|
- int last = f.size() + shift -1;
|
2811
|
- for ( int i = last; i > offset + size; i-- )
|
2812
|
- {
|
2813
|
- f.at(i-shift);
|
2814
|
- QByteArray ba = f.read(1);
|
2815
|
- f.at(i);
|
2816
|
- f.write(ba);
|
2817
|
- }
|
2818
|
- */
|
2819
|
- shiftFileContent ( &f, offset + size + 1, shift );
|
2820
|
- }
|
2821
|
-
|
2822
|
- // Overwrite the row
|
2823
|
- if ( ! f.at(offset) ) {
|
2824
|
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot seek"));
|
2825
|
- } else {
|
2826
|
- /* Write spaces (for case the size > s.length() ) */
|
2827
|
- QString es;
|
2828
|
- es.fill(' ', size-1 );
|
2829
|
- f.flush();
|
2830
|
- if ( f.writeBlock ( es.toLocal8Bit().data(), size-1 ) < size-1 ) {
|
2831
|
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite translate"));
|
2832
|
- }
|
2833
|
- f.flush();
|
2834
|
- f.at(offset);
|
2835
|
- f.flush();
|
2836
|
- if ( f.writeBlock ( s.toLocal8Bit().data(), s.length() ) < s.length()-1 ) {
|
2837
|
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite translate"));
|
2838
|
- }
|
2839
|
- f.flush();
|
2840
|
- }
|
2841
|
- } else {
|
2842
|
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot find translate"));
|
2843
|
- }
|
2844
|
- f.close();
|
2845
|
- }
|
2846
|
- }
|
2847
|
- } catch (QgsIOException e) {
|
2848
|
- QMessageBox::warning(this, tr("File IO Error"), e.what());
|
2849
|
- }
|
2850
|
- } else { // print to printer
|
2851
|
- bool print = true;
|
2852
|
+ QRectF renderArea(0, 0, (mComposition->paperWidth() * mComposition->scale()),
|
2853
|
+ (mComposition->paperHeight() * mComposition->scale()));
|
2854
|
|
2855
|
- // Check size
|
2856
|
- std::cout << "Paper: " << mPrinter->widthMM() << " x " << mPrinter->heightMM() << std::endl;
|
2857
|
- if ( mComposition->paperWidth() != mPrinter->widthMM() ||
|
2858
|
- mComposition->paperHeight() != mPrinter->heightMM() )
|
2859
|
- {
|
2860
|
- int answer = QMessageBox::warning ( this, tr("Paper does not match"),
|
2861
|
- tr("The selected paper size does not match the composition size"),
|
2862
|
- QMessageBox::Ok | QMessageBox::Abort );
|
2863
|
+ mComposition->canvas()->render(&p, renderArea);
|
2864
|
|
2865
|
- if ( answer == QMessageBox::Abort )
|
2866
|
- print = false;
|
2867
|
+ p.end();
|
2868
|
|
2869
|
- }
|
2870
|
+ std::cout << "mPrinter->outputFormat() = " << mPrinter->outputFormat() << std::endl;
|
2871
|
|
2872
|
- if ( print ) {
|
2873
|
- std::cout << "Printing ... " << std::endl;
|
2874
|
- QPainter p(mPrinter);
|
2875
|
- p.scale ( scale, scale);
|
2876
|
- mComposition->canvas()->drawArea ( QRect(0,0,
|
2877
|
- (int) (mComposition->paperWidth() * mComposition->scale()),
|
2878
|
- (int) (mComposition->paperHeight() * mComposition->scale()) ),
|
2879
|
- &p, FALSE );
|
2880
|
- p.end();
|
2881
|
- std::cout << "... printing finished" << std::endl;
|
2882
|
- }
|
2883
|
- }
|
2884
|
|
2885
|
- mComposition->setPlotStyle ( QgsComposition::Preview );
|
2886
|
- mView->setCanvas(mComposition->canvas());
|
2887
|
- }
|
2888
|
- else
|
2889
|
- {
|
2890
|
- raise ();
|
2891
|
- }
|
2892
|
+ //if ( mPrinter->outputFormat() == QPrinter::PostScriptFormat )
|
2893
|
+ if (isPs)
|
2894
|
+ {
|
2895
|
+ // reset the page
|
2896
|
+ mPrinter->setPageSize(psize);
|
2897
|
+
|
2898
|
+ QFile f(mPrinter->outputFileName());
|
2899
|
+
|
2900
|
+ // Overwrite the bounding box
|
2901
|
+ std::cout << "Overwrite the bounding box" << std::endl;
|
2902
|
+ if (!f.open(QIODevice::ReadWrite))
|
2903
|
+ {
|
2904
|
+ throw QgsIOException(tr("Couldn't open " + f.name() + tr(" for read/write")));
|
2905
|
+ }
|
2906
|
+ Q_LONG offset = 0;
|
2907
|
+ Q_LONG size;
|
2908
|
+ bool found = false;
|
2909
|
+ QString s;
|
2910
|
+ char buf[101];
|
2911
|
+ while (!f.atEnd())
|
2912
|
+ {
|
2913
|
+ size = f.readLine(buf, 100);
|
2914
|
+ s = QString(buf);
|
2915
|
+ if (s.find("%%BoundingBox:") == 0)
|
2916
|
+ {
|
2917
|
+ found = true;
|
2918
|
+ break;
|
2919
|
+ }
|
2920
|
+ offset += size;
|
2921
|
+ }
|
2922
|
+
|
2923
|
+ if (found)
|
2924
|
+ {
|
2925
|
+ int w, h;
|
2926
|
+
|
2927
|
+ w = (int) (72 * mComposition->paperWidth() / 25.4);
|
2928
|
+ h = (int) (72 * mComposition->paperHeight() / 25.4);
|
2929
|
+ if (mPrinter->orientation() == QPrinter::Landscape)
|
2930
|
+ {
|
2931
|
+ int tmp = w;
|
2932
|
+ w = h;
|
2933
|
+ h = tmp;
|
2934
|
+ }
|
2935
|
+ s.sprintf("%%%%BoundingBox: 0 0 %d %d", w, h);
|
2936
|
+
|
2937
|
+ if (s.length() > size)
|
2938
|
+ {
|
2939
|
+ int shift = s.length() - size;
|
2940
|
+ shiftFileContent(&f, offset + size + 1, shift);
|
2941
|
+ } else
|
2942
|
+ {
|
2943
|
+ if (!f.at(offset))
|
2944
|
+ {
|
2945
|
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot seek"));
|
2946
|
+ } else
|
2947
|
+ {
|
2948
|
+ // Write spaces (for case the size > s.length() )
|
2949
|
+ QString es;
|
2950
|
+ es.fill(' ', size - 1);
|
2951
|
+ f.flush();
|
2952
|
+ if (f.writeBlock(es.toLocal8Bit().data(), size - 1) < size - 1)
|
2953
|
+ {
|
2954
|
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite BoundingBox"));
|
2955
|
+ }
|
2956
|
+ f.flush();
|
2957
|
+ f.at(offset);
|
2958
|
+ f.flush();
|
2959
|
+ if (f.writeBlock(s.toLocal8Bit().data(), s.length()) < s.length() - 1)
|
2960
|
+ {
|
2961
|
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite BoundingBox"));
|
2962
|
+ }
|
2963
|
+ f.flush();
|
2964
|
+ } //END else (!f.at(offset))
|
2965
|
+ } //END else (s.length() > size)
|
2966
|
+ } //END if(found)
|
2967
|
+ else
|
2968
|
+ {
|
2969
|
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot find BoundingBox"));
|
2970
|
+ }
|
2971
|
+ f.close();
|
2972
|
+
|
2973
|
+ // Overwrite translate
|
2974
|
+ if (mPrinter->orientation() == QPrinter::Portrait)
|
2975
|
+ {
|
2976
|
+ std::cout << "Orientation portraint -> overwrite translate" << std::endl;
|
2977
|
+ if (!f.open(QIODevice::ReadWrite))
|
2978
|
+ {
|
2979
|
+ throw QgsIOException(tr("Couldn't open ") + f.name() + tr(" for read/write"));
|
2980
|
+ }
|
2981
|
+ offset = 0;
|
2982
|
+ found = false;
|
2983
|
+
|
2984
|
+ //Example Qt3:
|
2985
|
+ //0 4008 translate 1 -1 scale/defM ...
|
2986
|
+ //QRegExp rx ( "^0 [^ ]+ translate ([^ ]+ [^ ]+) scale/defM matrix CM d \\} d" );
|
2987
|
+ //Example Qt4:
|
2988
|
+ //0 0 translate 0.239999 -0.239999 scale } def
|
2989
|
+ QRegExp rx("^0 [^ ]+ translate ([^ ]+ [^ ]+) scale \\} def");
|
2990
|
+
|
2991
|
+ while (!f.atEnd())
|
2992
|
+ {
|
2993
|
+ size = f.readLine(buf, 100);
|
2994
|
+ s = QString(buf);
|
2995
|
+ if (rx.search(s) != -1)
|
2996
|
+ {
|
2997
|
+ found = true;
|
2998
|
+ break;
|
2999
|
+ }
|
3000
|
+ offset += size;
|
3001
|
+ } //END while( !f.atEnd() )
|
3002
|
+
|
3003
|
+ if (found)
|
3004
|
+ {
|
3005
|
+ int trans;
|
3006
|
+
|
3007
|
+ trans = (int) (72 * mComposition->paperHeight() / 25.4);
|
3008
|
+ std::cout << "trans = " << trans << std::endl;
|
3009
|
+ //Qt3:
|
3010
|
+ //s.sprintf( "0 %d translate %s scale/defM matrix CM d } d", trans, (const char *)rx.cap(1).toLocal8Bit().data() );
|
3011
|
+ //Qt4:
|
3012
|
+ s.sprintf("0 %d translate %s scale } def\n", trans, (const char *) rx.cap(1).toLocal8Bit().data());
|
3013
|
+
|
3014
|
+ std::cout << "s.length() = " << s.length() << " size = " << size << std::endl;
|
3015
|
+ if (s.length() > size)
|
3016
|
+ {
|
3017
|
+ //QMessageBox::warning(this, tr("Error in Print"), tr("Cannot format translate"));
|
3018
|
+ // Move the content up
|
3019
|
+ int shift = s.length() - size;
|
3020
|
+ /*
|
3021
|
+ int last = f.size() + shift -1;
|
3022
|
+ for ( int i = last; i > offset + size; i-- )
|
3023
|
+ {
|
3024
|
+ f.at(i-shift);
|
3025
|
+ QByteArray ba = f.read(1);
|
3026
|
+ f.at(i);
|
3027
|
+ f.write(ba);
|
3028
|
+ }
|
3029
|
+ */
|
3030
|
+ shiftFileContent(&f, offset + size + 1, shift);
|
3031
|
+ } //END if( s.length() > size)
|
3032
|
+
|
3033
|
+ // Overwrite the row
|
3034
|
+ if (!f.at(offset))
|
3035
|
+ {
|
3036
|
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot seek"));
|
3037
|
+ } else
|
3038
|
+ {
|
3039
|
+ /* Write spaces (for case the size > s.length() ) */
|
3040
|
+ QString es;
|
3041
|
+ es.fill(' ', size - 1);
|
3042
|
+ f.flush();
|
3043
|
+ if (f.writeBlock(es.toLocal8Bit().data(), size - 1) < size - 1)
|
3044
|
+ {
|
3045
|
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite translate"));
|
3046
|
+ }
|
3047
|
+ f.flush();
|
3048
|
+ f.at(offset);
|
3049
|
+ f.flush();
|
3050
|
+ if (f.writeBlock(s.toLocal8Bit().data(), s.length()) < s.length() - 1)
|
3051
|
+ {
|
3052
|
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite translate"));
|
3053
|
+ }
|
3054
|
+ f.flush();
|
3055
|
+ } //END else
|
3056
|
+ } else
|
3057
|
+ {
|
3058
|
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot find translate"));
|
3059
|
+ }
|
3060
|
+ f.close();
|
3061
|
+ }
|
3062
|
+ }
|
3063
|
+ }
|
3064
|
+ catch(QgsIOException e)
|
3065
|
+ {
|
3066
|
+ QMessageBox::warning(this, tr("File IO Error"), e.what());
|
3067
|
+ }
|
3068
|
+ } else
|
3069
|
+ { // print to printer
|
3070
|
+ bool print = true;
|
3071
|
+
|
3072
|
+ // Check size
|
3073
|
+ std::cout << "Paper: " << mPrinter->widthMM() << " x " << mPrinter->heightMM() << std::endl;
|
3074
|
+ if (mComposition->paperWidth() != mPrinter->widthMM() || mComposition->paperHeight() != mPrinter->heightMM())
|
3075
|
+ {
|
3076
|
+ int answer = QMessageBox::warning(0, tr("Paper does not match"),
|
3077
|
+ tr("The selected paper size does not match the composition size"),
|
3078
|
+ QMessageBox::Ok, QMessageBox::Abort);
|
3079
|
+
|
3080
|
+ if (answer == QMessageBox::Abort)
|
3081
|
+ {
|
3082
|
+ print = false;
|
3083
|
+ }
|
3084
|
+ } //END if(compositionSize != paperSize)
|
3085
|
+
|
3086
|
+ if (print)
|
3087
|
+ {
|
3088
|
+ std::cout << "Printing ... " << std::endl;
|
3089
|
+ QPainter p(mPrinter);
|
3090
|
+ p.scale(scale, scale);
|
3091
|
+
|
3092
|
+ QRectF renderArea(0, 0, (mComposition->paperWidth() * mComposition->scale()),
|
3093
|
+ (mComposition->paperHeight() * mComposition->scale()));
|
3094
|
+
|
3095
|
+ mComposition->canvas()->render(&p, renderArea);
|
3096
|
+
|
3097
|
+ p.end();
|
3098
|
+ std::cout << "... printing finished" << std::endl;
|
3099
|
+ } //END if ( print )
|
3100
|
+ }
|
3101
|
+
|
3102
|
+ mComposition->setPlotStyle(QgsComposition::Preview);
|
3103
|
+ mView->setScene(mComposition->canvas());
|
3104
|
+ } else
|
3105
|
+ {
|
3106
|
+ raise();
|
3107
|
+ }
|
3108
|
+
|
3109
|
}
|
3110
|
|
3111
|
+
|
3112
|
bool QgsComposer::shiftFileContent ( QFile *file, Q_LONG start, int shift )
|
3113
|
{
|
3114
|
int last = file->size() + shift -1;
|
3115
|
@@ -602,6 +642,7 @@
|
3116
|
|
3117
|
void QgsComposer::on_mActionExportAsImage_activated(void)
|
3118
|
{
|
3119
|
+
|
3120
|
// Image size
|
3121
|
int width = (int) (mComposition->resolution() * mComposition->paperWidth() / 25.4);
|
3122
|
int height = (int) (mComposition->resolution() * mComposition->paperHeight() / 25.4);
|
3123
|
@@ -613,12 +654,12 @@
|
3124
|
#endif
|
3125
|
|
3126
|
if ( memuse > 200 ) { // cca 4500 x 4500
|
3127
|
- int answer = QMessageBox::warning ( this, tr("Big image"),
|
3128
|
+ int answer = QMessageBox::warning ( 0, tr("Big image"),
|
3129
|
tr("To create image ") + QString::number(width) + " x "
|
3130
|
+ QString::number(height)
|
3131
|
+ tr(" requires circa ")
|
3132
|
+ QString::number(memuse) + tr(" MB of memory"),
|
3133
|
- QMessageBox::Ok | QMessageBox::Abort );
|
3134
|
+ QMessageBox::Ok, QMessageBox::Abort );
|
3135
|
|
3136
|
raise ();
|
3137
|
if ( answer == QMessageBox::Abort ) return;
|
3138
|
@@ -633,7 +674,7 @@
|
3139
|
|
3140
|
//find out the last used filter
|
3141
|
QSettings myQSettings; // where we keep last used filter in persistant state
|
3142
|
- QString myLastUsedFormat = myQSettings.readEntry("/UI/lastSaveAsImageFormat", "PNG" );
|
3143
|
+ QString myLastUsedFormat = myQSettings.readEntry("/UI/lastSaveAsImageFormat", "PNG" ); //<- BUG #729 is probably here
|
3144
|
QString myLastUsedFile = myQSettings.readEntry("/UI/lastSaveAsImageFile","qgis.png");
|
3145
|
QFileInfo file(myLastUsedFile);
|
3146
|
|
3147
|
@@ -704,27 +745,32 @@
|
3148
|
|
3149
|
double scale = (double) (mComposition->resolution() / 25.4 / mComposition->scale());
|
3150
|
|
3151
|
- mView->setCanvas(0);
|
3152
|
+ mView->setScene(0);
|
3153
|
mComposition->setPlotStyle ( QgsComposition::Print );
|
3154
|
|
3155
|
QPixmap pixmap ( width, height );
|
3156
|
pixmap.fill ( QColor(255,255,255) ) ;
|
3157
|
QPainter p(&pixmap);
|
3158
|
- p.scale ( scale, scale);
|
3159
|
- mComposition->canvas()->drawArea ( QRect(0,0,
|
3160
|
- (int) (mComposition->paperWidth() * mComposition->scale()),
|
3161
|
- (int) (mComposition->paperHeight() * mComposition->scale()) ),
|
3162
|
- &p, FALSE );
|
3163
|
+ p.scale ( scale, scale);
|
3164
|
+
|
3165
|
+QRectF renderArea(0,0,(mComposition->paperWidth() * mComposition->scale()),(mComposition->paperHeight() * mComposition->scale()));
|
3166
|
+
|
3167
|
+ mComposition->canvas()->render(&p, renderArea);
|
3168
|
p.end();
|
3169
|
|
3170
|
mComposition->setPlotStyle ( QgsComposition::Preview );
|
3171
|
- mView->setCanvas(mComposition->canvas());
|
3172
|
+ mView->setScene(mComposition->canvas());
|
3173
|
|
3174
|
pixmap.save ( myOutputFileNameQString, myFilterMap[myFilterString].toLocal8Bit().data() );
|
3175
|
}
|
3176
|
|
3177
|
+
|
3178
|
void QgsComposer::on_mActionExportAsSVG_activated(void)
|
3179
|
{
|
3180
|
+
|
3181
|
+// QT 4 QPicture does not support export to SVG, so we're still using Q3Picture.
|
3182
|
+// When QGIS moves to Qt 4.3, we can use QSvgGenerator instead.
|
3183
|
+
|
3184
|
QSettings myQSettings;
|
3185
|
|
3186
|
bool displaySVGWarning = myQSettings.value("/UI/displaySVGWarning", true).toBool();
|
3187
|
@@ -747,53 +793,56 @@
|
3188
|
"to PostScript if the SVG output is not "
|
3189
|
"satisfactory."
|
3190
|
"</p>"));
|
3191
|
- m->showMessage();
|
3192
|
+ m->exec();
|
3193
|
|
3194
|
if (m->checkBoxState() == Qt::Checked)
|
3195
|
- myQSettings.setValue("/UI/displaySVGWarning", false);
|
3196
|
+ {
|
3197
|
+ myQSettings.setValue("/UI/displaySVGWarning", false); //turn off the warning next time
|
3198
|
+ }
|
3199
|
else
|
3200
|
+ {
|
3201
|
myQSettings.setValue("/UI/displaySVGWarning", true);
|
3202
|
+ }
|
3203
|
+ //delete m; // this causes a segfault
|
3204
|
+
|
3205
|
}
|
3206
|
-
|
3207
|
QString myLastUsedFile = myQSettings.readEntry("/UI/lastSaveAsSvgFile","qgis.svg");
|
3208
|
QFileInfo file(myLastUsedFile);
|
3209
|
-
|
3210
|
QFileDialog *myQFileDialog = new QFileDialog( this, tr("Choose a filename to save the map as"),
|
3211
|
file.path(), tr("SVG Format") + " (*.svg *SVG)" );
|
3212
|
-
|
3213
|
myQFileDialog->selectFile( file.fileName() );
|
3214
|
myQFileDialog->setMode(QFileDialog::AnyFile);
|
3215
|
myQFileDialog->setAcceptMode(QFileDialog::AcceptSave);
|
3216
|
|
3217
|
int result = myQFileDialog->exec();
|
3218
|
raise ();
|
3219
|
-
|
3220
|
if ( result != QDialog::Accepted) return;
|
3221
|
+
|
3222
|
QString myOutputFileNameQString = myQFileDialog->selectedFile();
|
3223
|
-
|
3224
|
if ( myOutputFileNameQString == "" ) return;
|
3225
|
|
3226
|
myQSettings.writeEntry("/UI/lastSaveAsSvgFile", myOutputFileNameQString);
|
3227
|
|
3228
|
- mView->setCanvas(0);
|
3229
|
+ mView->setScene(0);//don't redraw the scene on the display while we render
|
3230
|
mComposition->setPlotStyle ( QgsComposition::Print );
|
3231
|
|
3232
|
Q3Picture pic;
|
3233
|
QPainter p(&pic);
|
3234
|
- mComposition->canvas()->drawArea ( QRect(0,0,
|
3235
|
- (int) (mComposition->paperWidth() * mComposition->scale()),
|
3236
|
- (int) (mComposition->paperHeight() * mComposition->scale()) ),
|
3237
|
- &p, FALSE );
|
3238
|
+ QRectF renderArea(0,0, (mComposition->paperWidth() * mComposition->scale()), (mComposition->paperHeight() * mComposition->scale()) );
|
3239
|
+
|
3240
|
+ mComposition->canvas()->render(&p, renderArea);
|
3241
|
p.end();
|
3242
|
|
3243
|
mComposition->setPlotStyle ( QgsComposition::Preview );
|
3244
|
- mView->setCanvas(mComposition->canvas());
|
3245
|
+ mView->setScene(mComposition->canvas()); //now that we're done, set the view to show the scene again
|
3246
|
|
3247
|
QRect br = pic.boundingRect();
|
3248
|
|
3249
|
pic.save ( myOutputFileNameQString, "svg" );
|
3250
|
+
|
3251
|
}
|
3252
|
|
3253
|
+
|
3254
|
void QgsComposer::setToolActionsOff(void)
|
3255
|
{
|
3256
|
mActionOpenTemplate->setOn ( false );
|
3257
|
@@ -875,6 +924,7 @@
|
3258
|
#ifdef QGISDEBUG
|
3259
|
std::cout << "QgsComposer::saveWindowState" << std::endl;
|
3260
|
#endif
|
3261
|
+
|
3262
|
QSettings settings;
|
3263
|
|
3264
|
QPoint p = this->pos();
|
3265
|
@@ -890,10 +940,15 @@
|
3266
|
settings.writeEntry("/Composer/geometry/wiev", (int)(*it) );
|
3267
|
it++;
|
3268
|
settings.writeEntry("/Composer/geometry/options", (int)(*it) );
|
3269
|
+
|
3270
|
+if(this->isMaximized()){
|
3271
|
+ std::cout << "maximized!" << std::endl;
|
3272
|
}
|
3273
|
+}
|
3274
|
|
3275
|
void QgsComposer::restoreWindowState()
|
3276
|
{
|
3277
|
+
|
3278
|
QSettings settings;
|
3279
|
|
3280
|
QDesktopWidget *d = QApplication::desktop();
|
3281
|
@@ -906,6 +961,10 @@
|
3282
|
resize(w, h);
|
3283
|
move(x, y);
|
3284
|
|
3285
|
+//We also need to save the maximized state
|
3286
|
+
|
3287
|
+//std::cout << "x: " << x << "y: " << y << "w: " << w << "h: " << h << std::endl;
|
3288
|
+
|
3289
|
// This doesn't work
|
3290
|
Q3ValueList<int> list;
|
3291
|
w = settings.readNumEntry("/Composer/geometry/view", 300);
|
3292
|
@@ -913,6 +972,7 @@
|
3293
|
w = settings.readNumEntry("/Composer/geometry/options", 300);
|
3294
|
list.push_back( w );
|
3295
|
mSplitter->setSizes ( list );
|
3296
|
+
|
3297
|
}
|
3298
|
|
3299
|
void QgsComposer::on_helpPButton_clicked()
|
3300
|
Index: src/app/composer/qgscomposerview.h
|
3301
|
===================================================================
|
3302
|
--- src/app/composer/qgscomposerview.h (revision 7070)
|
3303
|
+++ src/app/composer/qgscomposerview.h (working copy)
|
3304
|
@@ -18,14 +18,15 @@
|
3305
|
#ifndef QGSCOMPOSERVIEW_H
|
3306
|
#define QGSCOMPOSERVIEW_H
|
3307
|
|
3308
|
-#include <Q3Canvas>
|
3309
|
-#include <Q3CanvasView>
|
3310
|
|
3311
|
+#include <QGraphicsScene>
|
3312
|
+#include <QGraphicsView>
|
3313
|
+
|
3314
|
class QgsComposer;
|
3315
|
class QKeyEvent;
|
3316
|
class QMouseEvent;
|
3317
|
|
3318
|
-class QgsComposerView: public Q3CanvasView
|
3319
|
+class QgsComposerView: public QGraphicsView
|
3320
|
{
|
3321
|
Q_OBJECT
|
3322
|
|
3323
|
@@ -33,9 +34,9 @@
|
3324
|
QgsComposerView (QgsComposer *composer, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
|
3325
|
|
3326
|
protected:
|
3327
|
- void contentsMousePressEvent(QMouseEvent*);
|
3328
|
- void contentsMouseReleaseEvent(QMouseEvent*);
|
3329
|
- void contentsMouseMoveEvent(QMouseEvent*);
|
3330
|
+ void mousePressEvent(QMouseEvent*);
|
3331
|
+ void mouseReleaseEvent(QMouseEvent*);
|
3332
|
+ void mouseMoveEvent(QMouseEvent*);
|
3333
|
|
3334
|
void keyPressEvent ( QKeyEvent * e );
|
3335
|
void resizeEvent ( QResizeEvent * );
|
3336
|
Index: src/app/composer/qgscomposerpicture.h
|
3337
|
===================================================================
|
3338
|
--- src/app/composer/qgscomposerpicture.h (revision 7070)
|
3339
|
+++ src/app/composer/qgscomposerpicture.h (working copy)
|
3340
|
@@ -19,10 +19,10 @@
|
3341
|
|
3342
|
#include "ui_qgscomposerpicturebase.h"
|
3343
|
#include "qgscomposeritem.h"
|
3344
|
-#include <Q3CanvasPolygonalItem>
|
3345
|
+#include <QAbstractGraphicsShapeItem>
|
3346
|
#include <QPen>
|
3347
|
-#include <Q3Picture>
|
3348
|
-#include <Q3PointArray>
|
3349
|
+#include <QPicture>
|
3350
|
+#include <QPolygonF>
|
3351
|
#include <QRect>
|
3352
|
|
3353
|
class QgsComposition;
|
3354
|
@@ -36,8 +36,7 @@
|
3355
|
// NOTE: QgsComposerPictureBase must be first, otherwise does not compile
|
3356
|
// public QCanvasRectangle,
|
3357
|
class QgsComposerPicture : public QWidget, private Ui::QgsComposerPictureBase,
|
3358
|
- public Q3CanvasPolygonalItem,
|
3359
|
- public QgsComposerItem
|
3360
|
+ public QAbstractGraphicsShapeItem, public QgsComposerItem
|
3361
|
{
|
3362
|
Q_OBJECT
|
3363
|
|
3364
|
@@ -68,17 +67,12 @@
|
3365
|
|
3366
|
|
3367
|
// Reimplement QCanvasItem::boundingRect
|
3368
|
- QRect boundingRect ( void ) const;
|
3369
|
+ QRectF boundingRect ( void ) const;
|
3370
|
|
3371
|
- Q3PointArray areaPoints() const;
|
3372
|
+ QPolygonF areaPoints() const;
|
3373
|
|
3374
|
- // Reimplemented
|
3375
|
- void moveBy( double x, double y);
|
3376
|
-
|
3377
|
- /** \brief Reimplementation of QCanvasItem::draw - draw on canvas */
|
3378
|
- void draw ( QPainter & painter );
|
3379
|
-
|
3380
|
- void drawShape( QPainter & painter );
|
3381
|
+ /** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
|
3382
|
+ void paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
|
3383
|
|
3384
|
/** \brief Set values in GUI to current values */
|
3385
|
void setOptions ( void );
|
3386
|
@@ -88,7 +82,7 @@
|
3387
|
|
3388
|
// Set box, picture will be inside box, used when placed by mouse.
|
3389
|
// Coordinates do not need to be oriented
|
3390
|
- void setBox ( int x1, int y1, int x2, int y2 );
|
3391
|
+ void setSize(double width, double height );
|
3392
|
|
3393
|
// Picture dialog, returns file name or empty string
|
3394
|
static QString pictureDialog ( void );
|
3395
|
@@ -117,7 +111,7 @@
|
3396
|
QString mPicturePath;
|
3397
|
|
3398
|
// Picture
|
3399
|
- Q3Picture mPicture;
|
3400
|
+ QPicture mPicture;
|
3401
|
|
3402
|
bool mPictureValid;
|
3403
|
|
3404
|
@@ -127,8 +121,8 @@
|
3405
|
// Coordinates of upper left picture corner
|
3406
|
int mX, mY;
|
3407
|
|
3408
|
- // Picture width and height in paper
|
3409
|
- int mWidth, mHeight;
|
3410
|
+ // Picture width and height in scene units
|
3411
|
+ double mWidth, mHeight;
|
3412
|
|
3413
|
// Scale, number of canvas units / image unit
|
3414
|
|
3415
|
@@ -147,13 +141,13 @@
|
3416
|
/** \brief Calculate size according to current settings */
|
3417
|
void recalculate ( void );
|
3418
|
|
3419
|
- Q3PointArray mAreaPoints;
|
3420
|
+ QPolygonF mAreaPoints;
|
3421
|
|
3422
|
// Called when picture file is changed
|
3423
|
void pictureChanged ( void );
|
3424
|
|
3425
|
// Current bounding box
|
3426
|
- QRect mBoundingRect;
|
3427
|
+ QRectF mBoundingRect;
|
3428
|
|
3429
|
// Adjust size so that picture fits to current box
|
3430
|
void adjustPictureSize();
|
3431
|
Index: src/app/composer/qgscomposervectorlegend.cpp
|
3432
|
===================================================================
|
3433
|
--- src/app/composer/qgscomposervectorlegend.cpp (revision 7070)
|
3434
|
+++ src/app/composer/qgscomposervectorlegend.cpp (working copy)
|
3435
|
@@ -14,6 +14,7 @@
|
3436
|
* (at your option) any later version. *
|
3437
|
* *
|
3438
|
***************************************************************************/
|
3439
|
+
|
3440
|
#include "qgscomposervectorlegend.h"
|
3441
|
#include "qgscomposermap.h"
|
3442
|
#include "qgscontinuouscolorrenderer.h"
|
3443
|
@@ -27,13 +28,15 @@
|
3444
|
#include <QFontDialog>
|
3445
|
#include <QPainter>
|
3446
|
#include <Q3PopupMenu>
|
3447
|
+#include <QGraphicsScene>
|
3448
|
|
3449
|
+
|
3450
|
#include <iostream>
|
3451
|
#include <vector>
|
3452
|
|
3453
|
QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition, int id,
|
3454
|
int x, int y, int fontSize )
|
3455
|
- : QWidget(composition), Q3CanvasRectangle(x,y,10,10,0)
|
3456
|
+ : QWidget(composition), QGraphicsRectItem(x,y,10,10,0)
|
3457
|
{
|
3458
|
setupUi(this);
|
3459
|
|
3460
|
@@ -57,18 +60,17 @@
|
3461
|
// Calc size and cache
|
3462
|
recalculate();
|
3463
|
|
3464
|
- // Add to canvas
|
3465
|
- setCanvas(mComposition->canvas());
|
3466
|
+ // Add to scene
|
3467
|
+ mComposition->canvas()->addItem(this);
|
3468
|
+ QGraphicsRectItem::show();
|
3469
|
+ QGraphicsRectItem::update();
|
3470
|
|
3471
|
- Q3CanvasRectangle::show();
|
3472
|
- Q3CanvasRectangle::update();
|
3473
|
-
|
3474
|
|
3475
|
writeSettings();
|
3476
|
}
|
3477
|
|
3478
|
QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition, int id )
|
3479
|
- : Q3CanvasRectangle(0,0,10,10,0)
|
3480
|
+ : QGraphicsRectItem(0,0,10,10,0)
|
3481
|
{
|
3482
|
std::cout << "QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
|
3483
|
|
3484
|
@@ -85,11 +87,11 @@
|
3485
|
// Calc size and cache
|
3486
|
recalculate();
|
3487
|
|
3488
|
- // Add to canvas
|
3489
|
- setCanvas(mComposition->canvas());
|
3490
|
+ // Add to scene
|
3491
|
+ mComposition->canvas()->addItem(this);
|
3492
|
|
3493
|
- Q3CanvasRectangle::show();
|
3494
|
- Q3CanvasRectangle::update();
|
3495
|
+ QGraphicsRectItem::show();
|
3496
|
+ QGraphicsRectItem::update();
|
3497
|
}
|
3498
|
|
3499
|
void QgsComposerVectorLegend::init ( void )
|
3500
|
@@ -105,8 +107,8 @@
|
3501
|
mCacheUpdated = false;
|
3502
|
|
3503
|
// Rectangle
|
3504
|
- Q3CanvasRectangle::setZ(50);
|
3505
|
- setActive(true);
|
3506
|
+ QGraphicsRectItem::setZValue(50);
|
3507
|
+// setActive(true);
|
3508
|
|
3509
|
// Layers list view
|
3510
|
mLayersListView->setColumnText(0,tr("Layers"));
|
3511
|
@@ -143,7 +145,7 @@
|
3512
|
std::cerr << "QgsComposerVectorLegend::~QgsComposerVectorLegend()" << std::endl;
|
3513
|
}
|
3514
|
|
3515
|
-QRect QgsComposerVectorLegend::render ( QPainter *p )
|
3516
|
+QRectF QgsComposerVectorLegend::render ( QPainter *p )
|
3517
|
{
|
3518
|
std::cout << "QgsComposerVectorLegend::render p = " << p << std::endl;
|
3519
|
|
3520
|
@@ -177,13 +179,13 @@
|
3521
|
QFontMetrics titleMetrics ( titleFont );
|
3522
|
QFontMetrics sectionMetrics ( sectionFont );
|
3523
|
QFontMetrics metrics ( font );
|
3524
|
-
|
3525
|
- // Fonts for rendering
|
3526
|
- double psTitleSize = titleMetrics.ascent() * 72.0 / mComposition->resolution();
|
3527
|
+
|
3528
|
+ // Fonts for Postscript rendering
|
3529
|
+ double psTitleSize = titleMetrics.ascent() * 72.0 / mComposition->resolution(); //What??
|
3530
|
double psSectionSize = sectionMetrics.ascent() * 72.0 / mComposition->resolution();
|
3531
|
double psSize = metrics.ascent() * 72.0 / mComposition->resolution();
|
3532
|
|
3533
|
- if ( plotStyle() == QgsComposition::Postscript)
|
3534
|
+ if ( plotStyle() == QgsComposition::Postscript) //do we need seperate PostScript rendering settings?
|
3535
|
{
|
3536
|
titleFont.setPointSizeFloat ( psTitleSize );
|
3537
|
sectionFont.setPointSizeFloat ( psSectionSize );
|
3538
|
@@ -203,31 +205,33 @@
|
3539
|
|
3540
|
int x, y;
|
3541
|
|
3542
|
- // Title
|
3543
|
+ // Legend title -if we do this later, we can center it
|
3544
|
y = mMargin + titleMetrics.height();
|
3545
|
painter->setPen ( mPen );
|
3546
|
painter->setFont ( titleFont );
|
3547
|
|
3548
|
painter->drawText( (int) (2*mMargin), y, mTitle );
|
3549
|
|
3550
|
+//used to keep track of total width and height
|
3551
|
int width = 4 * mMargin + titleMetrics.width ( mTitle );
|
3552
|
int height = mMargin + mSymbolSpace + titleMetrics.height(); // mSymbolSpace?
|
3553
|
-
|
3554
|
+
|
3555
|
// Layers
|
3556
|
- QgsComposerMap *map = mComposition->map ( mMap );
|
3557
|
+ QgsComposerMap *map = mComposition->map ( mMap ); //Get the map from the composition by ID number
|
3558
|
if ( map ) {
|
3559
|
+
|
3560
|
std::map<int,int> doneGroups;
|
3561
|
|
3562
|
int nlayers = mMapCanvas->layerCount();
|
3563
|
for ( int i = nlayers - 1; i >= 0; i-- ) {
|
3564
|
QgsMapLayer *layer = mMapCanvas->getZpos(i);
|
3565
|
- // TODO: visibility [MD]
|
3566
|
- //if ( !layer->visible() ) continue;
|
3567
|
- if ( layer->type() != QgsMapLayer::VECTOR ) continue;
|
3568
|
+// if ( !layer->visible() ) continue; // skip non-visible layers
|
3569
|
+ if ( layer->type() != QgsMapLayer::VECTOR ) continue; //skip raster layers
|
3570
|
|
3571
|
QString layerId = layer->getLayerID();
|
3572
|
- if( ! layerOn(layerId) ) continue;
|
3573
|
-
|
3574
|
+
|
3575
|
+// if( ! layerOn(layerId) ) continue; //does this need to go away?
|
3576
|
+
|
3577
|
int group = layerGroup ( layerId );
|
3578
|
if ( group > 0 ) {
|
3579
|
if ( doneGroups.find(group) != doneGroups.end() ) {
|
3580
|
@@ -237,20 +241,21 @@
|
3581
|
}
|
3582
|
}
|
3583
|
|
3584
|
- /* Make list of all layers in the group and count section items */
|
3585
|
+ // Make list of all layers in the group and count section items
|
3586
|
std::vector<int> groupLayers; // vector of layers
|
3587
|
std::vector<int> itemHeights; // maximum item sizes
|
3588
|
std::vector<QString> itemLabels; // item labels
|
3589
|
int sectionItemsCount = 0;
|
3590
|
QString sectionTitle;
|
3591
|
|
3592
|
- for ( int j = nlayers - 1; j >= 0; j-- ) {
|
3593
|
+
|
3594
|
+ for ( int j = nlayers - 1; j >= 0; j-- )
|
3595
|
+ {
|
3596
|
QgsMapLayer *layer2 = mMapCanvas->getZpos(j);
|
3597
|
- // TODO: visibility [MD]
|
3598
|
- //if ( !layer2->visible() ) continue;
|
3599
|
+// if ( !layer2->visible() ) continue;
|
3600
|
if ( layer2->type() != QgsMapLayer::VECTOR ) continue;
|
3601
|
|
3602
|
- QString layerId2 = layer2->getLayerID();;
|
3603
|
+ QString layerId2 = layer2->getLayerID();
|
3604
|
if( ! layerOn(layerId2) ) continue;
|
3605
|
|
3606
|
int group2 = layerGroup ( layerId2 );
|
3607
|
@@ -314,8 +319,10 @@
|
3608
|
//std::cout << "group size = " << groupLayers.size() << std::endl;
|
3609
|
//std::cout << "sectionItemsCount = " << sectionItemsCount << std::endl;
|
3610
|
|
3611
|
+
|
3612
|
// Section title
|
3613
|
- if ( sectionItemsCount > 1 ) {
|
3614
|
+ if ( sectionItemsCount > 1 )
|
3615
|
+ {
|
3616
|
height += mSymbolSpace;
|
3617
|
|
3618
|
x = (int) ( 2*mMargin );
|
3619
|
@@ -323,7 +330,7 @@
|
3620
|
painter->setPen ( mPen );
|
3621
|
painter->setFont ( sectionFont );
|
3622
|
|
3623
|
- painter->drawText( x, y,sectionTitle );
|
3624
|
+ painter->drawText( x, y, sectionTitle );
|
3625
|
|
3626
|
int w = 3*mMargin + sectionMetrics.width( sectionTitle );
|
3627
|
if ( w > width ) width = w;
|
3628
|
@@ -331,33 +338,36 @@
|
3629
|
height += (int) (0.7*mSymbolSpace);
|
3630
|
}
|
3631
|
|
3632
|
+
|
3633
|
// Draw all layers in group
|
3634
|
int groupStartHeight = height;
|
3635
|
- for ( int j = groupLayers.size()-1; j >= 0; j-- ) {
|
3636
|
- std::cout << "layer = " << groupLayers[j] << std::endl;
|
3637
|
+ for ( int j = groupLayers.size()-1; j >= 0; j-- )
|
3638
|
+ {
|
3639
|
+ std::cout << "layer = " << groupLayers[j] << std::endl;
|
3640
|
|
3641
|
- int localHeight = groupStartHeight;
|
3642
|
+ int localHeight = groupStartHeight;
|
3643
|
|
3644
|
- layer = mMapCanvas->getZpos(groupLayers[j]);
|
3645
|
- QgsVectorLayer *vector = dynamic_cast <QgsVectorLayer*> (layer);
|
3646
|
- const QgsRenderer *renderer = vector->renderer();
|
3647
|
+ layer = mMapCanvas->getZpos(groupLayers[j]);
|
3648
|
+ QgsVectorLayer *vector = dynamic_cast <QgsVectorLayer*> (layer);
|
3649
|
+ const QgsRenderer *renderer = vector->renderer();
|
3650
|
|
3651
|
- // Symbol
|
3652
|
- QList<QgsSymbol*> symbols = renderer->symbols();
|
3653
|
+ // Get a list of the symbols from the renderer - some renderers can have several symbols
|
3654
|
+ QList<QgsSymbol*> symbols = renderer->symbols();
|
3655
|
|
3656
|
- int icnt = 0;
|
3657
|
- for ( QList<QgsSymbol*>::iterator it = symbols.begin(); it != symbols.end(); ++it ) {
|
3658
|
+
|
3659
|
+ int icnt = 0;
|
3660
|
+ for ( QList<QgsSymbol*>::iterator it = symbols.begin(); it != symbols.end(); ++it ) {
|
3661
|
localHeight += mSymbolSpace;
|
3662
|
|
3663
|
int symbolHeight = itemHeights[icnt];
|
3664
|
QgsSymbol* sym = (*it);
|
3665
|
|
3666
|
QPen pen = sym->pen();
|
3667
|
- double widthScale = map->widthScale() * mComposition->scale();
|
3668
|
- if ( plotStyle() == QgsComposition::Preview && mPreviewMode == Render ) {
|
3669
|
- widthScale *= mComposition->viewScale();
|
3670
|
- }
|
3671
|
- pen.setWidth ( (int) ( widthScale * pen.width() ) );
|
3672
|
+ double widthScale = map->widthScale();
|
3673
|
+
|
3674
|
+std::cout << "widthScale: " << widthScale << std::endl;
|
3675
|
+
|
3676
|
+ pen.setWidthF( ( widthScale * pen.widthF() ) );
|
3677
|
painter->setPen ( pen );
|
3678
|
painter->setBrush ( sym->brush() );
|
3679
|
|
3680
|
@@ -378,6 +388,9 @@
|
3681
|
painter->drawLine ( mMargin, localHeight+mSymbolHeight/2,
|
3682
|
mMargin+mSymbolWidth, localHeight+mSymbolHeight/2 );
|
3683
|
} else if ( vector->vectorType() == QGis::Polygon ) {
|
3684
|
+ pen.setWidth(0); //use a cosmetic pen to outline the fill box
|
3685
|
+ pen.setCapStyle(Qt::FlatCap);
|
3686
|
+ painter->setPen ( pen );
|
3687
|
painter->drawRect ( mMargin, localHeight, mSymbolWidth, mSymbolHeight );
|
3688
|
}
|
3689
|
|
3690
|
@@ -391,7 +404,7 @@
|
3691
|
lab = itemLabels[icnt];
|
3692
|
}
|
3693
|
|
3694
|
- // drawText (x, y w, h, ...) was cutting last letter (the box was tto small)
|
3695
|
+ // drawText (x, y w, h, ...) was cutting last letter (the box was too small)
|
3696
|
QRect br = metrics.boundingRect ( lab );
|
3697
|
x = (int) ( 2*mMargin + mSymbolWidth );
|
3698
|
y = (int) ( localHeight + symbolHeight/2 + ( metrics.height()/2 - metrics.descent()) );
|
3699
|
@@ -403,36 +416,50 @@
|
3700
|
|
3701
|
localHeight += symbolHeight;
|
3702
|
icnt++;
|
3703
|
- }
|
3704
|
+
|
3705
|
+ }//End of iterating through the symbols in the renderer
|
3706
|
+
|
3707
|
}
|
3708
|
- /* add height of section items */
|
3709
|
+ // add height of section items to the total height
|
3710
|
height = groupStartHeight;
|
3711
|
- for ( uint j = 0; j < itemHeights.size(); j++ ) {
|
3712
|
- height += mSymbolSpace + itemHeights[j];
|
3713
|
+ for ( int j = 0; j < (int)itemHeights.size(); j++ ) {
|
3714
|
+ height += mSymbolSpace + itemHeights[j];
|
3715
|
}
|
3716
|
if ( sectionItemsCount > 1 ) { // add more space to separate section from next item
|
3717
|
height += mSymbolSpace;
|
3718
|
}
|
3719
|
- }
|
3720
|
+
|
3721
|
+ }//End of iterating through the layers
|
3722
|
+ }//END if(map)
|
3723
|
+
|
3724
|
+ height += mMargin;
|
3725
|
+
|
3726
|
+ if(mFrame)
|
3727
|
+ {
|
3728
|
+ QPen pen(QColor(0,0,0), 0.5);
|
3729
|
+ painter->setPen( pen );
|
3730
|
+ painter->setBrush( QBrush( QColor(255,255,255), Qt::NoBrush));
|
3731
|
+ painter->setRenderHint(QPainter::Antialiasing, true);//turn on antialiasing
|
3732
|
+ painter->drawRect ( 0, 0, width, height );
|
3733
|
}
|
3734
|
|
3735
|
- height += mMargin;
|
3736
|
|
3737
|
- Q3CanvasRectangle::setSize ( width, height );
|
3738
|
+// QGraphicsRectItem::setRect(0, 0, width, height); //BUG! - calling this causes a re-draw, which means we are continuously re-drawing.
|
3739
|
|
3740
|
if ( !p ) {
|
3741
|
delete painter;
|
3742
|
delete pixmap;
|
3743
|
}
|
3744
|
|
3745
|
- return QRect ( 0, 0, width, height);
|
3746
|
+ return QRectF ( 0, 0, width, height);
|
3747
|
}
|
3748
|
|
3749
|
void QgsComposerVectorLegend::cache ( void )
|
3750
|
{
|
3751
|
std::cout << "QgsComposerVectorLegend::cache()" << std::endl;
|
3752
|
|
3753
|
- mCachePixmap.resize ( Q3CanvasRectangle::width(), Q3CanvasRectangle::height() );
|
3754
|
+//typical boundingRect size is 15 units wide,
|
3755
|
+ mCachePixmap.resize ((int)QGraphicsRectItem::rect().width(), (int)QGraphicsRectItem::rect().height() );
|
3756
|
|
3757
|
QPainter p(&mCachePixmap);
|
3758
|
|
3759
|
@@ -444,70 +471,50 @@
|
3760
|
mCacheUpdated = true;
|
3761
|
}
|
3762
|
|
3763
|
-void QgsComposerVectorLegend::draw ( QPainter & painter )
|
3764
|
+void QgsComposerVectorLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
|
3765
|
{
|
3766
|
- std::cout << "draw mPlotStyle = " << plotStyle()
|
3767
|
- << " mPreviewMode = " << mPreviewMode << std::endl;
|
3768
|
+#ifdef QGISDEBUG
|
3769
|
+ std::cout << "paint mPlotStyle = " << plotStyle() << " mPreviewMode = " << mPreviewMode << std::endl;
|
3770
|
+#endif
|
3771
|
|
3772
|
- // Draw background rectangle
|
3773
|
-
|
3774
|
- if ( mFrame ) {
|
3775
|
- QPen pen(QColor(0,0,0));
|
3776
|
- pen.setWidthF(0.5);
|
3777
|
- painter.setPen( pen );
|
3778
|
- painter.setBrush( QBrush( QColor(255,255,255), Qt::SolidPattern) );
|
3779
|
-
|
3780
|
- painter.save();
|
3781
|
-
|
3782
|
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
|
3783
|
- painter.drawRect ( 0, 0, Q3CanvasRectangle::width()+1, Q3CanvasRectangle::height()+1 ); // is it right?
|
3784
|
- painter.restore();
|
3785
|
- }
|
3786
|
-
|
3787
|
- if ( plotStyle() == QgsComposition::Preview && mPreviewMode == Cache ) { // Draw from cache
|
3788
|
- std::cout << "use cache" << std::endl;
|
3789
|
-
|
3790
|
- if ( !mCacheUpdated || mMapCanvas->layerCount() != mNumCachedLayers ) {
|
3791
|
+ if ( plotStyle() == QgsComposition::Preview && mPreviewMode == Cache )
|
3792
|
+ {
|
3793
|
+ if ( !mCacheUpdated || mMapCanvas->layerCount() != mNumCachedLayers ) //If the cache is out of date, update it.
|
3794
|
+ {
|
3795
|
cache();
|
3796
|
}
|
3797
|
-
|
3798
|
- painter.save();
|
3799
|
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
|
3800
|
- std::cout << "translate: " << Q3CanvasRectangle::x() << ", " << Q3CanvasRectangle::y() << std::endl;
|
3801
|
- painter.drawPixmap(0,0, mCachePixmap);
|
3802
|
-
|
3803
|
- painter.restore();
|
3804
|
-
|
3805
|
- } else if ( (plotStyle() == QgsComposition::Preview && mPreviewMode == Render) ||
|
3806
|
+ painter->drawPixmap(0,0, mCachePixmap);
|
3807
|
+ }
|
3808
|
+ else if(plotStyle() == QgsComposition::Preview && mPreviewMode == Rectangle)
|
3809
|
+ {
|
3810
|
+ QPen pen(QColor(0,0,0), 0.5);
|
3811
|
+ painter->setPen( pen );
|
3812
|
+ painter->setBrush( QBrush( QColor(255,255,255), Qt::NoBrush)); //use SolidPattern instead?
|
3813
|
+ painter->drawRect(QRectF(0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height()));
|
3814
|
+ }
|
3815
|
+ else if ( (plotStyle() == QgsComposition::Preview && mPreviewMode == Render) ||
|
3816
|
plotStyle() == QgsComposition::Print ||
|
3817
|
plotStyle() == QgsComposition::Postscript )
|
3818
|
- {
|
3819
|
- std::cout << "render" << std::endl;
|
3820
|
-
|
3821
|
- painter.save();
|
3822
|
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
|
3823
|
- render( &painter );
|
3824
|
- painter.restore();
|
3825
|
- }
|
3826
|
+ //We're in render preview mode or printing, so do a full render of the legend.
|
3827
|
+ {
|
3828
|
+ painter->save();
|
3829
|
+ render(painter);
|
3830
|
+ painter->restore();
|
3831
|
+ }
|
3832
|
|
3833
|
- // Show selected / Highlight
|
3834
|
- std::cout << "mSelected = " << mSelected << std::endl;
|
3835
|
+
|
3836
|
+ // Draw the "selected highlight" boxes
|
3837
|
if ( mSelected && plotStyle() == QgsComposition::Preview ) {
|
3838
|
- std::cout << "highlight" << std::endl;
|
3839
|
- painter.setPen( mComposition->selectionPen() );
|
3840
|
- painter.setBrush( mComposition->selectionBrush() );
|
3841
|
+
|
3842
|
+ painter->setPen( mComposition->selectionPen() );
|
3843
|
+ painter->setBrush( mComposition->selectionBrush() );
|
3844
|
|
3845
|
- int x = (int) Q3CanvasRectangle::x();
|
3846
|
- int y = (int) Q3CanvasRectangle::y();
|
3847
|
- int s = mComposition->selectionBoxSize();
|
3848
|
+ double s = mComposition->selectionBoxSize();
|
3849
|
|
3850
|
- painter.drawRect ( x, y, s, s );
|
3851
|
- x += Q3CanvasRectangle::width();
|
3852
|
- painter.drawRect ( x-s, y, s, s );
|
3853
|
- y += Q3CanvasRectangle::height();
|
3854
|
- painter.drawRect ( x-s, y-s, s, s );
|
3855
|
- x -= Q3CanvasRectangle::width();
|
3856
|
- painter.drawRect ( x, y-s, s, s );
|
3857
|
+ painter->drawRect(QRectF(0, 0, s, s)); //top left
|
3858
|
+ painter->drawRect(QRectF(QGraphicsRectItem::rect().width()-s, 0, s, s)); //top right
|
3859
|
+ painter->drawRect(QRectF(QGraphicsRectItem::rect().width()-s, QGraphicsRectItem::rect().height()-s, s, s)); //bottom right
|
3860
|
+ painter->drawRect(QRectF(0, QGraphicsRectItem::rect().height()-s, s, s)); //bottom left
|
3861
|
}
|
3862
|
}
|
3863
|
|
3864
|
@@ -519,8 +526,8 @@
|
3865
|
|
3866
|
if ( result ) {
|
3867
|
recalculate();
|
3868
|
- Q3CanvasRectangle::update();
|
3869
|
- Q3CanvasRectangle::canvas()->update();
|
3870
|
+ QGraphicsRectItem::update();
|
3871
|
+ QGraphicsRectItem::scene()->update();
|
3872
|
writeSettings();
|
3873
|
}
|
3874
|
}
|
3875
|
@@ -529,8 +536,8 @@
|
3876
|
{
|
3877
|
mTitle = mTitleLineEdit->text();
|
3878
|
recalculate();
|
3879
|
- Q3CanvasRectangle::update();
|
3880
|
- Q3CanvasRectangle::canvas()->update();
|
3881
|
+ QGraphicsRectItem::update();
|
3882
|
+ QGraphicsRectItem::scene()->update();
|
3883
|
writeSettings();
|
3884
|
}
|
3885
|
|
3886
|
@@ -545,8 +552,8 @@
|
3887
|
{
|
3888
|
mMap = mMaps[i];
|
3889
|
recalculate();
|
3890
|
- Q3CanvasRectangle::update();
|
3891
|
- Q3CanvasRectangle::canvas()->update();
|
3892
|
+ QGraphicsRectItem::update();
|
3893
|
+ QGraphicsRectItem::scene()->update();
|
3894
|
writeSettings();
|
3895
|
}
|
3896
|
|
3897
|
@@ -555,16 +562,16 @@
|
3898
|
if ( id != mMap ) return;
|
3899
|
|
3900
|
recalculate();
|
3901
|
- Q3CanvasRectangle::update();
|
3902
|
- Q3CanvasRectangle::canvas()->update();
|
3903
|
+ QGraphicsRectItem::update();
|
3904
|
+ QGraphicsRectItem::scene()->update();
|
3905
|
}
|
3906
|
|
3907
|
void QgsComposerVectorLegend::on_mFrameCheckBox_stateChanged ( int )
|
3908
|
{
|
3909
|
mFrame = mFrameCheckBox->isChecked();
|
3910
|
|
3911
|
- Q3CanvasRectangle::update();
|
3912
|
- Q3CanvasRectangle::canvas()->update();
|
3913
|
+ QGraphicsRectItem::update();
|
3914
|
+ QGraphicsRectItem::scene()->update();
|
3915
|
|
3916
|
writeSettings();
|
3917
|
}
|
3918
|
@@ -595,9 +602,9 @@
|
3919
|
std::cout << "mMargin = " << mMargin << " mSymbolHeight = " << mSymbolHeight
|
3920
|
<< "mSymbolWidth = " << mSymbolWidth << " mSymbolSpace = " << mSymbolSpace << std::endl;
|
3921
|
|
3922
|
- QRect r = render(0);
|
3923
|
+ QRectF r = render(0);
|
3924
|
|
3925
|
- Q3CanvasRectangle::setSize ( r.width(), r.height() );
|
3926
|
+ QGraphicsRectItem::setRect(0, 0, r.width(), r.height() );
|
3927
|
|
3928
|
mCacheUpdated = false;
|
3929
|
}
|
3930
|
@@ -615,7 +622,7 @@
|
3931
|
bool found = false;
|
3932
|
mMapComboBox->insertItem ( "", 0 );
|
3933
|
mMaps.push_back ( 0 );
|
3934
|
- for ( uint i = 0; i < maps.size(); i++ ) {
|
3935
|
+ for ( int i = 0; i < (int)maps.size(); i++ ) {
|
3936
|
mMapComboBox->insertItem ( maps[i]->name(), i+1 );
|
3937
|
mMaps.push_back ( maps[i]->id() );
|
3938
|
|
3939
|
@@ -643,9 +650,7 @@
|
3940
|
for ( int i = 0; i < nlayers; i++ ) {
|
3941
|
QgsMapLayer *layer = mMapCanvas->getZpos(i);
|
3942
|
|
3943
|
- // TODO: visibility [MD]
|
3944
|
- //if ( !layer->visible() ) continue;
|
3945
|
-
|
3946
|
+// if ( !layer->visible() ) continue;
|
3947
|
//if ( layer->type() != QgsMapLayer::VECTOR ) continue;
|
3948
|
|
3949
|
Q3CheckListItem *li = new Q3CheckListItem ( mLayersListView, layer->name(), Q3CheckListItem::CheckBox );
|
3950
|
@@ -671,7 +676,7 @@
|
3951
|
void QgsComposerVectorLegend::setSelected ( bool s )
|
3952
|
{
|
3953
|
mSelected = s;
|
3954
|
- Q3CanvasRectangle::update(); // show highlight
|
3955
|
+ QGraphicsRectItem::update(); // show highlight
|
3956
|
}
|
3957
|
|
3958
|
bool QgsComposerVectorLegend::selected( void )
|
3959
|
@@ -743,8 +748,8 @@
|
3960
|
writeSettings();
|
3961
|
|
3962
|
recalculate();
|
3963
|
- Q3CanvasRectangle::update();
|
3964
|
- Q3CanvasRectangle::canvas()->update();
|
3965
|
+ QGraphicsRectItem::update();
|
3966
|
+ QGraphicsRectItem::scene()->update();
|
3967
|
}
|
3968
|
|
3969
|
void QgsComposerVectorLegend::groupLayers ( void )
|
3970
|
@@ -753,7 +758,7 @@
|
3971
|
|
3972
|
Q3ListViewItemIterator it( mLayersListView );
|
3973
|
int count = 0;
|
3974
|
- Q3ListViewItem *lastItem = NULL;
|
3975
|
+ Q3ListViewItem *lastItem;
|
3976
|
QString id;
|
3977
|
while ( it.current() ) {
|
3978
|
if ( it.current()->isSelected() ) {
|
3979
|
@@ -783,8 +788,8 @@
|
3980
|
writeSettings();
|
3981
|
|
3982
|
recalculate();
|
3983
|
- Q3CanvasRectangle::update();
|
3984
|
- Q3CanvasRectangle::canvas()->update();
|
3985
|
+ QGraphicsRectItem::update();
|
3986
|
+ QGraphicsRectItem::scene()->update();
|
3987
|
}
|
3988
|
|
3989
|
QWidget *QgsComposerVectorLegend::options ( void )
|
3990
|
@@ -799,8 +804,8 @@
|
3991
|
QString path;
|
3992
|
path.sprintf("/composition_%d/vectorlegend_%d/", mComposition->id(), mId );
|
3993
|
|
3994
|
- QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)Q3CanvasRectangle::x()) );
|
3995
|
- QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)Q3CanvasRectangle::y()) );
|
3996
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QGraphicsRectItem::x()) );
|
3997
|
+ QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QGraphicsRectItem::y()) );
|
3998
|
|
3999
|
QgsProject::instance()->writeEntry( "Compositions", path+"map", mMap );
|
4000
|
|
4001
|
@@ -826,8 +831,7 @@
|
4002
|
for ( int i = 0; i < nlayers; i++ ) {
|
4003
|
QgsMapLayer *layer = mMapCanvas->getZpos(i);
|
4004
|
|
4005
|
- // TODO: visibility [MD]
|
4006
|
- //if ( !layer->visible() ) continue;
|
4007
|
+// if ( !layer->visible() ) continue;
|
4008
|
|
4009
|
QString id = layer->getLayerID();
|
4010
|
path.sprintf("/composition_%d/vectorlegend_%d/layers/layer_%s/", mComposition->id(), mId, id.toLocal8Bit().data() );
|
4011
|
@@ -848,9 +852,11 @@
|
4012
|
QString path;
|
4013
|
path.sprintf("/composition_%d/vectorlegend_%d/", mComposition->id(), mId );
|
4014
|
|
4015
|
- Q3CanvasRectangle::setX( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok)) );
|
4016
|
- Q3CanvasRectangle::setY( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok)) );
|
4017
|
+ double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok));
|
4018
|
+ double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok));
|
4019
|
|
4020
|
+ QGraphicsRectItem::setPos(x, y);
|
4021
|
+
|
4022
|
mMap = QgsProject::instance()->readNumEntry("Compositions", path+"map", 0, &ok);
|
4023
|
mTitle = QgsProject::instance()->readEntry("Compositions", path+"title", "???", &ok);
|
4024
|
|
4025
|
Index: src/app/composer/qgscomposerscalebar.h
|
4026
|
===================================================================
|
4027
|
--- src/app/composer/qgscomposerscalebar.h (revision 7070)
|
4028
|
+++ src/app/composer/qgscomposerscalebar.h (working copy)
|
4029
|
@@ -18,9 +18,10 @@
|
4030
|
|
4031
|
#include "ui_qgscomposerscalebarbase.h"
|
4032
|
#include "qgscomposeritem.h"
|
4033
|
-#include <Q3CanvasPolygonalItem>
|
4034
|
+#include <QAbstractGraphicsShapeItem>
|
4035
|
#include <Q3PointArray>
|
4036
|
#include <QRect>
|
4037
|
+#include <QPen>
|
4038
|
|
4039
|
class QgsMapCanvas;
|
4040
|
class QgsComposition;
|
4041
|
@@ -33,10 +34,9 @@
|
4042
|
|
4043
|
/** \class QgsComposerScalebar
|
4044
|
* \brief Object representing map window.
|
4045
|
- * x,y is center of upper side of the bar, the center position depends on scalebar style
|
4046
|
*/
|
4047
|
// NOTE: QgsComposerScalebarBase must be first, otherwise does not compile
|
4048
|
-class QgsComposerScalebar : public QWidget, private Ui::QgsComposerScalebarBase, public Q3CanvasPolygonalItem, public QgsComposerItem
|
4049
|
+class QgsComposerScalebar : public QWidget, private Ui::QgsComposerScalebarBase, public QAbstractGraphicsShapeItem, public QgsComposerItem
|
4050
|
{
|
4051
|
Q_OBJECT
|
4052
|
|
4053
|
@@ -66,19 +66,19 @@
|
4054
|
bool writeXML( QDomNode & node, QDomDocument & document, bool temp = false );
|
4055
|
bool readXML( QDomNode & node );
|
4056
|
|
4057
|
- QRect boundingRect ( void ) const;
|
4058
|
+ QRectF boundingRect ( void ) const;
|
4059
|
|
4060
|
/** \brief Draw to paint device, internal use
|
4061
|
* \param painter painter or 0
|
4062
|
* \return bounding box
|
4063
|
*/
|
4064
|
- QRect render (QPainter *painter);
|
4065
|
+ QRectF render (QPainter *painter);
|
4066
|
|
4067
|
- /** \brief Reimplementation of QCanvasItem::draw - draw on canvas */
|
4068
|
- void draw ( QPainter & painter );
|
4069
|
+ /** \brief Reimplementation of QGraphicsItem::paint - draw on canvas */
|
4070
|
+ void paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget);
|
4071
|
|
4072
|
- void drawShape(QPainter&);
|
4073
|
- Q3PointArray areaPoints() const;
|
4074
|
+ //void drawShape(QPainter&);
|
4075
|
+ QPolygonF areaPoints() const;
|
4076
|
|
4077
|
/** \brief Calculate size according to current settings */
|
4078
|
void recalculate ( void );
|
4079
|
@@ -87,7 +87,7 @@
|
4080
|
void setOptions ( void );
|
4081
|
|
4082
|
// Move to position
|
4083
|
- void moveBy ( double x, double y );
|
4084
|
+// void moveBy ( double x, double y );
|
4085
|
|
4086
|
public slots:
|
4087
|
// Open font dialog
|
4088
|
@@ -122,7 +122,7 @@
|
4089
|
std::vector<int> mMaps;
|
4090
|
|
4091
|
// Current bounding box
|
4092
|
- QRect mBoundingRect;
|
4093
|
+ QRectF mBoundingRect;
|
4094
|
|
4095
|
// Number of map units in scalebar unit
|
4096
|
double mMapUnitsPerUnit;
|
4097
|
@@ -134,7 +134,7 @@
|
4098
|
QFont mFont;
|
4099
|
|
4100
|
// Pen
|
4101
|
- QPen mPen;
|
4102
|
+ QPen mPen;
|
4103
|
|
4104
|
// Brush
|
4105
|
QBrush mBrush;
|
4106
|
@@ -146,7 +146,7 @@
|
4107
|
double mSegmentLength;
|
4108
|
|
4109
|
// Height of scalebar box in canvas units (box style only)
|
4110
|
- int mHeight;
|
4111
|
+ double mHeight;
|
4112
|
|
4113
|
// Margin
|
4114
|
int mMargin;
|
4115
|
Index: src/app/composer/qgscomposermap.h
|
4116
|
===================================================================
|
4117
|
--- src/app/composer/qgscomposermap.h (revision 7070)
|
4118
|
+++ src/app/composer/qgscomposermap.h (working copy)
|
4119
|
@@ -20,7 +20,7 @@
|
4120
|
#include "ui_qgscomposermapbase.h"
|
4121
|
#include "qgscomposeritem.h"
|
4122
|
#include "qgsrect.h"
|
4123
|
-#include <Q3CanvasRectangle>
|
4124
|
+#include <QGraphicsRectItem>
|
4125
|
#include <QPixmap>
|
4126
|
|
4127
|
class QgsComposition;
|
4128
|
@@ -34,7 +34,7 @@
|
4129
|
* \brief Object representing map window.
|
4130
|
*/
|
4131
|
// NOTE: QgsComposerMapBase must be first, otherwise does not compile
|
4132
|
-class QgsComposerMap : public QWidget, private Ui::QgsComposerMapBase, public Q3CanvasRectangle, public QgsComposerItem
|
4133
|
+class QgsComposerMap : public QWidget, private Ui::QgsComposerMapBase, public QGraphicsRectItem, public QgsComposerItem
|
4134
|
{
|
4135
|
Q_OBJECT
|
4136
|
|
4137
|
@@ -74,8 +74,8 @@
|
4138
|
/** \brief Draw to paint device */
|
4139
|
void draw(QPainter *painter, QgsRect &extent, QgsMapToPixel *transform);
|
4140
|
|
4141
|
- /** \brief Reimplementation of QCanvasItem::draw - draw on canvas */
|
4142
|
- void draw ( QPainter & painter );
|
4143
|
+ /** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
|
4144
|
+ void paint (QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget);
|
4145
|
|
4146
|
/** \brief Set extent requested by user */
|
4147
|
void setUserExtent ( QgsRect const & rect);
|
4148
|
Index: src/app/composer/qgscomposerlabel.h
|
4149
|
===================================================================
|
4150
|
--- src/app/composer/qgscomposerlabel.h (revision 7070)
|
4151
|
+++ src/app/composer/qgscomposerlabel.h (working copy)
|
4152
|
@@ -19,10 +19,10 @@
|
4153
|
|
4154
|
#include "ui_qgscomposerlabelbase.h"
|
4155
|
#include "qgscomposeritem.h"
|
4156
|
-#include <Q3CanvasPolygonalItem>
|
4157
|
+#include <QAbstractGraphicsShapeItem>
|
4158
|
#include <QFont>
|
4159
|
#include <QPen>
|
4160
|
-#include <Q3PointArray>
|
4161
|
+#include <QPolygon>
|
4162
|
#include <QRect>
|
4163
|
#include <QString>
|
4164
|
|
4165
|
@@ -35,7 +35,7 @@
|
4166
|
*/
|
4167
|
// NOTE: QgsComposerLabelBase must be first, otherwise does not compile
|
4168
|
//class QgsComposerLabel : public QgsComposerLabelBase, public QCanvasRectangle, public QgsComposerItem
|
4169
|
-class QgsComposerLabel : public QWidget, private Ui::QgsComposerLabelBase, public Q3CanvasPolygonalItem, public QgsComposerItem
|
4170
|
+class QgsComposerLabel : public QWidget, private Ui::QgsComposerLabelBase, public QAbstractGraphicsShapeItem, public QgsComposerItem
|
4171
|
{
|
4172
|
Q_OBJECT
|
4173
|
|
4174
|
@@ -63,13 +63,13 @@
|
4175
|
bool writeXML( QDomNode & node, QDomDocument & document, bool temp = false );
|
4176
|
bool readXML( QDomNode & node );
|
4177
|
|
4178
|
- QRect boundingRect ( void ) const;
|
4179
|
+ QRectF boundingRect ( void ) const; //errors about overriding things?
|
4180
|
|
4181
|
- /** \brief Reimplementation of QCanvasItem::draw - draw on canvas */
|
4182
|
- void draw ( QPainter & painter );
|
4183
|
+ /** \brief Reimplementation of QGraphicsItem::paint() - draw on canvas */
|
4184
|
+ void paint ( QPainter*, const QStyleOptionGraphicsItem*, QWidget* );
|
4185
|
|
4186
|
- void drawShape(QPainter&);
|
4187
|
- Q3PointArray areaPoints() const;
|
4188
|
+// void drawShape(QPainter&, const QStyleOptionGraphicsItem*, QWidget*);
|
4189
|
+ QPolygonF areaPoints() const;
|
4190
|
|
4191
|
/** \brief Set values in GUI to current values */
|
4192
|
void setOptions ( void );
|
4193
|
Index: src/app/composer/qgscomposervectorlegend.h
|
4194
|
===================================================================
|
4195
|
--- src/app/composer/qgscomposervectorlegend.h (revision 7070)
|
4196
|
+++ src/app/composer/qgscomposervectorlegend.h (working copy)
|
4197
|
@@ -43,7 +43,9 @@
|
4198
|
|
4199
|
#include "ui_qgscomposervectorlegendbase.h"
|
4200
|
#include "qgscomposeritem.h"
|
4201
|
-#include <Q3CanvasPolygonalItem>
|
4202
|
+
|
4203
|
+#include <QAbstractGraphicsShapeItem>
|
4204
|
+#include <QPen>
|
4205
|
#include <QPixmap>
|
4206
|
#include <map>
|
4207
|
|
4208
|
@@ -63,7 +65,7 @@
|
4209
|
// NOTE: QgsComposerVectorLegendBase must be first, otherwise does not compile
|
4210
|
class QgsComposerVectorLegend : public QWidget,
|
4211
|
private Ui::QgsComposerVectorLegendBase,
|
4212
|
- public Q3CanvasRectangle,
|
4213
|
+ public QGraphicsRectItem,
|
4214
|
public QgsComposerItem
|
4215
|
{
|
4216
|
Q_OBJECT
|
4217
|
@@ -105,10 +107,10 @@
|
4218
|
* \param painter painter or 0
|
4219
|
* \return bounding box
|
4220
|
*/
|
4221
|
- QRect render (QPainter *painter);
|
4222
|
+ QRectF render (QPainter *painter);
|
4223
|
|
4224
|
- /** \brief Reimplementation of QCanvasItem::draw - draw on canvas */
|
4225
|
- void draw ( QPainter & painter );
|
4226
|
+ /** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
|
4227
|
+ void paint ( QPainter*, const QStyleOptionGraphicsItem*, QWidget*);
|
4228
|
|
4229
|
/** \brief Calculate size according to current settings */
|
4230
|
void recalculate ( void );
|
4231
|
Index: src/app/composer/qgscomposition.cpp
|
4232
|
===================================================================
|
4233
|
--- src/app/composer/qgscomposition.cpp (revision 7070)
|
4234
|
+++ src/app/composer/qgscomposition.cpp (working copy)
|
4235
|
@@ -18,19 +18,22 @@
|
4236
|
#include "qgscomposer.h"
|
4237
|
#include "qgscomposeritem.h"
|
4238
|
#include "qgscomposerlabel.h"
|
4239
|
+
|
4240
|
#include "qgscomposermap.h"
|
4241
|
#include "qgscomposerpicture.h"
|
4242
|
#include "qgscomposerscalebar.h"
|
4243
|
#include "qgscomposervectorlegend.h"
|
4244
|
+
|
4245
|
#include "qgscomposerview.h"
|
4246
|
#include "qgsmapcanvas.h"
|
4247
|
#include "qgsproject.h"
|
4248
|
|
4249
|
-#include <Q3CanvasRectangle>
|
4250
|
+#include <QGraphicsRectItem>
|
4251
|
#include <QMatrix>
|
4252
|
#include <QMessageBox>
|
4253
|
|
4254
|
#include <iostream>
|
4255
|
+#include <math.h>
|
4256
|
|
4257
|
QgsCompositionPaper::QgsCompositionPaper ( QString name, int w, int h, bool c)
|
4258
|
:mName(name), mWidth(w), mHeight(h), mCustom(c)
|
4259
|
@@ -95,7 +98,7 @@
|
4260
|
mPapers.push_back ( QgsCompositionPaper( tr("Legal (8.5x14 inches)"), 216, 356 ) );
|
4261
|
|
4262
|
mPaper = mDefaultPaper = mCustomPaper = 0;
|
4263
|
- for( uint i = 0; i < mPapers.size(); i++ ) {
|
4264
|
+ for( int i = 0; i < (int)mPapers.size(); i++ ) {
|
4265
|
mPaperSizeComboBox->insertItem( mPapers[i].mName );
|
4266
|
// Map - A4 land for now, if future read from template
|
4267
|
if ( mPapers[i].mWidth == 210 && mPapers[i].mHeight == 297 ){
|
4268
|
@@ -137,7 +140,7 @@
|
4269
|
|
4270
|
setOptions();
|
4271
|
|
4272
|
- // Add the map to coposition
|
4273
|
+ // Add the map to composition
|
4274
|
/*
|
4275
|
QgsComposerMap *m = new QgsComposerMap ( this, mNextItemId++,
|
4276
|
mScale*15, mScale*15, mScale*180, mScale*180 );
|
4277
|
@@ -171,28 +174,26 @@
|
4278
|
{
|
4279
|
if ( mCanvas ) delete mCanvas;
|
4280
|
|
4281
|
- mCanvas = new Q3Canvas ( (int) mPaperWidth * mScale, (int) mPaperHeight * mScale);
|
4282
|
- mCanvas->setBackgroundColor( QColor(180,180,180) );
|
4283
|
- // mCanvas->setDoubleBuffering( false ); // makes the move very unpleasant and doesn't make it faster
|
4284
|
+ mCanvas = new QGraphicsScene (0, 0, (int) mPaperWidth, (int) mPaperHeight);//top, left, width, height
|
4285
|
+ mCanvas->setBackgroundBrush( QColor(180,180,180) );
|
4286
|
|
4287
|
// Paper
|
4288
|
if ( mPaperItem ) delete mPaperItem;
|
4289
|
- mPaperItem = new Q3CanvasRectangle( 0, 0, (int) mPaperWidth * mScale,
|
4290
|
- (int) mPaperHeight * mScale, mCanvas );
|
4291
|
+ mPaperItem = new QGraphicsRectItem( 0, 0, (int) mPaperWidth, (int) mPaperHeight, mPaperItem, mCanvas );
|
4292
|
+
|
4293
|
mPaperItem->setBrush( QColor(255,255,255) );
|
4294
|
- mPaperItem->setPen( QPen(QColor(0,0,0), 1) );
|
4295
|
- mPaperItem->setZ(0);
|
4296
|
- mPaperItem->setActive(false);
|
4297
|
+ mPaperItem->setPen( QPen(QColor(0,0,0), 0) ); // 0 line width makes it use a cosmetic pen - 1px, regardless of scale.
|
4298
|
+ mPaperItem->setZValue(0);
|
4299
|
mPaperItem->show();
|
4300
|
}
|
4301
|
|
4302
|
void QgsComposition::resizeCanvas(void)
|
4303
|
{
|
4304
|
- mCanvas->resize ( (int) mPaperWidth * mScale, (int) mPaperHeight * mScale );
|
4305
|
+ mCanvas->setSceneRect(0, 0, (int) mPaperWidth * mScale, (int) mPaperHeight * mScale );
|
4306
|
#ifdef QGISDEBUG
|
4307
|
std::cout << "mCanvas width = " << mCanvas->width() << " height = " << mCanvas->height() << std::endl;
|
4308
|
#endif
|
4309
|
- mPaperItem->setSize ( (int) mPaperWidth * mScale, (int) mPaperHeight * mScale );
|
4310
|
+ mPaperItem->setRect(QRectF(0, 0, (int) mPaperWidth * mScale, (int) mPaperHeight * mScale ));
|
4311
|
}
|
4312
|
|
4313
|
QgsComposition::~QgsComposition()
|
4314
|
@@ -200,7 +201,7 @@
|
4315
|
#ifdef QGISDEBUG
|
4316
|
std::cerr << "QgsComposition::~QgsComposition" << std::endl;
|
4317
|
#endif
|
4318
|
- mView->setCanvas ( 0 );
|
4319
|
+ mView->setScene ( 0 );
|
4320
|
|
4321
|
if ( mPaperItem ) delete mPaperItem;
|
4322
|
|
4323
|
@@ -218,40 +219,48 @@
|
4324
|
void QgsComposition::setActive ( bool active )
|
4325
|
{
|
4326
|
if ( active ) {
|
4327
|
- mView->setCanvas ( mCanvas );
|
4328
|
+ mView->setScene ( mCanvas );
|
4329
|
mComposer->showCompositionOptions ( this );
|
4330
|
} else {
|
4331
|
// TODO
|
4332
|
}
|
4333
|
}
|
4334
|
|
4335
|
-void QgsComposition::contentsMousePressEvent(QMouseEvent* e)
|
4336
|
+void QgsComposition::mousePressEvent(QMouseEvent* e)
|
4337
|
{
|
4338
|
#ifdef QGISDEBUG
|
4339
|
- std::cerr << "QgsComposition::contentsMousePressEvent() mTool = " << mTool << " mToolStep = "
|
4340
|
+ std::cerr << "QgsComposition::mousePressEvent() mTool = " << mTool << " mToolStep = "
|
4341
|
<< mToolStep << std::endl;
|
4342
|
#endif
|
4343
|
|
4344
|
- QPoint p = mView->inverseWorldMatrix().map(e->pos());
|
4345
|
- mLastPoint = p;
|
4346
|
+ QPointF p = mView->mapToScene(e->pos());
|
4347
|
|
4348
|
- double x,y;
|
4349
|
- mView->inverseWorldMatrix().map( e->pos().x(), e->pos().y(), &x, &y );
|
4350
|
+// mGrabPoint = mCanvas.mapToItem(p);
|
4351
|
|
4352
|
switch ( mTool ) {
|
4353
|
case Select:
|
4354
|
{
|
4355
|
- Q3CanvasItemList l = mCanvas->collisions(p);
|
4356
|
|
4357
|
- Q3CanvasItem * newItem = 0;
|
4358
|
+ QGraphicsItem* newItem = 0;
|
4359
|
+ newItem = mCanvas->itemAt(p);
|
4360
|
+ if(newItem == mPaperItem) //ignore clicks on the paper
|
4361
|
+ {
|
4362
|
+ newItem = 0;
|
4363
|
+ }
|
4364
|
|
4365
|
- for ( Q3CanvasItemList::Iterator it=l.fromLast(); it!=l.end(); --it) {
|
4366
|
+//what is this doing? Grabbing the first item in the list?
|
4367
|
+/*
|
4368
|
+ QList<QGraphicsItem*> l = mCanvas->items(p);
|
4369
|
+ for ( QList<QGraphicsItem*>::Iterator it=l.fromLast(); it!=l.end(); --it) {
|
4370
|
if (! (*it)->isActive() ) continue;
|
4371
|
newItem = *it;
|
4372
|
}
|
4373
|
+*/
|
4374
|
|
4375
|
if ( newItem ) { // found
|
4376
|
+ mGrabPoint = newItem->mapFromScene(p);
|
4377
|
if ( newItem != mSelectedItem ) { // Show options
|
4378
|
+
|
4379
|
if ( mSelectedItem ) {
|
4380
|
QgsComposerItem *coi = dynamic_cast <QgsComposerItem *> (mSelectedItem);
|
4381
|
coi->setSelected ( false );
|
4382
|
@@ -262,9 +271,7 @@
|
4383
|
|
4384
|
mComposer->showItemOptions ( coi->options() );
|
4385
|
mSelectedItem = newItem;
|
4386
|
- }
|
4387
|
- mLastX = x;
|
4388
|
- mLastY = y;
|
4389
|
+ }
|
4390
|
} else { // not found
|
4391
|
if ( mSelectedItem ) {
|
4392
|
QgsComposerItem *coi = dynamic_cast <QgsComposerItem *> (mSelectedItem);
|
4393
|
@@ -278,15 +285,16 @@
|
4394
|
break;
|
4395
|
|
4396
|
case AddMap:
|
4397
|
+
|
4398
|
#ifdef QGISDEBUG
|
4399
|
std::cerr << "AddMap" << std::endl;
|
4400
|
#endif
|
4401
|
if ( mToolStep == 0 ) {
|
4402
|
- mRectangleItem = new Q3CanvasRectangle( p.x(), p.y(), 0, 0, mCanvas );
|
4403
|
+ mRectangleItem = new QGraphicsRectItem( p.x(), p.y(), 0, 0, 0, mCanvas );//null parent
|
4404
|
mRectangleItem->setBrush( Qt::NoBrush );
|
4405
|
- mRectangleItem->setPen( QPen(QColor(0,0,0), 1) );
|
4406
|
- mRectangleItem->setZ(100);
|
4407
|
- mRectangleItem->setActive(false);
|
4408
|
+ mRectangleItem->setPen( QPen(QColor(0,0,0), 0) );
|
4409
|
+ mRectangleItem->setZValue(100);
|
4410
|
+ //mRectangleItem->setActive(false);
|
4411
|
mRectangleItem->show();
|
4412
|
mToolStep = 1;
|
4413
|
}
|
4414
|
@@ -297,8 +305,7 @@
|
4415
|
|
4416
|
case AddVectorLegend:
|
4417
|
{
|
4418
|
- mNewCanvasItem->setX( p.x() );
|
4419
|
- mNewCanvasItem->setY( p.y() );
|
4420
|
+ mNewCanvasItem->setPos(p);
|
4421
|
QgsComposerVectorLegend *vl = dynamic_cast <QgsComposerVectorLegend*> (mNewCanvasItem);
|
4422
|
vl->writeSettings();
|
4423
|
mItems.push_back(vl);
|
4424
|
@@ -308,20 +315,16 @@
|
4425
|
// Select and show options
|
4426
|
vl->setSelected ( true );
|
4427
|
mComposer->showItemOptions ( vl->options() );
|
4428
|
- mSelectedItem = dynamic_cast <Q3CanvasItem*> (vl);
|
4429
|
+ mSelectedItem = dynamic_cast <QGraphicsItem*> (vl);
|
4430
|
|
4431
|
mCanvas->update();
|
4432
|
-
|
4433
|
- // Remember this position for later
|
4434
|
- mLastX = x;
|
4435
|
- mLastY = y;
|
4436
|
}
|
4437
|
break;
|
4438
|
|
4439
|
case AddLabel:
|
4440
|
{
|
4441
|
- mNewCanvasItem->setX( p.x() );
|
4442
|
- mNewCanvasItem->setY( p.y() );
|
4443
|
+ mNewCanvasItem->setPos(p);
|
4444
|
+
|
4445
|
QgsComposerLabel *lab = dynamic_cast <QgsComposerLabel*> (mNewCanvasItem);
|
4446
|
lab->writeSettings();
|
4447
|
mItems.push_back(lab);
|
4448
|
@@ -331,20 +334,15 @@
|
4449
|
// Select and show options
|
4450
|
lab->setSelected ( true );
|
4451
|
mComposer->showItemOptions ( lab->options() );
|
4452
|
- mSelectedItem = dynamic_cast <Q3CanvasItem*> (lab);
|
4453
|
+ mSelectedItem = dynamic_cast <QGraphicsItem*> (lab);
|
4454
|
|
4455
|
mCanvas->update();
|
4456
|
-
|
4457
|
- // Remember this position for later
|
4458
|
- mLastX = x;
|
4459
|
- mLastY = y;
|
4460
|
}
|
4461
|
break;
|
4462
|
|
4463
|
case AddScalebar:
|
4464
|
{
|
4465
|
- mNewCanvasItem->setX( p.x() );
|
4466
|
- mNewCanvasItem->setY( p.y() );
|
4467
|
+ mNewCanvasItem->setPos(p);
|
4468
|
QgsComposerScalebar *sb = dynamic_cast <QgsComposerScalebar*> (mNewCanvasItem);
|
4469
|
sb->writeSettings();
|
4470
|
mItems.push_back(sb);
|
4471
|
@@ -354,127 +352,123 @@
|
4472
|
// Select and show options
|
4473
|
sb->setSelected ( true );
|
4474
|
mComposer->showItemOptions ( sb->options() );
|
4475
|
- mSelectedItem = dynamic_cast <Q3CanvasItem*> (sb);
|
4476
|
+ mSelectedItem = dynamic_cast <QGraphicsItem*> (sb);
|
4477
|
|
4478
|
mCanvas->update();
|
4479
|
-
|
4480
|
- // Remember this position for later
|
4481
|
- mLastX = x;
|
4482
|
- mLastY = y;
|
4483
|
}
|
4484
|
break;
|
4485
|
|
4486
|
case AddPicture:
|
4487
|
{
|
4488
|
- //mNewCanvasItem->setX( p.x() );
|
4489
|
- //mNewCanvasItem->setY( p.y() );
|
4490
|
+ //set up the bounding rectangle
|
4491
|
+ //note: this rectangle gets used to keep track of the beginning click point for a picture
|
4492
|
+ mRectangleItem = new QGraphicsRectItem( p.x(), p.y(), 0, 0, 0, mCanvas );//null parent
|
4493
|
+ mRectangleItem->setBrush( Qt::NoBrush );
|
4494
|
+ mRectangleItem->setPen( QPen(QColor(0,0,0), 0, Qt::DashLine) );
|
4495
|
+ mRectangleItem->setZValue(100);
|
4496
|
+ mRectangleItem->show();
|
4497
|
|
4498
|
+
|
4499
|
+ mNewCanvasItem->setPos(p);
|
4500
|
+
|
4501
|
QgsComposerPicture *pi = dynamic_cast <QgsComposerPicture*> (mNewCanvasItem);
|
4502
|
- //pi->setSize (0, 0);
|
4503
|
- pi->setBox ( p.x(), p.y(), p.x(), p.y() );
|
4504
|
|
4505
|
+ pi->setSize( 0, 0 );
|
4506
|
+
|
4507
|
mCanvas->update();
|
4508
|
|
4509
|
mToolStep = 1;
|
4510
|
-
|
4511
|
}
|
4512
|
break;
|
4513
|
- }
|
4514
|
+ }
|
4515
|
}
|
4516
|
|
4517
|
-void QgsComposition::contentsMouseMoveEvent(QMouseEvent* e)
|
4518
|
+void QgsComposition::mouseMoveEvent(QMouseEvent* e)
|
4519
|
{
|
4520
|
#ifdef QGISDEBUG
|
4521
|
- std::cerr << "QgsComposition::contentsMouseMoveEvent() mTool = " << mTool << " mToolStep = "
|
4522
|
+#endif
|
4523
|
+ std::cerr << "QgsComposition::mouseMoveEvent() mTool = " << mTool << " mToolStep = "
|
4524
|
<< mToolStep << std::endl;
|
4525
|
-#endif
|
4526
|
|
4527
|
- QPoint p = mView->inverseWorldMatrix().map(e->pos());
|
4528
|
|
4529
|
+ QPointF p = mView->mapToScene(e->pos());
|
4530
|
+
|
4531
|
switch ( mTool ) {
|
4532
|
case Select:
|
4533
|
if ( mSelectedItem ) {
|
4534
|
- double x,y;
|
4535
|
- mView->inverseWorldMatrix().map( e->pos().x(), e->pos().y(), &x, &y );
|
4536
|
-
|
4537
|
- mSelectedItem->moveBy ( x - mLastX, y - mLastY );
|
4538
|
-
|
4539
|
- mLastX = x;
|
4540
|
- mLastY = y;
|
4541
|
+ mSelectedItem->setPos(p - mGrabPoint);
|
4542
|
mCanvas->update();
|
4543
|
}
|
4544
|
break;
|
4545
|
|
4546
|
case AddMap:
|
4547
|
- if ( mToolStep == 1 ) { // draw rectangle
|
4548
|
+ if ( mToolStep == 1 ) // draw rectangle while dragging
|
4549
|
+ {
|
4550
|
double x, y;
|
4551
|
- int w, h;
|
4552
|
+ double w, h;
|
4553
|
|
4554
|
- x = p.x() < mRectangleItem->x() ? p.x() : mRectangleItem->x();
|
4555
|
- y = p.y() < mRectangleItem->y() ? p.y() : mRectangleItem->y();
|
4556
|
+ x = p.x() < mRectangleItem->x() ? p.x() : mRectangleItem->rect().x();
|
4557
|
+ y = p.y() < mRectangleItem->y() ? p.y() : mRectangleItem->rect().y();
|
4558
|
|
4559
|
- w = abs ( p.x() - (int)mRectangleItem->x() );
|
4560
|
- h = abs ( p.y() - (int)mRectangleItem->y() );
|
4561
|
+ w = fabs ( p.x() - mRectangleItem->rect().x() );
|
4562
|
+ h = fabs ( p.y() - mRectangleItem->rect().y() );
|
4563
|
|
4564
|
- mRectangleItem->setX(x);
|
4565
|
- mRectangleItem->setY(y);
|
4566
|
+ mRectangleItem->setRect(QRectF(x, y, w, h));
|
4567
|
|
4568
|
- mRectangleItem->setSize(w,h);
|
4569
|
-
|
4570
|
mCanvas->update();
|
4571
|
- }
|
4572
|
+ }//END if(mToolStep == 1)
|
4573
|
break;
|
4574
|
|
4575
|
- case AddVectorLegend:
|
4576
|
- case AddLabel:
|
4577
|
- case AddScalebar:
|
4578
|
- mNewCanvasItem->move ( p.x(), p.y() );
|
4579
|
- mCanvas->update();
|
4580
|
- break;
|
4581
|
-
|
4582
|
case AddPicture:
|
4583
|
- if ( mToolStep == 1 ) { // draw rectangle
|
4584
|
+ if ( mToolStep == 1 )
|
4585
|
+ {
|
4586
|
QgsComposerPicture *pi = dynamic_cast <QgsComposerPicture*> (mNewCanvasItem);
|
4587
|
|
4588
|
- pi->setBox ( mLastPoint.x(), mLastPoint.y(), p.x(), p.y() );
|
4589
|
-/*
|
4590
|
double x, y;
|
4591
|
- int w, h;
|
4592
|
+ double w, h;
|
4593
|
|
4594
|
- x = p.x() < pi->QCanvasRectangle::x() ? p.x() : pi->QCanvasRectangle::x();
|
4595
|
- y = p.y() < pi->QCanvasRectangle::y() ? p.y() : pi->QCanvasRectangle::y();
|
4596
|
+ x = p.x() < mRectangleItem->x() ? p.x() : mRectangleItem->rect().x();
|
4597
|
+ y = p.y() < mRectangleItem->y() ? p.y() : mRectangleItem->rect().y();
|
4598
|
|
4599
|
- w = abs ( p.x() - (int)pi->QCanvasRectangle::x() );
|
4600
|
- h = abs ( p.y() - (int)pi->QCanvasRectangle::y() );
|
4601
|
+ w = fabs ( p.x() - mRectangleItem->rect().x() );
|
4602
|
+ h = fabs ( p.y() - mRectangleItem->rect().y() );
|
4603
|
|
4604
|
- pi->setX(x);
|
4605
|
- pi->setY(y);
|
4606
|
+ pi->setPos(x + w/2, y + h/2);
|
4607
|
+ pi->setSize(w, h);
|
4608
|
|
4609
|
- pi->setSize(w,h);
|
4610
|
-*/
|
4611
|
+ mRectangleItem->setRect(QRectF(x, y, w, h));
|
4612
|
|
4613
|
mCanvas->update();
|
4614
|
- break;
|
4615
|
- }
|
4616
|
+ }//END if(mToolStep == 1)
|
4617
|
+ break;
|
4618
|
+
|
4619
|
+ case AddScalebar:
|
4620
|
+ case AddVectorLegend:
|
4621
|
+ case AddLabel:
|
4622
|
+
|
4623
|
+ mNewCanvasItem->setPos(p);
|
4624
|
+ mCanvas->update();
|
4625
|
+ break;
|
4626
|
+
|
4627
|
}
|
4628
|
}
|
4629
|
|
4630
|
-void QgsComposition::contentsMouseReleaseEvent(QMouseEvent* e)
|
4631
|
+void QgsComposition::mouseReleaseEvent(QMouseEvent* e)
|
4632
|
{
|
4633
|
#ifdef QGISDEBUG
|
4634
|
- std::cerr << "QgsComposition::contentsMouseReleaseEvent() mTool = " << mTool
|
4635
|
+ std::cerr << "QgsComposition::mouseReleaseEvent() mTool = " << mTool
|
4636
|
<< " mToolStep = " << mToolStep << std::endl;
|
4637
|
#endif
|
4638
|
|
4639
|
- QPoint p = mView->inverseWorldMatrix().map(e->pos());
|
4640
|
+ QPoint p = mView->mapFromScene(e->pos());
|
4641
|
|
4642
|
switch ( mTool ) {
|
4643
|
case AddMap: // mToolStep should be always 1 but rectangle can be 0 size
|
4644
|
{
|
4645
|
- int x = (int) mRectangleItem->x();
|
4646
|
- int y = (int) mRectangleItem->y();
|
4647
|
- int w = mRectangleItem->width();
|
4648
|
- int h = mRectangleItem->height();
|
4649
|
+ int x = (int) mRectangleItem->rect().x();//use doubles?
|
4650
|
+ int y = (int) mRectangleItem->rect().y();
|
4651
|
+ int w = (int)mRectangleItem->rect().width();
|
4652
|
+ int h = (int)mRectangleItem->rect().height();
|
4653
|
delete mRectangleItem;
|
4654
|
mRectangleItem = 0;
|
4655
|
|
4656
|
@@ -483,9 +477,11 @@
|
4657
|
|
4658
|
QgsComposerMap *m = new QgsComposerMap ( this, mNextItemId++, x, y, w, h );
|
4659
|
|
4660
|
+ m->setPos(x, y);
|
4661
|
+
|
4662
|
m->setUserExtent( mMapCanvas->extent());
|
4663
|
mItems.push_back(m);
|
4664
|
- m->setSelected ( true );
|
4665
|
+ m->setSelected ( true );//do we need this twice?
|
4666
|
|
4667
|
if ( mSelectedItem ) {
|
4668
|
QgsComposerItem *coi = dynamic_cast <QgsComposerItem *> (mSelectedItem);
|
4669
|
@@ -494,31 +490,36 @@
|
4670
|
|
4671
|
m->setSelected ( true );
|
4672
|
mComposer->showItemOptions ( m->options() );
|
4673
|
- mSelectedItem = dynamic_cast <Q3CanvasItem *> (m);
|
4674
|
+ mSelectedItem = dynamic_cast <QGraphicsItem *> (m);
|
4675
|
} else {
|
4676
|
mToolStep = 0;
|
4677
|
}
|
4678
|
- mCanvas->setChanged ( QRect( x, y, w, h) ); // Should not be necessary
|
4679
|
mCanvas->update();
|
4680
|
}
|
4681
|
break;
|
4682
|
|
4683
|
case AddPicture:
|
4684
|
{
|
4685
|
+ double w = mRectangleItem->rect().width();
|
4686
|
+ double h = mRectangleItem->rect().height();
|
4687
|
+ delete mRectangleItem;
|
4688
|
+ mRectangleItem = 0;
|
4689
|
+
|
4690
|
QgsComposerPicture *pi = dynamic_cast <QgsComposerPicture*> (mNewCanvasItem);
|
4691
|
|
4692
|
- if ( mLastPoint.x()-p.x() != 0 && mLastPoint.y()-p.y() != 0 ) {
|
4693
|
- mNewCanvasItem = 0; // !!! Must be before mComposer->selectItem()
|
4694
|
- mComposer->selectItem(); // usually just one ???
|
4695
|
+ if ( w > 0 && h > 0 )
|
4696
|
+ {
|
4697
|
+ mNewCanvasItem = 0; // !!! Must be before mComposer->selectItem()
|
4698
|
+ mComposer->selectItem(); // usually just one ???
|
4699
|
|
4700
|
- pi->writeSettings();
|
4701
|
- mItems.push_back(pi);
|
4702
|
+ pi->writeSettings();
|
4703
|
+ mItems.push_back(pi);
|
4704
|
|
4705
|
- pi->setSelected ( true );
|
4706
|
- mComposer->showItemOptions ( pi->options() );
|
4707
|
- mSelectedItem = dynamic_cast <Q3CanvasItem*> (pi);
|
4708
|
+ pi->setSelected ( true );
|
4709
|
+ mComposer->showItemOptions ( pi->options() );
|
4710
|
+ mSelectedItem = dynamic_cast <QGraphicsItem*> (pi);
|
4711
|
|
4712
|
- mCanvas->update();
|
4713
|
+ mCanvas->update();
|
4714
|
|
4715
|
} else {
|
4716
|
mToolStep = 0;
|
4717
|
@@ -534,9 +535,12 @@
|
4718
|
}
|
4719
|
break;
|
4720
|
|
4721
|
- default:
|
4722
|
- // ignore any others...
|
4723
|
+ //We don't do anything special for labels, scalebars, or vector legends
|
4724
|
+ case AddLabel:
|
4725
|
+ case AddScalebar:
|
4726
|
+ case AddVectorLegend:
|
4727
|
break;
|
4728
|
+
|
4729
|
}
|
4730
|
}
|
4731
|
|
4732
|
@@ -599,13 +603,13 @@
|
4733
|
// A better solution here would be to set the canvas back to the
|
4734
|
// original size and carry on, but for the moment this will
|
4735
|
// prevent a crash due to an uncaught exception.
|
4736
|
- QMessageBox::critical( this, tr("Out of memory"),
|
4737
|
+ QMessageBox::critical( 0, tr("Out of memory"),
|
4738
|
tr("Qgis is unable to resize the paper size due to "
|
4739
|
"insufficient memory.\n It is best that you avoid "
|
4740
|
"using the map composer until you restart qgis.\n") );
|
4741
|
}
|
4742
|
|
4743
|
- mView->repaintContents();
|
4744
|
+// mView->repaintContents(); //just repaint();?
|
4745
|
writeSettings();
|
4746
|
}
|
4747
|
|
4748
|
@@ -653,21 +657,22 @@
|
4749
|
|
4750
|
// Remove paper if Print, reset if Preview
|
4751
|
if ( mPlotStyle == Print ) {
|
4752
|
- mPaperItem->setCanvas(0);
|
4753
|
- mCanvas->setBackgroundColor( Qt::white );
|
4754
|
+// mPaperItem->setScene(0);
|
4755
|
+// mCanvas->setBackgroundColor( Qt::white );
|
4756
|
} else {
|
4757
|
- mPaperItem->setCanvas(mCanvas);
|
4758
|
- mCanvas->setBackgroundColor( QColor(180,180,180) );
|
4759
|
+// mPaperItem->setScene(mCanvas);
|
4760
|
+// mCanvas->setBackgroundColor( QColor(180,180,180) );
|
4761
|
|
4762
|
}
|
4763
|
}
|
4764
|
|
4765
|
double QgsComposition::viewScale ( void )
|
4766
|
{
|
4767
|
- double scale = mView->worldMatrix().m11();
|
4768
|
+ double scale = mView->matrix().m11();
|
4769
|
return scale;
|
4770
|
}
|
4771
|
|
4772
|
+//does this even work?
|
4773
|
void QgsComposition::refresh()
|
4774
|
{
|
4775
|
// TODO add signals to map canvas
|
4776
|
@@ -681,14 +686,14 @@
|
4777
|
vl->recalculate();
|
4778
|
}
|
4779
|
}
|
4780
|
-
|
4781
|
+ mCanvas->update();
|
4782
|
}
|
4783
|
|
4784
|
int QgsComposition::id ( void ) { return mId; }
|
4785
|
|
4786
|
QgsComposer *QgsComposition::composer(void) { return mComposer; }
|
4787
|
|
4788
|
-Q3Canvas *QgsComposition::canvas(void) { return mCanvas; }
|
4789
|
+QGraphicsScene *QgsComposition::canvas(void) { return mCanvas; }
|
4790
|
|
4791
|
double QgsComposition::paperWidth ( void ) { return mPaperWidth; }
|
4792
|
|
4793
|
@@ -698,9 +703,7 @@
|
4794
|
|
4795
|
int QgsComposition::resolution ( void ) { return mResolution; }
|
4796
|
|
4797
|
-int QgsComposition::scale( void ) {
|
4798
|
- return mScale;
|
4799
|
-}
|
4800
|
+int QgsComposition::scale( void ) { return mScale; }
|
4801
|
|
4802
|
double QgsComposition::toMM ( int v ) { return v/mScale ; }
|
4803
|
|
4804
|
@@ -719,8 +722,7 @@
|
4805
|
mComposer->showItemOptions ( (QWidget *) 0 );
|
4806
|
|
4807
|
if ( mNewCanvasItem ) {
|
4808
|
- mNewCanvasItem->setX( -1000 );
|
4809
|
- mNewCanvasItem->setY( -1000 );
|
4810
|
+ mNewCanvasItem->setPos(-1000, -1000);
|
4811
|
mCanvas->update();
|
4812
|
|
4813
|
delete mNewCanvasItem;
|
4814
|
@@ -737,71 +739,75 @@
|
4815
|
if ( mNewCanvasItem ) delete mNewCanvasItem;
|
4816
|
|
4817
|
// Create new object outside the visible area
|
4818
|
- QgsComposerVectorLegend *vl = new QgsComposerVectorLegend ( this, mNextItemId++,
|
4819
|
- (-1000)*mScale, (-1000)*mScale, (int) (mScale*mPaperHeight/50) );
|
4820
|
- mNewCanvasItem = dynamic_cast <Q3CanvasItem *> (vl);
|
4821
|
-
|
4822
|
+ QgsComposerVectorLegend *vl = new QgsComposerVectorLegend ( this, mNextItemId++, -1000, -1000, (int) (mPaperHeight/50));
|
4823
|
+ mNewCanvasItem = dynamic_cast <QGraphicsItem *> (vl);
|
4824
|
mComposer->showItemOptions ( vl->options() );
|
4825
|
|
4826
|
mView->viewport()->setMouseTracking ( true ); // to recieve mouse move
|
4827
|
- } else if ( tool == AddLabel ) {
|
4828
|
+
|
4829
|
+ }
|
4830
|
+ else if ( tool == AddLabel ) {
|
4831
|
if ( mNewCanvasItem ) delete mNewCanvasItem;
|
4832
|
|
4833
|
// Create new object outside the visible area
|
4834
|
- QgsComposerLabel *lab = new QgsComposerLabel ( this, mNextItemId++,
|
4835
|
- (-1000)*mScale, (-1000)*mScale, tr("Label"), (int) (mScale*mPaperHeight/40) );
|
4836
|
- mNewCanvasItem = dynamic_cast <Q3CanvasItem *> (lab);
|
4837
|
+ QgsComposerLabel *lab = new QgsComposerLabel ( this, mNextItemId++, -1000, -1000, tr("Label"), (int) (mPaperHeight/40));
|
4838
|
+
|
4839
|
+ mNewCanvasItem = dynamic_cast <QGraphicsItem *> (lab);
|
4840
|
mComposer->showItemOptions ( lab->options() );
|
4841
|
|
4842
|
mView->viewport()->setMouseTracking ( true ); // to recieve mouse move
|
4843
|
- } else if ( tool == AddScalebar ) {
|
4844
|
+ }
|
4845
|
+ else if ( tool == AddScalebar ) {
|
4846
|
if ( mNewCanvasItem ) delete mNewCanvasItem;
|
4847
|
|
4848
|
// Create new object outside the visible area
|
4849
|
- QgsComposerScalebar *sb = new QgsComposerScalebar ( this, mNextItemId++,
|
4850
|
- (-1000)*mScale, (-1000)*mScale );
|
4851
|
- mNewCanvasItem = dynamic_cast <Q3CanvasItem *> (sb);
|
4852
|
+ QgsComposerScalebar *sb = new QgsComposerScalebar ( this, mNextItemId++, -1000, -1000);
|
4853
|
+ mNewCanvasItem = dynamic_cast <QGraphicsItem*> (sb);
|
4854
|
mComposer->showItemOptions ( sb->options() );
|
4855
|
|
4856
|
mView->viewport()->setMouseTracking ( true ); // to recieve mouse move
|
4857
|
- } else if ( tool == AddPicture ) {
|
4858
|
+ }
|
4859
|
+ else if ( tool == AddPicture )
|
4860
|
+ {
|
4861
|
if ( mNewCanvasItem ) delete mNewCanvasItem;
|
4862
|
|
4863
|
- while ( 1 )
|
4864
|
+ while ( 1 ) // keep trying until we get a valid image or the user clicks cancel
|
4865
|
{
|
4866
|
- QString file = QgsComposerPicture::pictureDialog();
|
4867
|
+ QString file = QgsComposerPicture::pictureDialog();
|
4868
|
|
4869
|
- if ( file.isNull() )
|
4870
|
- {
|
4871
|
+ if ( file.isNull() ) //user clicked cancel
|
4872
|
+ {
|
4873
|
// TODO: This is not nice, because selectItem() calls
|
4874
|
// this function, do it better
|
4875
|
mComposer->selectItem();
|
4876
|
tool = Select;
|
4877
|
- break;
|
4878
|
- }
|
4879
|
+ break; //quit the loop
|
4880
|
+ }
|
4881
|
|
4882
|
- // Create new object outside the visible area
|
4883
|
- QgsComposerPicture *pi = new QgsComposerPicture ( this, mNextItemId++, file );
|
4884
|
+ // Create new object outside the visible area
|
4885
|
+ QgsComposerPicture *pi = new QgsComposerPicture ( this, mNextItemId++, file );
|
4886
|
|
4887
|
- if ( pi->pictureValid() )
|
4888
|
- {
|
4889
|
+ if ( pi->pictureValid() )
|
4890
|
+ {
|
4891
|
+#ifdef QGISDEBUG
|
4892
|
std::cout << "picture is valid" << std::endl;
|
4893
|
- mNewCanvasItem = dynamic_cast <Q3CanvasItem *> (pi);
|
4894
|
+#endif
|
4895
|
+ mNewCanvasItem = dynamic_cast <QGraphicsItem *> (pi);
|
4896
|
mComposer->showItemOptions ( pi->options() );
|
4897
|
|
4898
|
- mView->viewport()->setMouseTracking ( true ); // to recieve mouse move
|
4899
|
- break;
|
4900
|
- }
|
4901
|
- else
|
4902
|
- {
|
4903
|
+ mView->viewport()->setMouseTracking ( true ); // start tracking the mouse
|
4904
|
+ break; //quit the loop
|
4905
|
+ }
|
4906
|
+ else
|
4907
|
+ {
|
4908
|
QMessageBox::warning( this, tr("Warning"),
|
4909
|
tr("Cannot load picture.") );
|
4910
|
-
|
4911
|
delete pi;
|
4912
|
- }
|
4913
|
+ }
|
4914
|
}
|
4915
|
- }
|
4916
|
|
4917
|
+ }//END if(tool == AddPicture)*/
|
4918
|
+
|
4919
|
mTool = tool;
|
4920
|
mToolStep = 0;
|
4921
|
}
|
4922
|
@@ -830,10 +836,10 @@
|
4923
|
return 0;
|
4924
|
}
|
4925
|
|
4926
|
-int QgsComposition::selectionBoxSize ( void )
|
4927
|
+double QgsComposition::selectionBoxSize ( void )
|
4928
|
{
|
4929
|
- // Scale rectangle, keep rectangle of fixed size in screen points
|
4930
|
- return (int) (7/viewScale());
|
4931
|
+ // Scale rectangle based on the zoom level, so we keep the rectangle a fixed size on the screen
|
4932
|
+ return 7.0/viewScale();
|
4933
|
}
|
4934
|
|
4935
|
QPen QgsComposition::selectionPen ( void )
|
4936
|
@@ -900,7 +906,7 @@
|
4937
|
path.sprintf("/composition_%d", mId );
|
4938
|
QStringList el = QgsProject::instance()->subkeyList ( "Compositions", path );
|
4939
|
|
4940
|
- // First maps because they can be used by other objects
|
4941
|
+ // First create the map(s) because they are often required by other objects
|
4942
|
for ( QStringList::iterator it = el.begin(); it != el.end(); ++it ) {
|
4943
|
#ifdef QGISDEBUG
|
4944
|
std::cout << "key: " << (*it).toLocal8Bit().data() << std::endl;
|
4945
|
Index: src/app/composer/qgscomposition.h
|
4946
|
===================================================================
|
4947
|
--- src/app/composer/qgscomposition.h (revision 7070)
|
4948
|
+++ src/app/composer/qgscomposition.h (working copy)
|
4949
|
@@ -27,9 +27,10 @@
|
4950
|
class QgsComposerView;
|
4951
|
class QgsMapCanvas;
|
4952
|
|
4953
|
-class Q3Canvas;
|
4954
|
-class Q3CanvasItem;
|
4955
|
-class Q3CanvasRectangle;
|
4956
|
+class QGraphicsScene;
|
4957
|
+class QGraphicsItem;
|
4958
|
+class QGraphicsRectItem;
|
4959
|
+
|
4960
|
class QDomDocument;
|
4961
|
class QDomNode;
|
4962
|
class QKeyEvent;
|
4963
|
@@ -148,16 +149,16 @@
|
4964
|
void setActive ( bool active );
|
4965
|
|
4966
|
/** \brief returns pointer to canvas */
|
4967
|
- Q3Canvas *canvas(void);
|
4968
|
+ QGraphicsScene *canvas(void);
|
4969
|
|
4970
|
- /** \brief recieves contentsMousePressEvent from view */
|
4971
|
- void contentsMousePressEvent(QMouseEvent*);
|
4972
|
+ /** \brief recieves mousePressEvent from view */
|
4973
|
+ void mousePressEvent(QMouseEvent*);
|
4974
|
|
4975
|
- /** \brief recieves contentsMouseReleaseEvent from view */
|
4976
|
- void contentsMouseReleaseEvent(QMouseEvent*);
|
4977
|
+ /** \brief recieves mouseReleaseEvent from view */
|
4978
|
+ void mouseReleaseEvent(QMouseEvent*);
|
4979
|
|
4980
|
- /** \brief recieves contentsMouseMoveEvent from view */
|
4981
|
- void contentsMouseMoveEvent(QMouseEvent*);
|
4982
|
+ /** \brief recieves mouseMoveEvent from view */
|
4983
|
+ void mouseMoveEvent(QMouseEvent*);
|
4984
|
|
4985
|
/** \brief recieves keyPressEvent from view */
|
4986
|
void keyPressEvent ( QKeyEvent * e );
|
4987
|
@@ -188,8 +189,8 @@
|
4988
|
/** \brief Return number screen pixels / canvas point */
|
4989
|
double viewScale( void );
|
4990
|
|
4991
|
- /** \brief Selection box size in _canvas_ units */
|
4992
|
- int selectionBoxSize ( void );
|
4993
|
+ /** \brief Selection box size in _scene_ units */
|
4994
|
+ double selectionBoxSize ( void );
|
4995
|
|
4996
|
/** \brief Selection box pen and brush */
|
4997
|
QPen selectionPen ( void );
|
4998
|
@@ -268,7 +269,7 @@
|
4999
|
QgsComposer *mComposer;
|
5000
|
|
5001
|
/** \brief Canvas. One per composition, created by QgsComposition */
|
5002
|
- Q3Canvas *mCanvas;
|
5003
|
+ QGraphicsScene *mCanvas;
|
5004
|
|
5005
|
/** \brief Pointer to canvas view */
|
5006
|
QgsComposerView *mView;
|
5007
|
@@ -276,15 +277,11 @@
|
5008
|
/** \brief List of all composer items */
|
5009
|
std::list<QgsComposerItem*> mItems;
|
5010
|
|
5011
|
- /** \brief Last position of the mouse in mView */
|
5012
|
- double mLastX;
|
5013
|
- double mLastY;
|
5014
|
-
|
5015
|
/** \brief Selected item, 0 if no item is selected */
|
5016
|
- Q3CanvasItem* mSelectedItem;
|
5017
|
+ QGraphicsItem* mSelectedItem;
|
5018
|
|
5019
|
/** \brief Item representing the paper */
|
5020
|
- Q3CanvasRectangle *mPaperItem;
|
5021
|
+ QGraphicsRectItem *mPaperItem;
|
5022
|
|
5023
|
/** \brief Plot style */
|
5024
|
PlotStyle mPlotStyle;
|
5025
|
@@ -296,10 +293,10 @@
|
5026
|
int mToolStep;
|
5027
|
|
5028
|
/** \brief Temporary rectangle item used as rectangle drawn by mouse */
|
5029
|
- Q3CanvasRectangle *mRectangleItem;
|
5030
|
-
|
5031
|
+ QGraphicsRectItem *mRectangleItem;
|
5032
|
+
|
5033
|
/** \brief Temporary item used as pointer to new objecs which must be drawn */
|
5034
|
- Q3CanvasItem *mNewCanvasItem;
|
5035
|
+ QGraphicsItem *mNewCanvasItem;
|
5036
|
|
5037
|
/** \brief Resolution in DPI */
|
5038
|
int mResolution;
|
5039
|
@@ -310,14 +307,16 @@
|
5040
|
/** \brief id for next new item */
|
5041
|
int mNextItemId;
|
5042
|
|
5043
|
+ QGraphicsRectItem *sizeBox;
|
5044
|
+
|
5045
|
/** \brief Create canvas */
|
5046
|
void createCanvas(void);
|
5047
|
|
5048
|
/** \brief Resize canvas to current paper size */
|
5049
|
void resizeCanvas(void);
|
5050
|
|
5051
|
- /** \brief first point, set with MousePressEvent */
|
5052
|
- QPoint mLastPoint;
|
5053
|
+ /** \brief Grab point, set with MousePressEvent */
|
5054
|
+ QPointF mGrabPoint;
|
5055
|
};
|
5056
|
|
5057
|
#endif
|
5058
|
Index: src/app/composer/qgscomposerview.cpp
|
5059
|
===================================================================
|
5060
|
--- src/app/composer/qgscomposerview.cpp (revision 7070)
|
5061
|
+++ src/app/composer/qgscomposerview.cpp (working copy)
|
5062
|
@@ -29,7 +29,8 @@
|
5063
|
|
5064
|
// Note: |WRepaintNoErase|WResizeNoErase|WStaticContents doeen't make it faster
|
5065
|
QgsComposerView::QgsComposerView( QgsComposer *composer, QWidget* parent, const char* name, Qt::WFlags f) :
|
5066
|
- Q3CanvasView(parent,name,f|Qt::WNoAutoErase|Qt::WResizeNoErase|Qt::WStaticContents)
|
5067
|
+ QGraphicsView(parent)
|
5068
|
+//,name,f|Qt::WNoAutoErase|Qt::WResizeNoErase|Qt::WStaticContents
|
5069
|
{
|
5070
|
mComposer = composer;
|
5071
|
|
5072
|
@@ -37,23 +38,26 @@
|
5073
|
setEnabled ( true );
|
5074
|
setFocusPolicy ( Qt::StrongFocus );
|
5075
|
setFocusProxy ( 0 );
|
5076
|
+
|
5077
|
+ setResizeAnchor ( QGraphicsView::AnchorViewCenter );
|
5078
|
+
|
5079
|
}
|
5080
|
|
5081
|
-void QgsComposerView::contentsMousePressEvent(QMouseEvent* e)
|
5082
|
+void QgsComposerView::mousePressEvent(QMouseEvent* e)
|
5083
|
{
|
5084
|
// TODO: find how to get focus without setFocus
|
5085
|
setFocus ();
|
5086
|
- mComposer->composition()->contentsMousePressEvent(e);
|
5087
|
+ mComposer->composition()->mousePressEvent(e);
|
5088
|
}
|
5089
|
|
5090
|
-void QgsComposerView::contentsMouseReleaseEvent(QMouseEvent* e)
|
5091
|
+void QgsComposerView::mouseReleaseEvent(QMouseEvent* e)
|
5092
|
{
|
5093
|
- mComposer->composition()->contentsMouseReleaseEvent(e);
|
5094
|
+ mComposer->composition()->mouseReleaseEvent(e);
|
5095
|
}
|
5096
|
|
5097
|
-void QgsComposerView::contentsMouseMoveEvent(QMouseEvent* e)
|
5098
|
+void QgsComposerView::mouseMoveEvent(QMouseEvent* e)
|
5099
|
{
|
5100
|
- mComposer->composition()->contentsMouseMoveEvent(e);
|
5101
|
+ mComposer->composition()->mouseMoveEvent(e);
|
5102
|
}
|
5103
|
|
5104
|
void QgsComposerView::keyPressEvent ( QKeyEvent * e )
|
5105
|
@@ -63,5 +67,13 @@
|
5106
|
|
5107
|
void QgsComposerView::resizeEvent ( QResizeEvent * )
|
5108
|
{
|
5109
|
- mComposer->zoomFull();
|
5110
|
+/* BUG: When QT adds scrollbars because we're zooming in, it causes a resizeEvent.
|
5111
|
+ * If we call zoomFull(), we reset the view size, which keeps us from zooming in.
|
5112
|
+ * Really, we should do something like re-center the window.
|
5113
|
+*/
|
5114
|
+ //mComposer->zoomFull();
|
5115
|
+std::cout << "resize anchor: " << resizeAnchor() << std::endl;
|
5116
|
}
|
5117
|
+
|
5118
|
+//TODO: add mouse wheel event forwarding
|
5119
|
+
|