Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Tests and doxygen for QgsDataDefined
  • Loading branch information
nyalldawson committed Aug 6, 2015
1 parent 1e6483c commit 013e1da
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
32 changes: 32 additions & 0 deletions python/core/qgsdatadefined.sip
Expand Up @@ -65,11 +65,34 @@ class QgsDataDefined
bool isActive() const;
void setActive( bool active );

/**
* Returns if the field or the expression part is active.
*
* @return True if it is in expression mode.
*/
bool useExpression() const;
void setUseExpression( bool use );

/**
* Returns the expression string of this QgsDataDefined.
*
* @return An expression
*
* @see field()
* @see expressionOrField()
*/
QString expressionString() const;

void setExpressionString( const QString& expr );

/**
* Returns an expression which represents a single field if useExpression returns false, otherwise
* returns the current expression string.
* @return An expression
*
* @note added in 2.12
*/
QString expressionOrField() const;

// @note not available in python bindings
//QMap<QString, QVariant> expressionParams() const;
Expand Down Expand Up @@ -108,7 +131,16 @@ class QgsDataDefined
*/
QStringList referencedColumns( const QgsFields& fields = QgsFields() );

/**
* Get the field which this QgsDataDefined represents. Be aware that this may return
* a field name which may not be active if useExpression is true.
*
* @return A fieldname
*
* @see expressionOrField()
*/
QString field() const;

void setField( const QString& field );

/** Encodes the QgsDataDefined into a string map.
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsdatadefined.h
Expand Up @@ -113,8 +113,8 @@ class CORE_EXPORT QgsDataDefined
void setExpressionString( const QString& expr );

/**
* Returns an expression which represents a single field if useExpression returns false
*
* Returns an expression which represents a single field if useExpression returns false, otherwise
* returns the current expression string.
* @return An expression
*
* @note added in 2.12
Expand Down
14 changes: 14 additions & 0 deletions tests/src/core/testqgsdatadefined.cpp
Expand Up @@ -42,6 +42,7 @@ class TestQgsDataDefined: public QObject
void xmlMethods(); //test saving and reading from xml
void mapMethods(); //test saving and reading from a string map
void referencedColumns(); //test referenced columns method
void expressionOrString();

private:
};
Expand Down Expand Up @@ -307,5 +308,18 @@ void TestQgsDataDefined::referencedColumns()
QVERIFY( cols.contains( QString( "col3" ) ) );
}

void TestQgsDataDefined::expressionOrString()
{
QgsDataDefined dd;
dd.setActive( true );
dd.setField( "field" );
dd.setExpressionString( "1+col1+col2" );
dd.setUseExpression( true );
QCOMPARE( dd.expressionOrField(), QString( "1+col1+col2" ) );

dd.setUseExpression( false );
QCOMPARE( dd.expressionOrField(), QString( "\"field\"" ) );
}

QTEST_MAIN( TestQgsDataDefined )
#include "testqgsdatadefined.moc"
4 changes: 2 additions & 2 deletions tests/src/python/test_qgsdoccoverage.py
Expand Up @@ -32,7 +32,7 @@
# DON'T RAISE THIS THRESHOLD!!!
# (changes which lower this threshold are welcomed though!)

ACCEPTABLE_MISSING_DOCS = 4427
ACCEPTABLE_MISSING_DOCS = 4412


def elemIsDocumentableClass(elem):
Expand Down Expand Up @@ -128,7 +128,7 @@ def testCoverage(self):

documentable, documented = parseDocs(docPath)
coverage = 100.0 * documented / documentable
missing = documentable - documented
missing = documentable - documented

print "---------------------------------"
print "{} total documentable members".format(documentable)
Expand Down

0 comments on commit 013e1da

Please sign in to comment.