mirror of
https://github.com/qgis/QGIS.git
synced 2025-06-18 00:04:02 -04:00
Quote fields in size/width assistant (fix #14257)
This commit is contained in:
parent
cd145bb4b3
commit
d11e66749b
@ -46,6 +46,13 @@ class QgsFieldExpressionWidget : QWidget
|
||||
*/
|
||||
QString currentText() const;
|
||||
|
||||
/** Returns the currently selected field or expression. If a field is currently selected, the returned
|
||||
* value will be converted to a valid expression referencing this field (ie enclosing the field name with
|
||||
* appropriate quotations).
|
||||
* @note added in QGIS 2.14
|
||||
*/
|
||||
QString asExpression() const;
|
||||
|
||||
//! Returns the currently used layer
|
||||
QgsVectorLayer* layer() const;
|
||||
|
||||
|
@ -103,6 +103,11 @@ QString QgsFieldExpressionWidget::currentText() const
|
||||
return mCombo->currentText();
|
||||
}
|
||||
|
||||
QString QgsFieldExpressionWidget::asExpression() const
|
||||
{
|
||||
return isExpression() ? currentText() : QgsExpression::quotedColumnRef( currentText() );
|
||||
}
|
||||
|
||||
bool QgsFieldExpressionWidget::isValidExpression( QString *expressionError ) const
|
||||
{
|
||||
QString temp;
|
||||
|
@ -89,6 +89,13 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
|
||||
*/
|
||||
QString currentText() const;
|
||||
|
||||
/** Returns the currently selected field or expression. If a field is currently selected, the returned
|
||||
* value will be converted to a valid expression referencing this field (ie enclosing the field name with
|
||||
* appropriate quotations).
|
||||
* @note added in QGIS 2.14
|
||||
*/
|
||||
QString asExpression() const;
|
||||
|
||||
//! Returns the currently used layer
|
||||
QgsVectorLayer* layer() const;
|
||||
|
||||
|
@ -222,7 +222,7 @@ void QgsSizeScaleWidget::showEvent( QShowEvent* )
|
||||
QgsScaleExpression *QgsSizeScaleWidget::createExpression() const
|
||||
{
|
||||
return new QgsScaleExpression( QgsScaleExpression::Type( scaleMethodComboBox->itemData( scaleMethodComboBox->currentIndex() ).toInt() ),
|
||||
mExpressionWidget->currentField(),
|
||||
mExpressionWidget->asExpression(),
|
||||
minValueSpinBox->value(),
|
||||
maxValueSpinBox->value(),
|
||||
minSizeSpinBox->value(),
|
||||
|
@ -48,6 +48,7 @@ class TestQgsFieldExpressionWidget : public QObject
|
||||
void cleanup(); // will be called after every testfunction.
|
||||
|
||||
void testRemoveJoin();
|
||||
void asExpression();
|
||||
|
||||
private:
|
||||
QgsFieldExpressionWidget* mWidget;
|
||||
@ -133,6 +134,33 @@ void TestQgsFieldExpressionWidget::testRemoveJoin()
|
||||
// QVERIFY( !isValid ); TODO: the expression should not be valid anymore since the field doesn't exist anymore. Maybe we need a new expression method to get more details.
|
||||
}
|
||||
|
||||
void TestQgsFieldExpressionWidget::asExpression()
|
||||
{
|
||||
QgsVectorLayer* layer = new QgsVectorLayer( "point?field=fld:int&field=fld2:int&field=fld3:int", "x", "memory" );
|
||||
QgsMapLayerRegistry::instance()->addMapLayer( layer );
|
||||
|
||||
QScopedPointer< QgsFieldExpressionWidget > widget( new QgsFieldExpressionWidget() );
|
||||
widget->setLayer( layer );
|
||||
|
||||
// check with field set
|
||||
widget->setField( "fld" );
|
||||
QCOMPARE( widget->asExpression(), QString( "\"fld\"" ) );
|
||||
|
||||
// check with expressions set
|
||||
widget->setField( "fld + 1" );
|
||||
QCOMPARE( widget->asExpression(), QString( "fld + 1" ) );
|
||||
widget->setField( "1" );
|
||||
QCOMPARE( widget->asExpression(), QString( "1" ) );
|
||||
widget->setField( "\"fld2\"" );
|
||||
QCOMPARE( widget->asExpression(), QString( "\"fld2\"" ) );
|
||||
|
||||
// check switching back to a field
|
||||
widget->setField( "fld3" );
|
||||
QCOMPARE( widget->asExpression(), QString( "\"fld3\"" ) );
|
||||
|
||||
QgsMapLayerRegistry::instance()->removeMapLayer( layer );
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN( TestQgsFieldExpressionWidget )
|
||||
#include "testqgsfieldexpressionwidget.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user