27
27
#include < qinputdialog.h>
28
28
#include < qpainter.h>
29
29
#include < qpen.h>
30
- #include < q3pointarray .h>
30
+ #include < qpoint .h>
31
31
#include < qcursor.h>
32
32
#include < qnamespace.h>
33
33
#include < qsettings.h>
41
41
#include < qspinbox.h>
42
42
#include < qglobal.h>
43
43
44
+ #include < QRubberBand>
45
+
44
46
#include < qgsrasterlayer.h>
45
47
#include " qgis.h"
46
48
#include " qgisapp.h"
@@ -62,15 +64,15 @@ extern "C" {
62
64
bool QgsGrassRegion::mRunning = false ;
63
65
64
66
QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, QgisIface *iface,
65
- QWidget * parent, const char * name, Qt::WFlags f )
66
- // :QgsGrassRegionBase ( parent, name, f )
67
- // Tim removed params durint qt4 ui port - FIXME
68
- :QgsGrassRegionBase ( )
67
+ QWidget * parent, Qt::WFlags f )
68
+ :QDialog(parent, f), QgsGrassRegionBase ( )
69
69
{
70
70
#ifdef QGISDEBUG
71
71
std::cerr << " QgsGrassRegion()" << std::endl;
72
72
#endif
73
73
74
+ setupUi (this );
75
+
74
76
mRunning = true ;
75
77
mPlugin = plugin;
76
78
mQgisApp = qgisApp;
@@ -80,7 +82,6 @@ QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, Qgis
80
82
mDraw = false ;
81
83
mUpdatingGui = false ;
82
84
mDisplayed = false ;
83
- mPointArray .resize (5 );
84
85
85
86
// Set input validators
86
87
QDoubleValidator *dv = new QDoubleValidator (0 );
@@ -156,6 +157,9 @@ QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, Qgis
156
157
mWidthSpinBox ->setValue ( pen.width () );
157
158
connect ( mWidthSpinBox , SIGNAL (valueChanged (int )), this , SLOT (changeWidth ()));
158
159
160
+ mRubberBand = new QRubberBand ( QRubberBand::Rectangle, mCanvas );
161
+
162
+ setAttribute ( Qt::WA_DeleteOnClose );
159
163
displayRegion ();
160
164
}
161
165
@@ -211,6 +215,7 @@ void QgsGrassRegion::setGuiValues( bool north, bool south, bool east, bool west,
211
215
212
216
QgsGrassRegion::~QgsGrassRegion ()
213
217
{
218
+ delete mRubberBand ;
214
219
mRunning = false ;
215
220
}
216
221
@@ -336,10 +341,14 @@ void QgsGrassRegion::mouseEventReceiverClick( QgsPoint & point )
336
341
draw ( mX , mY , point.x (), point.y () );
337
342
mDraw = false ;
338
343
}
344
+ mRubberBand ->show ();
339
345
}
340
346
341
347
void QgsGrassRegion::mouseEventReceiverMove ( QgsPoint & point )
342
348
{
349
+ #ifdef QGISDEBUG
350
+ std::cerr << " QgsGrassRegion::mouseEventReceiverMove()" << std::endl;
351
+ #endif
343
352
if ( !mDraw ) return ;
344
353
draw ( mX , mY , point.x (), point.y () );
345
354
}
@@ -378,44 +387,20 @@ void QgsGrassRegion::displayRegion()
378
387
std::cerr << " QgsGrassRegion::displayRegion()" << std::endl;
379
388
#endif
380
389
381
- #if QT_VERSION < 0x040000
382
- QPainter *painter = new QPainter ();
383
- QPixmap *pixmap = mCanvas ->canvasPixmap ();
384
- painter->begin (pixmap);
385
- painter->setRasterOp (Qt::XorROP);
386
- painter->setPen ( QColor (125 ,125 ,125 ) );
387
-
388
- if ( mDisplayed ) { // delete old
389
- painter->drawPolyline ( mPointArray );
390
- }
391
-
392
- std::vector<QgsPoint> points;
393
- points.resize (5 );
394
-
395
- points[0 ].setX (mWindow .west ); points[0 ].setY (mWindow .south );
396
- points[1 ].setX (mWindow .east ); points[1 ].setY (mWindow .south );
397
- points[2 ].setX (mWindow .east ); points[2 ].setY (mWindow .north );
398
- points[3 ].setX (mWindow .west ); points[3 ].setY (mWindow .north );
399
- points[4 ].setX (mWindow .west ); points[4 ].setY (mWindow .south );
390
+ QgsPoint ul (mWindow .west , mWindow .north );
391
+ QgsPoint lr (mWindow .east , mWindow .south );
400
392
401
393
QgsMapToPixel *transform = mCanvas ->getCoordinateTransform ();
402
394
403
- for ( int i = 0 ; i < 5 ; i++ ) {
404
- transform->transform ( &(points[i]) );
405
- mPointArray .setPoint ( i, static_cast <int >(points[i].x ()),
406
- static_cast <int >(points[i].y ()) );
407
- }
408
-
409
- painter->drawPolyline ( mPointArray );
395
+ transform->transform ( &ul );
396
+ transform->transform ( &lr );
410
397
411
- painter->end ();
412
- mCanvas ->repaint (false );
413
- delete painter;
398
+ QPoint qul ( static_cast <int >(ul.x ()), static_cast <int >(ul.y ()) );
399
+ QPoint qlr ( static_cast <int >(lr.x ()), static_cast <int >(lr.y ()) );
400
+
401
+ mRubberBand ->setGeometry ( QRect (qul,qlr));
414
402
415
403
mDisplayed = true ;
416
- #else
417
- // TODO: Qt4 uses QRubberBand, need to refactor.
418
- #endif
419
404
420
405
}
421
406
@@ -453,15 +438,19 @@ void QgsGrassRegion::accept()
453
438
}
454
439
455
440
saveWindowLocation ();
441
+ mRubberBand ->hide ();
442
+ mRunning = false ;
456
443
close ();
457
- delete this ;
444
+ // delete this;
458
445
}
459
446
460
447
void QgsGrassRegion::reject ()
461
448
{
462
449
saveWindowLocation ();
450
+ mRubberBand ->hide ();
451
+ mRunning = false ;
463
452
close ();
464
- delete this ;
453
+ // delete this;
465
454
}
466
455
467
456
void QgsGrassRegion::restorePosition ()
0 commit comments