Skip to content

Commit 204cf75

Browse files
committed
Truncate expression preview result in builder widget if too long
Prevents window from resizing to extreme widths (fix #12433)
1 parent e249bfe commit 204cf75

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/gui/qgsexpressionbuilderwidget.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
468468
{
469469
QVariant value = exp.evaluate( &mFeature, mLayer->pendingFields() );
470470
if ( !exp.hasEvalError() )
471-
lblPreview->setText( value.toString() );
471+
lblPreview->setText( formatPreviewString( value.toString() ) );
472472
}
473473
else
474474
{
@@ -483,7 +483,7 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
483483
QVariant value = exp.evaluate();
484484
if ( !exp.hasEvalError() )
485485
{
486-
lblPreview->setText( value.toString() );
486+
lblPreview->setText( formatPreviewString( value.toString() ) );
487487
}
488488
}
489489

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

512+
QString QgsExpressionBuilderWidget::formatPreviewString( const QString& previewString ) const
513+
{
514+
if ( previewString.length() > 60 )
515+
{
516+
return QString( tr( "%1..." ) ).arg( previewString.left( 60 ) );
517+
}
518+
else
519+
{
520+
return previewString;
521+
}
522+
}
523+
512524
void QgsExpressionBuilderWidget::on_txtSearchEdit_textChanged()
513525
{
514526
mProxyModel->setFilterWildcard( txtSearchEdit->text() );

src/gui/qgsexpressionbuilderwidget.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
203203
void fillFieldValues( int fieldIndex, int countLimit );
204204
QString loadFunctionHelp( QgsExpressionItem* functionName );
205205

206+
/** Formats an expression preview result for display in the widget
207+
* by truncating the string
208+
* @param previewString expression preview result to format
209+
*/
210+
QString formatPreviewString( const QString &previewString ) const;
211+
206212
QString mFunctionsPath;
207213
QgsVectorLayer *mLayer;
208214
QStandardItemModel *mModel;
@@ -212,6 +218,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
212218
QgsExpressionHighlighter* highlighter;
213219
bool mExpressionValid;
214220
QgsDistanceArea mDa;
221+
215222
};
216223

217224
#endif // QGSEXPRESSIONBUILDER_H

0 commit comments

Comments
 (0)