shorter names

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@3087 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
rabla 2005-04-05 13:50:45 +00:00
parent 049caa5b6a
commit 8338cace6a

View File

@ -37,6 +37,7 @@
#include <qfiledialog.h> #include <qfiledialog.h>
#include <qfileinfo.h> #include <qfileinfo.h>
#include <qsettings.h> #include <qsettings.h>
#include <qregexp.h>
//non qt includes //non qt includes
#include <iostream> #include <iostream>
@ -295,25 +296,75 @@ void QgsGrassPlugin::addVector()
QgsGrassSelect *sel = new QgsGrassSelect(QgsGrassSelect::VECTOR ); QgsGrassSelect *sel = new QgsGrassSelect(QgsGrassSelect::VECTOR );
if ( sel->exec() ) { if ( sel->exec() ) {
uri = sel->gisdbase + "/" + sel->location + "/" + sel->mapset + "/" + sel->map + "/" + sel->layer; uri = sel->gisdbase + "/" + sel->location + "/" + sel->mapset + "/" + sel->map + "/" + sel->layer;
} }
#ifdef QGISDEBUG #ifdef QGISDEBUG
std::cerr << "plugin URI: " << uri << std::endl; std::cerr << "plugin URI: " << uri << std::endl;
#endif #endif
if ( uri.length() == 0 ) { if ( uri.length() == 0 ) {
std::cerr << "Nothing was selected" << std::endl; std::cerr << "Nothing was selected" << std::endl;
return; return;
} else { } else {
#ifdef QGISDEBUG #ifdef QGISDEBUG
std::cout << "Add new vector layer" << std::endl; std::cout << "Add new vector layer" << std::endl;
#endif #endif
// create vector name: vector layer
int pos = uri.findRev('/'); // create vector name: vector layer
pos = uri.findRev('/', pos-1); QString name = sel->map;
QString name = uri.right( uri.length() - pos - 1 );
name.replace('/', ' '); QString field;
QString type;
QRegExp rx ( "(\\d+)_(.+)" );
if ( rx.search ( sel->layer ) != -1 )
{
field = rx.cap(1);
type = rx.cap(2);
}
qGisInterface->addVectorLayer( uri, name, "grass"); // Set location
QgsGrass::setLocation ( sel->gisdbase, sel->location );
/* Open vector */
QgsGrass::resetError();
Vect_set_open_level (2);
struct Map_info map;
int level = Vect_open_old_head (&map, (char *) sel->map.ascii(),
(char *) sel->mapset.ascii());
if ( QgsGrass::getError() != QgsGrass::FATAL )
{
if ( level >= 2 )
{
// Count layers
int cnt = 0;
int ncidx = Vect_cidx_get_num_fields ( &map );
for ( int i = 0; i < ncidx; i++ )
{
int field = Vect_cidx_get_field_number ( &map, i);
if ( Vect_cidx_get_type_count( &map, field, GV_POINT|GV_LINE|GV_AREA) > 0 ||
(field > 1 && Vect_cidx_get_type_count( &map, field, GV_BOUNDARY) ) )
{
cnt++;
}
}
if( cnt > 1 )
{
name.append ( " " + field );
// No need to ad type, the type is obvious from the legend
}
}
Vect_close ( &map );
} else {
std::cerr << "Cannot open GRASS vector: " << QgsGrass::getErrorMessage() << std::endl;
}
qGisInterface->addVectorLayer( uri, name, "grass");
} }
} }