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 e0aa69d commit 8962d8436056d9cbe0ffa9c0707bc4a5a82554a1
Showing with 21 additions and 2 deletions.
  1. +14 −2 src/gui/qgsexpressionbuilderwidget.cpp
  2. +7 −0 src/gui/qgsexpressionbuilderwidget.h
@@ -467,7 +467,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
{
@@ -482,7 +482,7 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
QVariant value = exp.evaluate();
if ( !exp.hasEvalError() )
{
lblPreview->setText( value.toString() );
lblPreview->setText( formatPreviewString( value.toString() ) );
}
}

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

QString QgsExpressionBuilderWidget::formatPreviewString( const QString& previewString ) const
{
if ( previewString.length() > 63 )
{
return QString( tr( "%1..." ) ).arg( previewString.left( 60 ) );
}
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 8962d84

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