Skip to content

Commit 77ce11f

Browse files
author
brushtyler
committedNov 14, 2010
cleaned the "select region" GUI for GRASS,
fixed validation of input git-svn-id: http://svn.osgeo.org/qgis/trunk@14660 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7bb2641 commit 77ce11f

File tree

4 files changed

+378
-694
lines changed

4 files changed

+378
-694
lines changed
 

‎src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ void QgsGrassPlugin::changeRegion( void )
651651
}
652652

653653
// Warning: don't use Qt::WType_Dialog, it would ignore restorePosition
654-
mRegion = new QgsGrassRegion( this, qGisInterface, qGisInterface->mainWindow(), Qt::Window );
654+
mRegion = new QgsGrassRegion( this, qGisInterface, qGisInterface->mainWindow() );
655655

656656
connect( mRegion, SIGNAL( destroyed( QObject * ) ), this, SLOT( regionClosed() ) );
657657

‎src/plugins/grass/qgsgrassregion.cpp

Lines changed: 178 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -33,82 +33,76 @@
3333

3434

3535
/** map tool which uses rubber band for changing grass region */
36-
class QgsGrassRegionEdit : public QgsMapTool
36+
QgsGrassRegionEdit::QgsGrassRegionEdit( QgsMapCanvas* canvas )
37+
: QgsMapTool( canvas )
3738
{
38-
public:
39-
QgsGrassRegionEdit( QgsGrassRegion* reg )
40-
: QgsMapTool( reg->mCanvas ), mRegion( reg )
41-
{
42-
mDraw = false;
43-
mRubberBand = new QRubberBand( QRubberBand::Rectangle, mCanvas );
44-
}
45-
46-
~QgsGrassRegionEdit()
47-
{
48-
delete mRubberBand;
49-
}
50-
51-
//! mouse click in map canvas
52-
void canvasPressEvent( QMouseEvent * event )
53-
{
54-
QgsPoint point = toMapCoordinates( event->pos() );
55-
double x = point.x();
56-
double y = point.y();
57-
58-
QgsDebugMsg( "entered." );
59-
60-
if ( !mDraw ) // first corner
61-
{
62-
mRegion->mX = x;
63-
mRegion->mY = y;
64-
65-
mRegion->draw( x, y, x, y );
66-
mDraw = true;
67-
}
68-
else
69-
{
70-
mRegion->draw( mRegion->mX, mRegion->mY, x, y );
71-
mDraw = false;
72-
}
73-
mRubberBand->show();
74-
}
75-
76-
//! mouse movement in map canvas
77-
void canvasMoveEvent( QMouseEvent * event )
78-
{
79-
QgsPoint point = toMapCoordinates( event->pos() );
80-
81-
QgsDebugMsg( "entered." );
82-
83-
if ( !mDraw ) return;
84-
mRegion->draw( mRegion->mX, mRegion->mY, point.x(), point.y() );
85-
}
86-
87-
//! called when map tool is about to get inactive
88-
void deactivate()
89-
{
90-
mRubberBand->hide();
91-
92-
QgsMapTool::deactivate();
93-
}
94-
95-
void setRegion( const QgsPoint& ul, const QgsPoint& lr )
96-
{
97-
QPoint qul = toCanvasCoordinates( ul );
98-
QPoint qlr = toCanvasCoordinates( lr );
99-
mRubberBand->setGeometry( QRect( qul, qlr ) );
100-
}
101-
102-
103-
private:
104-
//! Rubber band for selecting grass region
105-
QRubberBand* mRubberBand;
106-
107-
//! Status of input from canvas
108-
bool mDraw;
109-
110-
QgsGrassRegion* mRegion;
111-
};
39+
mDraw = false;
40+
mRubberBand = new QgsRubberBand( mCanvas, true );
41+
}
42+
43+
QgsGrassRegionEdit::~QgsGrassRegionEdit()
44+
{
45+
delete mRubberBand;
46+
}
47+
48+
//! mouse pressed in map canvas
49+
void QgsGrassRegionEdit::canvasPressEvent( QMouseEvent * event )
50+
{
51+
QgsDebugMsg( "entered." );
52+
mDraw = true;
53+
mRubberBand->reset( true );
54+
emit captureStarted();
55+
56+
mStartPoint = toMapCoordinates( event->pos() );
57+
mEndPoint = mStartPoint;
58+
setRegion( mStartPoint, mEndPoint );
59+
}
60+
61+
//! mouse movement in map canvas
62+
void QgsGrassRegionEdit::canvasMoveEvent( QMouseEvent * event )
63+
{
64+
if ( !mDraw ) return;
65+
66+
mEndPoint = toMapCoordinates( event->pos() );
67+
setRegion( mStartPoint, mEndPoint );
68+
}
69+
70+
//! mouse button released
71+
void QgsGrassRegionEdit::canvasReleaseEvent( QMouseEvent * event )
72+
{
73+
if ( !mDraw ) return;
74+
75+
mEndPoint = toMapCoordinates( event->pos() );
76+
setRegion( mStartPoint, mEndPoint );
77+
mDraw = false;
78+
emit captureEnded();
79+
}
80+
81+
//! called when map tool is about to get inactive
82+
void QgsGrassRegionEdit::deactivate()
83+
{
84+
mRubberBand->reset( true );
85+
QgsMapTool::deactivate();
86+
}
87+
88+
void QgsGrassRegionEdit::setRegion( const QgsPoint& ul, const QgsPoint& lr )
89+
{
90+
mStartPoint = ul;
91+
mEndPoint = lr;
92+
93+
mRubberBand->reset( true );
94+
mRubberBand->addPoint( ul, false );
95+
mRubberBand->addPoint( QgsPoint( ul.x(), lr.y() ), false );
96+
mRubberBand->addPoint( lr, false );
97+
mRubberBand->addPoint( QgsPoint( lr.x(), ul.y() ), true ); // true to update canvas
98+
99+
mRubberBand->show();
100+
}
101+
102+
QgsRectangle QgsGrassRegionEdit::getRegion()
103+
{
104+
return QgsRectangle( mStartPoint, mEndPoint );
105+
}
112106

113107

114108
QgsGrassRegion::QgsGrassRegion( QgsGrassPlugin *plugin, QgisInterface *iface,
@@ -118,13 +112,16 @@ QgsGrassRegion::QgsGrassRegion( QgsGrassPlugin *plugin, QgisInterface *iface,
118112
QgsDebugMsg( "QgsGrassRegion()" );
119113

120114
setupUi( this );
115+
setAttribute( Qt::WA_DeleteOnClose );
116+
117+
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
118+
connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
121119

122120
mPlugin = plugin;
123121
mInterface = iface;
124122
mCanvas = mInterface->mapCanvas();
125123
restorePosition();
126124
mUpdatingGui = false;
127-
mDisplayed = false;
128125

129126
// Set input validators
130127
QDoubleValidator *dv = new QDoubleValidator( 0 );
@@ -140,18 +137,13 @@ QgsGrassRegion::QgsGrassRegion( QgsGrassPlugin *plugin, QgisInterface *iface,
140137
mCols->setValidator( iv );
141138

142139
// Group radio buttons
143-
mNSRadioGroup = new QButtonGroup();
144-
mEWRadioGroup = new QButtonGroup();
145-
mNSRadioGroup->addButton( mNSResRadio );
146-
mNSRadioGroup->addButton( mRowsRadio );
147-
mEWRadioGroup->addButton( mEWResRadio );
148-
mEWRadioGroup->addButton( mColsRadio );
149-
mNSResRadio->setChecked( true );
150-
mEWResRadio->setChecked( true );
151-
mRows->setEnabled( false );
152-
mCols->setEnabled( false );
153-
connect( mNSRadioGroup, SIGNAL( clicked( int ) ), this, SLOT( radioChanged() ) );
154-
connect( mEWRadioGroup, SIGNAL( clicked( int ) ), this, SLOT( radioChanged() ) );
140+
mRadioGroup = new QButtonGroup();
141+
mRadioGroup->addButton( mCellResRadio );
142+
mRadioGroup->addButton( mRowsColsRadio );
143+
mCellResRadio->setChecked( true );
144+
radioChanged();
145+
146+
connect( mRadioGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( radioChanged() ) );
155147

156148
// Set values to current region
157149
QString gisdbase = QgsGrass::getDefaultGisdbase();
@@ -169,23 +161,28 @@ QgsGrassRegion::QgsGrassRegion( QgsGrassPlugin *plugin, QgisInterface *iface,
169161

170162
if ( err )
171163
{
172-
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot read current region: %1" ).arg( err ) );
164+
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot read current region: %1" ).arg( QString::fromUtf8( err ) ) );
173165
return;
174166
}
175167

176-
setGuiValues();
168+
mRegionEdit = new QgsGrassRegionEdit( mCanvas );
169+
connect( mRegionEdit, SIGNAL( captureStarted() ), this, SLOT( hide() ) );
170+
connect( mRegionEdit, SIGNAL( captureEnded() ), this, SLOT( onCaptureFinished() ) );
171+
mCanvas->setMapTool( mRegionEdit );
172+
173+
refreshGui();
177174

178175
connect( mCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( postRender( QPainter * ) ) );
179176

180177
// Connect entries
181-
connect( mNorth, SIGNAL( textChanged( const QString & ) ), this, SLOT( northChanged( const QString & ) ) );
182-
connect( mSouth, SIGNAL( textChanged( const QString & ) ), this, SLOT( southChanged( const QString & ) ) );
183-
connect( mEast, SIGNAL( textChanged( const QString & ) ), this, SLOT( eastChanged( const QString & ) ) );
184-
connect( mWest, SIGNAL( textChanged( const QString & ) ), this, SLOT( westChanged( const QString & ) ) );
185-
connect( mNSRes, SIGNAL( textChanged( const QString & ) ), this, SLOT( NSResChanged( const QString & ) ) );
186-
connect( mEWRes, SIGNAL( textChanged( const QString & ) ), this, SLOT( EWResChanged( const QString & ) ) );
187-
connect( mRows, SIGNAL( textChanged( const QString & ) ), this, SLOT( rowsChanged( const QString & ) ) );
188-
connect( mCols, SIGNAL( textChanged( const QString & ) ), this, SLOT( colsChanged( const QString & ) ) );
178+
connect( mNorth, SIGNAL( editingFinished() ), this, SLOT( northChanged() ) );
179+
connect( mSouth, SIGNAL( editingFinished() ), this, SLOT( southChanged() ) );
180+
connect( mEast, SIGNAL( editingFinished() ), this, SLOT( eastChanged() ) );
181+
connect( mWest, SIGNAL( editingFinished() ), this, SLOT( westChanged() ) );
182+
connect( mNSRes, SIGNAL( editingFinished() ), this, SLOT( NSResChanged() ) );
183+
connect( mEWRes, SIGNAL( editingFinished() ), this, SLOT( EWResChanged() ) );
184+
connect( mRows, SIGNAL( editingFinished() ), this, SLOT( rowsChanged() ) );
185+
connect( mCols, SIGNAL( editingFinished() ), this, SLOT( colsChanged() ) );
189186

190187
// Symbology
191188
QPen pen = mPlugin->regionPen();
@@ -194,12 +191,6 @@ QgsGrassRegion::QgsGrassRegion( QgsGrassPlugin *plugin, QgisInterface *iface,
194191

195192
mWidthSpinBox->setValue( pen.width() );
196193
connect( mWidthSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( changeWidth() ) );
197-
198-
mRegionEdit = new QgsGrassRegionEdit( this ); // will be deleted by map canvas
199-
mCanvas->setMapTool( mRegionEdit );
200-
201-
setAttribute( Qt::WA_DeleteOnClose );
202-
displayRegion();
203194
}
204195

205196
void QgsGrassRegion::changeColor( void )
@@ -233,22 +224,25 @@ QString QgsGrassRegion::formatEdge( double v )
233224
return QString( "%1" ).arg( v, 0, 'g' );
234225
}
235226

236-
void QgsGrassRegion::setGuiValues( bool north, bool south, bool east, bool west,
237-
bool nsres, bool ewres, bool rows, bool cols )
227+
void QgsGrassRegion::refreshGui()
238228
{
239-
QgsDebugMsg( "entered." );
229+
if ( mUpdatingGui )
230+
return;
240231

241232
mUpdatingGui = true;
242233

243-
if ( north ) mNorth->setText( QString( "%1" ).arg( mWindow.north, 0, 'g', 15 ) );
244-
if ( south ) mSouth->setText( QString( "%1" ).arg( mWindow.south, 0, 'g', 15 ) );
245-
if ( east ) mEast->setText( QString( "%1" ).arg( mWindow.east, 0, 'g', 15 ) );
246-
if ( west ) mWest->setText( QString( "%1" ).arg( mWindow.west, 0, 'g', 15 ) );
247-
if ( nsres ) mNSRes->setText( QString( "%1" ).arg( mWindow.ns_res, 0, 'g' ) );
248-
if ( ewres ) mEWRes->setText( QString( "%1" ).arg( mWindow.ew_res, 0, 'g' ) );
249-
if ( rows ) mRows->setText( QString( "%1" ).arg( mWindow.rows ) );
250-
if ( cols ) mCols->setText( QString( "%1" ).arg( mWindow.cols ) );
234+
QgsDebugMsg( "entered." );
235+
236+
mNorth->setText( QString( "%1" ).arg( mWindow.north, 0, 'g', 15 ) );
237+
mSouth->setText( QString( "%1" ).arg( mWindow.south, 0, 'g', 15 ) );
238+
mEast->setText( QString( "%1" ).arg( mWindow.east, 0, 'g', 15 ) );
239+
mWest->setText( QString( "%1" ).arg( mWindow.west, 0, 'g', 15 ) );
240+
mNSRes->setText( QString( "%1" ).arg( mWindow.ns_res, 0, 'g' ) );
241+
mEWRes->setText( QString( "%1" ).arg( mWindow.ew_res, 0, 'g' ) );
242+
mRows->setText( QString( "%1" ).arg( mWindow.rows ) );
243+
mCols->setText( QString( "%1" ).arg( mWindow.cols ) );
251244

245+
displayRegion();
252246
mUpdatingGui = false;
253247
}
254248

@@ -257,160 +251,153 @@ QgsGrassRegion::~QgsGrassRegion()
257251
delete mRegionEdit;
258252
}
259253

260-
void QgsGrassRegion::northChanged( const QString &str )
254+
void QgsGrassRegion::northChanged()
261255
{
262256
if ( mUpdatingGui ) return;
257+
263258
mWindow.north = mNorth->text().toDouble();
259+
if ( mWindow.north < mWindow.south )
260+
mWindow.north = mWindow.south;
261+
264262
adjust();
265-
setGuiValues( false );
266-
displayRegion();
263+
refreshGui();
267264
}
268265

269-
void QgsGrassRegion::southChanged( const QString &str )
266+
void QgsGrassRegion::southChanged()
270267
{
271268
if ( mUpdatingGui ) return;
269+
272270
mWindow.south = mSouth->text().toDouble();
271+
if ( mWindow.south > mWindow.north )
272+
mWindow.south = mWindow.north;
273+
273274
adjust();
274-
setGuiValues( true, false );
275-
displayRegion();
275+
refreshGui();
276276
}
277277

278-
void QgsGrassRegion::eastChanged( const QString &str )
278+
void QgsGrassRegion::eastChanged()
279279
{
280280
if ( mUpdatingGui ) return;
281+
281282
mWindow.east = mEast->text().toDouble();
283+
if ( mWindow.east < mWindow.west )
284+
mWindow.east = mWindow.west;
285+
282286
adjust();
283-
setGuiValues( true, true, false );
284-
displayRegion();
287+
refreshGui();
285288
}
286289

287-
void QgsGrassRegion::westChanged( const QString &str )
290+
void QgsGrassRegion::westChanged()
288291
{
289292
if ( mUpdatingGui ) return;
293+
290294
mWindow.west = mWest->text().toDouble();
295+
if ( mWindow.west > mWindow.east )
296+
mWindow.west = mWindow.east;
297+
291298
adjust();
292-
setGuiValues( true, true, true, false );
293-
displayRegion();
299+
refreshGui();
294300
}
295301

296-
void QgsGrassRegion::NSResChanged( const QString &str )
302+
void QgsGrassRegion::NSResChanged()
297303
{
298304
if ( mUpdatingGui ) return;
305+
299306
mWindow.ns_res = mNSRes->text().toDouble();
307+
if ( mWindow.ns_res <= 0)
308+
mWindow.ns_res = 1;
309+
300310
adjust();
301-
setGuiValues( true, true, true, true, false );
302-
displayRegion();
311+
refreshGui();
303312
}
304313

305-
void QgsGrassRegion::EWResChanged( const QString &str )
314+
void QgsGrassRegion::EWResChanged()
306315
{
307316
if ( mUpdatingGui ) return;
317+
308318
mWindow.ew_res = mEWRes->text().toDouble();
319+
if ( mWindow.ew_res <= 0)
320+
mWindow.ew_res = 1;
321+
309322
adjust();
310-
setGuiValues( true, true, true, true, true, false );
311-
displayRegion();
323+
refreshGui();
312324
}
313325

314-
void QgsGrassRegion::rowsChanged( const QString &str )
326+
void QgsGrassRegion::rowsChanged()
315327
{
316328
if ( mUpdatingGui ) return;
329+
317330
mWindow.rows = mRows->text().toInt();
331+
if ( mWindow.rows < 1)
332+
mWindow.rows = 1;
333+
318334
adjust();
319-
setGuiValues( true, true, true, true, true, true, false );
320-
displayRegion();
335+
refreshGui();
321336
}
322337

323-
void QgsGrassRegion::colsChanged( const QString &str )
338+
void QgsGrassRegion::colsChanged()
324339
{
325340
if ( mUpdatingGui ) return;
341+
326342
mWindow.cols = mCols->text().toInt();
343+
if ( mWindow.cols < 1)
344+
mWindow.cols = 1;
345+
327346
adjust();
328-
setGuiValues( true, true, true, true, true, true, true, false );
329-
displayRegion();
347+
refreshGui();
330348
}
331349

332350
void QgsGrassRegion::adjust()
333351
{
334-
int r, c;
335-
if ( mRowsRadio->isChecked() ) r = 1; else r = 0;
336-
if ( mColsRadio->isChecked() ) c = 1; else c = 0;
337-
G_adjust_Cell_head( &mWindow, r, c );
352+
int rc = 0;
353+
if ( mRowsColsRadio->isChecked() )
354+
{
355+
rc = 1;
356+
}
357+
G_adjust_Cell_head( &mWindow, rc, rc );
338358
}
339359

340360
void QgsGrassRegion::radioChanged()
341361
{
342362
QgsDebugMsg( "entered." );
343363

344-
if ( mRowsRadio->isChecked() )
364+
if ( mRowsColsRadio->isChecked() )
345365
{
346366
mNSRes->setEnabled( false );
347-
mRows->setEnabled( true );
348-
}
349-
else
350-
{
351-
mNSRes->setEnabled( true );
352-
mRows->setEnabled( false );
353-
}
354-
if ( mColsRadio->isChecked() )
355-
{
356367
mEWRes->setEnabled( false );
368+
mRows->setEnabled( true );
357369
mCols->setEnabled( true );
358370
}
359371
else
360372
{
373+
mNSRes->setEnabled( true );
361374
mEWRes->setEnabled( true );
375+
mRows->setEnabled( false );
362376
mCols->setEnabled( false );
363377
}
364378
}
365379

366-
void QgsGrassRegion::draw( double x1, double y1, double x2, double y2 )
380+
void QgsGrassRegion::onCaptureFinished()
367381
{
368382
QgsDebugMsg( "entered." );
383+
QgsRectangle rect = mRegionEdit->getRegion();
369384

370-
if ( x1 < x2 )
371-
{
372-
mWindow.west = x1;
373-
mWindow.east = x2;
374-
}
375-
else
376-
{
377-
mWindow.west = x2;
378-
mWindow.east = x1;
379-
}
380-
if ( y1 < y2 )
381-
{
382-
mWindow.south = y1;
383-
mWindow.north = y2;
384-
}
385-
else
386-
{
387-
mWindow.south = y2;
388-
mWindow.north = y1;
389-
}
390-
385+
mWindow.west = rect.xMinimum();
386+
mWindow.east = rect.xMaximum();
387+
mWindow.south = rect.yMinimum();
388+
mWindow.north = rect.yMaximum();
391389
adjust();
392-
setGuiValues();
393-
displayRegion();
390+
391+
refreshGui();
392+
show();
394393
}
395394

396395
void QgsGrassRegion::displayRegion()
397396
{
398-
QgsDebugMsg( "entered." );
399-
400397
QgsPoint ul( mWindow.west, mWindow.north );
401398
QgsPoint lr( mWindow.east, mWindow.south );
402399

403400
mRegionEdit->setRegion( ul, lr );
404-
405-
mDisplayed = true;
406-
}
407-
408-
void QgsGrassRegion::postRender( QPainter *painter )
409-
{
410-
QgsDebugMsg( "entered." );
411-
412-
mDisplayed = false;
413-
displayRegion();
414401
}
415402

416403
void QgsGrassRegion::accept()
@@ -441,14 +428,14 @@ void QgsGrassRegion::accept()
441428

442429
saveWindowLocation();
443430
mCanvas->setMapTool( NULL );
444-
delete this;
431+
QDialog::accept();
445432
}
446433

447434
void QgsGrassRegion::reject()
448435
{
449436
saveWindowLocation();
450437
mCanvas->setMapTool( NULL );
451-
delete this;
438+
QDialog::reject();
452439
}
453440

454441
void QgsGrassRegion::restorePosition()

‎src/plugins/grass/qgsgrassregion.h

Lines changed: 66 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
#define QGSGRASSREGION_H
1818

1919
#include "ui_qgsgrassregionbase.h"
20+
#include "qgsmaptool.h"
21+
#include "qgsrubberband.h"
22+
#include "qgspoint.h"
2023

2124
class QgsGrassPlugin;
2225
class QgsGrassRegionEdit;
2326

2427
class QgisInterface;
2528
class QgsMapCanvas;
26-
//class QgsPoint;
29+
class QgsRectangle;
2730

2831
class QButtonGroup;
2932

@@ -50,16 +53,11 @@ class QgsGrassRegion: public QDialog, private Ui::QgsGrassRegionBase
5053

5154
public slots:
5255
//! OK
53-
void on_acceptButton_clicked() { accept(); }
5456
void accept( void );
5557

56-
//! Close
57-
void on_rejectButton_clicked() { reject(); }
58+
//! Cancel
5859
void reject( void );
5960

60-
//! Called when rendering is finished
61-
void postRender( QPainter * );
62-
6361
//! Mouse event receiver
6462
//void mouseEventReceiverMove ( QgsPoint & );
6563

@@ -70,14 +68,14 @@ class QgsGrassRegion: public QDialog, private Ui::QgsGrassRegionBase
7068
void adjust( void );
7169

7270
//! Value in GUI was changed
73-
void northChanged( const QString &str );
74-
void southChanged( const QString &str );
75-
void eastChanged( const QString &str );
76-
void westChanged( const QString &str );
77-
void NSResChanged( const QString &str );
78-
void EWResChanged( const QString &str );
79-
void rowsChanged( const QString &str );
80-
void colsChanged( const QString &str );
71+
void northChanged();
72+
void southChanged();
73+
void eastChanged();
74+
void westChanged();
75+
void NSResChanged();
76+
void EWResChanged();
77+
void rowsChanged();
78+
void colsChanged();
8179

8280
void radioChanged( void ) ;
8381

@@ -86,6 +84,9 @@ class QgsGrassRegion: public QDialog, private Ui::QgsGrassRegionBase
8684

8785
void restorePosition( void );
8886

87+
//! Called when the capture finished to refresh the mWindow values
88+
void onCaptureFinished();
89+
8990
private:
9091
//! Pointer to plugin
9192
QgsGrassPlugin *mPlugin;
@@ -96,20 +97,16 @@ class QgsGrassRegion: public QDialog, private Ui::QgsGrassRegionBase
9697
//! Pointer to canvas
9798
QgsMapCanvas *mCanvas;
9899

99-
QButtonGroup *mNSRadioGroup;
100-
QButtonGroup *mEWRadioGroup;
100+
QButtonGroup *mRadioGroup;
101101

102102
//! Current new region
103103
struct Cell_head mWindow;
104104

105105
//! Display current state of new region in XOR mode
106106
void displayRegion( void );
107107

108-
//! Region was displayed
109-
bool mDisplayed;
110-
111-
//! Draw region
112-
void draw( double x1, double y1, double x2, double y2 );
108+
// Set region values in GUI from mWindow
109+
void refreshGui();
113110

114111
//! First corner coordinates
115112
double mX;
@@ -118,19 +115,61 @@ class QgsGrassRegion: public QDialog, private Ui::QgsGrassRegionBase
118115
//! Currently updating GUI, don't run *Changed methods
119116
bool mUpdatingGui;
120117

121-
// Set region values in GUI from mWindow
122-
void setGuiValues( bool north = true, bool south = true, bool east = true, bool west = true,
123-
bool nsres = true, bool ewres = true, bool rows = true, bool cols = true );
124-
125118

126119
void saveWindowLocation( void );
127120

128121
// Format N, S, E, W value
129122
QString formatEdge( double v );
130123

131124
QgsGrassRegionEdit* mRegionEdit;
125+
};
126+
127+
/** map tool which uses rubber band for changing grass region */
128+
class QgsGrassRegionEdit : public QgsMapTool
129+
{
130+
Q_OBJECT
131+
132+
public:
133+
QgsGrassRegionEdit( QgsMapCanvas* );
134+
135+
~QgsGrassRegionEdit();
136+
137+
//! mouse pressed in map canvas
138+
void canvasPressEvent( QMouseEvent * );
139+
140+
//! mouse movement in map canvas
141+
void canvasMoveEvent( QMouseEvent * );
142+
143+
//! mouse released
144+
void canvasReleaseEvent( QMouseEvent * );
145+
146+
147+
//! called when map tool is about to get inactive
148+
void deactivate();
149+
150+
//! get the rectangle
151+
QgsRectangle getRegion();
152+
153+
//! refresh the rectangle displayed in canvas
154+
void setRegion( const QgsPoint&, const QgsPoint& );
155+
156+
signals:
157+
void captureStarted();
158+
void captureEnded();
159+
160+
161+
private:
162+
//! Rubber band for selecting grass region
163+
QgsRubberBand* mRubberBand;
164+
165+
//! Status of input from canvas
166+
bool mDraw;
167+
168+
//! First rectangle point
169+
QgsPoint mStartPoint;
170+
//! Last rectangle point
171+
QgsPoint mEndPoint;
132172

133-
friend class QgsGrassRegionEdit;
134173
};
135174

136175
#endif // QGSGRASSREGION_H

‎src/plugins/grass/qgsgrassregionbase.ui

Lines changed: 133 additions & 475 deletions
Original file line numberDiff line numberDiff line change
@@ -1,565 +1,223 @@
1-
<ui version="4.0" >
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
23
<class>QgsGrassRegionBase</class>
3-
<widget class="QDialog" name="QgsGrassRegionBase" >
4-
<property name="geometry" >
4+
<widget class="QDialog" name="QgsGrassRegionBase">
5+
<property name="geometry">
56
<rect>
67
<x>0</x>
78
<y>0</y>
8-
<width>420</width>
9-
<height>297</height>
9+
<width>445</width>
10+
<height>348</height>
1011
</rect>
1112
</property>
12-
<property name="windowTitle" >
13+
<property name="windowTitle">
1314
<string>GRASS Region Settings</string>
1415
</property>
15-
<layout class="QGridLayout" >
16-
<property name="leftMargin" >
17-
<number>2</number>
18-
</property>
19-
<property name="topMargin" >
20-
<number>2</number>
21-
</property>
22-
<property name="rightMargin" >
23-
<number>2</number>
24-
</property>
25-
<property name="bottomMargin" >
26-
<number>2</number>
27-
</property>
28-
<property name="horizontalSpacing" >
29-
<number>2</number>
30-
</property>
31-
<property name="verticalSpacing" >
32-
<number>2</number>
33-
</property>
34-
<item row="0" column="0" >
35-
<widget class="QFrame" name="frame4" >
36-
<property name="sizePolicy" >
37-
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
38-
<horstretch>0</horstretch>
39-
<verstretch>0</verstretch>
40-
</sizepolicy>
41-
</property>
42-
<property name="minimumSize" >
43-
<size>
44-
<width>0</width>
45-
<height>35</height>
46-
</size>
47-
</property>
48-
<property name="maximumSize" >
49-
<size>
50-
<width>32767</width>
51-
<height>35</height>
52-
</size>
53-
</property>
54-
<property name="frameShape" >
55-
<enum>QFrame::StyledPanel</enum>
56-
</property>
57-
<property name="frameShadow" >
58-
<enum>QFrame::Raised</enum>
59-
</property>
60-
<layout class="QHBoxLayout" >
61-
<property name="leftMargin" >
62-
<number>6</number>
63-
</property>
64-
<property name="topMargin" >
65-
<number>6</number>
66-
</property>
67-
<property name="rightMargin" >
68-
<number>6</number>
69-
</property>
70-
<property name="bottomMargin" >
71-
<number>6</number>
72-
</property>
73-
<item>
74-
<spacer>
75-
<property name="orientation" >
76-
<enum>Qt::Horizontal</enum>
77-
</property>
78-
<property name="sizeType" >
79-
<enum>QSizePolicy::Expanding</enum>
80-
</property>
81-
<property name="sizeHint" >
82-
<size>
83-
<width>72</width>
84-
<height>16</height>
85-
</size>
86-
</property>
87-
</spacer>
88-
</item>
89-
<item>
90-
<widget class="QLabel" name="textLabel1" >
91-
<property name="text" >
92-
<string>N</string>
16+
<layout class="QGridLayout" name="gridLayout_4">
17+
<item row="0" column="0">
18+
<widget class="QGroupBox" name="groupBox">
19+
<property name="title">
20+
<string>Extent</string>
21+
</property>
22+
<layout class="QGridLayout" name="gridLayout">
23+
<item row="0" column="2">
24+
<widget class="QLabel" name="textLabel1">
25+
<property name="sizePolicy">
26+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
27+
<horstretch>0</horstretch>
28+
<verstretch>0</verstretch>
29+
</sizepolicy>
30+
</property>
31+
<property name="text">
32+
<string>North</string>
9333
</property>
9434
</widget>
9535
</item>
96-
<item>
97-
<widget class="QLineEdit" name="mNorth" />
98-
</item>
99-
<item>
100-
<spacer>
101-
<property name="orientation" >
102-
<enum>Qt::Horizontal</enum>
103-
</property>
104-
<property name="sizeType" >
105-
<enum>QSizePolicy::Expanding</enum>
36+
<item row="1" column="0">
37+
<widget class="QLabel" name="textLabel2">
38+
<property name="sizePolicy">
39+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
40+
<horstretch>0</horstretch>
41+
<verstretch>0</verstretch>
42+
</sizepolicy>
10643
</property>
107-
<property name="sizeHint" >
108-
<size>
109-
<width>71</width>
110-
<height>21</height>
111-
</size>
112-
</property>
113-
</spacer>
114-
</item>
115-
</layout>
116-
</widget>
117-
</item>
118-
<item row="1" column="0" >
119-
<widget class="QFrame" name="frame19" >
120-
<property name="sizePolicy" >
121-
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
122-
<horstretch>0</horstretch>
123-
<verstretch>0</verstretch>
124-
</sizepolicy>
125-
</property>
126-
<property name="minimumSize" >
127-
<size>
128-
<width>0</width>
129-
<height>35</height>
130-
</size>
131-
</property>
132-
<property name="maximumSize" >
133-
<size>
134-
<width>32767</width>
135-
<height>35</height>
136-
</size>
137-
</property>
138-
<property name="frameShape" >
139-
<enum>QFrame::StyledPanel</enum>
140-
</property>
141-
<property name="frameShadow" >
142-
<enum>QFrame::Raised</enum>
143-
</property>
144-
<layout class="QHBoxLayout" >
145-
<property name="spacing" >
146-
<number>2</number>
147-
</property>
148-
<property name="leftMargin" >
149-
<number>2</number>
150-
</property>
151-
<property name="topMargin" >
152-
<number>2</number>
153-
</property>
154-
<property name="rightMargin" >
155-
<number>2</number>
156-
</property>
157-
<property name="bottomMargin" >
158-
<number>2</number>
159-
</property>
160-
<item>
161-
<widget class="QLabel" name="textLabel2" >
162-
<property name="frameShape" >
44+
<property name="frameShape">
16345
<enum>QFrame::NoFrame</enum>
16446
</property>
165-
<property name="frameShadow" >
47+
<property name="frameShadow">
16648
<enum>QFrame::Plain</enum>
16749
</property>
168-
<property name="text" >
169-
<string>W</string>
50+
<property name="text">
51+
<string>West</string>
17052
</property>
17153
</widget>
17254
</item>
173-
<item>
174-
<widget class="QLineEdit" name="mWest" />
55+
<item row="1" column="1" colspan="2">
56+
<widget class="QLineEdit" name="mWest"/>
17557
</item>
176-
<item>
177-
<spacer>
178-
<property name="orientation" >
179-
<enum>Qt::Horizontal</enum>
58+
<item row="1" column="4">
59+
<widget class="QLabel" name="textLabel3">
60+
<property name="sizePolicy">
61+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
62+
<horstretch>0</horstretch>
63+
<verstretch>0</verstretch>
64+
</sizepolicy>
18065
</property>
181-
<property name="sizeType" >
182-
<enum>QSizePolicy::Expanding</enum>
183-
</property>
184-
<property name="sizeHint" >
185-
<size>
186-
<width>51</width>
187-
<height>26</height>
188-
</size>
189-
</property>
190-
</spacer>
191-
</item>
192-
<item>
193-
<widget class="QLabel" name="textLabel3" >
194-
<property name="text" >
195-
<string>E</string>
66+
<property name="text">
67+
<string>East</string>
19668
</property>
19769
</widget>
19870
</item>
199-
<item>
200-
<widget class="QLineEdit" name="mEast" />
71+
<item row="1" column="5">
72+
<widget class="QLineEdit" name="mEast"/>
20173
</item>
202-
</layout>
203-
</widget>
204-
</item>
205-
<item row="2" column="0" >
206-
<widget class="QFrame" name="frame20" >
207-
<property name="sizePolicy" >
208-
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
209-
<horstretch>0</horstretch>
210-
<verstretch>0</verstretch>
211-
</sizepolicy>
212-
</property>
213-
<property name="minimumSize" >
214-
<size>
215-
<width>0</width>
216-
<height>35</height>
217-
</size>
218-
</property>
219-
<property name="maximumSize" >
220-
<size>
221-
<width>32767</width>
222-
<height>35</height>
223-
</size>
224-
</property>
225-
<property name="frameShape" >
226-
<enum>QFrame::StyledPanel</enum>
227-
</property>
228-
<property name="frameShadow" >
229-
<enum>QFrame::Raised</enum>
230-
</property>
231-
<layout class="QHBoxLayout" >
232-
<property name="spacing" >
233-
<number>2</number>
234-
</property>
235-
<property name="leftMargin" >
236-
<number>2</number>
237-
</property>
238-
<property name="topMargin" >
239-
<number>2</number>
240-
</property>
241-
<property name="rightMargin" >
242-
<number>2</number>
243-
</property>
244-
<property name="bottomMargin" >
245-
<number>2</number>
246-
</property>
247-
<item>
248-
<spacer>
249-
<property name="orientation" >
250-
<enum>Qt::Horizontal</enum>
74+
<item row="2" column="2">
75+
<widget class="QLabel" name="textLabel4">
76+
<property name="sizePolicy">
77+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
78+
<horstretch>0</horstretch>
79+
<verstretch>0</verstretch>
80+
</sizepolicy>
25181
</property>
252-
<property name="sizeType" >
253-
<enum>QSizePolicy::Expanding</enum>
254-
</property>
255-
<property name="sizeHint" >
256-
<size>
257-
<width>73</width>
258-
<height>26</height>
259-
</size>
260-
</property>
261-
</spacer>
262-
</item>
263-
<item>
264-
<widget class="QLabel" name="textLabel4" >
265-
<property name="text" >
266-
<string>S</string>
82+
<property name="text">
83+
<string>South</string>
26784
</property>
26885
</widget>
26986
</item>
270-
<item>
271-
<widget class="QLineEdit" name="mSouth" />
87+
<item row="2" column="3" colspan="2">
88+
<widget class="QLineEdit" name="mSouth"/>
27289
</item>
273-
<item>
274-
<spacer>
275-
<property name="orientation" >
276-
<enum>Qt::Horizontal</enum>
277-
</property>
278-
<property name="sizeType" >
279-
<enum>QSizePolicy::Expanding</enum>
280-
</property>
281-
<property name="sizeHint" >
282-
<size>
283-
<width>57</width>
284-
<height>23</height>
285-
</size>
286-
</property>
287-
</spacer>
90+
<item row="0" column="3" colspan="2">
91+
<widget class="QLineEdit" name="mNorth"/>
28892
</item>
28993
</layout>
29094
</widget>
29195
</item>
292-
<item row="3" column="0" >
293-
<widget class="QFrame" name="frame5" >
294-
<property name="frameShape" >
295-
<enum>QFrame::StyledPanel</enum>
296-
</property>
297-
<property name="frameShadow" >
298-
<enum>QFrame::Raised</enum>
299-
</property>
300-
<layout class="QGridLayout" >
301-
<property name="leftMargin" >
302-
<number>6</number>
303-
</property>
304-
<property name="topMargin" >
305-
<number>6</number>
306-
</property>
307-
<property name="rightMargin" >
308-
<number>6</number>
309-
</property>
310-
<property name="bottomMargin" >
311-
<number>6</number>
312-
</property>
313-
<item row="0" column="0" >
314-
<widget class="QRadioButton" name="mNSResRadio" >
315-
<property name="text" >
316-
<string>N-S Res</string>
317-
</property>
318-
<property name="checked" >
319-
<bool>false</bool>
96+
<item row="1" column="0">
97+
<widget class="QGroupBox" name="groupBox_2">
98+
<property name="title">
99+
<string>Resolution</string>
100+
</property>
101+
<layout class="QGridLayout" name="gridLayout_2">
102+
<item row="0" column="0">
103+
<widget class="QRadioButton" name="mCellResRadio">
104+
<property name="text">
105+
<string>Cell width</string>
106+
</property>
107+
<property name="checked">
108+
<bool>true</bool>
320109
</property>
321110
</widget>
322111
</item>
323-
<item row="0" column="1" >
324-
<widget class="QLineEdit" name="mNSRes" />
112+
<item row="0" column="1">
113+
<widget class="QLineEdit" name="mEWRes"/>
325114
</item>
326-
<item row="0" column="2" >
327-
<widget class="QRadioButton" name="mRowsRadio" >
328-
<property name="text" >
329-
<string>Rows</string>
115+
<item row="0" column="2">
116+
<widget class="QLabel" name="label_2">
117+
<property name="text">
118+
<string>Cell height</string>
119+
</property>
120+
<property name="indent">
121+
<number>20</number>
330122
</property>
331123
</widget>
332124
</item>
333-
<item row="0" column="3" >
334-
<widget class="QLineEdit" name="mRows" />
125+
<item row="0" column="3">
126+
<widget class="QLineEdit" name="mNSRes"/>
335127
</item>
336-
<item row="1" column="2" >
337-
<widget class="QRadioButton" name="mColsRadio" >
338-
<property name="text" >
339-
<string>Cols</string>
128+
<item row="1" column="0">
129+
<widget class="QRadioButton" name="mRowsColsRadio">
130+
<property name="text">
131+
<string>Columns</string>
340132
</property>
341133
</widget>
342134
</item>
343-
<item row="1" column="1" >
344-
<widget class="QLineEdit" name="mEWRes" />
135+
<item row="1" column="1">
136+
<widget class="QLineEdit" name="mCols"/>
345137
</item>
346-
<item row="1" column="3" >
347-
<widget class="QLineEdit" name="mCols" />
348-
</item>
349-
<item row="1" column="0" >
350-
<widget class="QRadioButton" name="mEWResRadio" >
351-
<property name="text" >
352-
<string>E-W Res</string>
138+
<item row="1" column="2">
139+
<widget class="QLabel" name="label">
140+
<property name="text">
141+
<string>Rows</string>
353142
</property>
354-
<property name="checked" >
355-
<bool>true</bool>
143+
<property name="indent">
144+
<number>20</number>
356145
</property>
357146
</widget>
358147
</item>
148+
<item row="1" column="3">
149+
<widget class="QLineEdit" name="mRows"/>
150+
</item>
359151
</layout>
360152
</widget>
361153
</item>
362-
<item row="4" column="0" >
363-
<widget class="QFrame" name="frame6" >
364-
<property name="sizePolicy" >
365-
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
366-
<horstretch>0</horstretch>
367-
<verstretch>0</verstretch>
368-
</sizepolicy>
369-
</property>
370-
<property name="minimumSize" >
371-
<size>
372-
<width>0</width>
373-
<height>35</height>
374-
</size>
375-
</property>
376-
<property name="maximumSize" >
377-
<size>
378-
<width>32767</width>
379-
<height>35</height>
380-
</size>
381-
</property>
382-
<property name="frameShape" >
383-
<enum>QFrame::StyledPanel</enum>
384-
</property>
385-
<property name="frameShadow" >
386-
<enum>QFrame::Raised</enum>
387-
</property>
388-
<layout class="QHBoxLayout" >
389-
<property name="spacing" >
390-
<number>3</number>
391-
</property>
392-
<property name="leftMargin" >
393-
<number>3</number>
394-
</property>
395-
<property name="topMargin" >
396-
<number>3</number>
397-
</property>
398-
<property name="rightMargin" >
399-
<number>3</number>
400-
</property>
401-
<property name="bottomMargin" >
402-
<number>3</number>
403-
</property>
404-
<item>
405-
<widget class="QLabel" name="textLabel7" >
406-
<property name="text" >
154+
<item row="2" column="0">
155+
<widget class="QGroupBox" name="groupBox_3">
156+
<property name="title">
157+
<string>Border</string>
158+
</property>
159+
<layout class="QGridLayout" name="gridLayout_3">
160+
<item row="0" column="0">
161+
<widget class="QLabel" name="textLabel7">
162+
<property name="text">
407163
<string>Color</string>
408164
</property>
409165
</widget>
410166
</item>
411-
<item>
412-
<widget class="QgsColorButton" native="1" name="mColorButton" >
413-
<property name="minimumSize" >
167+
<item row="0" column="1">
168+
<widget class="QgsColorButton" name="mColorButton" native="true">
169+
<property name="minimumSize">
414170
<size>
415171
<width>35</width>
416172
<height>25</height>
417173
</size>
418174
</property>
419-
<property name="text" stdset="0" >
175+
<property name="text" stdset="0">
420176
<string/>
421177
</property>
422178
</widget>
423179
</item>
424-
<item>
425-
<widget class="QLabel" name="textLabel6" >
426-
<property name="text" >
180+
<item row="0" column="2">
181+
<widget class="QLabel" name="textLabel6">
182+
<property name="text">
427183
<string>Width</string>
428184
</property>
185+
<property name="indent">
186+
<number>20</number>
187+
</property>
429188
</widget>
430189
</item>
431-
<item>
432-
<widget class="QSpinBox" name="mWidthSpinBox" />
190+
<item row="0" column="3">
191+
<widget class="QSpinBox" name="mWidthSpinBox"/>
433192
</item>
434-
<item>
435-
<spacer>
436-
<property name="orientation" >
193+
<item row="0" column="4">
194+
<spacer name="horizontalSpacer">
195+
<property name="orientation">
437196
<enum>Qt::Horizontal</enum>
438197
</property>
439-
<property name="sizeType" >
440-
<enum>QSizePolicy::Expanding</enum>
441-
</property>
442-
<property name="sizeHint" >
198+
<property name="sizeHint" stdset="0">
443199
<size>
444-
<width>69</width>
445-
<height>24</height>
200+
<width>40</width>
201+
<height>20</height>
446202
</size>
447203
</property>
448204
</spacer>
449205
</item>
450206
</layout>
451207
</widget>
452208
</item>
453-
<item row="5" column="0" >
454-
<widget class="QFrame" name="frame8" >
455-
<property name="sizePolicy" >
456-
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
457-
<horstretch>0</horstretch>
458-
<verstretch>0</verstretch>
459-
</sizepolicy>
460-
</property>
461-
<property name="minimumSize" >
462-
<size>
463-
<width>0</width>
464-
<height>38</height>
465-
</size>
209+
<item row="3" column="0">
210+
<widget class="QDialogButtonBox" name="buttonBox">
211+
<property name="orientation">
212+
<enum>Qt::Horizontal</enum>
466213
</property>
467-
<property name="maximumSize" >
468-
<size>
469-
<width>32767</width>
470-
<height>38</height>
471-
</size>
214+
<property name="standardButtons">
215+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
472216
</property>
473-
<property name="frameShape" >
474-
<enum>QFrame::StyledPanel</enum>
475-
</property>
476-
<property name="frameShadow" >
477-
<enum>QFrame::Raised</enum>
478-
</property>
479-
<layout class="QHBoxLayout" >
480-
<property name="spacing" >
481-
<number>3</number>
482-
</property>
483-
<property name="leftMargin" >
484-
<number>3</number>
485-
</property>
486-
<property name="topMargin" >
487-
<number>3</number>
488-
</property>
489-
<property name="rightMargin" >
490-
<number>3</number>
491-
</property>
492-
<property name="bottomMargin" >
493-
<number>3</number>
494-
</property>
495-
<item>
496-
<spacer>
497-
<property name="orientation" >
498-
<enum>Qt::Horizontal</enum>
499-
</property>
500-
<property name="sizeType" >
501-
<enum>QSizePolicy::Expanding</enum>
502-
</property>
503-
<property name="sizeHint" >
504-
<size>
505-
<width>45</width>
506-
<height>26</height>
507-
</size>
508-
</property>
509-
</spacer>
510-
</item>
511-
<item>
512-
<widget class="QPushButton" name="acceptButton" >
513-
<property name="text" >
514-
<string>OK</string>
515-
</property>
516-
</widget>
517-
</item>
518-
<item>
519-
<spacer>
520-
<property name="orientation" >
521-
<enum>Qt::Horizontal</enum>
522-
</property>
523-
<property name="sizeType" >
524-
<enum>QSizePolicy::Expanding</enum>
525-
</property>
526-
<property name="sizeHint" >
527-
<size>
528-
<width>47</width>
529-
<height>25</height>
530-
</size>
531-
</property>
532-
</spacer>
533-
</item>
534-
<item>
535-
<widget class="QPushButton" name="rejectButton" >
536-
<property name="text" >
537-
<string>Cancel</string>
538-
</property>
539-
</widget>
540-
</item>
541-
<item>
542-
<spacer>
543-
<property name="orientation" >
544-
<enum>Qt::Horizontal</enum>
545-
</property>
546-
<property name="sizeType" >
547-
<enum>QSizePolicy::Expanding</enum>
548-
</property>
549-
<property name="sizeHint" >
550-
<size>
551-
<width>54</width>
552-
<height>26</height>
553-
</size>
554-
</property>
555-
</spacer>
556-
</item>
557-
</layout>
558217
</widget>
559218
</item>
560219
</layout>
561220
</widget>
562-
<layoutdefault spacing="6" margin="11" />
563221
<customwidgets>
564222
<customwidget>
565223
<class>QgsColorButton</class>

0 commit comments

Comments
 (0)
Please sign in to comment.