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'" )
73 numeric ? QStringLiteral(
"=" ) : mCaseString,
75 exp.replace(
'\'', QLatin1String(
"''" ) )
77 '%' + exp.replace(
'\'', QLatin1String(
"''" ) ) +
'%' );
84 return new QWidget( parent );
99 case QMetaType::Type::Int:
100 case QMetaType::Type::UInt:
101 case QMetaType::Type::Double:
102 case QMetaType::Type::LongLong:
103 case QMetaType::Type::ULongLong:
104 case QMetaType::Type::QDate:
105 case QMetaType::Type::QDateTime:
106 case QMetaType::Type::QTime:
110 case QMetaType::Type::QString:
126 case QMetaType::Type::Int:
127 case QMetaType::Type::UInt:
128 case QMetaType::Type::Double:
129 case QMetaType::Type::LongLong:
130 case QMetaType::Type::ULongLong:
133 case QMetaType::Type::QDate:
134 case QMetaType::Type::QDateTime:
135 case QMetaType::Type::QTime:
138 case QMetaType::Type::QString:
156 return fieldName +
" IS NULL";
158 return fieldName +
" IS NOT NULL";
162 case QMetaType::Type::Int:
163 case QMetaType::Type::UInt:
164 case QMetaType::Type::Double:
165 case QMetaType::Type::LongLong:
166 case QMetaType::Type::ULongLong:
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();
179 return fieldName +
"<=" + mLineEdit->text();
183 case QMetaType::Type::QDate:
184 case QMetaType::Type::QDateTime:
185 case QMetaType::Type::QTime:
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() +
'\'';
198 return fieldName +
"<='" + mLineEdit->text() +
'\'';
202 case QMetaType::Type::QString:
207 if ( mCheckbox && mCheckbox->isChecked() )
208 return fieldName + ( ( flags &
EqualTo ) ?
"=" :
"<>" )
211 return QStringLiteral(
"lower(%1)" ).arg( fieldName )
212 + ( ( flags &
EqualTo ) ?
"=" :
"<>" ) +
217 QString exp = fieldName + ( mCheckbox && mCheckbox->isChecked() ?
" LIKE " :
" ILIKE " );
220 value = value.remove( 0, 1 );
229 exp.prepend(
"NOT (" ).append(
')' );
245 mLineEdit->setText( QString() );
250 mLineEdit->setEnabled( enabled );
252 mCheckbox->setEnabled( enabled );
258 mContainer->setLayout(
new QHBoxLayout() );
259 mContainer->layout()->setContentsMargins( 0, 0, 0, 0 );
262 if ( fldType == QMetaType::Type::QString )
272 mContainer->layout()->addWidget( mLineEdit );
273 mContainer->setFocusProxy( mLineEdit );
275 if ( fldType == QMetaType::Type::QString )
277 mCheckbox =
new QCheckBox( QStringLiteral(
"Case sensitive" ) );
278 mContainer->layout()->addWidget( mCheckbox );
279 connect( mCheckbox, &QCheckBox::stateChanged,
this, &QgsDefaultSearchWidgetWrapper::setCaseString );
280 mCheckbox->setChecked( Qt::Unchecked );
283 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsDefaultSearchWidgetWrapper::textChanged );
284 connect( mLineEdit, &QLineEdit::returnPressed,
this, &QgsDefaultSearchWidgetWrapper::filterChanged );
287 mCaseString = QStringLiteral(
"ILIKE" );
305void QgsDefaultSearchWidgetWrapper::filterChanged()
310void QgsDefaultSearchWidgetWrapper::textChanged(
const QString &text )
312 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.