17#include "moc_qgsdefaultsearchwidgetwrapper.cpp"
30 , mCaseString( QStringLiteral(
"LIKE" ) )
39void QgsDefaultSearchWidgetWrapper::setCaseString(
int caseSensitiveCheckState )
41 if ( caseSensitiveCheckState == Qt::Checked )
43 mCaseString = QStringLiteral(
"LIKE" );
47 mCaseString = QStringLiteral(
"ILIKE" );
59 const bool numeric = ( fldType == QMetaType::Type::Int || fldType == QMetaType::Type::Double || fldType == QMetaType::Type::LongLong );
65 if ( exp == nullValue )
71 str = QStringLiteral(
"%1 %2 '%3'" )
72 .arg(
QgsExpression::quotedColumnRef( fieldName ), numeric ? QStringLiteral(
"=" ) : mCaseString, numeric ? exp.replace(
'\'', QLatin1String(
"''" ) ) :
'%' + exp.replace(
'\'', QLatin1String(
"''" ) ) +
'%' );
79 return new QWidget( parent );
94 case QMetaType::Type::Int:
95 case QMetaType::Type::UInt:
96 case QMetaType::Type::Double:
97 case QMetaType::Type::LongLong:
98 case QMetaType::Type::ULongLong:
99 case QMetaType::Type::QDate:
100 case QMetaType::Type::QDateTime:
101 case QMetaType::Type::QTime:
105 case QMetaType::Type::QString:
121 case QMetaType::Type::Int:
122 case QMetaType::Type::UInt:
123 case QMetaType::Type::Double:
124 case QMetaType::Type::LongLong:
125 case QMetaType::Type::ULongLong:
128 case QMetaType::Type::QDate:
129 case QMetaType::Type::QDateTime:
130 case QMetaType::Type::QTime:
133 case QMetaType::Type::QString:
151 return fieldName +
" IS NULL";
153 return fieldName +
" IS NOT NULL";
157 case QMetaType::Type::Int:
158 case QMetaType::Type::UInt:
159 case QMetaType::Type::Double:
160 case QMetaType::Type::LongLong:
161 case QMetaType::Type::ULongLong:
164 return fieldName +
'=' + mLineEdit->text();
166 return fieldName +
"<>" + mLineEdit->text();
168 return fieldName +
'>' + mLineEdit->text();
170 return fieldName +
'<' + mLineEdit->text();
172 return fieldName +
">=" + mLineEdit->text();
174 return fieldName +
"<=" + mLineEdit->text();
178 case QMetaType::Type::QDate:
179 case QMetaType::Type::QDateTime:
180 case QMetaType::Type::QTime:
183 return fieldName +
"='" + mLineEdit->text() +
'\'';
185 return fieldName +
"<>'" + mLineEdit->text() +
'\'';
187 return fieldName +
">'" + mLineEdit->text() +
'\'';
189 return fieldName +
"<'" + mLineEdit->text() +
'\'';
191 return fieldName +
">='" + mLineEdit->text() +
'\'';
193 return fieldName +
"<='" + mLineEdit->text() +
'\'';
197 case QMetaType::Type::QString:
202 if ( mCheckbox && mCheckbox->isChecked() )
203 return fieldName + ( ( flags &
EqualTo ) ?
"=" :
"<>" )
206 return QStringLiteral(
"lower(%1)" ).arg( fieldName )
211 QString exp = fieldName + ( mCheckbox && mCheckbox->isChecked() ?
" LIKE " :
" ILIKE " );
214 value = value.remove( 0, 1 );
223 exp.prepend(
"NOT (" ).append(
')' );
239 mLineEdit->setText( QString() );
244 mLineEdit->setEnabled( enabled );
246 mCheckbox->setEnabled( enabled );
252 mContainer->setLayout(
new QHBoxLayout() );
253 mContainer->layout()->setContentsMargins( 0, 0, 0, 0 );
256 if ( fldType == QMetaType::Type::QString )
266 mContainer->layout()->addWidget( mLineEdit );
267 mContainer->setFocusProxy( mLineEdit );
269 if ( fldType == QMetaType::Type::QString )
271 mCheckbox =
new QCheckBox( QStringLiteral(
"Case sensitive" ) );
272 mContainer->layout()->addWidget( mCheckbox );
273 connect( mCheckbox, &QCheckBox::stateChanged,
this, &QgsDefaultSearchWidgetWrapper::setCaseString );
274 mCheckbox->setChecked( Qt::Unchecked );
277 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsDefaultSearchWidgetWrapper::textChanged );
278 connect( mLineEdit, &QLineEdit::returnPressed,
this, &QgsDefaultSearchWidgetWrapper::filterChanged );
281 mCaseString = QStringLiteral(
"ILIKE" );
299void QgsDefaultSearchWidgetWrapper::filterChanged()
304void QgsDefaultSearchWidgetWrapper::textChanged(
const QString &text )
306 if ( text.isEmpty() )
static QString nullRepresentation()
Returns the string used to represent the value NULL throughout QGIS.
static QString quotedString(QString text)
Returns a quoted version of a string (in single quotes)
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
A line edit with an autocompleter which takes unique values from a vector layer's fields.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
Represents a vector layer which manages a vector based data sets.