27 #include <QHBoxLayout>
28 #include <QVBoxLayout>
29 #include <QToolButton>
34 , mExpressionDialogTitle( tr(
"Expression Dialog" ) )
36 mButton =
new QToolButton();
37 mButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
39 connect( mButton, &QAbstractButton::clicked,
this, &QgsExpressionLineEdit::editExpression );
53 mExpressionDialogTitle = title;
60 if ( multiLine && !mCodeEditor )
63 mCodeEditor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
67 QHBoxLayout *newLayout =
new QHBoxLayout();
68 newLayout->setContentsMargins( 0, 0, 0, 0 );
69 newLayout->addWidget( mCodeEditor );
71 QVBoxLayout *vLayout =
new QVBoxLayout();
72 vLayout->addWidget( mButton );
73 vLayout->addStretch();
74 newLayout->addLayout( vLayout );
77 setLayout( newLayout );
79 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
81 setFocusProxy( mCodeEditor );
82 connect( mCodeEditor, &QsciScintilla::textChanged,
this,
static_cast < void (
QgsExpressionLineEdit::* )()
> ( &QgsExpressionLineEdit::expressionEdited ) );
86 else if ( !multiLine && !mLineEdit )
89 mCodeEditor =
nullptr;
91 mLineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
93 QHBoxLayout *newLayout =
new QHBoxLayout();
94 newLayout->setContentsMargins( 0, 0, 0, 0 );
95 newLayout->addWidget( mLineEdit );
96 newLayout->addWidget( mButton );
99 setLayout( newLayout );
101 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
103 setFocusProxy( mLineEdit );
104 connect( mLineEdit, &QLineEdit::textChanged,
this,
static_cast < void (
QgsExpressionLineEdit::* )(
const QString & )
> ( &QgsExpressionLineEdit::expressionEdited ) );
112 return mExpectedOutputFormat;
117 mExpectedOutputFormat = expected;
127 if ( !mExpressionContextGenerator || mExpressionContextGenerator == mLayer )
128 mExpressionContextGenerator = layer;
135 return mLineEdit->text();
136 else if ( mCodeEditor )
137 return mCodeEditor->text();
150 mExpressionContextGenerator = generator;
156 mLineEdit->setText( newExpression );
157 else if ( mCodeEditor )
158 mCodeEditor->setText( newExpression );
161 void QgsExpressionLineEdit::editExpression()
168 dlg.setExpectedOutputFormat( mExpectedOutputFormat );
171 dlg.setGeomCalculator( *mDa );
173 dlg.setWindowTitle( mExpressionDialogTitle );
177 QString newExpression = dlg.expressionText();
182 void QgsExpressionLineEdit::expressionEdited()
187 void QgsExpressionLineEdit::expressionEdited(
const QString &expression )
195 if ( event->type() == QEvent::EnabledChange )
201 void QgsExpressionLineEdit::updateLineEditStyle(
const QString &expression )
206 QPalette palette = mLineEdit->palette();
209 palette.setColor( QPalette::Text, Qt::gray );
220 palette.setColor( QPalette::Text, Qt::red );
224 palette.setColor( QPalette::Text, Qt::black );
227 mLineEdit->setPalette( palette );
230 bool QgsExpressionLineEdit::isExpressionValid(
const QString &expressionStr )