Skip to content

Commit 41fbc9d

Browse files
author
rblazek
committed
fixed restore position, must not use Qt::WType_Dialog
git-svn-id: http://svn.osgeo.org/qgis/trunk@5201 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent ddea8a1 commit 41fbc9d

File tree

4 files changed

+37
-42
lines changed

4 files changed

+37
-42
lines changed

src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ void QgsGrassPlugin::initGui()
136136
toolBarPointer = 0;
137137
mTools = 0;
138138
mNewMapset = 0;
139+
mRegion = 0;
139140

140141
QSettings settings("QuantumGIS", "qgis");
141142

@@ -148,9 +149,9 @@ void QgsGrassPlugin::initGui()
148149
connect( mQgis, SIGNAL( newProject() ), this, SLOT(newProject()));
149150

150151
// Create region rubber band
151-
mRegion = new QgsRubberBand(mCanvas, 1);
152-
mRegion->setZ(20);
153-
mRegion->hide();
152+
mRegionBand = new QgsRubberBand(mCanvas, 1);
153+
mRegionBand->setZ(20);
154+
mRegionBand->hide();
154155

155156
// Create the action for tool
156157
mOpenMapsetAction = new QAction( "Open mapset", this );
@@ -231,8 +232,8 @@ void QgsGrassPlugin::initGui()
231232
// Init Region symbology
232233
mRegionPen.setColor( QColor ( settings.readEntry ("/GRASS/region/color", "#ff0000" ) ) );
233234
mRegionPen.setWidth( settings.readNumEntry ("/GRASS/region/width", 0 ) );
234-
mRegion->setColor ( mRegionPen.color() );
235-
mRegion->setWidth ( mRegionPen.width() );
235+
mRegionBand->setColor ( mRegionPen.color() );
236+
mRegionBand->setWidth ( mRegionPen.width() );
236237

237238
mapsetChanged();
238239
}
@@ -264,7 +265,7 @@ void QgsGrassPlugin::mapsetChanged ()
264265
bool on = settings.readBoolEntry ("/GRASS/region/on", true );
265266
mRegionAction->setOn(on);
266267
if ( on ) {
267-
mRegion->show();
268+
mRegionBand->show();
268269
}
269270

270271
if ( mTools )
@@ -564,7 +565,7 @@ void QgsGrassPlugin::displayRegion()
564565
std::cout << "QgsGrassPlugin::displayRegion()" << std::endl;
565566
#endif
566567

567-
mRegion->reset();
568+
mRegionBand->reset();
568569

569570
// Display region of current mapset if in active mode
570571
if ( !QgsGrass::activeMode() ) return;
@@ -600,7 +601,7 @@ void QgsGrassPlugin::displayRegion()
600601

601602
for ( int i = 0; i < 5; i++ )
602603
{
603-
mRegion->addPoint( points[i] );
604+
mRegionBand->addPoint( points[i] );
604605
}
605606
}
606607

@@ -615,9 +616,9 @@ void QgsGrassPlugin::switchRegion(bool on)
615616

616617
if ( on ) {
617618
displayRegion();
618-
mRegion->show();
619+
mRegionBand->show();
619620
} else {
620-
mRegion->hide();
621+
mRegionBand->hide();
621622
}
622623
}
623624

@@ -638,15 +639,23 @@ void QgsGrassPlugin::changeRegion(void)
638639
std::cout << "QgsGrassPlugin::changeRegion()" << std::endl;
639640
#endif
640641

641-
if ( QgsGrassRegion::isRunning() ) {
642-
QMessageBox::warning( 0, "Warning", "The Region tool is already running." );
643-
return;
642+
if ( mRegion ) { // running
643+
mRegion->show();
644+
return;
644645
}
645646

646-
QgsGrassRegion *reg = new QgsGrassRegion(this, mQgis, qGisInterface,
647-
mQgis, Qt::WType_Dialog );
647+
// Warning: don't use Qt::WType_Dialog, it would ignore restorePosition
648+
mRegion = new QgsGrassRegion(this, mQgis, qGisInterface,
649+
mQgis, Qt::Window );
650+
651+
connect ( mRegion, SIGNAL(destroyed(QObject *)), this, SLOT( regionClosed() ));
648652

649-
reg->show();
653+
mRegion->show();
654+
}
655+
656+
void QgsGrassPlugin::regionClosed()
657+
{
658+
mRegion = 0;
650659
}
651660

652661
QPen & QgsGrassPlugin::regionPen()
@@ -658,8 +667,8 @@ void QgsGrassPlugin::setRegionPen(QPen & pen)
658667
{
659668
mRegionPen = pen;
660669

661-
mRegion->setColor ( mRegionPen.color() );
662-
mRegion->setWidth ( mRegionPen.width() );
670+
mRegionBand->setColor ( mRegionPen.color() );
671+
mRegionBand->setWidth ( mRegionPen.width() );
663672

664673
QSettings settings("QuantumGIS", "qgis");
665674
settings.writeEntry ("/GRASS/region/color", mRegionPen.color().name() );

src/plugins/grass/qgsgrassplugin.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class QgsRubberBand;
2828

2929
class QgsGrassTools;
3030
class QgsGrassNewMapset;
31+
class QgsGrassRegion;
3132
class QToolBar;
3233
/**
3334
* \class QgsGrassPlugin
@@ -88,6 +89,8 @@ public slots:
8889
void switchRegion(bool on);
8990
//! Change region
9091
void changeRegion(void);
92+
//! Region dialog closed
93+
void regionClosed();
9194
//! Redraw region
9295
void redrawRegion(void);
9396
//! Post render
@@ -136,8 +139,10 @@ public slots:
136139
QAction *mRegionAction;
137140
//! Region width
138141
QPen mRegionPen;
142+
//! Region dialog
143+
QgsGrassRegion *mRegion;
139144
// Region rubber band
140-
QgsRubberBand *mRegion;
145+
QgsRubberBand *mRegionBand;
141146
//! GRASS tools
142147
QgsGrassTools *mTools;
143148
//! Pointer to QgsGrassNewMapset

src/plugins/grass/qgsgrassregion.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ extern "C" {
6262
#include "qgsgrassplugin.h"
6363
#include "qgsgrassregion.h"
6464

65-
bool QgsGrassRegion::mRunning = false;
66-
6765
/** map tool which uses rubber band for changing grass region */
6866
class QgsGrassRegionEdit : public QgsMapTool
6967
{
@@ -156,7 +154,6 @@ QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, Qgis
156154

157155
setupUi(this);
158156

159-
mRunning = true;
160157
mPlugin = plugin;
161158
mQgisApp = qgisApp;
162159
mInterface = iface;
@@ -293,12 +290,6 @@ void QgsGrassRegion::setGuiValues( bool north, bool south, bool east, bool west,
293290

294291
QgsGrassRegion::~QgsGrassRegion ()
295292
{
296-
mRunning = false;
297-
}
298-
299-
bool QgsGrassRegion::isRunning(void)
300-
{
301-
return mRunning;
302293
}
303294

304295
void QgsGrassRegion::northChanged(const QString &str)
@@ -482,18 +473,14 @@ void QgsGrassRegion::accept()
482473

483474
saveWindowLocation();
484475
mQgisApp->pan(); // change to pan tool
485-
mRunning = false;
486-
close();
487-
//delete this;
476+
delete this;
488477
}
489478

490479
void QgsGrassRegion::reject()
491480
{
492481
saveWindowLocation();
493482
mQgisApp->pan(); // change to pan tool
494-
mRunning = false;
495-
close();
496-
//delete this;
483+
delete this;
497484
}
498485

499486
void QgsGrassRegion::restorePosition()

src/plugins/grass/qgsgrassregion.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class QgsGrassRegion: public QDialog, private Ui::QgsGrassRegionBase
5050
//! Destructor
5151
~QgsGrassRegion();
5252

53-
//! Is Running
54-
static bool isRunning (void);
55-
5653
public slots:
5754
//! OK
5855
void on_acceptButton_clicked() { accept(); }
@@ -89,10 +86,9 @@ public slots:
8986
void changeColor ( void ) ;
9087
void changeWidth ( void ) ;
9188

89+
void restorePosition(void);
90+
9291
private:
93-
//! Editing is already running
94-
static bool mRunning;
95-
9692
//! Pointer to plugin
9793
QgsGrassPlugin *mPlugin;
9894

@@ -131,8 +127,6 @@ public slots:
131127
void setGuiValues( bool north = true, bool south = true, bool east = true, bool west = true,
132128
bool nsres = true, bool ewres = true, bool rows = true, bool cols = true );
133129

134-
135-
void restorePosition(void);
136130

137131
void saveWindowLocation(void);
138132

0 commit comments

Comments
 (0)