[QGIS Commit] r14660 - trunk/qgis/src/plugins/grass

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Nov 14 16:41:55 EST 2010


Author: brushtyler
Date: 2010-11-14 13:41:55 -0800 (Sun, 14 Nov 2010)
New Revision: 14660

Modified:
   trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp
   trunk/qgis/src/plugins/grass/qgsgrassregion.cpp
   trunk/qgis/src/plugins/grass/qgsgrassregion.h
   trunk/qgis/src/plugins/grass/qgsgrassregionbase.ui
Log:
cleaned the "select region" GUI for GRASS, 
fixed validation of input


Modified: trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp	2010-11-14 21:33:34 UTC (rev 14659)
+++ trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp	2010-11-14 21:41:55 UTC (rev 14660)
@@ -651,7 +651,7 @@
   }
 
   // Warning: don't use Qt::WType_Dialog, it would ignore restorePosition
-  mRegion = new QgsGrassRegion( this, qGisInterface, qGisInterface->mainWindow(), Qt::Window );
+  mRegion = new QgsGrassRegion( this, qGisInterface, qGisInterface->mainWindow() );
 
   connect( mRegion, SIGNAL( destroyed( QObject * ) ), this, SLOT( regionClosed() ) );
 

Modified: trunk/qgis/src/plugins/grass/qgsgrassregion.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassregion.cpp	2010-11-14 21:33:34 UTC (rev 14659)
+++ trunk/qgis/src/plugins/grass/qgsgrassregion.cpp	2010-11-14 21:41:55 UTC (rev 14660)
@@ -33,84 +33,78 @@
 
 
 /** map tool which uses rubber band for changing grass region */
-class QgsGrassRegionEdit : public QgsMapTool
+QgsGrassRegionEdit::QgsGrassRegionEdit( QgsMapCanvas* canvas )
+    : QgsMapTool( canvas )
 {
-  public:
-    QgsGrassRegionEdit( QgsGrassRegion* reg )
-        : QgsMapTool( reg->mCanvas ), mRegion( reg )
-    {
-      mDraw = false;
-      mRubberBand = new QRubberBand( QRubberBand::Rectangle, mCanvas );
-    }
+  mDraw = false;
+  mRubberBand = new QgsRubberBand( mCanvas, true );
+}
 
-    ~QgsGrassRegionEdit()
-    {
-      delete mRubberBand;
-    }
+QgsGrassRegionEdit::~QgsGrassRegionEdit()
+{
+  delete mRubberBand;
+}
 
-    //! mouse click in map canvas
-    void canvasPressEvent( QMouseEvent * event )
-    {
-      QgsPoint point = toMapCoordinates( event->pos() );
-      double x = point.x();
-      double y = point.y();
+//! mouse pressed in map canvas
+void QgsGrassRegionEdit::canvasPressEvent( QMouseEvent * event )
+{
+  QgsDebugMsg( "entered." );
+  mDraw = true;
+  mRubberBand->reset( true );
+  emit captureStarted();
 
-      QgsDebugMsg( "entered." );
+  mStartPoint = toMapCoordinates( event->pos() );
+  mEndPoint = mStartPoint;
+  setRegion( mStartPoint, mEndPoint );
+}
 
-      if ( !mDraw )   // first corner
-      {
-        mRegion->mX = x;
-        mRegion->mY = y;
+//! mouse movement in map canvas
+void QgsGrassRegionEdit::canvasMoveEvent( QMouseEvent * event )
+{
+  if ( !mDraw ) return;
 
-        mRegion->draw( x, y, x, y );
-        mDraw = true;
-      }
-      else
-      {
-        mRegion->draw( mRegion->mX, mRegion->mY, x, y );
-        mDraw = false;
-      }
-      mRubberBand->show();
-    }
+  mEndPoint = toMapCoordinates( event->pos() );
+  setRegion( mStartPoint, mEndPoint );
+}
 
-    //! mouse movement in map canvas
-    void canvasMoveEvent( QMouseEvent * event )
-    {
-      QgsPoint point = toMapCoordinates( event->pos() );
+//! mouse button released
+void QgsGrassRegionEdit::canvasReleaseEvent( QMouseEvent * event )
+{
+  if ( !mDraw ) return;
 
-      QgsDebugMsg( "entered." );
+  mEndPoint = toMapCoordinates( event->pos() );
+  setRegion( mStartPoint, mEndPoint );
+  mDraw = false;
+  emit captureEnded();
+}
 
-      if ( !mDraw ) return;
-      mRegion->draw( mRegion->mX, mRegion->mY, point.x(), point.y() );
-    }
+//! called when map tool is about to get inactive
+void QgsGrassRegionEdit::deactivate()
+{
+  mRubberBand->reset( true );
+  QgsMapTool::deactivate();
+}
 
-    //! called when map tool is about to get inactive
-    void deactivate()
-    {
-      mRubberBand->hide();
+void QgsGrassRegionEdit::setRegion( const QgsPoint& ul, const QgsPoint& lr )
+{
+  mStartPoint = ul;
+  mEndPoint = lr;
 
-      QgsMapTool::deactivate();
-    }
+  mRubberBand->reset( true );
+  mRubberBand->addPoint( ul, false );
+  mRubberBand->addPoint( QgsPoint( ul.x(), lr.y() ), false );
+  mRubberBand->addPoint( lr, false );
+  mRubberBand->addPoint( QgsPoint( lr.x(), ul.y() ), true );	// true to update canvas
 
-    void setRegion( const QgsPoint& ul, const QgsPoint& lr )
-    {
-      QPoint qul = toCanvasCoordinates( ul );
-      QPoint qlr = toCanvasCoordinates( lr );
-      mRubberBand->setGeometry( QRect( qul, qlr ) );
-    }
+  mRubberBand->show();
+}
 
+QgsRectangle QgsGrassRegionEdit::getRegion()
+{
+  return QgsRectangle( mStartPoint, mEndPoint );
+}
 
-  private:
-    //! Rubber band for selecting grass region
-    QRubberBand* mRubberBand;
 
-    //! Status of input from canvas
-    bool mDraw;
-
-    QgsGrassRegion* mRegion;
-};
-
-
 QgsGrassRegion::QgsGrassRegion( QgsGrassPlugin *plugin,  QgisInterface *iface,
                                 QWidget * parent, Qt::WFlags f )
     : QDialog( parent, f ), QgsGrassRegionBase( )
@@ -118,13 +112,16 @@
   QgsDebugMsg( "QgsGrassRegion()" );
 
   setupUi( this );
+  setAttribute( Qt::WA_DeleteOnClose );
 
+  connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
+  connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
+
   mPlugin = plugin;
   mInterface = iface;
   mCanvas = mInterface->mapCanvas();
   restorePosition();
   mUpdatingGui = false;
-  mDisplayed = false;
 
   // Set input validators
   QDoubleValidator *dv = new QDoubleValidator( 0 );
@@ -140,19 +137,14 @@
   mCols->setValidator( iv );
 
   // Group radio buttons
-  mNSRadioGroup = new QButtonGroup();
-  mEWRadioGroup = new QButtonGroup();
-  mNSRadioGroup->addButton( mNSResRadio );
-  mNSRadioGroup->addButton( mRowsRadio );
-  mEWRadioGroup->addButton( mEWResRadio );
-  mEWRadioGroup->addButton( mColsRadio );
-  mNSResRadio->setChecked( true );
-  mEWResRadio->setChecked( true );
-  mRows->setEnabled( false );
-  mCols->setEnabled( false );
-  connect( mNSRadioGroup, SIGNAL( clicked( int ) ), this, SLOT( radioChanged() ) );
-  connect( mEWRadioGroup, SIGNAL( clicked( int ) ), this, SLOT( radioChanged() ) );
+  mRadioGroup = new QButtonGroup();
+  mRadioGroup->addButton( mCellResRadio );
+  mRadioGroup->addButton( mRowsColsRadio );
+  mCellResRadio->setChecked( true );
+  radioChanged();
 
+  connect( mRadioGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( radioChanged() ) );
+
   // Set values to current region
   QString gisdbase = QgsGrass::getDefaultGisdbase();
   QString location = QgsGrass::getDefaultLocation();
@@ -169,23 +161,28 @@
 
   if ( err )
   {
-    QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot read current region: %1" ).arg( err ) );
+    QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot read current region: %1" ).arg( QString::fromUtf8( err ) ) );
     return;
   }
 
-  setGuiValues();
+  mRegionEdit = new QgsGrassRegionEdit( mCanvas );
+  connect( mRegionEdit, SIGNAL( captureStarted() ), this, SLOT( hide() ) );
+  connect( mRegionEdit, SIGNAL( captureEnded() ), this, SLOT( onCaptureFinished() ) );
+  mCanvas->setMapTool( mRegionEdit );
 
+  refreshGui();
+
   connect( mCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( postRender( QPainter * ) ) );
 
   // Connect entries
-  connect( mNorth, SIGNAL( textChanged( const QString & ) ), this, SLOT( northChanged( const QString & ) ) );
-  connect( mSouth, SIGNAL( textChanged( const QString & ) ), this, SLOT( southChanged( const QString & ) ) );
-  connect( mEast, SIGNAL( textChanged( const QString & ) ), this, SLOT( eastChanged( const QString & ) ) );
-  connect( mWest, SIGNAL( textChanged( const QString & ) ), this, SLOT( westChanged( const QString & ) ) );
-  connect( mNSRes, SIGNAL( textChanged( const QString & ) ), this, SLOT( NSResChanged( const QString & ) ) );
-  connect( mEWRes, SIGNAL( textChanged( const QString & ) ), this, SLOT( EWResChanged( const QString & ) ) );
-  connect( mRows, SIGNAL( textChanged( const QString & ) ), this, SLOT( rowsChanged( const QString & ) ) );
-  connect( mCols, SIGNAL( textChanged( const QString & ) ), this, SLOT( colsChanged( const QString & ) ) );
+  connect( mNorth, SIGNAL( editingFinished() ), this, SLOT( northChanged() ) );
+  connect( mSouth, SIGNAL( editingFinished() ), this, SLOT( southChanged() ) );
+  connect( mEast, SIGNAL( editingFinished() ), this, SLOT( eastChanged() ) );
+  connect( mWest, SIGNAL( editingFinished() ), this, SLOT( westChanged() ) );
+  connect( mNSRes, SIGNAL( editingFinished() ), this, SLOT( NSResChanged() ) );
+  connect( mEWRes, SIGNAL( editingFinished() ), this, SLOT( EWResChanged() ) );
+  connect( mRows, SIGNAL( editingFinished() ), this, SLOT( rowsChanged() ) );
+  connect( mCols, SIGNAL( editingFinished() ), this, SLOT( colsChanged() ) );
 
   // Symbology
   QPen pen = mPlugin->regionPen();
@@ -194,12 +191,6 @@
 
   mWidthSpinBox->setValue( pen.width() );
   connect( mWidthSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( changeWidth() ) );
-
-  mRegionEdit = new QgsGrassRegionEdit( this ); // will be deleted by map canvas
-  mCanvas->setMapTool( mRegionEdit );
-
-  setAttribute( Qt::WA_DeleteOnClose );
-  displayRegion();
 }
 
 void QgsGrassRegion::changeColor( void )
@@ -233,22 +224,25 @@
   return QString( "%1" ).arg( v, 0, 'g' );
 }
 
-void QgsGrassRegion::setGuiValues( bool north, bool south, bool east, bool west,
-                                   bool nsres, bool ewres, bool rows, bool cols )
+void QgsGrassRegion::refreshGui()
 {
-  QgsDebugMsg( "entered." );
+  if ( mUpdatingGui )
+    return;
 
   mUpdatingGui = true;
 
-  if ( north ) mNorth->setText( QString( "%1" ).arg( mWindow.north, 0, 'g', 15 ) );
-  if ( south ) mSouth->setText( QString( "%1" ).arg( mWindow.south, 0, 'g', 15 ) );
-  if ( east )  mEast->setText( QString( "%1" ).arg( mWindow.east, 0, 'g', 15 ) );
-  if ( west )  mWest->setText( QString( "%1" ).arg( mWindow.west, 0, 'g', 15 ) );
-  if ( nsres ) mNSRes->setText( QString( "%1" ).arg( mWindow.ns_res, 0, 'g' ) );
-  if ( ewres ) mEWRes->setText( QString( "%1" ).arg( mWindow.ew_res, 0, 'g' ) );
-  if ( rows )  mRows->setText( QString( "%1" ).arg( mWindow.rows ) );
-  if ( cols )  mCols->setText( QString( "%1" ).arg( mWindow.cols ) );
+  QgsDebugMsg( "entered." );  
 
+  mNorth->setText( QString( "%1" ).arg( mWindow.north, 0, 'g', 15 ) );
+  mSouth->setText( QString( "%1" ).arg( mWindow.south, 0, 'g', 15 ) );
+  mEast->setText( QString( "%1" ).arg( mWindow.east, 0, 'g', 15 ) );
+  mWest->setText( QString( "%1" ).arg( mWindow.west, 0, 'g', 15 ) );
+  mNSRes->setText( QString( "%1" ).arg( mWindow.ns_res, 0, 'g' ) );
+  mEWRes->setText( QString( "%1" ).arg( mWindow.ew_res, 0, 'g' ) );
+  mRows->setText( QString( "%1" ).arg( mWindow.rows ) );
+  mCols->setText( QString( "%1" ).arg( mWindow.cols ) );
+
+  displayRegion();
   mUpdatingGui = false;
 }
 
@@ -257,162 +251,155 @@
   delete mRegionEdit;
 }
 
-void QgsGrassRegion::northChanged( const QString &str )
+void QgsGrassRegion::northChanged()
 {
   if ( mUpdatingGui ) return;
+
   mWindow.north = mNorth->text().toDouble();
+  if ( mWindow.north < mWindow.south )
+    mWindow.north = mWindow.south;
+
   adjust();
-  setGuiValues( false );
-  displayRegion();
+  refreshGui();
 }
 
-void QgsGrassRegion::southChanged( const QString &str )
+void QgsGrassRegion::southChanged()
 {
   if ( mUpdatingGui ) return;
+
   mWindow.south = mSouth->text().toDouble();
+  if ( mWindow.south > mWindow.north )
+    mWindow.south = mWindow.north;
+
   adjust();
-  setGuiValues( true, false );
-  displayRegion();
+  refreshGui();
 }
 
-void QgsGrassRegion::eastChanged( const QString &str )
+void QgsGrassRegion::eastChanged()
 {
   if ( mUpdatingGui ) return;
+
   mWindow.east = mEast->text().toDouble();
+  if ( mWindow.east < mWindow.west )
+    mWindow.east = mWindow.west;
+
   adjust();
-  setGuiValues( true, true, false );
-  displayRegion();
+  refreshGui();
 }
 
-void QgsGrassRegion::westChanged( const QString &str )
+void QgsGrassRegion::westChanged()
 {
   if ( mUpdatingGui ) return;
+
   mWindow.west = mWest->text().toDouble();
+  if ( mWindow.west > mWindow.east )
+    mWindow.west = mWindow.east;
+
   adjust();
-  setGuiValues( true, true, true, false );
-  displayRegion();
+  refreshGui();
 }
 
-void QgsGrassRegion::NSResChanged( const QString &str )
+void QgsGrassRegion::NSResChanged()
 {
   if ( mUpdatingGui ) return;
+
   mWindow.ns_res = mNSRes->text().toDouble();
+  if ( mWindow.ns_res <= 0)
+    mWindow.ns_res = 1;
+
   adjust();
-  setGuiValues( true, true, true, true, false );
-  displayRegion();
+  refreshGui();
 }
 
-void QgsGrassRegion::EWResChanged( const QString &str )
+void QgsGrassRegion::EWResChanged()
 {
   if ( mUpdatingGui ) return;
+
   mWindow.ew_res = mEWRes->text().toDouble();
+  if ( mWindow.ew_res <= 0)
+    mWindow.ew_res = 1;
+
   adjust();
-  setGuiValues( true, true, true, true, true, false );
-  displayRegion();
+  refreshGui();
 }
 
-void QgsGrassRegion::rowsChanged( const QString &str )
+void QgsGrassRegion::rowsChanged()
 {
   if ( mUpdatingGui ) return;
+
   mWindow.rows = mRows->text().toInt();
+  if ( mWindow.rows < 1)
+    mWindow.rows = 1;
+
   adjust();
-  setGuiValues( true, true, true, true, true, true, false );
-  displayRegion();
+  refreshGui();
 }
 
-void QgsGrassRegion::colsChanged( const QString &str )
+void QgsGrassRegion::colsChanged()
 {
   if ( mUpdatingGui ) return;
+
   mWindow.cols = mCols->text().toInt();
+  if ( mWindow.cols < 1)
+    mWindow.cols = 1;
+
   adjust();
-  setGuiValues( true, true, true, true, true, true, true, false );
-  displayRegion();
+  refreshGui();
 }
 
 void QgsGrassRegion::adjust()
 {
-  int r, c;
-  if ( mRowsRadio->isChecked() ) r = 1; else r = 0;
-  if ( mColsRadio->isChecked() ) c = 1; else c = 0;
-  G_adjust_Cell_head( &mWindow, r, c );
+  int rc = 0;
+  if ( mRowsColsRadio->isChecked() )
+  {
+    rc = 1;
+  }
+  G_adjust_Cell_head( &mWindow, rc, rc );
 }
 
 void QgsGrassRegion::radioChanged()
 {
   QgsDebugMsg( "entered." );
 
-  if ( mRowsRadio->isChecked() )
+  if ( mRowsColsRadio->isChecked() )
   {
     mNSRes->setEnabled( false );
-    mRows->setEnabled( true );
-  }
-  else
-  {
-    mNSRes->setEnabled( true );
-    mRows->setEnabled( false );
-  }
-  if ( mColsRadio->isChecked() )
-  {
     mEWRes->setEnabled( false );
+    mRows->setEnabled( true );
     mCols->setEnabled( true );
   }
   else
   {
+    mNSRes->setEnabled( true );
     mEWRes->setEnabled( true );
+    mRows->setEnabled( false );
     mCols->setEnabled( false );
   }
 }
 
-void QgsGrassRegion::draw( double x1, double y1, double x2, double y2 )
+void QgsGrassRegion::onCaptureFinished()
 {
   QgsDebugMsg( "entered." );
+  QgsRectangle rect = mRegionEdit->getRegion();
 
-  if ( x1 < x2 )
-  {
-    mWindow.west = x1;
-    mWindow.east = x2;
-  }
-  else
-  {
-    mWindow.west = x2;
-    mWindow.east = x1;
-  }
-  if ( y1 < y2 )
-  {
-    mWindow.south = y1;
-    mWindow.north = y2;
-  }
-  else
-  {
-    mWindow.south = y2;
-    mWindow.north = y1;
-  }
-
+  mWindow.west = rect.xMinimum();
+  mWindow.east = rect.xMaximum();
+  mWindow.south = rect.yMinimum();
+  mWindow.north = rect.yMaximum();
   adjust();
-  setGuiValues();
-  displayRegion();
+
+  refreshGui();
+  show();
 }
 
 void QgsGrassRegion::displayRegion()
 {
-  QgsDebugMsg( "entered." );
-
   QgsPoint ul( mWindow.west, mWindow.north );
   QgsPoint lr( mWindow.east, mWindow.south );
 
   mRegionEdit->setRegion( ul, lr );
-
-  mDisplayed = true;
 }
 
-void QgsGrassRegion::postRender( QPainter *painter )
-{
-  QgsDebugMsg( "entered." );
-
-  mDisplayed = false;
-  displayRegion();
-}
-
 void QgsGrassRegion::accept()
 {
   // TODO: better repaint region
@@ -441,14 +428,14 @@
 
   saveWindowLocation();
   mCanvas->setMapTool( NULL );
-  delete this;
+  QDialog::accept();
 }
 
 void QgsGrassRegion::reject()
 {
   saveWindowLocation();
   mCanvas->setMapTool( NULL );
-  delete this;
+  QDialog::reject();
 }
 
 void QgsGrassRegion::restorePosition()

Modified: trunk/qgis/src/plugins/grass/qgsgrassregion.h
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassregion.h	2010-11-14 21:33:34 UTC (rev 14659)
+++ trunk/qgis/src/plugins/grass/qgsgrassregion.h	2010-11-14 21:41:55 UTC (rev 14660)
@@ -17,13 +17,16 @@
 #define QGSGRASSREGION_H
 
 #include "ui_qgsgrassregionbase.h"
+#include "qgsmaptool.h"
+#include "qgsrubberband.h"
+#include "qgspoint.h"
 
 class QgsGrassPlugin;
 class QgsGrassRegionEdit;
 
 class QgisInterface;
 class QgsMapCanvas;
-//class QgsPoint;
+class QgsRectangle;
 
 class QButtonGroup;
 
@@ -50,16 +53,11 @@
 
   public slots:
     //! OK
-    void on_acceptButton_clicked() { accept(); }
     void accept( void );
 
-    //! Close
-    void on_rejectButton_clicked() { reject(); }
+    //! Cancel
     void reject( void );
 
-    //! Called when rendering is finished
-    void postRender( QPainter * );
-
     //! Mouse event receiver
     //void mouseEventReceiverMove ( QgsPoint & );
 
@@ -70,14 +68,14 @@
     void adjust( void );
 
     //! Value in GUI was changed
-    void northChanged( const QString &str );
-    void southChanged( const QString &str );
-    void eastChanged( const QString &str );
-    void westChanged( const QString &str );
-    void NSResChanged( const QString &str );
-    void EWResChanged( const QString &str );
-    void rowsChanged( const QString &str );
-    void colsChanged( const QString &str );
+    void northChanged();
+    void southChanged();
+    void eastChanged();
+    void westChanged();
+    void NSResChanged();
+    void EWResChanged();
+    void rowsChanged();
+    void colsChanged();
 
     void radioChanged( void ) ;
 
@@ -86,6 +84,9 @@
 
     void restorePosition( void );
 
+    //! Called when the capture finished to refresh the mWindow values
+    void onCaptureFinished();
+
   private:
     //! Pointer to plugin
     QgsGrassPlugin *mPlugin;
@@ -96,8 +97,7 @@
     //! Pointer to canvas
     QgsMapCanvas *mCanvas;
 
-    QButtonGroup *mNSRadioGroup;
-    QButtonGroup *mEWRadioGroup;
+    QButtonGroup *mRadioGroup;
 
     //! Current new region
     struct Cell_head mWindow;
@@ -105,12 +105,9 @@
     //! Display current state of new region in XOR mode
     void displayRegion( void );
 
-    //! Region was displayed
-    bool mDisplayed;
+    // Set region values in GUI from mWindow
+    void refreshGui();
 
-    //! Draw region
-    void draw( double x1, double y1, double x2, double y2 );
-
     //! First corner coordinates
     double mX;
     double mY;
@@ -118,19 +115,61 @@
     //! Currently updating GUI, don't run *Changed methods
     bool mUpdatingGui;
 
-    // Set region values in GUI from mWindow
-    void setGuiValues( bool north = true, bool south = true, bool east = true, bool west = true,
-                       bool nsres = true, bool ewres = true, bool rows = true, bool cols = true );
 
-
     void saveWindowLocation( void );
 
     // Format N, S, E, W value
     QString formatEdge( double v );
 
     QgsGrassRegionEdit* mRegionEdit;
+};
 
-    friend class QgsGrassRegionEdit;
+/** map tool which uses rubber band for changing grass region */
+class QgsGrassRegionEdit : public QgsMapTool
+{
+    Q_OBJECT
+
+  public:
+    QgsGrassRegionEdit( QgsMapCanvas* );
+
+    ~QgsGrassRegionEdit();
+
+    //! mouse pressed in map canvas
+    void canvasPressEvent( QMouseEvent * );
+
+    //! mouse movement in map canvas
+    void canvasMoveEvent( QMouseEvent * );
+
+    //! mouse released
+    void canvasReleaseEvent( QMouseEvent * );
+
+
+    //! called when map tool is about to get inactive
+    void deactivate();
+
+    //! get the rectangle
+    QgsRectangle getRegion();
+
+    //! refresh the rectangle displayed in canvas
+    void setRegion( const QgsPoint&, const QgsPoint& );
+
+  signals:
+    void captureStarted();
+    void captureEnded();
+
+
+  private:
+    //! Rubber band for selecting grass region
+    QgsRubberBand* mRubberBand;
+
+    //! Status of input from canvas
+    bool mDraw;
+
+    //! First rectangle point
+    QgsPoint mStartPoint;
+    //! Last rectangle point
+    QgsPoint mEndPoint;
+
 };
 
 #endif // QGSGRASSREGION_H

Modified: trunk/qgis/src/plugins/grass/qgsgrassregionbase.ui
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassregionbase.ui	2010-11-14 21:33:34 UTC (rev 14659)
+++ trunk/qgis/src/plugins/grass/qgsgrassregionbase.ui	2010-11-14 21:41:55 UTC (rev 14660)
@@ -1,448 +1,204 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>QgsGrassRegionBase</class>
- <widget class="QDialog" name="QgsGrassRegionBase" >
-  <property name="geometry" >
+ <widget class="QDialog" name="QgsGrassRegionBase">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>420</width>
-    <height>297</height>
+    <width>445</width>
+    <height>348</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>GRASS Region Settings</string>
   </property>
-  <layout class="QGridLayout" >
-   <property name="leftMargin" >
-    <number>2</number>
-   </property>
-   <property name="topMargin" >
-    <number>2</number>
-   </property>
-   <property name="rightMargin" >
-    <number>2</number>
-   </property>
-   <property name="bottomMargin" >
-    <number>2</number>
-   </property>
-   <property name="horizontalSpacing" >
-    <number>2</number>
-   </property>
-   <property name="verticalSpacing" >
-    <number>2</number>
-   </property>
-   <item row="0" column="0" >
-    <widget class="QFrame" name="frame4" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
+  <layout class="QGridLayout" name="gridLayout_4">
+   <item row="0" column="0">
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Extent</string>
      </property>
-     <property name="minimumSize" >
-      <size>
-       <width>0</width>
-       <height>35</height>
-      </size>
-     </property>
-     <property name="maximumSize" >
-      <size>
-       <width>32767</width>
-       <height>35</height>
-      </size>
-     </property>
-     <property name="frameShape" >
-      <enum>QFrame::StyledPanel</enum>
-     </property>
-     <property name="frameShadow" >
-      <enum>QFrame::Raised</enum>
-     </property>
-     <layout class="QHBoxLayout" >
-      <property name="leftMargin" >
-       <number>6</number>
-      </property>
-      <property name="topMargin" >
-       <number>6</number>
-      </property>
-      <property name="rightMargin" >
-       <number>6</number>
-      </property>
-      <property name="bottomMargin" >
-       <number>6</number>
-      </property>
-      <item>
-       <spacer>
-        <property name="orientation" >
-         <enum>Qt::Horizontal</enum>
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="0" column="2">
+       <widget class="QLabel" name="textLabel1">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
         </property>
-        <property name="sizeType" >
-         <enum>QSizePolicy::Expanding</enum>
+        <property name="text">
+         <string>North</string>
         </property>
-        <property name="sizeHint" >
-         <size>
-          <width>72</width>
-          <height>16</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item>
-       <widget class="QLabel" name="textLabel1" >
-        <property name="text" >
-         <string>N</string>
-        </property>
        </widget>
       </item>
-      <item>
-       <widget class="QLineEdit" name="mNorth" />
-      </item>
-      <item>
-       <spacer>
-        <property name="orientation" >
-         <enum>Qt::Horizontal</enum>
+      <item row="1" column="0">
+       <widget class="QLabel" name="textLabel2">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
         </property>
-        <property name="sizeType" >
-         <enum>QSizePolicy::Expanding</enum>
-        </property>
-        <property name="sizeHint" >
-         <size>
-          <width>71</width>
-          <height>21</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-     </layout>
-    </widget>
-   </item>
-   <item row="1" column="0" >
-    <widget class="QFrame" name="frame19" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="minimumSize" >
-      <size>
-       <width>0</width>
-       <height>35</height>
-      </size>
-     </property>
-     <property name="maximumSize" >
-      <size>
-       <width>32767</width>
-       <height>35</height>
-      </size>
-     </property>
-     <property name="frameShape" >
-      <enum>QFrame::StyledPanel</enum>
-     </property>
-     <property name="frameShadow" >
-      <enum>QFrame::Raised</enum>
-     </property>
-     <layout class="QHBoxLayout" >
-      <property name="spacing" >
-       <number>2</number>
-      </property>
-      <property name="leftMargin" >
-       <number>2</number>
-      </property>
-      <property name="topMargin" >
-       <number>2</number>
-      </property>
-      <property name="rightMargin" >
-       <number>2</number>
-      </property>
-      <property name="bottomMargin" >
-       <number>2</number>
-      </property>
-      <item>
-       <widget class="QLabel" name="textLabel2" >
-        <property name="frameShape" >
+        <property name="frameShape">
          <enum>QFrame::NoFrame</enum>
         </property>
-        <property name="frameShadow" >
+        <property name="frameShadow">
          <enum>QFrame::Plain</enum>
         </property>
-        <property name="text" >
-         <string>W</string>
+        <property name="text">
+         <string>West</string>
         </property>
        </widget>
       </item>
-      <item>
-       <widget class="QLineEdit" name="mWest" />
+      <item row="1" column="1" colspan="2">
+       <widget class="QLineEdit" name="mWest"/>
       </item>
-      <item>
-       <spacer>
-        <property name="orientation" >
-         <enum>Qt::Horizontal</enum>
+      <item row="1" column="4">
+       <widget class="QLabel" name="textLabel3">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
         </property>
-        <property name="sizeType" >
-         <enum>QSizePolicy::Expanding</enum>
+        <property name="text">
+         <string>East</string>
         </property>
-        <property name="sizeHint" >
-         <size>
-          <width>51</width>
-          <height>26</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item>
-       <widget class="QLabel" name="textLabel3" >
-        <property name="text" >
-         <string>E</string>
-        </property>
        </widget>
       </item>
-      <item>
-       <widget class="QLineEdit" name="mEast" />
+      <item row="1" column="5">
+       <widget class="QLineEdit" name="mEast"/>
       </item>
-     </layout>
-    </widget>
-   </item>
-   <item row="2" column="0" >
-    <widget class="QFrame" name="frame20" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="minimumSize" >
-      <size>
-       <width>0</width>
-       <height>35</height>
-      </size>
-     </property>
-     <property name="maximumSize" >
-      <size>
-       <width>32767</width>
-       <height>35</height>
-      </size>
-     </property>
-     <property name="frameShape" >
-      <enum>QFrame::StyledPanel</enum>
-     </property>
-     <property name="frameShadow" >
-      <enum>QFrame::Raised</enum>
-     </property>
-     <layout class="QHBoxLayout" >
-      <property name="spacing" >
-       <number>2</number>
-      </property>
-      <property name="leftMargin" >
-       <number>2</number>
-      </property>
-      <property name="topMargin" >
-       <number>2</number>
-      </property>
-      <property name="rightMargin" >
-       <number>2</number>
-      </property>
-      <property name="bottomMargin" >
-       <number>2</number>
-      </property>
-      <item>
-       <spacer>
-        <property name="orientation" >
-         <enum>Qt::Horizontal</enum>
+      <item row="2" column="2">
+       <widget class="QLabel" name="textLabel4">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
         </property>
-        <property name="sizeType" >
-         <enum>QSizePolicy::Expanding</enum>
+        <property name="text">
+         <string>South</string>
         </property>
-        <property name="sizeHint" >
-         <size>
-          <width>73</width>
-          <height>26</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item>
-       <widget class="QLabel" name="textLabel4" >
-        <property name="text" >
-         <string>S</string>
-        </property>
        </widget>
       </item>
-      <item>
-       <widget class="QLineEdit" name="mSouth" />
+      <item row="2" column="3" colspan="2">
+       <widget class="QLineEdit" name="mSouth"/>
       </item>
-      <item>
-       <spacer>
-        <property name="orientation" >
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeType" >
-         <enum>QSizePolicy::Expanding</enum>
-        </property>
-        <property name="sizeHint" >
-         <size>
-          <width>57</width>
-          <height>23</height>
-         </size>
-        </property>
-       </spacer>
+      <item row="0" column="3" colspan="2">
+       <widget class="QLineEdit" name="mNorth"/>
       </item>
      </layout>
     </widget>
    </item>
-   <item row="3" column="0" >
-    <widget class="QFrame" name="frame5" >
-     <property name="frameShape" >
-      <enum>QFrame::StyledPanel</enum>
+   <item row="1" column="0">
+    <widget class="QGroupBox" name="groupBox_2">
+     <property name="title">
+      <string>Resolution</string>
      </property>
-     <property name="frameShadow" >
-      <enum>QFrame::Raised</enum>
-     </property>
-     <layout class="QGridLayout" >
-      <property name="leftMargin" >
-       <number>6</number>
-      </property>
-      <property name="topMargin" >
-       <number>6</number>
-      </property>
-      <property name="rightMargin" >
-       <number>6</number>
-      </property>
-      <property name="bottomMargin" >
-       <number>6</number>
-      </property>
-      <item row="0" column="0" >
-       <widget class="QRadioButton" name="mNSResRadio" >
-        <property name="text" >
-         <string>N-S Res</string>
+     <layout class="QGridLayout" name="gridLayout_2">
+      <item row="0" column="0">
+       <widget class="QRadioButton" name="mCellResRadio">
+        <property name="text">
+         <string>Cell width</string>
         </property>
-        <property name="checked" >
-         <bool>false</bool>
+        <property name="checked">
+         <bool>true</bool>
         </property>
        </widget>
       </item>
-      <item row="0" column="1" >
-       <widget class="QLineEdit" name="mNSRes" />
+      <item row="0" column="1">
+       <widget class="QLineEdit" name="mEWRes"/>
       </item>
-      <item row="0" column="2" >
-       <widget class="QRadioButton" name="mRowsRadio" >
-        <property name="text" >
-         <string>Rows</string>
+      <item row="0" column="2">
+       <widget class="QLabel" name="label_2">
+        <property name="text">
+         <string>Cell height</string>
         </property>
+        <property name="indent">
+         <number>20</number>
+        </property>
        </widget>
       </item>
-      <item row="0" column="3" >
-       <widget class="QLineEdit" name="mRows" />
+      <item row="0" column="3">
+       <widget class="QLineEdit" name="mNSRes"/>
       </item>
-      <item row="1" column="2" >
-       <widget class="QRadioButton" name="mColsRadio" >
-        <property name="text" >
-         <string>Cols</string>
+      <item row="1" column="0">
+       <widget class="QRadioButton" name="mRowsColsRadio">
+        <property name="text">
+         <string>Columns</string>
         </property>
        </widget>
       </item>
-      <item row="1" column="1" >
-       <widget class="QLineEdit" name="mEWRes" />
+      <item row="1" column="1">
+       <widget class="QLineEdit" name="mCols"/>
       </item>
-      <item row="1" column="3" >
-       <widget class="QLineEdit" name="mCols" />
-      </item>
-      <item row="1" column="0" >
-       <widget class="QRadioButton" name="mEWResRadio" >
-        <property name="text" >
-         <string>E-W Res</string>
+      <item row="1" column="2">
+       <widget class="QLabel" name="label">
+        <property name="text">
+         <string>Rows</string>
         </property>
-        <property name="checked" >
-         <bool>true</bool>
+        <property name="indent">
+         <number>20</number>
         </property>
        </widget>
       </item>
+      <item row="1" column="3">
+       <widget class="QLineEdit" name="mRows"/>
+      </item>
      </layout>
     </widget>
    </item>
-   <item row="4" column="0" >
-    <widget class="QFrame" name="frame6" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
+   <item row="2" column="0">
+    <widget class="QGroupBox" name="groupBox_3">
+     <property name="title">
+      <string>Border</string>
      </property>
-     <property name="minimumSize" >
-      <size>
-       <width>0</width>
-       <height>35</height>
-      </size>
-     </property>
-     <property name="maximumSize" >
-      <size>
-       <width>32767</width>
-       <height>35</height>
-      </size>
-     </property>
-     <property name="frameShape" >
-      <enum>QFrame::StyledPanel</enum>
-     </property>
-     <property name="frameShadow" >
-      <enum>QFrame::Raised</enum>
-     </property>
-     <layout class="QHBoxLayout" >
-      <property name="spacing" >
-       <number>3</number>
-      </property>
-      <property name="leftMargin" >
-       <number>3</number>
-      </property>
-      <property name="topMargin" >
-       <number>3</number>
-      </property>
-      <property name="rightMargin" >
-       <number>3</number>
-      </property>
-      <property name="bottomMargin" >
-       <number>3</number>
-      </property>
-      <item>
-       <widget class="QLabel" name="textLabel7" >
-        <property name="text" >
+     <layout class="QGridLayout" name="gridLayout_3">
+      <item row="0" column="0">
+       <widget class="QLabel" name="textLabel7">
+        <property name="text">
          <string>Color</string>
         </property>
        </widget>
       </item>
-      <item>
-       <widget class="QgsColorButton" native="1" name="mColorButton" >
-        <property name="minimumSize" >
+      <item row="0" column="1">
+       <widget class="QgsColorButton" name="mColorButton" native="true">
+        <property name="minimumSize">
          <size>
           <width>35</width>
           <height>25</height>
          </size>
         </property>
-        <property name="text" stdset="0" >
+        <property name="text" stdset="0">
          <string/>
         </property>
        </widget>
       </item>
-      <item>
-       <widget class="QLabel" name="textLabel6" >
-        <property name="text" >
+      <item row="0" column="2">
+       <widget class="QLabel" name="textLabel6">
+        <property name="text">
          <string>Width</string>
         </property>
+        <property name="indent">
+         <number>20</number>
+        </property>
        </widget>
       </item>
-      <item>
-       <widget class="QSpinBox" name="mWidthSpinBox" />
+      <item row="0" column="3">
+       <widget class="QSpinBox" name="mWidthSpinBox"/>
       </item>
-      <item>
-       <spacer>
-        <property name="orientation" >
+      <item row="0" column="4">
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
-        <property name="sizeType" >
-         <enum>QSizePolicy::Expanding</enum>
-        </property>
-        <property name="sizeHint" >
+        <property name="sizeHint" stdset="0">
          <size>
-          <width>69</width>
-          <height>24</height>
+          <width>40</width>
+          <height>20</height>
          </size>
         </property>
        </spacer>
@@ -450,116 +206,18 @@
      </layout>
     </widget>
    </item>
-   <item row="5" column="0" >
-    <widget class="QFrame" name="frame8" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
+   <item row="3" column="0">
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
      </property>
-     <property name="minimumSize" >
-      <size>
-       <width>0</width>
-       <height>38</height>
-      </size>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
      </property>
-     <property name="maximumSize" >
-      <size>
-       <width>32767</width>
-       <height>38</height>
-      </size>
-     </property>
-     <property name="frameShape" >
-      <enum>QFrame::StyledPanel</enum>
-     </property>
-     <property name="frameShadow" >
-      <enum>QFrame::Raised</enum>
-     </property>
-     <layout class="QHBoxLayout" >
-      <property name="spacing" >
-       <number>3</number>
-      </property>
-      <property name="leftMargin" >
-       <number>3</number>
-      </property>
-      <property name="topMargin" >
-       <number>3</number>
-      </property>
-      <property name="rightMargin" >
-       <number>3</number>
-      </property>
-      <property name="bottomMargin" >
-       <number>3</number>
-      </property>
-      <item>
-       <spacer>
-        <property name="orientation" >
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeType" >
-         <enum>QSizePolicy::Expanding</enum>
-        </property>
-        <property name="sizeHint" >
-         <size>
-          <width>45</width>
-          <height>26</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item>
-       <widget class="QPushButton" name="acceptButton" >
-        <property name="text" >
-         <string>OK</string>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <spacer>
-        <property name="orientation" >
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeType" >
-         <enum>QSizePolicy::Expanding</enum>
-        </property>
-        <property name="sizeHint" >
-         <size>
-          <width>47</width>
-          <height>25</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item>
-       <widget class="QPushButton" name="rejectButton" >
-        <property name="text" >
-         <string>Cancel</string>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <spacer>
-        <property name="orientation" >
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeType" >
-         <enum>QSizePolicy::Expanding</enum>
-        </property>
-        <property name="sizeHint" >
-         <size>
-          <width>54</width>
-          <height>26</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-     </layout>
     </widget>
    </item>
   </layout>
  </widget>
- <layoutdefault spacing="6" margin="11" />
  <customwidgets>
   <customwidget>
    <class>QgsColorButton</class>



More information about the QGIS-commit mailing list