Skip to content

Commit

Permalink
fixed restore position, must not use Qt::WType_Dialog
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5201 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Apr 6, 2006
1 parent 336dc01 commit 8cd51e9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 42 deletions.
45 changes: 27 additions & 18 deletions src/plugins/grass/qgsgrassplugin.cpp
Expand Up @@ -136,6 +136,7 @@ void QgsGrassPlugin::initGui()
toolBarPointer = 0;
mTools = 0;
mNewMapset = 0;
mRegion = 0;

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

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

// Create region rubber band
mRegion = new QgsRubberBand(mCanvas, 1);
mRegion->setZ(20);
mRegion->hide();
mRegionBand = new QgsRubberBand(mCanvas, 1);
mRegionBand->setZ(20);
mRegionBand->hide();

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

mapsetChanged();
}
Expand Down Expand Up @@ -264,7 +265,7 @@ void QgsGrassPlugin::mapsetChanged ()
bool on = settings.readBoolEntry ("/GRASS/region/on", true );
mRegionAction->setOn(on);
if ( on ) {
mRegion->show();
mRegionBand->show();
}

if ( mTools )
Expand Down Expand Up @@ -564,7 +565,7 @@ void QgsGrassPlugin::displayRegion()
std::cout << "QgsGrassPlugin::displayRegion()" << std::endl;
#endif

mRegion->reset();
mRegionBand->reset();

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

for ( int i = 0; i < 5; i++ )
{
mRegion->addPoint( points[i] );
mRegionBand->addPoint( points[i] );
}
}

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

if ( on ) {
displayRegion();
mRegion->show();
mRegionBand->show();
} else {
mRegion->hide();
mRegionBand->hide();
}
}

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

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

QgsGrassRegion *reg = new QgsGrassRegion(this, mQgis, qGisInterface,
mQgis, Qt::WType_Dialog );
// Warning: don't use Qt::WType_Dialog, it would ignore restorePosition
mRegion = new QgsGrassRegion(this, mQgis, qGisInterface,
mQgis, Qt::Window );

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

reg->show();
mRegion->show();
}

void QgsGrassPlugin::regionClosed()
{
mRegion = 0;
}

QPen & QgsGrassPlugin::regionPen()
Expand All @@ -658,8 +667,8 @@ void QgsGrassPlugin::setRegionPen(QPen & pen)
{
mRegionPen = pen;

mRegion->setColor ( mRegionPen.color() );
mRegion->setWidth ( mRegionPen.width() );
mRegionBand->setColor ( mRegionPen.color() );
mRegionBand->setWidth ( mRegionPen.width() );

QSettings settings("QuantumGIS", "qgis");
settings.writeEntry ("/GRASS/region/color", mRegionPen.color().name() );
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/grass/qgsgrassplugin.h
Expand Up @@ -28,6 +28,7 @@ class QgsRubberBand;

class QgsGrassTools;
class QgsGrassNewMapset;
class QgsGrassRegion;
class QToolBar;
/**
* \class QgsGrassPlugin
Expand Down Expand Up @@ -88,6 +89,8 @@ public slots:
void switchRegion(bool on);
//! Change region
void changeRegion(void);
//! Region dialog closed
void regionClosed();
//! Redraw region
void redrawRegion(void);
//! Post render
Expand Down Expand Up @@ -136,8 +139,10 @@ public slots:
QAction *mRegionAction;
//! Region width
QPen mRegionPen;
//! Region dialog
QgsGrassRegion *mRegion;
// Region rubber band
QgsRubberBand *mRegion;
QgsRubberBand *mRegionBand;
//! GRASS tools
QgsGrassTools *mTools;
//! Pointer to QgsGrassNewMapset
Expand Down
17 changes: 2 additions & 15 deletions src/plugins/grass/qgsgrassregion.cpp
Expand Up @@ -62,8 +62,6 @@ extern "C" {
#include "qgsgrassplugin.h"
#include "qgsgrassregion.h"

bool QgsGrassRegion::mRunning = false;

/** map tool which uses rubber band for changing grass region */
class QgsGrassRegionEdit : public QgsMapTool
{
Expand Down Expand Up @@ -156,7 +154,6 @@ QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, Qgis

setupUi(this);

mRunning = true;
mPlugin = plugin;
mQgisApp = qgisApp;
mInterface = iface;
Expand Down Expand Up @@ -293,12 +290,6 @@ void QgsGrassRegion::setGuiValues( bool north, bool south, bool east, bool west,

QgsGrassRegion::~QgsGrassRegion ()
{
mRunning = false;
}

bool QgsGrassRegion::isRunning(void)
{
return mRunning;
}

void QgsGrassRegion::northChanged(const QString &str)
Expand Down Expand Up @@ -482,18 +473,14 @@ void QgsGrassRegion::accept()

saveWindowLocation();
mQgisApp->pan(); // change to pan tool
mRunning = false;
close();
//delete this;
delete this;
}

void QgsGrassRegion::reject()
{
saveWindowLocation();
mQgisApp->pan(); // change to pan tool
mRunning = false;
close();
//delete this;
delete this;
}

void QgsGrassRegion::restorePosition()
Expand Down
10 changes: 2 additions & 8 deletions src/plugins/grass/qgsgrassregion.h
Expand Up @@ -50,9 +50,6 @@ class QgsGrassRegion: public QDialog, private Ui::QgsGrassRegionBase
//! Destructor
~QgsGrassRegion();

//! Is Running
static bool isRunning (void);

public slots:
//! OK
void on_acceptButton_clicked() { accept(); }
Expand Down Expand Up @@ -89,10 +86,9 @@ public slots:
void changeColor ( void ) ;
void changeWidth ( void ) ;

void restorePosition(void);

private:
//! Editing is already running
static bool mRunning;

//! Pointer to plugin
QgsGrassPlugin *mPlugin;

Expand Down Expand Up @@ -131,8 +127,6 @@ public slots:
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 restorePosition(void);

void saveWindowLocation(void);

Expand Down

0 comments on commit 8cd51e9

Please sign in to comment.