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();
151 mExpressionContextGenerator = generator;
157 mLineEdit->setText( newExpression );
158 else if ( mCodeEditor )
159 mCodeEditor->setText( newExpression );
162 void QgsExpressionLineEdit::editExpression()
164 const QString currentExpression =
expression();
169 dlg.setExpectedOutputFormat( mExpectedOutputFormat );
172 dlg.setGeomCalculator( *mDa );
174 dlg.setWindowTitle( mExpressionDialogTitle );
178 const QString newExpression = dlg.expressionText();
183 void QgsExpressionLineEdit::expressionEdited()
188 void QgsExpressionLineEdit::expressionEdited(
const QString &expression )
196 if ( event->type() == QEvent::EnabledChange )
202 void QgsExpressionLineEdit::updateLineEditStyle(
const QString &expression )
207 QPalette palette = mLineEdit->palette();
210 palette.setColor( QPalette::Text, Qt::gray );
221 palette.setColor( QPalette::Text, Qt::red );
225 palette.setColor( QPalette::Text, Qt::black );
228 mLineEdit->setPalette( palette );
231 bool QgsExpressionLineEdit::isExpressionValid(
const QString &expressionStr )