Skip to content
Permalink
Browse files

move grassprovider to grass library (might fix #3999)

  • Loading branch information
jef-n committed Apr 2, 2012
1 parent 9e15906 commit 9e57e20f61d025132f5b44f60a892e7263043661
@@ -399,6 +399,12 @@ IF (WIN32)
SET(DLLIMPORT "__declspec(dllimport)")
SET(DLLEXPORT "__declspec(dllexport)")
ELSE (WIN32)
IF(PEDANTIC)
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
ENDIF(PEDANTIC)

SET(DLLIMPORT "")
SET(DLLEXPORT "")
ENDIF(WIN32)
@@ -45,7 +45,7 @@ FIND_PATH(PROJ_INCLUDE_DIR proj_api.h
)
FIND_PATH(PROJ_INCLUDE_DIR proj_api.h)

FIND_LIBRARY(PROJ_LIBRARY NAMES proj PATHS
FIND_LIBRARY(PROJ_LIBRARY NAMES proj proj_i PATHS
"$ENV{LIB_DIR}/lib"
#mingw
c:/msys/local/lib
@@ -143,17 +143,6 @@ TARGET_LINK_LIBRARIES(grassplugin
${OPENPTY_LIBRARY}
)

# provider must be built as module on OS X so it gets loaded,
# lookup symbols dynamically instead of linking at compile time
IF (APPLE)
SET_TARGET_PROPERTIES(grassplugin PROPERTIES
LINK_FLAGS "-undefined dynamic_lookup")
ELSE (APPLE)
TARGET_LINK_LIBRARIES(grassplugin
grassprovider
)
ENDIF (APPLE)

# override default path where built files are put to allow running qgis without installing
# the binary goes under libexec subdir
SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_LIBEXEC_SUBDIR}/grass/bin)
@@ -16,7 +16,8 @@ INCLUDE_DIRECTORIES(
# GRASS library
#

ADD_LIBRARY(qgisgrass SHARED qgsgrass.cpp)
QT4_WRAP_CPP(GRASS_PROVIDER_MOC_SRCS qgsgrassprovider.h)
ADD_LIBRARY(qgisgrass SHARED qgsgrass.cpp qgsgrassprovider.cpp ${GRASS_PROVIDER_MOC_SRCS})

SET_TARGET_PROPERTIES(qgisgrass PROPERTIES
CLEAN_DIRECT_OUTPUT 1
@@ -52,14 +53,7 @@ ENDIF (APPLE)
# GRASS vector provider
#

QT4_WRAP_CPP(GRASS_PROVIDER_MOC_SRCS qgsgrassprovider.h)
# provider must be built as module on OS X so it gets loaded,
# other modules that need provider symbols must dynamically lookup them
IF (APPLE)
ADD_LIBRARY(grassprovider MODULE qgsgrassprovider.cpp ${GRASS_PROVIDER_MOC_SRCS})
ELSE (APPLE)
ADD_LIBRARY(grassprovider SHARED qgsgrassprovider.cpp ${GRASS_PROVIDER_MOC_SRCS})
ENDIF (APPLE)
ADD_LIBRARY(grassprovider MODULE qgsgrassprovidermodule.cpp)
SET_TARGET_PROPERTIES(grassprovider PROPERTIES COMPILE_FLAGS "\"-DGRASS_EXPORT=${DLLEXPORT}\" \"-DGRASS_LIB_EXPORT=${DLLIMPORT}\"" )
TARGET_LINK_LIBRARIES(grassprovider qgisgrass)

@@ -30,10 +30,6 @@
#include "qgsgrass.h"
#include "qgsgrassprovider.h"


#include "qgsgrassprovider.h"
#include "qgsgrass.h"

#include "qgsapplication.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsfield.h"
@@ -45,9 +41,6 @@
#include <QFileInfo>
#include <QMessageBox>
#include <QTextCodec>
//#include <QtGui/qwindowdefs.h>
//#include <QtGui/qmacincludes_mac.h>
//#include <ApplicationServices/ApplicationServices.h>

#ifdef _MSC_VER
// enable grass prototypes
@@ -2421,179 +2414,13 @@ int QgsGrassProvider::cidxGetMaxCat( int idx )
return ( cat );
}



QString QgsGrassProvider::name() const
{
return GRASS_KEY;
} // QgsGrassProvider::name()



QString QgsGrassProvider::description() const
{
return GRASS_DESCRIPTION;
} // QgsGrassProvider::description()


QgsGrassLocationItem::QgsGrassLocationItem( QgsDataItem* parent, QString path )
: QgsDataCollectionItem( parent, "", path )
{
QFileInfo fi( path );
mName = fi.baseName();
mIcon = QIcon( getThemePixmap( "grass_location.png" ) );
}
QgsGrassLocationItem::~QgsGrassLocationItem() {}

bool QgsGrassLocationItem::isLocation( QString path )
{
//QgsDebugMsg( "path = " + path );
return QFile::exists( path + QDir::separator() + "PERMANENT" + QDir::separator() + "DEFAULT_WIND" );
}

QVector<QgsDataItem*>QgsGrassLocationItem::createChildren()
{
QVector<QgsDataItem*> mapsets;

QDir dir( mPath );

QStringList entries = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name );
foreach( QString name, entries )
{
QString path = dir.absoluteFilePath( name );

if ( QgsGrassMapsetItem::isMapset( path ) )
{
QgsGrassMapsetItem * mapset = new QgsGrassMapsetItem( this, path );
mapsets.append( mapset );
}
}
return mapsets;
}

QgsGrassMapsetItem::QgsGrassMapsetItem( QgsDataItem* parent, QString path )
: QgsDataCollectionItem( parent, "", path )
{
QDir dir( path );
mName = dir.dirName();
dir.cdUp();
mLocation = dir.dirName();
dir.cdUp();
mGisdbase = dir.path();

mIcon = QIcon( getThemePixmap( "grass_mapset.png" ) );
}

QgsGrassMapsetItem::~QgsGrassMapsetItem() {}

bool QgsGrassMapsetItem::isMapset( QString path )
{
return QFile::exists( path + QDir::separator() + "WIND" );
}

QVector<QgsDataItem*> QgsGrassMapsetItem::createChildren()
{
QVector<QgsDataItem*> items;

QStringList vectorNames = QgsGrass::vectors( mPath );

foreach( QString name, vectorNames )
{
QStringList layerNames = QgsGrass::vectorLayers( mGisdbase , mLocation, mName, name );

QString path = mPath + QDir::separator() + "vector" + QDir::separator() + name;

QgsDataCollectionItem *map = 0;
if ( layerNames.size() != 1 )
map = new QgsDataCollectionItem( this, name );
foreach( QString layerName, layerNames )
{
QString uri = mPath + QDir::separator() + name + QDir::separator() + layerName;
QgsLayerItem::LayerType layerType = QgsLayerItem::Vector;
QString typeName = layerName.split( "_" )[1];
QString baseLayerName = layerName.split( "_" )[0];

if ( typeName == "point" )
layerType = QgsLayerItem::Point;
else if ( typeName == "line" )
layerType = QgsLayerItem::Line;
else if ( typeName == "polygon" )
layerType = QgsLayerItem::Polygon;

if ( layerNames.size() == 1 )
{
QgsLayerItem *layer = new QgsLayerItem( this, name + " " + baseLayerName, path, uri, layerType, "grass" );
items.append( layer );
}
else
{
QgsLayerItem *layer = new QgsLayerItem( map, baseLayerName, path, uri, layerType, "grass" );
map->addChild( layer );
}
}
if ( layerNames.size() != 1 )
items.append( map );
}

QStringList rasterNames = QgsGrass::rasters( mPath );

foreach( QString name, rasterNames )
{
QString uri = mPath + QDir::separator() + "cellhd" + QDir::separator() + name;
QgsDebugMsg( "uri = " + uri );

QgsLayerItem *layer = new QgsLayerItem( this, name, uri, uri, QgsLayerItem::Raster, "grassraster" );

items.append( layer );
}

return items;
}

QGISEXTERN int dataCapabilities()
{
return QgsDataProvider::Dir;
}

QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
{
if ( QgsGrassLocationItem::isLocation( thePath ) )
{
QgsGrassLocationItem * location = new QgsGrassLocationItem( parentItem, thePath );
return location;
}
return 0;
}

/**
* Class factory to return a pointer to a newly created
* QgsGrassProvider object
*/
QGISEXTERN QgsGrassProvider * classFactory( const QString *uri )
{
return new QgsGrassProvider( *uri );
}

/** Required key function (used to map the plugin to a data store type)
*/
QGISEXTERN QString providerKey()
{
return QString( "grass" );
}

/**
* Required description function
*/
QGISEXTERN QString description()
{
return QString( "GRASS data provider" );
}

/**
* Required isProvider function. Used to determine if this shared library
* is a data provider plugin
*/
QGISEXTERN bool isProvider()
{
return true;
}
@@ -20,7 +20,6 @@ class QgsFeature;
class QgsField;
#include <QDateTime>

#include "qgsdataitem.h"
#include "qgsvectordataprovider.h"
#include <vector>

@@ -110,7 +109,7 @@ struct GMAP
\class QgsGrassProvider
\brief Data provider for GRASS vectors
*/
class GRASS_EXPORT QgsGrassProvider : public QgsVectorDataProvider
class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider
{
Q_OBJECT

@@ -687,30 +686,4 @@ class GRASS_EXPORT QgsGrassProvider : public QgsVectorDataProvider
static std::vector<GMAP> mMaps; // Map
};


class QgsGrassLocationItem : public QgsDataCollectionItem
{
public:
QgsGrassLocationItem( QgsDataItem* parent, QString path );
~QgsGrassLocationItem();

static bool isLocation( QString path );
QVector<QgsDataItem*> createChildren();
};

class QgsGrassMapsetItem : public QgsDataCollectionItem
{
public:
QgsGrassMapsetItem( QgsDataItem* parent, QString path );
~QgsGrassMapsetItem();

static bool isMapset( QString path );
QVector<QgsDataItem*> createChildren();

QString mLocation;
QString mGisdbase;
};



#endif // QGSGRASSPROVIDER_H

0 comments on commit 9e57e20

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