Skip to content
Permalink
Browse files

Truncate expression preview result in builder widget if too long

Prevents window from resizing to extreme widths (fix #12433)
  • Loading branch information
nyalldawson committed May 17, 2015
1 parent e249bfe commit 204cf7519500de7ceff298ef450c60479fe11acf
Showing with 21 additions and 2 deletions.
  1. +14 −2 src/gui/qgsexpressionbuilderwidget.cpp
  2. +7 −0 src/gui/qgsexpressionbuilderwidget.h
@@ -468,7 +468,7 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
{
QVariant value = exp.evaluate( &mFeature, mLayer->pendingFields() );
if ( !exp.hasEvalError() )
lblPreview->setText( value.toString() );
lblPreview->setText( formatPreviewString( value.toString() ) );
}
else
{
@@ -483,7 +483,7 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
QVariant value = exp.evaluate();
if ( !exp.hasEvalError() )
{
lblPreview->setText( value.toString() );
lblPreview->setText( formatPreviewString( value.toString() ) );
}
}

@@ -509,6 +509,18 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
}
}

QString QgsExpressionBuilderWidget::formatPreviewString( const QString& previewString ) const
{
if ( previewString.length() > 60 )
{
return QString( tr( "%1..." ) ).arg( previewString.left( 60 ) );

This comment has been minimized.

Copy link
@3nids

3nids May 18, 2015

Member

small remark: I would use 63 for the test.
Let's say the string is 62 length, it makes no sense to display its first 60 characters + 3 dots.

}
else
{
return previewString;
}
}

void QgsExpressionBuilderWidget::on_txtSearchEdit_textChanged()
{
mProxyModel->setFilterWildcard( txtSearchEdit->text() );
@@ -203,6 +203,12 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
void fillFieldValues( int fieldIndex, int countLimit );
QString loadFunctionHelp( QgsExpressionItem* functionName );

/** Formats an expression preview result for display in the widget
* by truncating the string
* @param previewString expression preview result to format
*/
QString formatPreviewString( const QString &previewString ) const;

QString mFunctionsPath;
QgsVectorLayer *mLayer;
QStandardItemModel *mModel;
@@ -212,6 +218,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
QgsExpressionHighlighter* highlighter;
bool mExpressionValid;
QgsDistanceArea mDa;

};

#endif // QGSEXPRESSIONBUILDER_H

0 comments on commit 204cf75

Please sign in to comment.
You can’t perform that action at this time.