Skip to content
Permalink
Browse files

fixed crash on non grass layer

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5096 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Mar 24, 2006
1 parent 20e4b99 commit 56ad17dc728eb650fad0f11b9733e3394bc460e4
@@ -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 ?
@@ -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,
@@ -897,7 +900,7 @@ QgsGrassEdit::~QgsGrassEdit()
std::cerr << "QgsGrassEdit::~QgsGrassEdit()" << std::endl;
#endif

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

emit finished();
delete this;
}

@@ -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;
@@ -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 ) );
@@ -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
@@ -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;

0 comments on commit 56ad17d

Please sign in to comment.
You can’t perform that action at this time.