18 #include <QMessageBox> 20 #include <QPushButton> 30 , mPreviousFieldRow( -1 )
39 buttonBox->addButton( pbn, QDialogButtonBox::ActionRole );
40 connect( pbn, SIGNAL( clicked() ),
this, SLOT(
test() ) );
43 buttonBox->addButton( pbn, QDialogButtonBox::ActionRole );
44 connect( pbn, SIGNAL( clicked() ),
this, SLOT(
clear() ) );
52 lblDataUri->setText(
tr(
"Set provider filter on %1" ).arg( layer->
name() ) );
53 txtSQL->setText( mOrigSubsetString );
70 void QgsQueryBuilder::populateFields()
73 for (
int idx = 0; idx < fields.
count(); ++idx )
87 setupLstFieldsModel();
90 void QgsQueryBuilder::setupLstFieldsModel()
92 lstFields->setModel( mModelFields );
95 void QgsQueryBuilder::setupGuiViews()
101 lstFields->setViewMode( QListView::ListMode );
102 lstValues->setViewMode( QListView::ListMode );
103 lstFields->setSelectionBehavior( QAbstractItemView::SelectRows );
104 lstValues->setSelectionBehavior( QAbstractItemView::SelectRows );
106 lstFields->setUniformItemSizes(
true );
107 lstValues->setUniformItemSizes(
true );
109 lstFields->setAlternatingRowColors(
true );
110 lstValues->setAlternatingRowColors(
true );
113 void QgsQueryBuilder::fillValues(
int idx,
int limit )
116 mModelValues->
clear();
127 for (
int i = 0; i < values.
size(); i++ )
132 else if ( values[i].type() == QVariant::Date && mLayer->
providerType() ==
"ogr" && mLayer->
storageType() ==
"ESRI Shapefile" )
133 value = values[i].toDate().toString(
"yyyy/MM/dd" );
135 value = values[i].toString();
139 myItem->
setData( values[i], Qt::UserRole + 1 );
147 lstValues->setCursor( Qt::WaitCursor );
150 if ( mUseUnfilteredLayer->isChecked() && !prevSubsetString.
isEmpty() )
157 lstValues->setModel( tmp );
159 fillValues( mModelFields->
data( lstFields->currentIndex(), Qt::UserRole + 1 ).toInt(), 25 );
160 lstValues->setModel( mModelValues );
169 lstValues->setCursor( Qt::ArrowCursor );
174 lstValues->setCursor( Qt::WaitCursor );
177 if ( mUseUnfilteredLayer->isChecked() && !prevSubsetString.
isEmpty() )
184 lstValues->setModel( tmp );
186 fillValues( mModelFields->
data( lstFields->currentIndex(), Qt::UserRole + 1 ).toInt(), -1 );
187 lstValues->setModel( mModelValues );
196 lstValues->setCursor( Qt::ArrowCursor );
210 tr(
"Query Result" ),
211 tr(
"The where clause returned %n row(s).",
"returned test rows", mLayer->
featureCount() ) );
216 tr(
"Query Failed" ),
217 tr(
"An error occurred when executing the query." )
224 tr(
"Query Failed" ),
225 tr(
"An error occurred when executing the query." ) );
237 tr(
"Query Failed" ),
238 tr(
"An error occurred when executing the query." )
263 txtSQL->insertText(
" = " );
269 txtSQL->insertText(
" < " );
275 txtSQL->insertText(
" > " );
281 txtSQL->insertText(
"%" );
287 txtSQL->insertText(
" IN " );
293 txtSQL->insertText(
" NOT IN " );
299 txtSQL->insertText(
" LIKE " );
305 return txtSQL->text();
310 txtSQL->setText( sqlStatement );
315 if ( mPreviousFieldRow != index.
row() )
317 mPreviousFieldRow = index.
row();
319 btnSampleValues->setEnabled(
true );
320 btnGetAllValues->setEnabled(
true );
322 mModelValues->
clear();
328 txtSQL->insertText(
'\"' + mLayer->
fields().
at( mModelFields->
data( index, Qt::UserRole + 1 ).
toInt() ).
name() +
'\"' );
334 QVariant value = mModelValues->
data( index, Qt::UserRole + 1 );
336 txtSQL->insertText(
"NULL" );
338 txtSQL->insertText(
'\'' + value.
toDate().
toString(
"yyyy/MM/dd" ) +
'\'' );
339 else if ( value.
type() == QVariant::Int || value.
type() == QVariant::Double || value.
type() == QVariant::LongLong )
340 txtSQL->insertText( value.
toString() );
342 txtSQL->insertText(
'\'' + value.
toString().
replace(
'\'',
"''" ) +
'\'' );
349 txtSQL->insertText(
" <= " );
355 txtSQL->insertText(
" >= " );
361 txtSQL->insertText(
" != " );
367 txtSQL->insertText(
" AND " );
373 txtSQL->insertText(
" NOT " );
379 txtSQL->insertText(
" OR " );
387 mUseUnfilteredLayer->setDisabled(
true );
392 txtSQL->insertText(
" ILIKE " );
398 lblDataUri->setText( uri );
virtual QString subsetString()
Get the string (typically sql) used to define a subset of the layer.
QByteArray toByteArray() const
virtual bool event(QEvent *e)
void on_btnLike_clicked()
void on_btnLessEqual_clicked()
FieldOrigin fieldOrigin(int fieldIdx) const
Get field's origin (value from an enumeration)
void test()
Test the constructed sql statement to see if the vector layer data provider likes it...
virtual QVariant data(const QModelIndex &index, int role) const
QString toString(Qt::DateFormat format) const
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
void uniqueValues(int index, QList< QVariant > &uniqueValues, int limit=-1)
Calculates a list of unique values contained within an attribute in the layer.
Container of fields for a vector layer.
QStringList errors()
Get recorded errors.
void on_btnNotIn_clicked()
field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
QString join(const QString &separator) const
void on_btnGetAllValues_clicked()
int count() const
Return number of items.
QString tr(const char *sourceText, const char *disambiguation, int n)
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
virtual void setData(const QVariant &value, int role)
QgsFields fields() const
Returns the list of fields of this layer.
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol.
void setValue(const QString &key, const QVariant &value)
const char * name() const
void setSql(const QString &sqlStatement)
int toInt(bool *ok) const
QgsQueryBuilder(QgsVectorLayer *layer, QWidget *parent=nullptr, const Qt::WindowFlags &fl=QgisGui::ModalDialogFlags)
This constructor is used when the query builder is called from the vector layer properties dialog...
bool hasErrors()
Provider has errors to report.
void on_lstFields_doubleClicked(const QModelIndex &index)
void on_btnEqual_clicked()
void clearErrors()
Clear recorded errors.
void insertRow(int row, const QList< QStandardItem * > &items)
void on_lstFields_clicked(const QModelIndex &index)
void on_btnGreaterEqual_clicked()
QString & replace(int position, int n, QChar after)
QVariant value(const QString &key, const QVariant &defaultValue) const
void on_btnNotEqual_clicked()
void setDatasourceDescription(const QString &uri)
virtual int rowCount(const QModelIndex &parent) const
virtual bool setSubsetString(const QString &subset)
Set the string (typically sql) used to define a subset of the layer.
virtual void showEvent(QShowEvent *event)
void on_btnSampleValues_clicked()
void on_btnGreaterThan_clicked()
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
QString name
Read property of QString layerName.
void on_btnILike_clicked()
QgsVectorDataProvider * dataProvider()
Returns the data provider.
QString providerType() const
Return the provider type for this layer.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
void on_lstValues_doubleClicked(const QModelIndex &index)
bool isNull(const QVariant &v)
void showEvent(QShowEvent *event) override
void setEditable(bool editable)
void on_btnLessThan_clicked()