Skip to content

Commit

Permalink
Merge branch 'master' into MultiColumnPK_DbManagerQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
SebDieBln committed Oct 18, 2015
2 parents d8deb8c + cc9c789 commit 974e60c
Show file tree
Hide file tree
Showing 31 changed files with 391 additions and 109 deletions.
21 changes: 20 additions & 1 deletion cmake/FindGRASS.cmake
Expand Up @@ -62,6 +62,25 @@ MACRO (CHECK_GRASS G_PREFIX)

# LIB_PATH is only temporary variable, so hide it (is it possible to delete a variable?)
UNSET(LIB_PATH CACHE)

# Find off_t size
IF( (GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} EQUAL 7) AND (GRASS_MINOR_VERSION${GRASS_FIND_VERSION} GREATER 0) )
SET(GRASS_TEST_MAPSET ${CMAKE_BINARY_DIR}/grass-location/PERMANENT)
FILE(MAKE_DIRECTORY ${GRASS_TEST_MAPSET})
FILE(WRITE ${GRASS_TEST_MAPSET}/DEFAULT_WIND "")
FILE(WRITE ${GRASS_TEST_MAPSET}/WIND "")
# grass command is not in G_PREFIX but in some bin dir, so it must be in PATH
SET(GRASS_EXE grass7${GRASS_MINOR_VERSION${GRASS_FIND_VERSION}})
#MESSAGE(STATUS "GRASS_EXE = ${GRASS_EXE}")
EXECUTE_PROCESS(COMMAND ${GRASS_EXE} ${GRASS_TEST_MAPSET} --exec g.version -g
COMMAND grep build_off_t_size
COMMAND sed "s/.*\\([0-9]\\).*/\\1/"
ERROR_VARIABLE GRASS_TMP_ERROR
OUTPUT_VARIABLE GRASS_OFF_T_SIZE${GRASS_FIND_VERSION}
)
STRING(STRIP ${GRASS_OFF_T_SIZE${GRASS_FIND_VERSION}} GRASS_OFF_T_SIZE${GRASS_FIND_VERSION})
#MESSAGE(STATUS "GRASS_OFF_T_SIZE${GRASS_FIND_VERSION} = ${GRASS_OFF_T_SIZE${GRASS_FIND_VERSION}}")
ENDIF( (GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} EQUAL 7) AND (GRASS_MINOR_VERSION${GRASS_FIND_VERSION} GREATER 0) )

IF(GRASS_LIBRARIES_FOUND${GRASS_FIND_VERSION})
SET(GRASS_FOUND${GRASS_FIND_VERSION} TRUE)
Expand Down Expand Up @@ -127,7 +146,7 @@ ENDIF (WITH_GRASS${GRASS_CACHE_VERSION})

IF (GRASS_FOUND${GRASS_FIND_VERSION})
IF (NOT GRASS_FIND_QUIETLY)
MESSAGE(STATUS "Found GRASS ${GRASS_FIND_VERSION}: ${GRASS_PREFIX${GRASS_CACHE_VERSION}} (${GRASS_VERSION${GRASS_FIND_VERSION}})")
MESSAGE(STATUS "Found GRASS ${GRASS_FIND_VERSION}: ${GRASS_PREFIX${GRASS_CACHE_VERSION}} (${GRASS_VERSION${GRASS_FIND_VERSION}}, off_t size = ${GRASS_OFF_T_SIZE${GRASS_FIND_VERSION}})")
ENDIF (NOT GRASS_FIND_QUIETLY)

ELSE (GRASS_FOUND${GRASS_FIND_VERSION})
Expand Down
6 changes: 5 additions & 1 deletion python/core/__init__.py
@@ -1,6 +1,7 @@
import inspect
import string
from qgis._core import *
from PyQt4.QtCore import QCoreApplication


def register_function(function, arg_count, group, usesgeometry=False, **kwargs):
Expand Down Expand Up @@ -66,7 +67,10 @@ def func(self, values, feature, parent):
register = kwargs.get('register', True)
if register and QgsExpression.isFunctionName(name):
if not QgsExpression.unregisterFunction(name):
raise TypeError("Unable to unregister function")
msgtitle = QCoreApplication.translate("UserExpressions", "User expressions")
msg = QCoreApplication.translate("UserExpressions", "The user expression {0} already exists and could not be unregistered.").format(name)
QgsMessageLog.logMessage(msg + "\n", msgtitle, QgsMessageLog.WARNING)
return None

function.__name__ = name
helptext = helptemplate.safe_substitute(name=name, doc=helptext)
Expand Down
104 changes: 104 additions & 0 deletions python/core/conversions.sip
Expand Up @@ -1834,6 +1834,110 @@ template <TYPE>
%End
};

// QList<QgsField> is implemented as a Python list of QgsField.
%MappedType QList<QgsField> /DocType="list-of-qgsfield"/
{
%TypeHeaderCode
#include <qgsfield.h>
%End

%ConvertFromTypeCode
PyObject *l = PyList_New(sipCpp->size());

if (!l)
return 0;

for (int i = 0; i < sipCpp->size(); ++i)
{
QgsField *t = new QgsField(sipCpp->at(i));
PyObject *tobj = sipConvertFromNewType(t, sipType_QgsField, sipTransferObj);

if (!tobj)
{
delete t;
Py_DECREF(l);

return 0;
}

PyList_SET_ITEM(l, i, tobj);
}

return l;
%End

%ConvertToTypeCode
PyObject *iter = PyObject_GetIter(sipPy);

if (!sipIsErr)
{
Py_XDECREF(iter);

return (iter
#if PY_MAJOR_VERSION < 3
&& !PyString_Check(sipPy)
#endif
&& !PyUnicode_Check(sipPy));
}

if (!iter)
{
*sipIsErr = 1;

return 0;
}

QList<QgsField> *ql = new QList<QgsField>;

for (SIP_SSIZE_T i = 0; ; ++i)
{
PyErr_Clear();
PyObject *itm = PyIter_Next(iter);

if (!itm)
{
if (PyErr_Occurred())
{
delete ql;
Py_DECREF(iter);
*sipIsErr = 1;

return 0;
}

break;
}

int state;
QgsField *t = reinterpret_cast<QgsField *>( sipForceConvertToType(itm, sipType_QgsField, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

if (*sipIsErr)
{
PyErr_Format(PyExc_TypeError,
"index %ld has type '%s' but 'QgsField' is expected",
(long) i, Py_TYPE(itm)->tp_name);

Py_DECREF(itm);
delete ql;
Py_DECREF(iter);

return 0;
}

ql->append(*t);

sipReleaseType(t, sipType_QgsField, state);
Py_DECREF(itm);
}

Py_DECREF(iter);

*sipCppPtr = ql;

return sipGetState(sipTransferObj);
%End
};

%If (QVECTORINT_CONVERSION)
// QVector<int> is implemented as a Python list of integers.
%MappedType QVector<int> /DocType="list-of-int"/
Expand Down
22 changes: 19 additions & 3 deletions python/core/geometry/qgsabstractgeometryv2.sip
Expand Up @@ -49,14 +49,16 @@ class QgsAbstractGeometryV2
sipClass = sipClass_QgsCurvePolygonV2;
else if (dynamic_cast<QgsMultiPointV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsMultiPointV2;
else if (dynamic_cast<QgsLineStringV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsLineStringV2;
else if (dynamic_cast<QgsMultiLineStringV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsMultiLineStringV2;
else if (dynamic_cast<QgsMultiPolygonV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsMultiPolygonV2;
else if (dynamic_cast<QgsMultiSurfaceV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsMultiSurfaceV2;
else if (dynamic_cast<QgsMultiCurveV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsMultiCurveV2;
else if (dynamic_cast<QgsGeometryCollectionV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsGeometryCollectionV2;
else
sipClass = 0;
%End
Expand Down Expand Up @@ -116,8 +118,22 @@ class QgsAbstractGeometryV2
virtual bool moveVertex( const QgsVertexId& position, const QgsPointV2& newPos ) = 0;
virtual bool deleteVertex( const QgsVertexId& position ) = 0;

/** Length for linear geometries,perimeter for area geometries*/
/** Returns the length of the geometry.
* @see area()
* @see perimeter()
*/
virtual double length() const;

/** Returns the perimeter of the geometry.
* @see area()
* @see length()
*/
virtual double perimeter() const;

/** Returns the area of the geometry.
* @see length()
* @see perimeter()
*/
virtual double area() const;

/** Returns the centroid of the geometry*/
Expand Down
2 changes: 1 addition & 1 deletion python/core/geometry/qgscurvepolygonv2.sip
Expand Up @@ -29,7 +29,7 @@ class QgsCurvePolygonV2: public QgsSurfaceV2

//surface interface
virtual double area() const;
virtual double length() const;
virtual double perimeter() const;
QgsPointV2 pointOnSurface() const;
QgsPolygonV2* surfaceToPolygon() const;

Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgsgeometrycollectionv2.sip
Expand Up @@ -58,6 +58,7 @@ class QgsGeometryCollectionV2: public QgsAbstractGeometryV2

virtual double length() const;
virtual double area() const;
virtual double perimeter() const;

bool hasCurvedSegments() const;

Expand Down
4 changes: 2 additions & 2 deletions python/core/qgsfield.sip
Expand Up @@ -249,13 +249,13 @@ class QgsFields

//! Get field at particular index (must be in range 0..N-1)
// const QgsField& operator[]( int i ) const;
QgsField& operator[](int i) /Factory/;
QgsField& operator[](int i);
%MethodCode
SIP_SSIZE_T idx = sipConvertFromSequenceIndex(a0, sipCpp->count());
if (idx < 0)
sipIsErr = 1;
else
sipRes = new QgsField(sipCpp->operator[](idx));
sipRes = &(*sipCpp)[idx];
%End

//! Get field at particular index (must be in range 0..N-1)
Expand Down
2 changes: 1 addition & 1 deletion python/user.py
Expand Up @@ -68,5 +68,5 @@ def func(value1, feature, parent):
except ImportError:
# We get a import error and crash for some reason even if we make the expressions package
# TODO Fix the crash on first load with no expressions folder
# But for now it's not the end of the world if it doesn't laod the first time
# But for now it's not the end of the world if it doesn't load the first time
pass
2 changes: 1 addition & 1 deletion src/app/qgsattributetypedialog.cpp
Expand Up @@ -80,7 +80,7 @@ QgsAttributeTypeDialog::~QgsAttributeTypeDialog()
QSettings settings;
settings.setValue( "/Windows/QgsAttributeTypeDialog/geometry", saveGeometry() );

qDeleteAll( mEditorConfigWidgets.values() );
qDeleteAll( mEditorConfigWidgets );
}

const QString QgsAttributeTypeDialog::editorWidgetV2Type()
Expand Down
2 changes: 1 addition & 1 deletion src/auth/identcert/qgsauthidentcertmethod.cpp
Expand Up @@ -48,7 +48,7 @@ QgsAuthIdentCertMethod::QgsAuthIdentCertMethod()

QgsAuthIdentCertMethod::~QgsAuthIdentCertMethod()
{
qDeleteAll( mPkiConfigBundleCache.values() );
qDeleteAll( mPkiConfigBundleCache );
mPkiConfigBundleCache.clear();
}

Expand Down
2 changes: 1 addition & 1 deletion src/auth/pkipaths/qgsauthpkipathsmethod.cpp
Expand Up @@ -48,7 +48,7 @@ QgsAuthPkiPathsMethod::QgsAuthPkiPathsMethod()

QgsAuthPkiPathsMethod::~QgsAuthPkiPathsMethod()
{
qDeleteAll( mPkiConfigBundleCache.values() );
qDeleteAll( mPkiConfigBundleCache );
mPkiConfigBundleCache.clear();
}

Expand Down
2 changes: 1 addition & 1 deletion src/auth/pkipkcs12/qgsauthpkcs12method.cpp
Expand Up @@ -48,7 +48,7 @@ QgsAuthPkcs12Method::QgsAuthPkcs12Method()

QgsAuthPkcs12Method::~QgsAuthPkcs12Method()
{
qDeleteAll( mPkiConfigBundleCache.values() );
qDeleteAll( mPkiConfigBundleCache );
mPkiConfigBundleCache.clear();
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/auth/qgsauthmanager.cpp
Expand Up @@ -746,7 +746,7 @@ bool QgsAuthManager::registerCoreAuthMethods()
if ( isDisabled() )
return false;

qDeleteAll( mAuthMethods.values() );
qDeleteAll( mAuthMethods );
mAuthMethods.clear();
Q_FOREACH ( const QString& authMethodKey, QgsAuthMethodRegistry::instance()->authMethodList() )
{
Expand Down Expand Up @@ -2819,7 +2819,7 @@ QgsAuthManager::~QgsAuthManager()
if ( !isDisabled() )
{
delete QgsAuthMethodRegistry::instance();
qDeleteAll( mAuthMethods.values() );
qDeleteAll( mAuthMethods );

QSqlDatabase authConn = authDbConnection();
if ( authConn.isValid() && authConn.isOpen() )
Expand Down
14 changes: 11 additions & 3 deletions src/core/geometry/qgsabstractgeometryv2.h
Expand Up @@ -259,13 +259,21 @@ class CORE_EXPORT QgsAbstractGeometryV2
*/
virtual bool deleteVertex( const QgsVertexId& position ) = 0;

/** Returns the length (or perimeter for area geometries) of the geometry.
* @see area
/** Returns the length of the geometry.
* @see area()
* @see perimeter()
*/
virtual double length() const { return 0.0; }

/** Returns the perimeter of the geometry.
* @see area()
* @see length()
*/
virtual double perimeter() const { return 0.0; }

/** Returns the area of the geometry.
* @see length
* @see length()
* @see perimeter()
*/
virtual double area() const { return 0.0; }

Expand Down
8 changes: 4 additions & 4 deletions src/core/geometry/qgscurvepolygonv2.cpp
Expand Up @@ -336,16 +336,16 @@ double QgsCurvePolygonV2::area() const
return area;
}

double QgsCurvePolygonV2::length() const
double QgsCurvePolygonV2::perimeter() const
{
//sum perimeter of rings
double length = mExteriorRing->length();
double perimeter = mExteriorRing->length();
QList<QgsCurveV2*>::const_iterator ringIt = mInteriorRings.constBegin();
for ( ; ringIt != mInteriorRings.constEnd(); ++ringIt )
{
length += ( *ringIt )->length();
perimeter += ( *ringIt )->length();
}
return length;
return perimeter;
}

QgsPointV2 QgsCurvePolygonV2::pointOnSurface() const
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscurvepolygonv2.h
Expand Up @@ -55,7 +55,7 @@ class CORE_EXPORT QgsCurvePolygonV2: public QgsSurfaceV2

//surface interface
virtual double area() const override;
virtual double length() const override;
virtual double perimeter() const override;
QgsPointV2 pointOnSurface() const override;
QgsPolygonV2* surfaceToPolygon() const override;

Expand Down
11 changes: 11 additions & 0 deletions src/core/geometry/qgsgeometrycollectionv2.cpp
Expand Up @@ -454,6 +454,17 @@ double QgsGeometryCollectionV2::area() const
return area;
}

double QgsGeometryCollectionV2::perimeter() const
{
double perimeter = 0.0;
QVector< QgsAbstractGeometryV2* >::const_iterator geomIt = mGeometries.constBegin();
for ( ; geomIt != mGeometries.constEnd(); ++geomIt )
{
perimeter += ( *geomIt )->perimeter();
}
return perimeter;
}

bool QgsGeometryCollectionV2::fromCollectionWkt( const QString &wkt, const QList<QgsAbstractGeometryV2*>& subtypes, const QString& defaultChildWkbType )
{
clear();
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgsgeometrycollectionv2.h
Expand Up @@ -103,6 +103,7 @@ class CORE_EXPORT QgsGeometryCollectionV2: public QgsAbstractGeometryV2

virtual double length() const override;
virtual double area() const override;
virtual double perimeter() const override;

bool hasCurvedSegments() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdistancearea.cpp
Expand Up @@ -384,7 +384,7 @@ double QgsDistanceArea::measurePerimeter( const QgsGeometry* geometry ) const

if ( !mEllipsoidalMode || mEllipsoid == GEO_NONE )
{
return geomV2->length();
return geomV2->perimeter();
}

//create list with (single) surfaces
Expand Down

0 comments on commit 974e60c

Please sign in to comment.