Skip to content

File tree

3 files changed

+40
-66
lines changed

3 files changed

+40
-66
lines changed
 

‎src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,41 +188,26 @@ void QgsGrassPlugin::initGui()
188188
mCanvas = qGisInterface->getMapCanvas();
189189

190190
// Create the action for tool
191-
#if QT_VERSION < 0x040000
192-
mOpenMapsetAction = new QAction( "Open mapset", 0, this );
193-
mNewMapsetAction = new QAction( "New mapset", 0, this );
194-
mCloseMapsetAction = new QAction( "Close mapset", 0, this );
195-
mAddVectorAction = new QAction("Add GRASS vector layer", QIcon(icon_add_vector),
196-
"Add GRASS vector layer",0, this, "addVector");
197-
mAddRasterAction = new QAction("Add GRASS raster layer", QIcon(icon_add_raster),
198-
"Add GRASS raster layer",0, this, "addRaster");
199-
mOpenToolsAction = new QAction("Open GRASS tools", QIcon(icon_grass_tools),
200-
"Open GRASS tools",0, this, "openTools");
201-
mRegionAction = new QAction("Display Current Grass Region", QIcon(icon_grass_region),
202-
"Display Current Grass Region",0, this, "region", true);
203-
mEditRegionAction = new QAction("Edit Current Grass Region", QIcon(icon_grass_region_edit),
204-
"Edit Current Grass Region",0, this, "editRegion");
205-
mEditAction = new QAction("Edit Grass Vector layer", QIcon(icon_grass_edit),
206-
"Edit Grass Vector layer",0, this, "edit");
207-
mNewVectorAction = new QAction("Create new Grass Vector", 0, this);
208-
#else
209191
mOpenMapsetAction = new QAction( "Open mapset", this );
210192
mNewMapsetAction = new QAction( "New mapset", this );
211193
mCloseMapsetAction = new QAction( "Close mapset", this );
194+
212195
mAddVectorAction = new QAction(QIcon(icon_add_vector),
213196
"Add GRASS vector layer", this);
214197
mAddRasterAction = new QAction(QIcon(icon_add_raster),
215198
"Add GRASS raster layer", this);
216199
mOpenToolsAction = new QAction(QIcon(icon_grass_tools),
217200
"Open GRASS tools", this);
201+
218202
mRegionAction = new QAction(QIcon(icon_grass_region),
219203
"Display Current Grass Region", this);
204+
mRegionAction->setCheckable(true);
205+
220206
mEditRegionAction = new QAction(QIcon(icon_grass_region_edit),
221207
"Edit Current Grass Region", this);
222208
mEditAction = new QAction(QIcon(icon_grass_edit),
223209
"Edit Grass Vector layer", this);
224210
mNewVectorAction = new QAction("Create new Grass Vector", this);
225-
#endif
226211

227212
mAddVectorAction->setWhatsThis("Adds a GRASS vector layer to the map canvas");
228213
mAddRasterAction->setWhatsThis("Adds a GRASS raster layer to the map canvas");
@@ -700,8 +685,7 @@ void QgsGrassPlugin::changeRegion(void)
700685
}
701686

702687
QgsGrassRegion *reg = new QgsGrassRegion(this, qgisMainWindowPointer, qGisInterface,
703-
qgisMainWindowPointer, 0,
704-
Qt::WType_Dialog );
688+
qgisMainWindowPointer, Qt::WType_Dialog );
705689

706690
reg->show();
707691
}

‎src/plugins/grass/qgsgrassregion.cpp

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <qinputdialog.h>
2828
#include <qpainter.h>
2929
#include <qpen.h>
30-
#include <q3pointarray.h>
30+
#include <qpoint.h>
3131
#include <qcursor.h>
3232
#include <qnamespace.h>
3333
#include <qsettings.h>
@@ -41,6 +41,8 @@
4141
#include <qspinbox.h>
4242
#include <qglobal.h>
4343

44+
#include <QRubberBand>
45+
4446
#include <qgsrasterlayer.h>
4547
#include "qgis.h"
4648
#include "qgisapp.h"
@@ -62,15 +64,15 @@ extern "C" {
6264
bool QgsGrassRegion::mRunning = false;
6365

6466
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 ( )
6969
{
7070
#ifdef QGISDEBUG
7171
std::cerr << "QgsGrassRegion()" << std::endl;
7272
#endif
7373

74+
setupUi(this);
75+
7476
mRunning = true;
7577
mPlugin = plugin;
7678
mQgisApp = qgisApp;
@@ -80,7 +82,6 @@ QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, Qgis
8082
mDraw = false;
8183
mUpdatingGui = false;
8284
mDisplayed = false;
83-
mPointArray.resize(5);
8485

8586
// Set input validators
8687
QDoubleValidator *dv = new QDoubleValidator(0);
@@ -156,6 +157,9 @@ QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, Qgis
156157
mWidthSpinBox->setValue( pen.width() );
157158
connect( mWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeWidth()));
158159

160+
mRubberBand = new QRubberBand ( QRubberBand::Rectangle, mCanvas );
161+
162+
setAttribute ( Qt::WA_DeleteOnClose );
159163
displayRegion();
160164
}
161165

@@ -211,6 +215,7 @@ void QgsGrassRegion::setGuiValues( bool north, bool south, bool east, bool west,
211215

212216
QgsGrassRegion::~QgsGrassRegion ()
213217
{
218+
delete mRubberBand;
214219
mRunning = false;
215220
}
216221

@@ -336,10 +341,14 @@ void QgsGrassRegion::mouseEventReceiverClick( QgsPoint & point )
336341
draw ( mX, mY, point.x(), point.y() );
337342
mDraw = false;
338343
}
344+
mRubberBand->show();
339345
}
340346

341347
void QgsGrassRegion::mouseEventReceiverMove( QgsPoint & point )
342348
{
349+
#ifdef QGISDEBUG
350+
std::cerr << "QgsGrassRegion::mouseEventReceiverMove()" << std::endl;
351+
#endif
343352
if ( !mDraw ) return;
344353
draw ( mX, mY, point.x(), point.y() );
345354
}
@@ -378,44 +387,20 @@ void QgsGrassRegion::displayRegion()
378387
std::cerr << "QgsGrassRegion::displayRegion()" << std::endl;
379388
#endif
380389

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);
400392

401393
QgsMapToPixel *transform = mCanvas->getCoordinateTransform();
402394

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 );
410397

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));
414402

415403
mDisplayed = true;
416-
#else
417-
// TODO: Qt4 uses QRubberBand, need to refactor.
418-
#endif
419404

420405
}
421406

@@ -453,15 +438,19 @@ void QgsGrassRegion::accept()
453438
}
454439

455440
saveWindowLocation();
441+
mRubberBand->hide();
442+
mRunning = false;
456443
close();
457-
delete this;
444+
//delete this;
458445
}
459446

460447
void QgsGrassRegion::reject()
461448
{
462449
saveWindowLocation();
450+
mRubberBand->hide();
451+
mRunning = false;
463452
close();
464-
delete this;
453+
//delete this;
465454
}
466455

467456
void QgsGrassRegion::restorePosition()

‎src/plugins/grass/qgsgrassregion.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Q3ButtonGroup;
2727
class QgsPoint;
2828
#include "ui_qgsgrassregionbase.h"
2929
#include <QDialog>
30+
#include <QRubberBand>
3031

3132
extern "C" {
3233
#include <gis.h>
@@ -43,8 +44,7 @@ class QgsGrassRegion: public QDialog, private Ui::QgsGrassRegionBase
4344
public:
4445
//! Constructor
4546
QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, QgisIface *iface,
46-
QWidget * parent = 0, const char * name = 0,
47-
Qt::WFlags f = 0 );
47+
QWidget * parent = 0, Qt::WFlags f = 0 );
4848

4949
//! Destructor
5050
~QgsGrassRegion();
@@ -54,9 +54,11 @@ class QgsGrassRegion: public QDialog, private Ui::QgsGrassRegionBase
5454

5555
public slots:
5656
//! OK
57+
void on_acceptButton_clicked() { accept(); }
5758
void accept ( void );
5859

5960
//! Close
61+
void on_rejectButton_clicked() { reject(); }
6062
void reject ( void );
6163

6264
//! Called when rendering is finished
@@ -114,9 +116,6 @@ public slots:
114116
//! Region was displayed
115117
bool mDisplayed;
116118

117-
//! Old displayed region points
118-
Q3PointArray mPointArray;
119-
120119
//! Draw region
121120
void draw ( double x1, double y1, double x2, double y2 );
122121

@@ -141,6 +140,8 @@ public slots:
141140

142141
// Format N, S, E, W value
143142
QString formatEdge ( double v );
143+
144+
QRubberBand *mRubberBand;
144145
};
145146

146147
#endif // QGSGRASSREGION_H

0 commit comments

Comments
 (0)
Please sign in to comment.