|
| 1 | +/******************************************************************* |
| 2 | + qgsgrassutils.cpp |
| 3 | + ------------------- |
| 4 | + begin : March, 2006 |
| 5 | + copyright : (C) 2006 by Radim Blazek |
| 6 | + email : radim.blazek@gmail.com |
| 7 | +********************************************************************/ |
| 8 | +/******************************************************************** |
| 9 | + This program is free software; you can redistribute it and/or modify |
| 10 | + it under the terms of the GNU General Public License as published by |
| 11 | + the Free Software Foundation; either version 2 of the License, or |
| 12 | + (at your option) any later version. |
| 13 | +*******************************************************************/ |
| 14 | +#include <iostream> |
| 15 | +#include <vector> |
| 16 | + |
| 17 | +#include <QApplication> |
| 18 | + |
| 19 | +//#include "qgis.h" |
| 20 | +//#include "qgsapplication.h" |
| 21 | + |
| 22 | +extern "C" { |
| 23 | +#include <grass/gis.h> |
| 24 | +#include <grass/Vect.h> |
| 25 | +} |
| 26 | + |
| 27 | +#include "../../src/providers/grass/qgsgrass.h" |
| 28 | +#include "qgsgrassutils.h" |
| 29 | +#include "qgsgrassselect.h" |
| 30 | + |
| 31 | +QgsGrassUtils::QgsGrassUtils() {} |
| 32 | +QgsGrassUtils::~QgsGrassUtils() {} |
| 33 | + |
| 34 | +QString QgsGrassUtils::vectorLayerName( QString map, QString layer, |
| 35 | + int nLayers ) |
| 36 | +{ |
| 37 | + QString name = map; |
| 38 | + if ( nLayers > 1 ) name += " " + layer; |
| 39 | + return name; |
| 40 | +} |
| 41 | + |
| 42 | +void QgsGrassUtils::addVectorLayers ( QgisIface *iface, |
| 43 | + QString gisbase, QString location, QString mapset, QString map) |
| 44 | +{ |
| 45 | + QStringList layers = QgsGrassSelect::vectorLayers( |
| 46 | + gisbase, location, mapset, map ); |
| 47 | + |
| 48 | + |
| 49 | + for ( int i = 0; i < layers.count(); i++ ) |
| 50 | + { |
| 51 | + QString name = QgsGrassUtils::vectorLayerName ( |
| 52 | + map, layers[i], layers.size() ); |
| 53 | + |
| 54 | + QString uri = gisbase + "/" + location + "/" |
| 55 | + + mapset + "/" + map + "/" + layers[i]; |
| 56 | + |
| 57 | +#ifdef QGISDEBUG |
| 58 | + std::cerr << "layer = " << layers[i].local8Bit().data() << std::endl; |
| 59 | + std::cerr << "uri = " << uri.local8Bit().data() << std::endl; |
| 60 | + std::cerr << "name = " << name.local8Bit().data() << std::endl; |
| 61 | +#endif |
| 62 | + |
| 63 | + iface->addVectorLayer( uri, name, "grass"); |
| 64 | + } |
| 65 | +} |
0 commit comments