Skip to content

Commit 013e1da

Browse files
committed
Tests and doxygen for QgsDataDefined
1 parent 1e6483c commit 013e1da

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

python/core/qgsdatadefined.sip

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,34 @@ class QgsDataDefined
6565
bool isActive() const;
6666
void setActive( bool active );
6767

68+
/**
69+
* Returns if the field or the expression part is active.
70+
*
71+
* @return True if it is in expression mode.
72+
*/
6873
bool useExpression() const;
6974
void setUseExpression( bool use );
7075

76+
/**
77+
* Returns the expression string of this QgsDataDefined.
78+
*
79+
* @return An expression
80+
*
81+
* @see field()
82+
* @see expressionOrField()
83+
*/
7184
QString expressionString() const;
85+
7286
void setExpressionString( const QString& expr );
87+
88+
/**
89+
* Returns an expression which represents a single field if useExpression returns false, otherwise
90+
* returns the current expression string.
91+
* @return An expression
92+
*
93+
* @note added in 2.12
94+
*/
95+
QString expressionOrField() const;
7396

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

134+
/**
135+
* Get the field which this QgsDataDefined represents. Be aware that this may return
136+
* a field name which may not be active if useExpression is true.
137+
*
138+
* @return A fieldname
139+
*
140+
* @see expressionOrField()
141+
*/
111142
QString field() const;
143+
112144
void setField( const QString& field );
113145

114146
/** Encodes the QgsDataDefined into a string map.

src/core/qgsdatadefined.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class CORE_EXPORT QgsDataDefined
113113
void setExpressionString( const QString& expr );
114114

115115
/**
116-
* Returns an expression which represents a single field if useExpression returns false
117-
*
116+
* Returns an expression which represents a single field if useExpression returns false, otherwise
117+
* returns the current expression string.
118118
* @return An expression
119119
*
120120
* @note added in 2.12

tests/src/core/testqgsdatadefined.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TestQgsDataDefined: public QObject
4242
void xmlMethods(); //test saving and reading from xml
4343
void mapMethods(); //test saving and reading from a string map
4444
void referencedColumns(); //test referenced columns method
45+
void expressionOrString();
4546

4647
private:
4748
};
@@ -307,5 +308,18 @@ void TestQgsDataDefined::referencedColumns()
307308
QVERIFY( cols.contains( QString( "col3" ) ) );
308309
}
309310

311+
void TestQgsDataDefined::expressionOrString()
312+
{
313+
QgsDataDefined dd;
314+
dd.setActive( true );
315+
dd.setField( "field" );
316+
dd.setExpressionString( "1+col1+col2" );
317+
dd.setUseExpression( true );
318+
QCOMPARE( dd.expressionOrField(), QString( "1+col1+col2" ) );
319+
320+
dd.setUseExpression( false );
321+
QCOMPARE( dd.expressionOrField(), QString( "\"field\"" ) );
322+
}
323+
310324
QTEST_MAIN( TestQgsDataDefined )
311325
#include "testqgsdatadefined.moc"

tests/src/python/test_qgsdoccoverage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# DON'T RAISE THIS THRESHOLD!!!
3333
# (changes which lower this threshold are welcomed though!)
3434

35-
ACCEPTABLE_MISSING_DOCS = 4427
35+
ACCEPTABLE_MISSING_DOCS = 4412
3636

3737

3838
def elemIsDocumentableClass(elem):
@@ -128,7 +128,7 @@ def testCoverage(self):
128128

129129
documentable, documented = parseDocs(docPath)
130130
coverage = 100.0 * documented / documentable
131-
missing = documentable - documented
131+
missing = documentable - documented
132132

133133
print "---------------------------------"
134134
print "{} total documentable members".format(documentable)

0 commit comments

Comments
 (0)