20 #include "qgsexpression.h" 24 #include <QHBoxLayout> 28 , mCaseString( QStringLiteral(
"LIKE" ) )
37 void QgsDefaultSearchWidgetWrapper::setCaseString(
int caseSensitiveCheckState )
39 if ( caseSensitiveCheckState == Qt::Checked )
41 mCaseString = QStringLiteral(
"LIKE" );
45 mCaseString = QStringLiteral(
"ILIKE" );
57 bool numeric = ( fldType == QVariant::Int || fldType == QVariant::Double || fldType == QVariant::LongLong );
63 if ( exp == nullValue )
65 str = QStringLiteral(
"%1 IS NULL" ).arg( QgsExpression::quotedColumnRef( fieldName ) );
69 str = QStringLiteral(
"%1 %2 '%3'" )
70 .arg( QgsExpression::quotedColumnRef( fieldName ),
71 numeric ? QStringLiteral(
"=" ) : mCaseString,
73 exp.replace(
'\'', QLatin1String(
"''" ) )
75 '%' + exp.replace(
'\'', QLatin1String(
"''" ) ) +
'%' );
82 return new QWidget( parent );
99 case QVariant::Double:
100 case QVariant::LongLong:
101 case QVariant::ULongLong:
103 case QVariant::DateTime:
108 case QVariant::String:
125 case QVariant::Double:
126 case QVariant::LongLong:
127 case QVariant::ULongLong:
132 case QVariant::DateTime:
136 case QVariant::String:
154 return fieldName +
" IS NULL";
156 return fieldName +
" IS NOT NULL";
162 case QVariant::Double:
163 case QVariant::LongLong:
164 case QVariant::ULongLong:
167 return fieldName +
'=' + mLineEdit->text();
169 return fieldName +
"<>" + mLineEdit->text();
171 return fieldName +
'>' + mLineEdit->text();
173 return fieldName +
'<' + mLineEdit->text();
175 return fieldName +
">=" + mLineEdit->text();
177 return fieldName +
"<=" + mLineEdit->text();
182 case QVariant::DateTime:
186 return fieldName +
"='" + mLineEdit->text() +
'\'';
188 return fieldName +
"<>'" + mLineEdit->text() +
'\'';
190 return fieldName +
">'" + mLineEdit->text() +
'\'';
192 return fieldName +
"<'" + mLineEdit->text() +
'\'';
194 return fieldName +
">='" + mLineEdit->text() +
'\'';
196 return fieldName +
"<='" + mLineEdit->text() +
'\'';
200 case QVariant::String:
205 if ( mCheckbox && mCheckbox->isChecked() )
206 return fieldName + ( flags &
EqualTo ?
"=" :
"<>" )
207 + QgsExpression::quotedString( mLineEdit->text() );
209 return QStringLiteral(
"lower(%1)" ).arg( fieldName )
210 + ( flags & EqualTo ?
"=" :
"<>" ) +
211 QStringLiteral(
"lower(%1)" ).arg( QgsExpression::quotedString( mLineEdit->text() ) );
215 QString exp = fieldName + ( mCheckbox && mCheckbox->isChecked() ?
" LIKE " :
" ILIKE " );
216 QString value = QgsExpression::quotedString( mLineEdit->text() );
218 value = value.remove( 0, 1 );
223 if ( !flags.testFlag( EndsWith ) )
227 exp.prepend(
"NOT (" ).append(
')' );
243 mLineEdit->setText( QString() );
248 mLineEdit->setEnabled( enabled );
250 mCheckbox->setEnabled( enabled );
256 mContainer->setLayout(
new QHBoxLayout() );
257 mContainer->layout()->setMargin( 0 );
258 mContainer->layout()->setContentsMargins( 0, 0, 0, 0 );
261 if ( fldType == QVariant::String )
271 mContainer->layout()->addWidget( mLineEdit );
272 mContainer->setFocusProxy( mLineEdit );
274 if ( fldType == QVariant::String )
276 mCheckbox =
new QCheckBox( QStringLiteral(
"Case sensitive" ) );
277 mContainer->layout()->addWidget( mCheckbox );
278 connect( mCheckbox, &QCheckBox::stateChanged,
this, &QgsDefaultSearchWidgetWrapper::setCaseString );
279 mCheckbox->setChecked( Qt::Unchecked );
282 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsDefaultSearchWidgetWrapper::textChanged );
283 connect( mLineEdit, &QLineEdit::returnPressed,
this, &QgsDefaultSearchWidgetWrapper::filterChanged );
286 mCaseString = QStringLiteral(
"ILIKE" );
304 void QgsDefaultSearchWidgetWrapper::filterChanged()
309 void QgsDefaultSearchWidgetWrapper::textChanged(
const QString &text )
311 if ( text.isEmpty() )
QgsField at(int i) const
Get field at particular index (must be in range 0..N-1)
QgsFields fields() const override
Returns the list of fields of this layer.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
A line edit with an autocompleter which takes unique values from a vector layer's fields...
Represents a vector layer which manages a vector based data sets.