Skip to content
Permalink
Browse files

apply #1878 (fixes #1900)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11560 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Sep 5, 2009
1 parent 5b0baad commit 0b697b8cd7beed0c2596c98f8847e46d35882c65
@@ -36,8 +36,7 @@ extern "C"
class QgsGrassModelItem
{
public:
QgsGrassModelItem( QgsGrassModelItem *parent, int row, QString name,
QString path, int type );
QgsGrassModelItem( QgsGrassModelItem *parent, int row, QString name, QString path, int type );
QgsGrassModelItem();
~QgsGrassModelItem();

@@ -81,7 +80,7 @@ QgsGrassModelItem::QgsGrassModelItem()

QgsGrassModelItem::~QgsGrassModelItem()
{
for ( int i = 0; i < mChildren.size();i++ )
for ( int i = 0; i < mChildren.size(); i++ )
{
delete mChildren[i];
}
@@ -606,13 +605,13 @@ void QgsGrassModel::addItems( QgsGrassModelItem *item, QStringList list, int typ

// Add new items

for ( int i = 0; i < list.size();i++ )
for ( int i = 0; i < list.size(); i++ )
{
QString name = list.at( i );
// QgsDebugMsg(QString("? add %1").arg(name));

int insertAt = item->mChildren.size();
for ( int i = 0; i < item->mChildren.size();i++ )
for ( int i = 0; i < item->mChildren.size(); i++ )
{
if ( item->mChildren[i]->name() == name )
{
@@ -897,7 +896,6 @@ QVariant QgsGrassModel::data( const QModelIndex &index, int role ) const
default:
return mIconDirectory;
}
return mIconDirectory;
}
return item->data( role );
}
@@ -47,24 +47,9 @@ extern "C"

#include <gdal.h> // to collect version information

#if defined(WIN32)
#include <windows.h>
static QString getShortPath( const QString &path )
{
TCHAR buf[MAX_PATH];
GetShortPathName( path.toAscii().data(), buf, MAX_PATH );
return buf;
}
#endif

bool QgsGrassModule::mExecPathInited = 0;
QStringList QgsGrassModule::mExecPath;






QString QgsGrassModule::findExec( QString file )
{
QgsDebugMsg( "called." );
@@ -78,7 +63,7 @@ QString QgsGrassModule::findExec( QString file )

#ifdef WIN32
mExecPath = path.split( ";" );
mExecPath.prepend( getShortPath( QgsApplication::applicationDirPath() ) );
mExecPath.prepend( QgsGrass::shortPath( QgsApplication::applicationDirPath() ) );
#else
mExecPath = path.split( ":" );
mExecPath.prepend( QgsApplication::applicationDirPath() );
@@ -1392,7 +1377,7 @@ void QgsGrassModule::readStdout()
{
//line = QString::fromLocal8Bit( mProcess.readLineStdout().ascii() );
QByteArray ba = mProcess.readLine();
line = QString::fromLocal8Bit( QString( ba ).toAscii() );
line = QString::fromUtf8( ba );

// GRASS_INFO_PERCENT is catched here only because of bugs in GRASS,
// normaly it should be printed to stderr
@@ -1426,7 +1411,7 @@ void QgsGrassModule::readStderr()
{
//line = QString::fromLocal8Bit( mProcess.readLineStderr().ascii() );
QByteArray ba = mProcess.readLine();
line = QString::fromLocal8Bit( QString( ba ).toAscii() );
line = QString::fromUtf8( ba );
//QgsDebugMsg(QString("line: '%1'").arg(line));

if ( rxpercent.indexIn( line ) != -1 )
@@ -49,16 +49,6 @@ QString temp3( GRASS_VERSION_MINOR );
QString temp4( GRASS_VERSION_RELEASE );
#endif

#if defined(WIN32)
#include <windows.h>
static QString getShortPath( const QString &path )
{
TCHAR buf[MAX_PATH];
GetShortPathName( path.toAscii(), buf, MAX_PATH );
return buf;
}
#endif

bool QgsGrassNewMapset::mRunning = false;

QgsGrassNewMapset::QgsGrassNewMapset( QgisInterface *iface,
@@ -439,7 +429,7 @@ void QgsGrassNewMapset::setGrassProjection()
int errcode;
const char *oldlocale = setlocale( LC_NUMERIC, NULL );
setlocale( LC_NUMERIC, "C" );
errcode = OSRImportFromProj4( hCRS, proj4.toAscii() );
errcode = OSRImportFromProj4( hCRS, proj4.toUtf8() );
setlocale( LC_NUMERIC, oldlocale );
if ( errcode != OGRERR_NONE )
{
@@ -1261,24 +1251,27 @@ void QgsGrassNewMapset::createMapset()
// database path
QgsGrass::activeMode(); // because it calls private gsGrass::init()
#if defined(WIN32)
G__setenv(( char * ) "GISDBASE", getShortPath( mDatabaseLineEdit->text() ).toAscii().data() );
G__setenv(( char * ) "GISDBASE", QgsGrass::shortPath( mDatabaseLineEdit->text() ).toUtf8().data() );
#else
G__setenv(( char * ) "GISDBASE", mDatabaseLineEdit->text().toAscii().data() );
G__setenv(( char * ) "GISDBASE", mDatabaseLineEdit->text().toUtf8().data() );
#endif

int ret = 0;

QgsGrass::resetError();
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
try
{
ret = G_make_location( location.toUtf8().data(), &mCellHead, mProjInfo, mProjUnits, stdout );
}
catch ( QgsGrass::Exception &e )
{
ret = G_make_location( location.toAscii().data(), &mCellHead, mProjInfo, mProjUnits, stdout );
ret = -1;
Q_UNUSED( e );
}
QgsGrass::clearErrorEnv();

if ( QgsGrass::getError() == QgsGrass::FATAL || ret != 0 )
if ( ret != 0 )
{
QMessageBox::warning( this, tr( "Create location" ),
tr( "Cannot create new location: %1" ).arg( QgsGrass::getErrorMessage() ) );
tr( "Cannot create new location: %1" ).arg( QgsGrass::errorMessage() ) );
return;
}

@@ -301,14 +301,13 @@ void QgsGrassPlugin::addVector()
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, sel->map.toAscii().data(),
sel->mapset.toAscii().data() );

if ( QgsGrass::getError() != QgsGrass::FATAL )
try
{
Vect_set_open_level( 2 );
struct Map_info map;
int level = Vect_open_old_head( &map, sel->map.toUtf8().data(),
sel->mapset.toUtf8().data() );

if ( level >= 2 )
{
// Count layers
@@ -336,9 +335,9 @@ void QgsGrassPlugin::addVector()

Vect_close( &map );
}
else
catch ( QgsGrass::Exception &e )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( QgsGrass::getErrorMessage() ) );
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( QString::fromUtf8( e.what() ) ) );
}

qGisInterface->addVectorLayer( uri, name, "grass" );
@@ -486,25 +485,28 @@ void QgsGrassPlugin::newVector()
QgsGrass::getDefaultLocation(),
QgsGrass::getDefaultMapset() );

QgsGrass::resetError();
struct Map_info Map;
Vect_open_new( &Map, name.toAscii().data(), 0 );

if ( QgsGrass::getError() == QgsGrass::FATAL )
try
{
QMessageBox::warning( 0, tr( "Warning" ),
tr( "Cannot create new vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
return;
}
struct Map_info Map;
Vect_open_new( &Map, name.toUtf8().data(), 0 );

#if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \
( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 )
Vect_build( &Map );
Vect_build( &Map );
#else
Vect_build( &Map, stderr );
Vect_build( &Map, stderr );
#endif
Vect_set_release_support( &Map );
Vect_close( &Map );
Vect_set_release_support( &Map );
Vect_close( &Map );
}
catch ( QgsGrass::Exception &e )
{
QMessageBox::warning( 0, tr( "Warning" ),
tr( "Cannot create new vector: %1" ).arg( QString::fromUtf8( e.what() ) ) );
return;
}



// Open in GRASS vector provider

@@ -346,7 +346,7 @@ void QgsGrassSelect::setLayers()

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

int idx = 0;
int sel = -1;
@@ -410,15 +410,15 @@ QStringList QgsGrassSelect::vectorLayers( QString gisdbase,
// Call to setjmp() returns 0 first time. In case of fatal error,
// our error routine uses longjmp() to come back to this context,
// this time setjmp() will return non-zero value and we can continue...
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )

try
{
level = Vect_open_old_head( &map, ( char * ) mapName.toAscii().data(), ( char * ) mapset.toAscii().data() );
level = Vect_open_old_head( &map, ( char * ) mapName.toUtf8().data(), ( char * ) mapset.toUtf8().data() );
}
QgsGrass::clearErrorEnv();

if ( QgsGrass::getError() == QgsGrass::FATAL )
catch ( QgsGrass::Exception &e )
{
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
Q_UNUSED( e );
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
return list;
}

@@ -43,17 +43,6 @@
#include <QStandardItem>


#if defined(WIN32)
#include <windows.h>
static QString getShortPath( const QString &path )
{
TCHAR buf[MAX_PATH];
GetShortPathName( path.toAscii(), buf, MAX_PATH );
return buf;
}
#endif


QgsGrassTools::QgsGrassTools( QgisInterface *iface,
QWidget * parent, const char * name, Qt::WFlags f )
: QDialog( parent, f ), QgsGrassToolsBase()
@@ -360,7 +349,7 @@ QgsGrassTools::~QgsGrassTools()
QString QgsGrassTools::appDir( void )
{
#if defined(WIN32)
return getShortPath( QgsApplication::applicationDirPath() );
return QgsGrass::shortPath( QgsApplication::applicationDirPath() );
#else
return QgsApplication::applicationDirPath();
#endif
@@ -14,7 +14,6 @@
* *
***************************************************************************/
#include <string.h>
#include <iostream>
#include <vector>
#include <cfloat>

0 comments on commit 0b697b8

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