Skip to content

Commit

Permalink
[GRASS] fixed add new layer if vector is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Oct 5, 2015
1 parent 0caf944 commit d3f79af
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/plugins/grass/qgsgrassplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,11 @@ void QgsGrassPlugin::onNewLayer( QString uri, QString name )
{
QgsDebugMsg( "uri = " + uri + " name = " + name );
QgsVectorLayer* vectorLayer = qGisInterface->addVectorLayer( uri, name, "grass" );
vectorLayer->startEditing();
qGisInterface->setActiveLayer( vectorLayer );
if ( vectorLayer )
{
vectorLayer->startEditing();
qGisInterface->setActiveLayer( vectorLayer );
}
}

void QgsGrassPlugin::postRender( QPainter *painter )
Expand Down
5 changes: 4 additions & 1 deletion src/providers/grass/qgsgrassprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ void QgsGrassProvider::update()
QgsGrassProvider::~QgsGrassProvider()
{
QgsDebugMsg( "entered" );
mLayer->close();
if ( mLayer )
{
mLayer->close();
}
}


Expand Down
14 changes: 8 additions & 6 deletions src/providers/grass/qgsgrassprovidermodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
#include <QTextEdit>

//----------------------- QgsGrassItemActions ------------------------------
QgsGrassItemActions::QgsGrassItemActions( QgsGrassObject grassObject, QObject *parent )
QgsGrassItemActions::QgsGrassItemActions( QgsGrassObject grassObject, bool valid, QObject *parent )
: QObject( parent )
, mGrassObject( grassObject )
, mValid( valid )
{
}

Expand Down Expand Up @@ -79,7 +80,8 @@ QList<QAction*> QgsGrassItemActions::actions()
list << deleteAction;
}

if ( mGrassObject.type() == QgsGrassObject::Mapset || mGrassObject.type() == QgsGrassObject::Vector )
if (( mGrassObject.type() == QgsGrassObject::Mapset || mGrassObject.type() == QgsGrassObject::Vector )
&& mValid )
{
// TODO: disable new layer actions on maps currently being edited
QAction* newPointAction = new QAction( tr( "New Point Layer" ), this );
Expand Down Expand Up @@ -313,7 +315,7 @@ QgsGrassLocationItem::QgsGrassLocationItem( QgsDataItem* parent, QString dirPath
QString gisdbase = dir.path();

mGrassObject = QgsGrassObject( gisdbase, mName, "", "", QgsGrassObject::Location );
mActions = new QgsGrassItemActions( mGrassObject, this );
mActions = new QgsGrassItemActions( mGrassObject, true, this );

mIconName = "grass_location.png";

Expand Down Expand Up @@ -360,7 +362,7 @@ QgsGrassMapsetItem::QgsGrassMapsetItem( QgsDataItem* parent, QString dirPath, QS
QString gisdbase = dir.path();

mGrassObject = QgsGrassObject( gisdbase, location, mName, "", QgsGrassObject::Mapset );
mActions = new QgsGrassItemActions( mGrassObject, this );
mActions = new QgsGrassItemActions( mGrassObject, true, this );

mIconName = "grass_mapset.png";
}
Expand Down Expand Up @@ -920,7 +922,7 @@ QgsGrassObjectItem::QgsGrassObjectItem( QgsDataItem* parent, QgsGrassObject gras
, mActions( 0 )
{
setState( Populated ); // no children, to show non expandable in browser
mActions = new QgsGrassItemActions( mGrassObject, this );
mActions = new QgsGrassItemActions( mGrassObject, true, this );
}

bool QgsGrassObjectItem::equal( const QgsDataItem *other )
Expand All @@ -946,7 +948,7 @@ QgsGrassVectorItem::QgsGrassVectorItem( QgsDataItem* parent, QgsGrassObject gras
setState( Populated );
setIconName( "/mIconDelete.png" );
}
mActions = new QgsGrassItemActions( mGrassObject, this );
mActions = new QgsGrassItemActions( mGrassObject, mValid, this );

QString watchPath = mGrassObject.mapsetPath() + "/vector/" + mGrassObject.name();
QgsDebugMsg( "add watcher on " + watchPath );
Expand Down
4 changes: 3 additions & 1 deletion src/providers/grass/qgsgrassprovidermodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class QgsGrassItemActions : public QObject
{
Q_OBJECT
public:
QgsGrassItemActions( QgsGrassObject grassObject, QObject *parent );
QgsGrassItemActions( QgsGrassObject grassObject, bool valid, QObject *parent );

QList<QAction*> actions();

Expand All @@ -52,6 +52,8 @@ class QgsGrassItemActions : public QObject
QString newVectorMap();
void newLayer( QString type );
QgsGrassObject mGrassObject;
// Grass object is valid
bool mValid;
};

class QgsGrassObjectItemBase
Expand Down
5 changes: 4 additions & 1 deletion src/providers/grass/qgsgrassvectormaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ void QgsGrassVectorMapLayer::close()
{
QgsDebugMsg( "close" );
//removeUser(); // removed by map
mMap->closeLayer( this );
if ( mMap )
{
mMap->closeLayer( this );
}
}

QStringList QgsGrassVectorMapLayer::fieldNames( QgsFields & fields )
Expand Down

0 comments on commit d3f79af

Please sign in to comment.