Skip to content

Commit 4e0c7fe

Browse files
author
wonder
committed
Fix for crash - ticket #756
git-svn-id: http://svn.osgeo.org/qgis/trunk@8057 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 61fd895 commit 4e0c7fe

File tree

3 files changed

+10
-46
lines changed

3 files changed

+10
-46
lines changed

src/plugins/grass/qgsgrassedit.cpp

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class QgsGrassEditLayer : public QgsMapCanvasItem
112112

113113
bool QgsGrassEdit::mRunning = false;
114114

115-
QgsGrassEdit::QgsGrassEdit ( QgisInterface *iface,
115+
QgsGrassEdit::QgsGrassEdit ( QgisInterface *iface, QgsMapLayer* layer, bool newMap,
116116
QWidget * parent, Qt::WFlags f )
117117
:QMainWindow(parent,f), QgsGrassEditBase (), mInited(false),
118118
mMapTool(0), mCanvasEdit(0), mRubberBandLine(0), mRubberBandIcon(0)
@@ -128,17 +128,12 @@ QgsGrassEdit::QgsGrassEdit ( QgisInterface *iface,
128128
mTool = QgsGrassEdit::NONE;
129129
mSuspend = false;
130130
mIface = iface;
131-
mNewMap = false;
131+
mNewMap = newMap;
132132

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

135135
mCanvas = mIface->getMapCanvas();
136136

137-
// TODO QGIS: crash if canvas is empty
138-
139-
// At moment QgisIface::activeLayer() does not work
140-
QgsMapLayer *layer = (QgsMapLayer *) mIface->activeLayer();
141-
142137
if ( !isEditable(layer) ) return;
143138

144139
//TODO dynamic_cast ?
@@ -198,33 +193,6 @@ void QgsGrassEdit::keyPress(QKeyEvent *e)
198193
}
199194
}
200195

201-
QgsGrassEdit::QgsGrassEdit ( QgisInterface *iface,
202-
QgsGrassProvider *provider,
203-
QWidget * parent, Qt::WFlags f )
204-
:QMainWindow(parent, 0, f), QgsGrassEditBase (), mInited(false),
205-
mMapTool(0), mCanvasEdit(0), mRubberBandLine(0), mRubberBandIcon(0)
206-
{
207-
#ifdef QGISDEBUG
208-
std::cerr << "QgsGrassEdit()" << std::endl;
209-
#endif
210-
211-
setupUi(this);
212-
213-
mRunning = true;
214-
mValid = false;
215-
mTool = QgsGrassEdit::NONE;
216-
mSuspend = false;
217-
mIface = iface;
218-
mNewMap = true;
219-
220-
mProjectionEnabled = (QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0)!=0);
221-
222-
mCanvas = mIface->getMapCanvas();
223-
224-
mProvider = provider;
225-
226-
init();
227-
}
228196

229197
void QgsGrassEdit::init()
230198
{

src/plugins/grass/qgsgrassedit.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ class QgsGrassEdit: public QMainWindow, private Ui::QgsGrassEditBase
116116

117117
//! Constructor
118118
QgsGrassEdit ( QgisInterface *iface,
119-
QWidget * parent = 0, Qt::WFlags f = 0 );
120-
121-
QgsGrassEdit ( QgisInterface *iface,
122-
QgsGrassProvider *provider,
119+
QgsMapLayer *layer, bool newMap,
123120
QWidget * parent = 0, Qt::WFlags f = 0 );
124121

125122
// Shared by constructors

src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ void QgsGrassPlugin::edit()
440440
}
441441

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

445446
if ( ed->isValid() ) {
446447
ed->show();
@@ -511,24 +512,22 @@ void QgsGrassPlugin::newVector()
511512
Vect_close ( &Map );
512513

513514
// Open in GRASS vector provider
514-
QgsProviderRegistry *pr = QgsProviderRegistry::instance();
515515

516516
QString uri = QgsGrass::getDefaultGisdbase() + "/"
517517
+ QgsGrass::getDefaultLocation() + "/"
518518
+ QgsGrass::getDefaultMapset() + "/"
519519
+ name + "/0_point";
520-
521-
QgsGrassProvider *provider = (QgsGrassProvider *)
522-
pr->getProvider ( "grass", uri );
523-
524-
if ( !provider )
520+
521+
QgsVectorLayer* layer = new QgsVectorLayer(uri, name, "grass");
522+
523+
if ( !layer )
525524
{
526525
QMessageBox::warning( 0, tr("Warning"), tr("New vector created "
527526
"but cannot be opened by data provider.") );
528527
return;
529528
}
530529

531-
QgsGrassEdit *ed = new QgsGrassEdit(qGisInterface, provider,
530+
QgsGrassEdit *ed = new QgsGrassEdit(qGisInterface, layer, true,
532531
qGisInterface->getMainWindow(), Qt::WType_Dialog );
533532

534533
if ( ed->isValid() ) {

0 commit comments

Comments
 (0)