Skip to content

Commit

Permalink
apply #1878 (fixes #1900)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11560 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 5, 2009
1 parent 5b0baad commit 0b697b8
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 281 deletions.
10 changes: 4 additions & 6 deletions src/plugins/grass/qgsgrassmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -897,7 +896,6 @@ QVariant QgsGrassModel::data( const QModelIndex &index, int role ) const
default:
return mIconDirectory;
}
return mIconDirectory;
}
return item->data( role );
}
Expand Down
21 changes: 3 additions & 18 deletions src/plugins/grass/qgsgrassmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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." );
Expand All @@ -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() );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down
31 changes: 12 additions & 19 deletions src/plugins/grass/qgsgrassnewmapset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
}

Expand Down
46 changes: 24 additions & 22 deletions src/plugins/grass/qgsgrassplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions src/plugins/grass/qgsgrassselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 1 addition & 12 deletions src/plugins/grass/qgsgrasstools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/providers/grass/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* *
***************************************************************************/
#include <string.h>
#include <iostream>
#include <vector>
#include <cfloat>

Expand Down
Loading

0 comments on commit 0b697b8

Please sign in to comment.