Skip to content
Permalink
Browse files

grass support for qbrowser

  • Loading branch information
blazek committed May 22, 2011
1 parent b02d06b commit 9784cd78e514416eccbf3258646a244af39b6fb4
@@ -13,6 +13,8 @@
<file>themes/default/geographic.png</file>
<file>themes/default/gpsicons/barchart.svg</file>
<file>themes/default/gpsicons/polarchart.svg</file>
<file>themes/default/grass_location.png</file>
<file>themes/default/grass_mapset.png</file>
<file>themes/default/join_bevel.png</file>
<file>themes/default/join_miter.png</file>
<file>themes/default/join_round.png</file>
Binary file not shown.
Binary file not shown.
@@ -419,7 +419,7 @@ void QgsBrowser::updateCurrentTab()

if (current == Metadata && mDirtyMetadata)
{
if (mLayer)
if (mLayer && mLayer->isValid())
{
// Set meta
QString myStyle = QgsApplication::reportStyleSheet();
@@ -436,7 +436,7 @@ void QgsBrowser::updateCurrentTab()

if (current == Preview && mDirtyPreview)
{
if (mLayer)
if (mLayer && mLayer->isValid())
{
// Create preview: add to map canvas
QList<QgsMapCanvasLayer> layers;
@@ -452,7 +452,7 @@ void QgsBrowser::updateCurrentTab()

if (current == Attributes && mDirtyAttributes)
{
if ( mLayer && mLayer->type() == QgsMapLayer::VectorLayer )
if ( mLayer && mLayer->isValid() && mLayer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( mLayer );
QApplication::setOverrideCursor(Qt::WaitCursor);
@@ -93,7 +93,7 @@ const QIcon &QgsDataCollectionItem::iconDir()
{
static QIcon icon;

if ( !icon.isNull() )
if ( icon.isNull() )
{
// initialize shared icons
QStyle *style = QApplication::style();
@@ -250,6 +250,16 @@ void QgsDataItem::refresh()
}
}

bool QgsDataItem::equal( const QgsDataItem *other )
{
if ( typeid ( this ) == typeid ( other ) &&
mPath == other->path() )
{
return true;
}
return false;
}

// ---------------------------------------------------------------------

QgsLayerItem::QgsLayerItem( QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType, QString providerKey )
@@ -327,9 +337,10 @@ QgsDirectoryItem::QgsDirectoryItem( QgsDataItem* parent, QString name, QString p
}
if ( dataCapabilities() == QgsDataProvider::NoDataCapabilities )
{
QgsDebugMsg( library->fileName() + " does not have File capability" );
QgsDebugMsg( library->fileName() + " has NoDataCapabilities" );
continue;
}
QgsDebugMsg( QString ( "%1 dataCapabilities : %2").arg(library->fileName()).arg(dataCapabilities() ) );
mLibraries.append( library );
}
else
@@ -360,10 +371,11 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren( )
children.append( item );
}

QStringList fileEntries = dir.entryList( QDir::Files, QDir::Name );
QStringList fileEntries = dir.entryList( QDir::Dirs|QDir::NoDotAndDotDot|QDir::Files, QDir::Name );
foreach( QString name, fileEntries )
{
QString path = dir.absoluteFilePath( name );
QFileInfo fileInfo ( path );
foreach( QLibrary *library, mLibraries )
{
// we could/should create separate list of providers for each purpose
@@ -374,7 +386,11 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren( )

int capabilities = dataCapabilities();

if ( !( capabilities & QgsDataProvider::File ) ) continue;
if ( !( (fileInfo.isFile() && (capabilities & QgsDataProvider::File)) ||
(fileInfo.isDir() && (capabilities & QgsDataProvider::Dir))) )
{
continue;
}

dataItem_t * dataItem = ( dataItem_t * ) cast_to_fptr( library->resolve( "dataItem" ) );
if ( ! dataItem )
@@ -73,7 +73,7 @@ class CORE_EXPORT QgsDataItem : public QObject
// remove and delete child item, signals to browser are emited
virtual void deleteChildItem( QgsDataItem * child );

virtual bool equal( const QgsDataItem *other ) { return false; }
virtual bool equal( const QgsDataItem *other );

virtual QWidget * paramWidget() { return 0; }

@@ -162,7 +162,7 @@ void QgsGrassBrowser::addMap()
else if ( type == QgsGrassModel::VectorLayer )
{

QStringList list = QgsGrassSelect::vectorLayers(
QStringList list = QgsGrass::vectorLayers(
QgsGrass::getDefaultGisdbase(),
QgsGrass::getDefaultLocation(),
mModel->itemMapset( *it ), map );
@@ -759,7 +759,7 @@ void QgsGrassModel::refreshItem( QgsGrassModelItem *item )

case QgsGrassModel::Vector:
{
QStringList list = QgsGrassSelect::vectorLayers(
QStringList list = QgsGrass::vectorLayers(
QgsGrass::getDefaultGisdbase(),
QgsGrass::getDefaultLocation(),
item->mMapset, item->mMap );
@@ -1593,7 +1593,7 @@ void QgsGrassModule::viewOutput()
{
QString map = mOutputVector.at( i );

QStringList layers = QgsGrassSelect::vectorLayers(
QStringList layers = QgsGrass::vectorLayers(
QgsGrass::getDefaultGisdbase(),
QgsGrass::getDefaultLocation(),
QgsGrass::getDefaultMapset(), map );
@@ -323,7 +323,7 @@ void QgsGrassSelect::setLayers()
if ( type != VECTOR ) return;
if ( emap->count() < 1 ) return;

QStringList layers = vectorLayers( egisdbase->text(),
QStringList layers = QgsGrass::vectorLayers( egisdbase->text(),
elocation->currentText(), emapset->currentText(),
emap->currentText().toUtf8() );

@@ -369,100 +369,6 @@ void QgsGrassSelect::setLayers()
}
}

QStringList QgsGrassSelect::vectorLayers( QString gisdbase,
QString location, QString mapset, QString mapName )
{
QStringList list;

// Set location
QgsGrass::setLocation( gisdbase, location );

/* Open vector */
QgsGrass::resetError();
//Vect_set_open_level( 2 );
struct Map_info map;
int level = -1;

try
{
level = Vect_open_old_head( &map, ( char * ) mapName.toUtf8().data(), ( char * ) mapset.toUtf8().data() );
}
catch ( QgsGrass::Exception &e )
{
Q_UNUSED( e );
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
return list;
}

if ( level == 1 )
{
QgsDebugMsg( "Cannot open vector on level 2" );
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open vector %1 in mapset %2 on level 2 (topology not available, try to rebuild topology using v.build module)." ).arg( mapName ).arg( mapset ) );
// Vect_close here is correct, it should work, but it seems to cause
// crash on win http://trac.osgeo.org/qgis/ticket/2003
// disabled on win test it
#if !defined(WIN32)
Vect_close( &map );
#endif
return list;
}
else if ( level < 1 )
{
QgsDebugMsg( "Cannot open vector" );
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open vector %1 in mapset %2" ).arg( mapName ).arg( mapset ) );
return list;
}

QgsDebugMsg( "GRASS vector successfully opened" );


// Get layers
int ncidx = Vect_cidx_get_num_fields( &map );

for ( int i = 0; i < ncidx; i++ )
{
int field = Vect_cidx_get_field_number( &map, i );
QString fs;
fs.sprintf( "%d", field );

QgsDebugMsg( QString( "i = %1 layer = %2" ).arg( i ).arg( field ) );

/* Points */
int npoints = Vect_cidx_get_type_count( &map, field, GV_POINT );
if ( npoints > 0 )
{
QString l = fs + "_point";
list.append( l );
}

/* Lines */
/* Lines without category appears in layer 0, but not boundaries */
int tp;
if ( field == 0 )
tp = GV_LINE;
else
tp = GV_LINE | GV_BOUNDARY;

int nlines = Vect_cidx_get_type_count( &map, field, tp );
if ( nlines > 0 )
{
QString l = fs + "_line";
list.append( l );
}

/* Polygons */
int nareas = Vect_cidx_get_type_count( &map, field, GV_AREA );
if ( nareas > 0 )
{
QString l = fs + "_polygon";
list.append( l );
}
}
Vect_close( &map );

return list;
}

void QgsGrassSelect::on_GisdbaseBrowse_clicked()
{
QString Gisdbase = QFileDialog::getExistingDirectory( this,
@@ -41,9 +41,6 @@ class QgsGrassSelect: public QDialog, private Ui::QgsGrassSelectBase
MAPCALC // file in $MAPSET/mapcalc directory (used by QgsGrassMapcalc)
};

//! Get list of vector layer
static QStringList vectorLayers( QString, QString, QString, QString );

QString gisdbase;
QString location;
QString mapset;
@@ -36,7 +36,7 @@ QString QgsGrassUtils::vectorLayerName( QString map, QString layer,
void QgsGrassUtils::addVectorLayers( QgisInterface *iface,
QString gisbase, QString location, QString mapset, QString map )
{
QStringList layers = QgsGrassSelect::vectorLayers(
QStringList layers = QgsGrass::vectorLayers(
gisbase, location, mapset, map );


@@ -3,11 +3,11 @@ ADD_DEFINITIONS(-DGRASS_BASE=\\\"${GRASS_PREFIX}\\\")
########################################################
# Files

SET(GRASS_PROVIDER_SRCS provider.cpp)
SET(GRASS_PROVIDER_SRCS provider.cpp qgsgrassprovider.cpp )

SET(GRASS_RASTER_PROVIDER_SRCS qgsgrassrasterprovider.cpp)

SET(GRASS_LIB_SRCS qgsgrassprovider.cpp qgsgrass.cpp)
SET(GRASS_LIB_SRCS qgsgrass.cpp)

SET(QGIS_D_RAST_SRCS qgis.d.rast.c)

@@ -767,6 +767,99 @@ QStringList GRASS_EXPORT QgsGrass::vectors( QString mapsetPath )
}
return list;
}
QStringList GRASS_EXPORT QgsGrass::vectorLayers( QString gisdbase,
QString location, QString mapset, QString mapName )
{
QStringList list;

// Set location
QgsGrass::setLocation( gisdbase, location );

/* Open vector */
QgsGrass::resetError();
//Vect_set_open_level( 2 );
struct Map_info map;
int level = -1;

try
{
level = Vect_open_old_head( &map, ( char * ) mapName.toUtf8().data(), ( char * ) mapset.toUtf8().data() );
}
catch ( QgsGrass::Exception &e )
{
Q_UNUSED( e );
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
return list;
}

if ( level == 1 )
{
QgsDebugMsg( "Cannot open vector on level 2" );
QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr( "Cannot open vector %1 in mapset %2 on level 2 (topology not available, try to rebuild topology using v.build module)." ).arg( mapName ).arg( mapset ) );
// Vect_close here is correct, it should work, but it seems to cause
// crash on win http://trac.osgeo.org/qgis/ticket/2003
// disabled on win test it
#if !defined(WIN32)
Vect_close( &map );
#endif
return list;
}
else if ( level < 1 )
{
QgsDebugMsg( "Cannot open vector" );
QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr( "Cannot open vector %1 in mapset %2" ).arg( mapName ).arg( mapset ) );
return list;
}

QgsDebugMsg( "GRASS vector successfully opened" );


// Get layers
int ncidx = Vect_cidx_get_num_fields( &map );

for ( int i = 0; i < ncidx; i++ )
{
int field = Vect_cidx_get_field_number( &map, i );
QString fs;
fs.sprintf( "%d", field );

QgsDebugMsg( QString( "i = %1 layer = %2" ).arg( i ).arg( field ) );

/* Points */
int npoints = Vect_cidx_get_type_count( &map, field, GV_POINT );
if ( npoints > 0 )
{
QString l = fs + "_point";
list.append( l );
}

/* Lines */
/* Lines without category appears in layer 0, but not boundaries */
int tp;
if ( field == 0 )
tp = GV_LINE;
else
tp = GV_LINE | GV_BOUNDARY;

int nlines = Vect_cidx_get_type_count( &map, field, tp );
if ( nlines > 0 )
{
QString l = fs + "_line";
list.append( l );
}

/* Polygons */
int nareas = Vect_cidx_get_type_count( &map, field, GV_AREA );
if ( nareas > 0 )
{
QString l = fs + "_polygon";
list.append( l );
}
}
Vect_close( &map );

return list;
}

QStringList GRASS_EXPORT QgsGrass::rasters( QString gisbase, QString locationName,
QString mapsetName )
@@ -139,6 +139,9 @@ class QgsGrass
QString mapsetName );
static GRASS_EXPORT QStringList rasters( QString mapsetPath );

//! Get list of vector layers
static QStringList vectorLayers( QString, QString, QString, QString );

//! List of elements
static GRASS_EXPORT QStringList elements( QString gisbase, QString locationName,
QString mapsetName, QString element );

0 comments on commit 9784cd7

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