Skip to content

Commit a111c85

Browse files
committed
Merge pull request #1590 from slarosa/query_builder_enhanchements
[query builder] editor enhancements: QTextEdit => QgsCodeEditorSQL
2 parents f1de497 + da3516c commit a111c85

File tree

3 files changed

+52
-47
lines changed

3 files changed

+52
-47
lines changed

src/gui/qgsquerybuilder.cpp

+22-22
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void QgsQueryBuilder::test()
197197
// by counting the number of records that would be
198198
// returned
199199

200-
if ( mLayer->setSubsetString( txtSQL->toPlainText() ) )
200+
if ( mLayer->setSubsetString( txtSQL->text() ) )
201201
{
202202
mUseUnfilteredLayer->setDisabled( mLayer->subsetString().isEmpty() );
203203

@@ -223,7 +223,7 @@ void QgsQueryBuilder::test()
223223

224224
void QgsQueryBuilder::accept()
225225
{
226-
if ( !mLayer->setSubsetString( txtSQL->toPlainText() ) )
226+
if ( !mLayer->setSubsetString( txtSQL->text() ) )
227227
{
228228
//error in query - show the problem
229229
if ( mLayer->dataProvider()->hasErrors() )
@@ -255,49 +255,49 @@ void QgsQueryBuilder::reject()
255255

256256
void QgsQueryBuilder::on_btnEqual_clicked()
257257
{
258-
txtSQL->insertPlainText( " = " );
258+
txtSQL->insertText( " = " );
259259
txtSQL->setFocus();
260260
}
261261

262262
void QgsQueryBuilder::on_btnLessThan_clicked()
263263
{
264-
txtSQL->insertPlainText( " < " );
264+
txtSQL->insertText( " < " );
265265
txtSQL->setFocus();
266266
}
267267

268268
void QgsQueryBuilder::on_btnGreaterThan_clicked()
269269
{
270-
txtSQL->insertPlainText( " > " );
270+
txtSQL->insertText( " > " );
271271
txtSQL->setFocus();
272272
}
273273

274274
void QgsQueryBuilder::on_btnPct_clicked()
275275
{
276-
txtSQL->insertPlainText( "%" );
276+
txtSQL->insertText( "%" );
277277
txtSQL->setFocus();
278278
}
279279

280280
void QgsQueryBuilder::on_btnIn_clicked()
281281
{
282-
txtSQL->insertPlainText( " IN " );
282+
txtSQL->insertText( " IN " );
283283
txtSQL->setFocus();
284284
}
285285

286286
void QgsQueryBuilder::on_btnNotIn_clicked()
287287
{
288-
txtSQL->insertPlainText( " NOT IN " );
288+
txtSQL->insertText( " NOT IN " );
289289
txtSQL->setFocus();
290290
}
291291

292292
void QgsQueryBuilder::on_btnLike_clicked()
293293
{
294-
txtSQL->insertPlainText( " LIKE " );
294+
txtSQL->insertText( " LIKE " );
295295
txtSQL->setFocus();
296296
}
297297

298298
QString QgsQueryBuilder::sql()
299299
{
300-
return txtSQL->toPlainText();
300+
return txtSQL->text();
301301
}
302302

303303
void QgsQueryBuilder::setSql( QString sqlStatement )
@@ -320,58 +320,58 @@ void QgsQueryBuilder::on_lstFields_clicked( const QModelIndex &index )
320320

321321
void QgsQueryBuilder::on_lstFields_doubleClicked( const QModelIndex &index )
322322
{
323-
txtSQL->insertPlainText( "\"" + mLayer->pendingFields()[ mModelFields->data( index, Qt::UserRole+1 ).toInt()].name() + "\"" );
323+
txtSQL->insertText( "\"" + mLayer->pendingFields()[ mModelFields->data( index, Qt::UserRole+1 ).toInt()].name() + "\"" );
324324
txtSQL->setFocus();
325325
}
326326

327327
void QgsQueryBuilder::on_lstValues_doubleClicked( const QModelIndex &index )
328328
{
329329
QVariant value = mModelValues->data( index, Qt::UserRole + 1 );
330330
if ( value.isNull() )
331-
txtSQL->insertPlainText( "NULL" );
331+
txtSQL->insertText( "NULL" );
332332
else if ( value.type() == QVariant::Date && mLayer->providerType() == "ogr" && mLayer->storageType() == "ESRI Shapefile" )
333-
txtSQL->insertPlainText( "'" + value.toDate().toString( "yyyy/MM/dd" ) + "'" );
333+
txtSQL->insertText( "'" + value.toDate().toString( "yyyy/MM/dd" ) + "'" );
334334
else if ( value.type() == QVariant::Int || value.type() == QVariant::Double || value.type() == QVariant::LongLong )
335-
txtSQL->insertPlainText( value.toString() );
335+
txtSQL->insertText( value.toString() );
336336
else
337-
txtSQL->insertPlainText( "'" + value.toString().replace( "'", "''" ) + "'" );
337+
txtSQL->insertText( "'" + value.toString().replace( "'", "''" ) + "'" );
338338

339339
txtSQL->setFocus();
340340
}
341341

342342
void QgsQueryBuilder::on_btnLessEqual_clicked()
343343
{
344-
txtSQL->insertPlainText( " <= " );
344+
txtSQL->insertText( " <= " );
345345
txtSQL->setFocus();
346346
}
347347

348348
void QgsQueryBuilder::on_btnGreaterEqual_clicked()
349349
{
350-
txtSQL->insertPlainText( " >= " );
350+
txtSQL->insertText( " >= " );
351351
txtSQL->setFocus();
352352
}
353353

354354
void QgsQueryBuilder::on_btnNotEqual_clicked()
355355
{
356-
txtSQL->insertPlainText( " != " );
356+
txtSQL->insertText( " != " );
357357
txtSQL->setFocus();
358358
}
359359

360360
void QgsQueryBuilder::on_btnAnd_clicked()
361361
{
362-
txtSQL->insertPlainText( " AND " );
362+
txtSQL->insertText( " AND " );
363363
txtSQL->setFocus();
364364
}
365365

366366
void QgsQueryBuilder::on_btnNot_clicked()
367367
{
368-
txtSQL->insertPlainText( " NOT " );
368+
txtSQL->insertText( " NOT " );
369369
txtSQL->setFocus();
370370
}
371371

372372
void QgsQueryBuilder::on_btnOr_clicked()
373373
{
374-
txtSQL->insertPlainText( " OR " );
374+
txtSQL->insertText( " OR " );
375375
txtSQL->setFocus();
376376
}
377377

@@ -384,7 +384,7 @@ void QgsQueryBuilder::clear()
384384

385385
void QgsQueryBuilder::on_btnILike_clicked()
386386
{
387-
txtSQL->insertPlainText( " ILIKE " );
387+
txtSQL->insertText( " ILIKE " );
388388
txtSQL->setFocus();
389389
}
390390

src/gui/qgssearchquerybuilder.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void QgsSearchQueryBuilder::on_btnGetAllValues_clicked()
173173

174174
void QgsSearchQueryBuilder::on_btnTest_clicked()
175175
{
176-
long count = countRecords( txtSQL->toPlainText() );
176+
long count = countRecords( txtSQL->text() );
177177

178178
// error?
179179
if ( count == -1 )
@@ -239,14 +239,14 @@ long QgsSearchQueryBuilder::countRecords( QString searchString )
239239
void QgsSearchQueryBuilder::on_btnOk_clicked()
240240
{
241241
// if user hits Ok and there is no query, skip the validation
242-
if ( txtSQL->toPlainText().trimmed().length() > 0 )
242+
if ( txtSQL->text().trimmed().length() > 0 )
243243
{
244244
accept();
245245
return;
246246
}
247247

248248
// test the query to see if it will result in a valid layer
249-
long numRecs = countRecords( txtSQL->toPlainText() );
249+
long numRecs = countRecords( txtSQL->text() );
250250
if ( numRecs == -1 )
251251
{
252252
// error shown in countRecords
@@ -264,87 +264,87 @@ void QgsSearchQueryBuilder::on_btnOk_clicked()
264264

265265
void QgsSearchQueryBuilder::on_btnEqual_clicked()
266266
{
267-
txtSQL->insertPlainText( " = " );
267+
txtSQL->insertText( " = " );
268268
}
269269

270270
void QgsSearchQueryBuilder::on_btnLessThan_clicked()
271271
{
272-
txtSQL->insertPlainText( " < " );
272+
txtSQL->insertText( " < " );
273273
}
274274

275275
void QgsSearchQueryBuilder::on_btnGreaterThan_clicked()
276276
{
277-
txtSQL->insertPlainText( " > " );
277+
txtSQL->insertText( " > " );
278278
}
279279

280280
void QgsSearchQueryBuilder::on_btnPct_clicked()
281281
{
282-
txtSQL->insertPlainText( "%" );
282+
txtSQL->insertText( "%" );
283283
}
284284

285285
void QgsSearchQueryBuilder::on_btnIn_clicked()
286286
{
287-
txtSQL->insertPlainText( " IN " );
287+
txtSQL->insertText( " IN " );
288288
}
289289

290290
void QgsSearchQueryBuilder::on_btnNotIn_clicked()
291291
{
292-
txtSQL->insertPlainText( " NOT IN " );
292+
txtSQL->insertText( " NOT IN " );
293293
}
294294

295295
void QgsSearchQueryBuilder::on_btnLike_clicked()
296296
{
297-
txtSQL->insertPlainText( " LIKE " );
297+
txtSQL->insertText( " LIKE " );
298298
}
299299

300300
QString QgsSearchQueryBuilder::searchString()
301301
{
302-
return txtSQL->toPlainText();
302+
return txtSQL->text();
303303
}
304304

305305
void QgsSearchQueryBuilder::setSearchString( QString searchString )
306306
{
307-
txtSQL->setPlainText( searchString );
307+
txtSQL->setText( searchString );
308308
}
309309

310310
void QgsSearchQueryBuilder::on_lstFields_doubleClicked( const QModelIndex &index )
311311
{
312-
txtSQL->insertPlainText( QgsExpression::quotedColumnRef( mModelFields->data( index ).toString() ) );
312+
txtSQL->insertText( QgsExpression::quotedColumnRef( mModelFields->data( index ).toString() ) );
313313
}
314314

315315
void QgsSearchQueryBuilder::on_lstValues_doubleClicked( const QModelIndex &index )
316316
{
317-
txtSQL->insertPlainText( mModelValues->data( index ).toString() );
317+
txtSQL->insertText( mModelValues->data( index ).toString() );
318318
}
319319

320320
void QgsSearchQueryBuilder::on_btnLessEqual_clicked()
321321
{
322-
txtSQL->insertPlainText( " <= " );
322+
txtSQL->insertText( " <= " );
323323
}
324324

325325
void QgsSearchQueryBuilder::on_btnGreaterEqual_clicked()
326326
{
327-
txtSQL->insertPlainText( " >= " );
327+
txtSQL->insertText( " >= " );
328328
}
329329

330330
void QgsSearchQueryBuilder::on_btnNotEqual_clicked()
331331
{
332-
txtSQL->insertPlainText( " != " );
332+
txtSQL->insertText( " != " );
333333
}
334334

335335
void QgsSearchQueryBuilder::on_btnAnd_clicked()
336336
{
337-
txtSQL->insertPlainText( " AND " );
337+
txtSQL->insertText( " AND " );
338338
}
339339

340340
void QgsSearchQueryBuilder::on_btnNot_clicked()
341341
{
342-
txtSQL->insertPlainText( " NOT " );
342+
txtSQL->insertText( " NOT " );
343343
}
344344

345345
void QgsSearchQueryBuilder::on_btnOr_clicked()
346346
{
347-
txtSQL->insertPlainText( " OR " );
347+
txtSQL->insertText( " OR " );
348348
}
349349

350350
void QgsSearchQueryBuilder::on_btnClear_clicked()
@@ -354,7 +354,7 @@ void QgsSearchQueryBuilder::on_btnClear_clicked()
354354

355355
void QgsSearchQueryBuilder::on_btnILike_clicked()
356356
{
357-
txtSQL->insertPlainText( " ILIKE " );
357+
txtSQL->insertText( " ILIKE " );
358358
}
359359

360360
void QgsSearchQueryBuilder::saveQuery()
@@ -382,7 +382,7 @@ void QgsSearchQueryBuilder::saveQuery()
382382

383383
QDomDocument xmlDoc;
384384
QDomElement queryElem = xmlDoc.createElement( "Query" );
385-
QDomText queryTextNode = xmlDoc.createTextNode( txtSQL->toPlainText() );
385+
QDomText queryTextNode = xmlDoc.createTextNode( txtSQL->text() );
386386
queryElem.appendChild( queryTextNode );
387387
xmlDoc.appendChild( queryElem );
388388

@@ -487,6 +487,6 @@ void QgsSearchQueryBuilder::loadQuery()
487487
#endif
488488

489489
txtSQL->clear();
490-
txtSQL->insertPlainText( newQueryText );
490+
txtSQL->insertText( newQueryText );
491491
}
492492

src/ui/qgsquerybuilderbase.ui

+7-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ p, li { white-space: pre-wrap; }
285285
<number>11</number>
286286
</property>
287287
<item row="0" column="0">
288-
<widget class="QTextEdit" name="txtSQL"/>
288+
<widget class="QgsCodeEditorSQL" name="txtSQL" native="true"/>
289289
</item>
290290
</layout>
291291
</widget>
@@ -314,6 +314,12 @@ p, li { white-space: pre-wrap; }
314314
<header>qgscollapsiblegroupbox.h</header>
315315
<container>1</container>
316316
</customwidget>
317+
<customwidget>
318+
<class>QgsCodeEditorSQL</class>
319+
<extends>QWidget</extends>
320+
<header>qgscodeeditorsql.h</header>
321+
<container>1</container>
322+
</customwidget>
317323
</customwidgets>
318324
<tabstops>
319325
<tabstop>lstFields</tabstop>
@@ -334,7 +340,6 @@ p, li { white-space: pre-wrap; }
334340
<tabstop>btnAnd</tabstop>
335341
<tabstop>btnOr</tabstop>
336342
<tabstop>btnNot</tabstop>
337-
<tabstop>txtSQL</tabstop>
338343
<tabstop>buttonBox</tabstop>
339344
</tabstops>
340345
<resources/>

0 commit comments

Comments
 (0)