Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/qgis/QGIS
Browse files Browse the repository at this point in the history
Conflicts:
	src/gui/attributetable/qgsfieldconditionalformatwidget.cpp
  • Loading branch information
NathanW2 committed Aug 25, 2015
2 parents 01d635a + 385a608 commit 9094575
Show file tree
Hide file tree
Showing 34 changed files with 182 additions and 66 deletions.
15 changes: 15 additions & 0 deletions python/core/qgsexpression.sip
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,24 @@ class QgsExpression
static const QList<QgsExpression::Function *>& Functions();
static const QStringList& BuiltinFunctions();

/** Registers a function to the expression engine. This is required to allow expressions to utilise the function.
* @param function function to register
* @returns true on successful registration
* @see unregisterFunction
*/
static bool registerFunction( Function* function );

/** Unregisters a function from the expression engine. The function will no longer be usable in expressions.
* @param name function name
* @see registerFunction
*/
static bool unregisterFunction( QString name );

/** Deletes all registered functions whose ownership have been transferred to the expression engine.
* @note added in QGIS 2.12
*/
static void cleanRegisteredFunctions();

// tells whether the identifier is a name of existing function
static bool isFunctionName( const QString& name );

Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ QgsComposerObject::QgsComposerObject( QgsComposition* composition )

QgsComposerObject::~QgsComposerObject()
{

qDeleteAll( mDataDefinedProperties );
}

bool QgsComposerObject::writeXML( QDomElement &elem, QDomDocument &doc ) const
Expand Down
7 changes: 7 additions & 0 deletions src/core/geometry/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ const QgsAbstractGeometryV2* QgsGeometry::geometry() const
void QgsGeometry::setGeometry( QgsAbstractGeometryV2* geometry )
{
detach( false );
if ( d->geometry )
{
delete d->geometry;
d->geometry = 0;
}
removeWkbGeos();

d->geometry = geometry;
}

Expand Down
9 changes: 9 additions & 0 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "qgsmaplayerregistry.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsproviderregistry.h"
#include "qgsexpression.h"

#include <QDir>
#include <QFile>
Expand Down Expand Up @@ -629,6 +630,14 @@ void QgsApplication::initQgis()
void QgsApplication::exitQgis()
{
delete QgsProviderRegistry::instance();

//Ensure that all remaining deleteLater QObjects are actually deleted before we exit.
//This isn't strictly necessary (since we're exiting anyway) but doing so prevents a lot of
//LeakSanitiser noise which hides real issues
QgsApplication::sendPostedEvents( 0, QEvent::DeferredDelete );

//delete all registered functions from expression engine (see above comment)
QgsExpression::cleanRegisteredFunctions();
}

QString QgsApplication::showSettings()
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsdistancearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ QgsDistanceArea::QgsDistanceArea()

//! Copy constructor
QgsDistanceArea::QgsDistanceArea( const QgsDistanceArea & origDA )
: mCoordTransform( 0 )
{
_copy( origDA );
}
Expand Down Expand Up @@ -88,6 +89,7 @@ void QgsDistanceArea::_copy( const QgsDistanceArea & origDA )
// Some calculations and trig. Should not be TOO time consuming.
// Alternatively we could copy the temp vars?
computeAreaInit();
delete mCoordTransform;
mCoordTransform = new QgsCoordinateTransform( origDA.mCoordTransform->sourceCrs(), origDA.mCoordTransform->destCRS() );
}

Expand Down
17 changes: 15 additions & 2 deletions src/core/qgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1767,14 +1767,16 @@ static QVariant fcnGetLayerProperty( const QVariantList& values, const QgsExpres
return QVariant();
}

bool QgsExpression::registerFunction( QgsExpression::Function* function )
bool QgsExpression::registerFunction( QgsExpression::Function* function, bool transferOwnership )
{
int fnIdx = functionIndex( function->name() );
if ( fnIdx != -1 )
{
return false;
}
QgsExpression::gmFunctions.append( function );
if ( transferOwnership )
QgsExpression::gmOwnedFunctions.append( function );
return true;
}

Expand All @@ -1794,7 +1796,11 @@ bool QgsExpression::unregisterFunction( QString name )
return false;
}


void QgsExpression::cleanRegisteredFunctions()
{
qDeleteAll( QgsExpression::gmOwnedFunctions );
QgsExpression::gmOwnedFunctions.clear();
}

QStringList QgsExpression::gmBuiltinFunctions;

Expand Down Expand Up @@ -1842,6 +1848,7 @@ const QStringList& QgsExpression::BuiltinFunctions()
}

QList<QgsExpression::Function*> QgsExpression::gmFunctions;
QList<QgsExpression::Function*> QgsExpression::gmOwnedFunctions;

const QList<QgsExpression::Function*>& QgsExpression::Functions()
{
Expand Down Expand Up @@ -1978,6 +1985,12 @@ const QList<QgsExpression::Function*>& QgsExpression::Functions()
;

QgsExpressionContextUtils::registerContextFunctions();

//QgsExpression has ownership of all built-in functions
Q_FOREACH ( QgsExpression::Function* func, gmFunctions )
{
gmOwnedFunctions << func;
}
}
return gmFunctions;
}
Expand Down
21 changes: 20 additions & 1 deletion src/core/qgsexpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,28 @@ class CORE_EXPORT QgsExpression
static QStringList gmBuiltinFunctions;
static const QStringList& BuiltinFunctions();

static bool registerFunction( Function* function );
/** Registers a function to the expression engine. This is required to allow expressions to utilise the function.
* @param function function to register
* @param transferOwnership set to true to transfer ownership of function to expression engine
* @returns true on successful registration
* @see unregisterFunction
*/
static bool registerFunction( Function* function, bool transferOwnership = false );

/** Unregisters a function from the expression engine. The function will no longer be usable in expressions.
* @param name function name
* @see registerFunction
*/
static bool unregisterFunction( QString name );

//! List of functions owned by the expression engine
static QList<Function*> gmOwnedFunctions;

/** Deletes all registered functions whose ownership have been transferred to the expression engine.
* @note added in QGIS 2.12
*/
static void cleanRegisteredFunctions();

// tells whether the identifier is a name of existing function
static bool isFunctionName( const QString& name );

Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsexpressionlexer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ struct expression_parser_context;

#define B_OP(x) yylval->b_op = QgsExpression::x
#define U_OP(x) yylval->u_op = QgsExpression::x
#define TEXT yylval->text = new QString(); *yylval->text = QString::fromUtf8(yytext);
#define TEXT_FILTER(filter_fn) yylval->text = new QString(); *yylval->text = filter_fn( QString::fromUtf8(yytext) );
#define TEXT yylval->text = new QString( QString::fromUtf8(yytext) );
#define TEXT_FILTER(filter_fn) yylval->text = new QString( filter_fn( QString::fromUtf8(yytext) ) );

static QString stripText(QString text)
{
Expand Down
44 changes: 25 additions & 19 deletions src/core/qgsexpressionparser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ struct expression_parser_context
%destructor { delete $$; } <node>
%destructor { delete $$; } <nodelist>
%destructor { delete $$; } <text>
%destructor { delete $$; } <whenthen>
%destructor { delete $$; } <whenthenlist>

%%

Expand Down Expand Up @@ -181,26 +183,29 @@ expression:
| FUNCTION '(' exp_list ')'
{
int fnIndex = QgsExpression::functionIndex(*$1);
delete $1;
if (fnIndex == -1)
{
// this should not actually happen because already in lexer we check whether an identifier is a known function
// (if the name is not known the token is parsed as a column)
exp_error(parser_ctx, "Function is not known");
delete $3;
YYERROR;
}
if ( QgsExpression::Functions()[fnIndex]->params() != -1
&& QgsExpression::Functions()[fnIndex]->params() != $3->count() )
{
exp_error(parser_ctx, "Function is called with wrong number of arguments");
delete $3;
YYERROR;
}
$$ = new QgsExpression::NodeFunction(fnIndex, $3);
delete $1;
}

| FUNCTION '(' ')'
{
int fnIndex = QgsExpression::functionIndex(*$1);
delete $1;
if (fnIndex == -1)
{
// this should not actually happen because already in lexer we check whether an identifier is a known function
Expand All @@ -214,7 +219,6 @@ expression:
YYERROR;
}
$$ = new QgsExpression::NodeFunction(fnIndex, new QgsExpression::NodeList());
delete $1;
}

| expression IN '(' exp_list ')' { $$ = new QgsExpression::NodeInOperator($1, $4, false); }
Expand All @@ -236,30 +240,31 @@ expression:
if (fnIndex == -1)
{
if ( !QgsExpression::hasSpecialColumn( *$1 ) )
{
{
exp_error(parser_ctx, "Special column is not known");
YYERROR;
}
// $var is equivalent to _specialcol_( "$var" )
QgsExpression::NodeList* args = new QgsExpression::NodeList();
QgsExpression::NodeLiteral* literal = new QgsExpression::NodeLiteral( *$1 );
args->append( literal );
$$ = new QgsExpression::NodeFunction( QgsExpression::functionIndex( "_specialcol_" ), args );
delete $1;
YYERROR;
}
// $var is equivalent to _specialcol_( "$var" )
QgsExpression::NodeList* args = new QgsExpression::NodeList();
QgsExpression::NodeLiteral* literal = new QgsExpression::NodeLiteral( *$1 );
args->append( literal );
$$ = new QgsExpression::NodeFunction( QgsExpression::functionIndex( "_specialcol_" ), args );
}
else
{
$$ = new QgsExpression::NodeFunction( fnIndex, NULL );
delete $1;
}
else
{
$$ = new QgsExpression::NodeFunction( fnIndex, NULL );
}
delete $1;
}

// variables
| VARIABLE
{
// @var is equivalent to var( "var" )
QgsExpression::NodeList* args = new QgsExpression::NodeList();
QgsExpression::NodeLiteral* literal = new QgsExpression::NodeLiteral( QString(*$1).mid(1) );
args->append( literal );
// @var is equivalent to var( "var" )
QgsExpression::NodeList* args = new QgsExpression::NodeList();
QgsExpression::NodeLiteral* literal = new QgsExpression::NodeLiteral( QString(*$1).mid(1) );
args->append( literal );
$$ = new QgsExpression::NodeFunction( QgsExpression::functionIndex( "var" ), args );
delete $1;
}
Expand Down Expand Up @@ -308,6 +313,7 @@ QgsExpression::Node* parseExpression(const QString& str, QString& parserErrorMsg
else // error?
{
parserErrorMsg = ctx.errorMsg;
delete ctx.rootNode;
return NULL;
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ QgsVectorLayer::~QgsVectorLayer()
delete mCache;
delete mLabel;
delete mDiagramLayerSettings;
delete mDiagramRenderer;

delete mActions;

Expand Down Expand Up @@ -2244,7 +2245,7 @@ bool QgsVectorLayer::deleteAttributes( QList<int> attrs )

qSort( attrs.begin(), attrs.end(), qGreater<int>() );

Q_FOREACH( int attr, attrs )
Q_FOREACH ( int attr, attrs )
{
if ( deleteAttribute( attr ) )
{
Expand Down Expand Up @@ -3003,7 +3004,7 @@ void QgsVectorLayer::uniqueValues( int index, QList<QVariant> &uniqueValues, int
if ( mEditBuffer )
{
QSet<QString> vals;
Q_FOREACH( const QVariant& v, uniqueValues )
Q_FOREACH ( const QVariant& v, uniqueValues )
{
vals << v.toString();
}
Expand Down Expand Up @@ -3833,7 +3834,7 @@ void QgsVectorLayer::invalidateSymbolCountedFlag()

void QgsVectorLayer::onRelationsLoaded()
{
Q_FOREACH( QgsAttributeEditorElement* elem, mAttributeEditorElements )
Q_FOREACH ( QgsAttributeEditorElement* elem, mAttributeEditorElements )
{
if ( elem->type() == QgsAttributeEditorElement::AeTypeContainer )
{
Expand All @@ -3842,7 +3843,7 @@ void QgsVectorLayer::onRelationsLoaded()
continue;

QList<QgsAttributeEditorElement*> relations = cont->findElements( QgsAttributeEditorElement::AeTypeRelation );
Q_FOREACH( QgsAttributeEditorElement* relElem, relations )
Q_FOREACH ( QgsAttributeEditorElement* relElem, relations )
{
QgsAttributeEditorRelation* rel = dynamic_cast< QgsAttributeEditorRelation* >( relElem );
if ( !rel )
Expand Down Expand Up @@ -3911,7 +3912,7 @@ QDomElement QgsAttributeEditorContainer::toDomElement( QDomDocument& doc ) const
QDomElement elem = doc.createElement( "attributeEditorContainer" );
elem.setAttribute( "name", mName );

Q_FOREACH( QgsAttributeEditorElement* child, mChildren )
Q_FOREACH ( QgsAttributeEditorElement* child, mChildren )
{
elem.appendChild( child->toDomElement( doc ) );
}
Expand All @@ -3932,7 +3933,7 @@ QList<QgsAttributeEditorElement*> QgsAttributeEditorContainer::findElements( Qgs
{
QList<QgsAttributeEditorElement*> results;

Q_FOREACH( QgsAttributeEditorElement* elem, mChildren )
Q_FOREACH ( QgsAttributeEditorElement* elem, mChildren )
{
if ( elem->type() == type )
{
Expand Down
6 changes: 4 additions & 2 deletions src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ QgsFeatureRendererV2* QgsInvertedPolygonRenderer::clone() const
}
else
{
newRenderer = new QgsInvertedPolygonRenderer( mSubRenderer->clone() );
newRenderer = new QgsInvertedPolygonRenderer( mSubRenderer.data() );
}
newRenderer->setPreprocessingEnabled( preprocessingEnabled() );
copyPaintEffect( newRenderer );
Expand All @@ -351,7 +351,9 @@ QgsFeatureRendererV2* QgsInvertedPolygonRenderer::create( QDomElement& element )
QDomElement embeddedRendererElem = element.firstChildElement( "renderer-v2" );
if ( !embeddedRendererElem.isNull() )
{
r->setEmbeddedRenderer( QgsFeatureRendererV2::load( embeddedRendererElem ) );
QgsFeatureRendererV2* renderer = QgsFeatureRendererV2::load( embeddedRendererElem );
r->setEmbeddedRenderer( renderer );
delete renderer;
}
r->setPreprocessingEnabled( element.attribute( "preprocessing", "0" ).toInt() == 1 );
return r;
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgslegendsymbolitemv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ QgsLegendSymbolItemV2& QgsLegendSymbolItemV2::operator=( const QgsLegendSymbolIt
if ( this == &other )
return *this;

setSymbol( other.mSymbol ? other.mSymbol->clone() : 0 );
setSymbol( other.mSymbol );
mLabel = other.mLabel;
mKey = other.mKey;
mCheckable = other.mCheckable;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/attributetable/qgsfieldconditionalformatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ QgsFieldConditionalFormatWidget::QgsFieldConditionalFormatWidget( QWidget *paren
btnBackgroundColor->setShowNoColor( true );
btnTextColor->setAllowAlpha( true );
btnTextColor->setShowNoColor( true );
mModel = new QStandardItemModel();
mPresetsModel = new QStandardItemModel();
mPresetsModel = new QStandardItemModel( listView );
mModel = new QStandardItemModel( listView );
listView->setModel( mModel );
mPresetsList->setModel( mPresetsModel );

Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgscolorschemeregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ void TestQgsColorSchemeRegistry::removeScheme()
QVERIFY( registry->schemes().length() == 0 );
//try removing a scheme not in the registry
QVERIFY( !registry->removeColorScheme( recentScheme ) );
delete recentScheme;
}

void TestQgsColorSchemeRegistry::matchingSchemes()
Expand Down
Loading

0 comments on commit 9094575

Please sign in to comment.