Skip to content

Commit

Permalink
Fix for crash - ticket #756
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@8057 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jan 27, 2008
1 parent 61fd895 commit 4e0c7fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 46 deletions.
36 changes: 2 additions & 34 deletions src/plugins/grass/qgsgrassedit.cpp
Expand Up @@ -112,7 +112,7 @@ class QgsGrassEditLayer : public QgsMapCanvasItem

bool QgsGrassEdit::mRunning = false;

QgsGrassEdit::QgsGrassEdit ( QgisInterface *iface,
QgsGrassEdit::QgsGrassEdit ( QgisInterface *iface, QgsMapLayer* layer, bool newMap,
QWidget * parent, Qt::WFlags f )
:QMainWindow(parent,f), QgsGrassEditBase (), mInited(false),
mMapTool(0), mCanvasEdit(0), mRubberBandLine(0), mRubberBandIcon(0)
Expand All @@ -128,17 +128,12 @@ QgsGrassEdit::QgsGrassEdit ( QgisInterface *iface,
mTool = QgsGrassEdit::NONE;
mSuspend = false;
mIface = iface;
mNewMap = false;
mNewMap = newMap;

mProjectionEnabled = (QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0)!=0);

mCanvas = mIface->getMapCanvas();

// TODO QGIS: crash if canvas is empty

// At moment QgisIface::activeLayer() does not work
QgsMapLayer *layer = (QgsMapLayer *) mIface->activeLayer();

if ( !isEditable(layer) ) return;

//TODO dynamic_cast ?
Expand Down Expand Up @@ -198,33 +193,6 @@ void QgsGrassEdit::keyPress(QKeyEvent *e)
}
}

QgsGrassEdit::QgsGrassEdit ( QgisInterface *iface,
QgsGrassProvider *provider,
QWidget * parent, Qt::WFlags f )
:QMainWindow(parent, 0, f), QgsGrassEditBase (), mInited(false),
mMapTool(0), mCanvasEdit(0), mRubberBandLine(0), mRubberBandIcon(0)
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassEdit()" << std::endl;
#endif

setupUi(this);

mRunning = true;
mValid = false;
mTool = QgsGrassEdit::NONE;
mSuspend = false;
mIface = iface;
mNewMap = true;

mProjectionEnabled = (QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0)!=0);

mCanvas = mIface->getMapCanvas();

mProvider = provider;

init();
}

void QgsGrassEdit::init()
{
Expand Down
5 changes: 1 addition & 4 deletions src/plugins/grass/qgsgrassedit.h
Expand Up @@ -116,10 +116,7 @@ class QgsGrassEdit: public QMainWindow, private Ui::QgsGrassEditBase

//! Constructor
QgsGrassEdit ( QgisInterface *iface,
QWidget * parent = 0, Qt::WFlags f = 0 );

QgsGrassEdit ( QgisInterface *iface,
QgsGrassProvider *provider,
QgsMapLayer *layer, bool newMap,
QWidget * parent = 0, Qt::WFlags f = 0 );

// Shared by constructors
Expand Down
15 changes: 7 additions & 8 deletions src/plugins/grass/qgsgrassplugin.cpp
Expand Up @@ -440,7 +440,8 @@ void QgsGrassPlugin::edit()
}

mEditAction->setEnabled(false);
QgsGrassEdit *ed = new QgsGrassEdit( qGisInterface, qGisInterface->getMainWindow(), Qt::WType_Dialog );
QgsGrassEdit *ed = new QgsGrassEdit( qGisInterface, qGisInterface->activeLayer(), false,
qGisInterface->getMainWindow(), Qt::WType_Dialog );

if ( ed->isValid() ) {
ed->show();
Expand Down Expand Up @@ -511,24 +512,22 @@ void QgsGrassPlugin::newVector()
Vect_close ( &Map );

// Open in GRASS vector provider
QgsProviderRegistry *pr = QgsProviderRegistry::instance();

QString uri = QgsGrass::getDefaultGisdbase() + "/"
+ QgsGrass::getDefaultLocation() + "/"
+ QgsGrass::getDefaultMapset() + "/"
+ name + "/0_point";

QgsGrassProvider *provider = (QgsGrassProvider *)
pr->getProvider ( "grass", uri );

if ( !provider )

QgsVectorLayer* layer = new QgsVectorLayer(uri, name, "grass");

if ( !layer )
{
QMessageBox::warning( 0, tr("Warning"), tr("New vector created "
"but cannot be opened by data provider.") );
return;
}

QgsGrassEdit *ed = new QgsGrassEdit(qGisInterface, provider,
QgsGrassEdit *ed = new QgsGrassEdit(qGisInterface, layer, true,
qGisInterface->getMainWindow(), Qt::WType_Dialog );

if ( ed->isValid() ) {
Expand Down

0 comments on commit 4e0c7fe

Please sign in to comment.