18 #include <QMessageBox>
20 #include <QPushButton>
28 QWidget *parent, Qt::WFlags fl )
29 : QDialog( parent, fl )
30 , mPreviousFieldRow( -1 )
36 restoreGeometry( settings.value(
"/Windows/QueryBuilder/geometry" ).toByteArray() );
38 QPushButton *pbn =
new QPushButton(
tr(
"&Test" ) );
39 buttonBox->addButton( pbn, QDialogButtonBox::ActionRole );
40 connect( pbn, SIGNAL( clicked() ),
this, SLOT(
test() ) );
42 pbn =
new QPushButton(
tr(
"&Clear" ) );
43 buttonBox->addButton( pbn, QDialogButtonBox::ActionRole );
44 connect( pbn, SIGNAL( clicked() ),
this, SLOT(
clear() ) );
52 lblDataUri->setText( layer->
name() );
61 settings.setValue(
"/Windows/QueryBuilder/geometry", saveGeometry() );
67 for (
int idx = 0; idx < fields.
count(); ++idx )
69 QStandardItem *myItem =
new QStandardItem( fields[idx].name() );
70 myItem->setData( idx );
71 myItem->setEditable(
false );
90 lstFields->setViewMode( QListView::ListMode );
91 lstValues->setViewMode( QListView::ListMode );
92 lstFields->setSelectionBehavior( QAbstractItemView::SelectRows );
93 lstValues->setSelectionBehavior( QAbstractItemView::SelectRows );
95 lstFields->setUniformItemSizes(
true );
96 lstValues->setUniformItemSizes(
true );
98 lstFields->setAlternatingRowColors(
true );
99 lstValues->setAlternatingRowColors(
true );
108 QList<QVariant> values;
112 QString nullValue = settings.value(
"qgis/nullValue",
"NULL" ).toString();
114 QgsDebugMsg( QString(
"nullValue: %1" ).arg( nullValue ) );
116 for (
int i = 0; i < values.size(); i++ )
122 value = values[i].toDate().toString(
"yyyy/MM/dd" );
124 value = values[i].toString();
126 QStandardItem *myItem =
new QStandardItem( value );
127 myItem->setEditable(
false );
128 myItem->setData( values[i], Qt::UserRole + 1 );
130 QgsDebugMsg( QString(
"Value is null: %1\nvalue: %2" ).arg( values[i].
isNull() ).arg( values[i].
isNull() ? nullValue : values[i].toString() ) );
136 lstValues->setCursor( Qt::WaitCursor );
139 if ( mUseUnfilteredLayer->isChecked() && !prevSubsetString.isEmpty() )
145 QStandardItemModel *tmp =
new QStandardItemModel();
146 lstValues->setModel( tmp );
158 lstValues->setCursor( Qt::ArrowCursor );
163 lstValues->setCursor( Qt::WaitCursor );
166 if ( mUseUnfilteredLayer->isChecked() && !prevSubsetString.isEmpty() )
172 QStandardItemModel *tmp =
new QStandardItemModel();
173 lstValues->setModel( tmp );
185 lstValues->setCursor( Qt::ArrowCursor );
198 QMessageBox::information(
this,
199 tr(
"Query Result" ),
204 QMessageBox::warning(
this,
205 tr(
"Query Failed" ),
206 tr(
"An error occurred when executing the query." )
212 QMessageBox::warning(
this,
213 tr(
"Query Failed" ),
214 tr(
"An error occurred when executing the query." ) );
225 QMessageBox::warning(
this,
226 tr(
"Query Failed" ),
227 tr(
"An error occurred when executing the query." )
233 QMessageBox::warning(
this,
tr(
"Error in Query" ),
tr(
"The subset string could not be set" ) );
252 txtSQL->insertPlainText(
" = " );
258 txtSQL->insertPlainText(
" < " );
264 txtSQL->insertPlainText(
" > " );
270 txtSQL->insertPlainText(
"%" );
276 txtSQL->insertPlainText(
" IN " );
282 txtSQL->insertPlainText(
" NOT IN " );
288 txtSQL->insertPlainText(
" LIKE " );
294 return txtSQL->toPlainText();
299 txtSQL->setText( sqlStatement );
308 btnSampleValues->setEnabled(
true );
309 btnGetAllValues->setEnabled(
true );
323 QVariant value =
mModelValues->data( index, Qt::UserRole + 1 );
324 if ( value.isNull() )
325 txtSQL->insertPlainText(
"NULL" );
327 txtSQL->insertPlainText(
"'" + value.toDate().toString(
"yyyy/MM/dd" ) +
"'" );
328 else if ( value.type() == QVariant::Int || value.type() == QVariant::Double || value.type() == QVariant::LongLong )
329 txtSQL->insertPlainText( value.toString() );
331 txtSQL->insertPlainText(
"'" + value.toString().replace(
"'",
"''" ) +
"'" );
338 txtSQL->insertPlainText(
" <= " );
344 txtSQL->insertPlainText(
" >= " );
350 txtSQL->insertPlainText(
" != " );
356 txtSQL->insertPlainText(
" AND " );
362 txtSQL->insertPlainText(
" NOT " );
368 txtSQL->insertPlainText(
" OR " );
376 mUseUnfilteredLayer->setDisabled(
true );
381 txtSQL->insertPlainText(
" ILIKE " );
387 lblDataUri->setText( uri );