60 changes: 35 additions & 25 deletions src/core/qgsgeometryvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ void QgsGeometryValidator::validatePolyline( int i, QgsPolyline line, bool ring
{
if ( ring )
{
if ( line.size() < 3 )
if ( line.size() < 4 )
{
QString msg = QObject::tr( "ring %1 with less than three points" ).arg( i );
QString msg = QObject::tr( "ring %1 with less than four points" ).arg( i );
QgsDebugMsg( msg );
emit errorFound( QgsGeometry::Error( msg ) );
mErrorCount++;
Expand Down Expand Up @@ -193,47 +193,55 @@ void QgsGeometryValidator::validatePolygon( int idx, const QgsPolygon &polygon )

void QgsGeometryValidator::run()
{
QgsDebugMsg( "validation thread started." );

mErrorCount = 0;
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
( (GEOS_VERSION_MAJOR==3 && GEOS_VERSION_MINOR>=3) || GEOS_VERSION_MAJOR>3)
QSettings settings;
if ( settings.value( "/qgis/digitizing/validate_geometries", 1 ).toInt() == 2 )
{
char *r = 0;
GEOSGeometry *g = 0;
if ( GEOSisValidDetail( mG.asGeos(), GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g ) != 1 )
GEOSGeometry *g0 = mG.asGeos();
if ( !g0 )
{
if ( g )
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:could not produce geometry for GEOS (check log window)" ) ) );
}
else
{
GEOSGeometry *g1 = 0;
if ( GEOSisValidDetail( g0, GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g1 ) != 1 )
{
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( g );
if ( g1 )
{
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( g1 );

unsigned int n;
if ( GEOSCoordSeq_getSize( cs, &n ) && n == 1 )
unsigned int n;
if ( GEOSCoordSeq_getSize( cs, &n ) && n == 1 )
{
double x, y;
GEOSCoordSeq_getX( cs, 0, &x );
GEOSCoordSeq_getY( cs, 0, &y );
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ), QgsPoint( x, y ) ) );
mErrorCount++;
}

GEOSGeom_destroy( g1 );
}
else
{
double x, y;
GEOSCoordSeq_getX( cs, 0, &x );
GEOSCoordSeq_getY( cs, 0, &y );
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ), QgsPoint( x, y ) ) );
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ) ) );
mErrorCount++;
}

GEOSGeom_destroy( g );
GEOSFree( r );
}
else
{
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ) ) );
mErrorCount++;
}

GEOSFree( r );
}

return;
}
#endif

QgsDebugMsg( "validation thread started." );

switch ( mG.wkbType() )
{
case QGis::WKBPoint:
Expand Down Expand Up @@ -309,14 +317,16 @@ void QgsGeometryValidator::run()
{
emit errorFound( QObject::tr( "Geometry validation was aborted." ) );
}
else if ( mErrorCount == 0 )
else if ( mErrorCount > 0 )
{
emit errorFound( QObject::tr( "Geometry is valid." ) );
emit errorFound( QObject::tr( "Geometry has %1 errors." ).arg( mErrorCount ) );
}
#if 0
else
{
emit errorFound( QObject::tr( "Geometry has %1 errors." ).arg( mErrorCount ) );
emit errorFound( QObject::tr( "Geometry is valid." ) );
}
#endif
}

void QgsGeometryValidator::addError( QgsGeometry::Error e )
Expand Down
17 changes: 10 additions & 7 deletions src/core/qgsmessageoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

#include "qgsmessageoutput.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"

#include <QRegExp>

static QgsMessageOutput* messageOutputConsole_()
{
Expand Down Expand Up @@ -47,9 +50,10 @@ QgsMessageOutputConsole::QgsMessageOutputConsole()
{
}

void QgsMessageOutputConsole::setMessage( const QString& message, MessageType )
void QgsMessageOutputConsole::setMessage( const QString& message, MessageType msgType )
{
mMessage = message;
mMsgType = msgType;
}

void QgsMessageOutputConsole::appendMessage( const QString& message )
Expand All @@ -59,14 +63,13 @@ void QgsMessageOutputConsole::appendMessage( const QString& message )

void QgsMessageOutputConsole::showMessage( bool )
{
// show title if provided
if ( !mTitle.isNull() )
if ( mMsgType == MessageHtml )
{
QgsDebugMsg( QString( "%1:" ).arg( mTitle ) );
mMessage.replace( "<br>", "\n" );
mMessage.replace( "&nbsp;", " " );
mMessage.replace( QRegExp("<\/?[^>]+>"), "" );
}

// show the message
QgsDebugMsg( mMessage );
QgsMessageLog::logMessage( mMessage, mTitle.isNull() ? QObject::tr( "Console" ) : mTitle );
emit destroyed();
delete this;
}
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsmessageoutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class CORE_EXPORT QgsMessageOutputConsole : public QObject, public QgsMessageOut
//! stores current title
QString mTitle;

MessageType mMsgType;
};

#endif