Skip to content

Commit

Permalink
fixed crash on non grass layer
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5096 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 24, 2006
1 parent 20e4b99 commit 56ad17d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
39 changes: 21 additions & 18 deletions src/plugins/grass/qgsgrassedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,27 @@ QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
// At moment QgisIface::activeLayer() does not work
QgsMapLayer *layer = (QgsMapLayer *) mIface->activeLayer();

if ( !layer ) {
std::cerr << "No layer is selected." << std::endl;
QMessageBox::warning( 0, "Warning", "No layer is selected." );
return;
}
if ( !isEditable(layer) ) return;

//TODO dynamic_cast ?
QgsVectorLayer *vector = (QgsVectorLayer*)layer;

//TODO dynamic_cast ?
mProvider = (QgsGrassProvider *) vector->getDataProvider();

init();

}

bool QgsGrassEdit::isEditable ( QgsMapLayer *layer )
{
if ( !layer ) return false;

std::cerr << "layer name: " << layer->name().toLocal8Bit().data() << std::endl;

if ( layer->type() != QgsMapLayer::VECTOR ) {
std::cerr << "The selected layer is not vector." << std::endl;
QMessageBox::warning( 0, "Warning", "The selected layer is not vector." );
return;
return false;
}

//TODO dynamic_cast ?
Expand All @@ -155,17 +164,11 @@ QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
std::cerr << "Vector layer type: " << vector->providerType().toLocal8Bit().data() << std::endl;

if ( vector->providerType() != "grass" ) {
QMessageBox::warning( 0, "Warning", "The selected vector is not in GRASS format." );
return;
std::cerr << "The selected layer is not GRASS." << std::endl;
return false;
}

std::cerr << "Vector layer type: " << vector->providerType().toLocal8Bit().data() << std::endl;

//TODO dynamic_cast ?
mProvider = (QgsGrassProvider *) vector->getDataProvider();

init();

return true;
}

QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
Expand Down Expand Up @@ -897,7 +900,7 @@ QgsGrassEdit::~QgsGrassEdit()
std::cerr << "QgsGrassEdit::~QgsGrassEdit()" << std::endl;
#endif

if (mCanvasEdit) {
if ( mValid && mCanvasEdit) {
eraseDynamic();
mRubberBandLine->hide();
mRubberBandIcon->hide();
Expand Down Expand Up @@ -965,7 +968,7 @@ void QgsGrassEdit::closeEdit(void)
QgsGrass::getDefaultLocation(),
mapset, map );
}

emit finished();
delete this;
}

Expand Down
5 changes: 5 additions & 0 deletions src/plugins/grass/qgsgrassedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ public slots:
// ! Close event
void closeEvent(QCloseEvent *e);

static bool isEditable ( QgsMapLayer *layer );

signals:
void finished();

private:
//! Editing is already running
static bool mRunning;
Expand Down
27 changes: 27 additions & 0 deletions src/plugins/grass/qgsgrassplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ void QgsGrassPlugin::initGui()
// Connect display region
connect( mCanvas, SIGNAL(renderComplete(QPainter *)), this, SLOT(postRender(QPainter *)));


connect ( mCanvas, SIGNAL(layersChanged()), this, SLOT(setEditAction()) );

// Init Region symbology
mRegionPen.setColor( QColor ( settings.readEntry ("/GRASS/region/color", "#ff0000" ) ) );
mRegionPen.setWidth( settings.readNumEntry ("/GRASS/region/width", 0 ) );
Expand Down Expand Up @@ -436,16 +439,40 @@ void QgsGrassPlugin::edit()
return;
}

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

if ( ed->isValid() ) {
ed->show();
mCanvas->refresh();
connect(ed, SIGNAL(finished()), this, SLOT(setEditAction()));
} else {
delete ed;
mEditAction->setEnabled(true);
}
}

void QgsGrassPlugin::setEditAction()
{
#ifdef QGISDEBUG
std::cout << "QgsGrassPlugin::setEditAction()" << std::endl;
#endif

QgsMapLayer *layer = (QgsMapLayer *) qGisInterface->activeLayer();

if ( QgsGrassEdit::isEditable(layer) )
{
mEditAction->setEnabled(true);
}
else
{
mEditAction->setEnabled(false);
}

// TODO connect to currentItemChanged()? and disable this:
mEditAction->setEnabled(true);
}

void QgsGrassPlugin::newVector()
{
#ifdef QGISDEBUG
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/grass/qgsgrassplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public slots:
void newProject();
//! Save mapset to project
void saveMapset();

//! Set edit action
void setEditAction();
private:
//! Name of the plugin
QString pluginNameQString;
Expand Down

0 comments on commit 56ad17d

Please sign in to comment.