Skip to content
Permalink
Browse files

[query builder] editor enhancements: QTextEdit => QgsCodeEditorSQL

  • Loading branch information
slarosa committed Sep 23, 2014
1 parent d37f75f commit da3516ca8743754437d51afa71e641a7cfb353b8
Showing with 52 additions and 47 deletions.
  1. +22 −22 src/gui/qgsquerybuilder.cpp
  2. +23 −23 src/gui/qgssearchquerybuilder.cpp
  3. +7 −2 src/ui/qgsquerybuilderbase.ui
@@ -197,7 +197,7 @@ void QgsQueryBuilder::test()
// by counting the number of records that would be
// returned

if ( mLayer->setSubsetString( txtSQL->toPlainText() ) )
if ( mLayer->setSubsetString( txtSQL->text() ) )
{
mUseUnfilteredLayer->setDisabled( mLayer->subsetString().isEmpty() );

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

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

void QgsQueryBuilder::on_btnEqual_clicked()
{
txtSQL->insertPlainText( " = " );
txtSQL->insertText( " = " );
txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnLessThan_clicked()
{
txtSQL->insertPlainText( " < " );
txtSQL->insertText( " < " );
txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnGreaterThan_clicked()
{
txtSQL->insertPlainText( " > " );
txtSQL->insertText( " > " );
txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnPct_clicked()
{
txtSQL->insertPlainText( "%" );
txtSQL->insertText( "%" );
txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnIn_clicked()
{
txtSQL->insertPlainText( " IN " );
txtSQL->insertText( " IN " );
txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnNotIn_clicked()
{
txtSQL->insertPlainText( " NOT IN " );
txtSQL->insertText( " NOT IN " );
txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnLike_clicked()
{
txtSQL->insertPlainText( " LIKE " );
txtSQL->insertText( " LIKE " );
txtSQL->setFocus();
}

QString QgsQueryBuilder::sql()
{
return txtSQL->toPlainText();
return txtSQL->text();
}

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

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

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

txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnLessEqual_clicked()
{
txtSQL->insertPlainText( " <= " );
txtSQL->insertText( " <= " );
txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnGreaterEqual_clicked()
{
txtSQL->insertPlainText( " >= " );
txtSQL->insertText( " >= " );
txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnNotEqual_clicked()
{
txtSQL->insertPlainText( " != " );
txtSQL->insertText( " != " );
txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnAnd_clicked()
{
txtSQL->insertPlainText( " AND " );
txtSQL->insertText( " AND " );
txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnNot_clicked()
{
txtSQL->insertPlainText( " NOT " );
txtSQL->insertText( " NOT " );
txtSQL->setFocus();
}

void QgsQueryBuilder::on_btnOr_clicked()
{
txtSQL->insertPlainText( " OR " );
txtSQL->insertText( " OR " );
txtSQL->setFocus();
}

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

void QgsQueryBuilder::on_btnILike_clicked()
{
txtSQL->insertPlainText( " ILIKE " );
txtSQL->insertText( " ILIKE " );
txtSQL->setFocus();
}

@@ -173,7 +173,7 @@ void QgsSearchQueryBuilder::on_btnGetAllValues_clicked()

void QgsSearchQueryBuilder::on_btnTest_clicked()
{
long count = countRecords( txtSQL->toPlainText() );
long count = countRecords( txtSQL->text() );

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

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

void QgsSearchQueryBuilder::on_btnEqual_clicked()
{
txtSQL->insertPlainText( " = " );
txtSQL->insertText( " = " );
}

void QgsSearchQueryBuilder::on_btnLessThan_clicked()
{
txtSQL->insertPlainText( " < " );
txtSQL->insertText( " < " );
}

void QgsSearchQueryBuilder::on_btnGreaterThan_clicked()
{
txtSQL->insertPlainText( " > " );
txtSQL->insertText( " > " );
}

void QgsSearchQueryBuilder::on_btnPct_clicked()
{
txtSQL->insertPlainText( "%" );
txtSQL->insertText( "%" );
}

void QgsSearchQueryBuilder::on_btnIn_clicked()
{
txtSQL->insertPlainText( " IN " );
txtSQL->insertText( " IN " );
}

void QgsSearchQueryBuilder::on_btnNotIn_clicked()
{
txtSQL->insertPlainText( " NOT IN " );
txtSQL->insertText( " NOT IN " );
}

void QgsSearchQueryBuilder::on_btnLike_clicked()
{
txtSQL->insertPlainText( " LIKE " );
txtSQL->insertText( " LIKE " );
}

QString QgsSearchQueryBuilder::searchString()
{
return txtSQL->toPlainText();
return txtSQL->text();
}

void QgsSearchQueryBuilder::setSearchString( QString searchString )
{
txtSQL->setPlainText( searchString );
txtSQL->setText( searchString );
}

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

void QgsSearchQueryBuilder::on_lstValues_doubleClicked( const QModelIndex &index )
{
txtSQL->insertPlainText( mModelValues->data( index ).toString() );
txtSQL->insertText( mModelValues->data( index ).toString() );
}

void QgsSearchQueryBuilder::on_btnLessEqual_clicked()
{
txtSQL->insertPlainText( " <= " );
txtSQL->insertText( " <= " );
}

void QgsSearchQueryBuilder::on_btnGreaterEqual_clicked()
{
txtSQL->insertPlainText( " >= " );
txtSQL->insertText( " >= " );
}

void QgsSearchQueryBuilder::on_btnNotEqual_clicked()
{
txtSQL->insertPlainText( " != " );
txtSQL->insertText( " != " );
}

void QgsSearchQueryBuilder::on_btnAnd_clicked()
{
txtSQL->insertPlainText( " AND " );
txtSQL->insertText( " AND " );
}

void QgsSearchQueryBuilder::on_btnNot_clicked()
{
txtSQL->insertPlainText( " NOT " );
txtSQL->insertText( " NOT " );
}

void QgsSearchQueryBuilder::on_btnOr_clicked()
{
txtSQL->insertPlainText( " OR " );
txtSQL->insertText( " OR " );
}

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

void QgsSearchQueryBuilder::on_btnILike_clicked()
{
txtSQL->insertPlainText( " ILIKE " );
txtSQL->insertText( " ILIKE " );
}

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

QDomDocument xmlDoc;
QDomElement queryElem = xmlDoc.createElement( "Query" );
QDomText queryTextNode = xmlDoc.createTextNode( txtSQL->toPlainText() );
QDomText queryTextNode = xmlDoc.createTextNode( txtSQL->text() );
queryElem.appendChild( queryTextNode );
xmlDoc.appendChild( queryElem );

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

txtSQL->clear();
txtSQL->insertPlainText( newQueryText );
txtSQL->insertText( newQueryText );
}

@@ -285,7 +285,7 @@ p, li { white-space: pre-wrap; }
<number>11</number>
</property>
<item row="0" column="0">
<widget class="QTextEdit" name="txtSQL"/>
<widget class="QgsCodeEditorSQL" name="txtSQL" native="true"/>
</item>
</layout>
</widget>
@@ -314,6 +314,12 @@ p, li { white-space: pre-wrap; }
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCodeEditorSQL</class>
<extends>QWidget</extends>
<header>qgscodeeditorsql.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>lstFields</tabstop>
@@ -334,7 +340,6 @@ p, li { white-space: pre-wrap; }
<tabstop>btnAnd</tabstop>
<tabstop>btnOr</tabstop>
<tabstop>btnNot</tabstop>
<tabstop>txtSQL</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>

0 comments on commit da3516c

Please sign in to comment.
You can’t perform that action at this time.