26 #include <QMessageBox> 
   29 #include <Qsci/qscilexer.h> 
   40   connect( mTablesCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsSQLComposerDialog::mTablesCombo_currentIndexChanged );
 
   41   connect( mColumnsCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsSQLComposerDialog::mColumnsCombo_currentIndexChanged );
 
   42   connect( mSpatialPredicatesCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsSQLComposerDialog::mSpatialPredicatesCombo_currentIndexChanged );
 
   43   connect( mFunctionsCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsSQLComposerDialog::mFunctionsCombo_currentIndexChanged );
 
   44   connect( mOperatorsCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsSQLComposerDialog::mOperatorsCombo_currentIndexChanged );
 
   45   connect( mAddJoinButton, &QPushButton::clicked, 
this, &QgsSQLComposerDialog::mAddJoinButton_clicked );
 
   46   connect( mRemoveJoinButton, &QPushButton::clicked, 
this, &QgsSQLComposerDialog::mRemoveJoinButton_clicked );
 
   47   connect( mTableJoins, &QTableWidget::itemSelectionChanged, 
this, &QgsSQLComposerDialog::mTableJoins_itemSelectionChanged );
 
   49   mQueryEdit->setWrapMode( QsciScintilla::WrapWord );
 
   50   mQueryEdit->installEventFilter( 
this );
 
   51   mColumnsEditor->installEventFilter( 
this );
 
   52   mTablesEditor->installEventFilter( 
this );
 
   53   mTableJoins->installEventFilter( 
this );
 
   54   mWhereEditor->installEventFilter( 
this );
 
   55   mOrderEditor->installEventFilter( 
this );
 
   56   mTablesCombo->view()->installEventFilter( 
this );
 
   59   connect( mButtonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
 
   60            this, &QgsSQLComposerDialog::reset );
 
   62   connect( mQueryEdit, &QsciScintilla::textChanged,
 
   63            this, &QgsSQLComposerDialog::splitSQLIntoFields );
 
   64   connect( mColumnsEditor, &QTextEdit::textChanged,
 
   65            this, &QgsSQLComposerDialog::buildSQLFromFields );
 
   66   connect( mTablesEditor, &QLineEdit::textChanged,
 
   67            this, &QgsSQLComposerDialog::buildSQLFromFields );
 
   68   connect( mWhereEditor, &QTextEdit::textChanged,
 
   69            this, &QgsSQLComposerDialog::buildSQLFromFields );
 
   70   connect( mOrderEditor, &QTextEdit::textChanged,
 
   71            this, &QgsSQLComposerDialog::buildSQLFromFields );
 
   72   connect( mTableJoins, &QTableWidget::cellChanged,
 
   73            this, &QgsSQLComposerDialog::buildSQLFromFields );
 
   74   connect( mButtonBox, &QDialogButtonBox::helpRequested,
 
   75            this, &QgsSQLComposerDialog::showHelp );
 
   78   baseList << QStringLiteral( 
"SELECT" );
 
   79   baseList << QStringLiteral( 
"FROM" );
 
   80   baseList << QStringLiteral( 
"JOIN" );
 
   81   baseList << QStringLiteral( 
"ON" );
 
   82   baseList << QStringLiteral( 
"USING" );
 
   83   baseList << QStringLiteral( 
"WHERE" );
 
   84   baseList << QStringLiteral( 
"AND" );
 
   85   baseList << QStringLiteral( 
"OR" );
 
   86   baseList << QStringLiteral( 
"NOT" );
 
   87   baseList << QStringLiteral( 
"IS" );
 
   88   baseList << QStringLiteral( 
"NULL" );
 
   89   baseList << QStringLiteral( 
"LIKE" );
 
   90   baseList << QStringLiteral( 
"ORDER" );
 
   91   baseList << QStringLiteral( 
"BY" );
 
   94   QStringList operatorsList;
 
   95   operatorsList << QStringLiteral( 
"AND" );
 
   96   operatorsList << QStringLiteral( 
"OR" );
 
   97   operatorsList << QStringLiteral( 
"NOT" );
 
   98   operatorsList << QStringLiteral( 
"=" );
 
   99   operatorsList << QStringLiteral( 
"<" );
 
  100   operatorsList << QStringLiteral( 
"<=" );
 
  101   operatorsList << QStringLiteral( 
">" );
 
  102   operatorsList << QStringLiteral( 
">=" );
 
  103   operatorsList << QStringLiteral( 
"<>" );
 
  104   operatorsList << QStringLiteral( 
"IS" );
 
  105   operatorsList << QStringLiteral( 
"IS NOT" );
 
  106   operatorsList << QStringLiteral( 
"IN" );
 
  107   operatorsList << QStringLiteral( 
"LIKE" );
 
  108   operatorsList << QStringLiteral( 
"BETWEEN" );
 
  111   mAggregatesCombo->hide();
 
  112   mFunctionsCombo->hide();
 
  113   mSpatialPredicatesCombo->hide();
 
  114   mStringFunctionsCombo->hide();
 
  116   delete mPageColumnsValues;
 
  117   mPageColumnsValues = 
nullptr;
 
  119   mRemoveJoinButton->setEnabled( 
false );
 
  121   mTableJoins->setRowCount( 0 );
 
  122   mTableJoins->setItem( 0, 0, 
new QTableWidgetItem( QString() ) );
 
  123   mTableJoins->setItem( 0, 1, 
new QTableWidgetItem( QString() ) );
 
  131   delete mQueryEdit->lexer()->apis();
 
  132   mQueryEdit->lexer()->setAPIs( 
nullptr );
 
  137   if ( event->type() == QEvent::FocusIn )
 
  139     if ( obj == mTablesCombo->view() )
 
  140       lastSearchedText.clear();
 
  142       mFocusedObject = obj;
 
  146   if ( event->type() == QEvent::KeyPress && obj == mTablesCombo->view() )
 
  148     QString currentString = ( ( QKeyEvent * )event )->text();
 
  149     if ( !currentString.isEmpty() && ( ( currentString[0] >= 
'a' && currentString[0] <= 
'z' ) ||
 
  150                                        ( currentString[0] >= 
'A' && currentString[0] <= 
'Z' ) ||
 
  151                                        ( currentString[0] >= 
'0' && currentString[0] <= 
'9' ) ||
 
  152                                        currentString[0] == 
':' || currentString[0] == 
'_' || currentString[0] == 
' ' ||
 
  153                                        currentString[0] == 
'(' || currentString[0] == 
')' ) )
 
  157       int attemptCount = ( lastSearchedText.isEmpty() ) ? 1 : 2;
 
  158       for ( 
int attempt = 0; attempt < attemptCount; attempt ++ )
 
  161           lastSearchedText += currentString;
 
  163           lastSearchedText = currentString;
 
  168         int iBestCandidate = 0;
 
  169         int idxInTextOfBestCandidate = 1000;
 
  170         for ( 
int i = 1; i < mTablesCombo->count(); i++ )
 
  172           int idxInText = mTablesCombo->itemText( i ).indexOf( lastSearchedText, Qt::CaseInsensitive );
 
  173           if ( idxInText >= 0 && idxInText < idxInTextOfBestCandidate )
 
  176             idxInTextOfBestCandidate = idxInText;
 
  179         if ( iBestCandidate > 0 )
 
  181           mTablesCombo->view()->setCurrentIndex( mTablesCombo->model()->index( 0, 0 ).sibling( iBestCandidate, 0 ) );
 
  185       lastSearchedText.clear();
 
  189   return QDialog::eventFilter( obj, event );
 
  194   mTableSelectedCallback = tableSelectedCallback;
 
  199   mSQLValidatorCallback = sqlValidatorCallback;
 
  205   mQueryEdit->setText( 
sql );
 
  210   return mQueryEdit->text();
 
  213 void QgsSQLComposerDialog::accept()
 
  215   if ( mSQLValidatorCallback )
 
  217     QString errorMsg, warningMsg;
 
  218     if ( !mSQLValidatorCallback->
isValid( 
sql(), errorMsg, warningMsg ) )
 
  220       if ( errorMsg.isEmpty() )
 
  221         errorMsg = tr( 
"An error occurred during evaluation of the SQL statement." );
 
  222       QMessageBox::critical( 
this, tr( 
"SQL Evaluation" ), errorMsg );
 
  225     if ( !warningMsg.isEmpty() )
 
  227       QMessageBox::warning( 
this, tr( 
"SQL Evaluation" ), warningMsg );
 
  237 void QgsSQLComposerDialog::buildSQLFromFields()
 
  239   if ( mAlreadyModifyingFields )
 
  241   mAlreadyModifyingFields = 
true;
 
  242   QString 
sql( QStringLiteral( 
"SELECT " ) );
 
  244     sql += QLatin1String( 
"DISTINCT " );
 
  245   sql += mColumnsEditor->toPlainText();
 
  246   sql += QLatin1String( 
" FROM " );
 
  247   sql += mTablesEditor->text();
 
  249   int rows = mTableJoins->rowCount();
 
  250   for ( 
int i = 0; i < rows; i++ )
 
  252     QTableWidgetItem *itemTable = mTableJoins->item( i, 0 );
 
  253     QTableWidgetItem *itemOn = mTableJoins->item( i, 1 );
 
  254     if ( itemTable && !itemTable->text().isEmpty() &&
 
  255          itemOn && !itemOn->text().isEmpty() )
 
  257       sql += QLatin1String( 
" JOIN " );
 
  258       sql += itemTable->text();
 
  259       sql += QLatin1String( 
" ON " );
 
  260       sql += itemOn->text();
 
  264   if ( !mWhereEditor->toPlainText().isEmpty() )
 
  266     sql += QLatin1String( 
" WHERE " );
 
  267     sql += mWhereEditor->toPlainText();
 
  269   if ( !mOrderEditor->toPlainText().isEmpty() )
 
  271     sql += QLatin1String( 
" ORDER BY " );
 
  272     sql += mOrderEditor->toPlainText();
 
  274   mQueryEdit->setText( 
sql );
 
  276   mAlreadyModifyingFields = 
false;
 
  279 void QgsSQLComposerDialog::splitSQLIntoFields()
 
  281   if ( mAlreadyModifyingFields )
 
  284   if ( 
sql.hasParserError() )
 
  290   QList<QgsSQLStatement::NodeSelectedColumn *> columns = nodeSelect->
columns();
 
  292   const auto constColumns = columns;
 
  295     if ( !columnText.isEmpty() )
 
  296       columnText += QLatin1String( 
", " );
 
  297     columnText += column->dump();
 
  300   QList<QgsSQLStatement::NodeTableDef *> tables = nodeSelect->
tables();
 
  302   const auto constTables = tables;
 
  305     if ( !tablesText.isEmpty() )
 
  306       tablesText += QLatin1String( 
", " );
 
  308     tablesText += table->dump();
 
  314     whereText = where->
dump();
 
  317   QList<QgsSQLStatement::NodeColumnSorted *> orderColumns = nodeSelect->
orderBy();
 
  318   const auto constOrderColumns = orderColumns;
 
  321     if ( !orderText.isEmpty() )
 
  322       orderText += QLatin1String( 
", " );
 
  323     orderText += column->dump();
 
  326   QList<QgsSQLStatement::NodeJoin *> joins = nodeSelect->
joins();
 
  328   mAlreadyModifyingFields = 
true;
 
  329   mColumnsEditor->setPlainText( columnText );
 
  330   mTablesEditor->setText( tablesText );
 
  331   mWhereEditor->setPlainText( whereText );
 
  332   mOrderEditor->setPlainText( orderText );
 
  334   mTableJoins->setRowCount( joins.size() + 1 );
 
  336   const auto constJoins = joins;
 
  340     mTableJoins->setItem( iRow, 0, 
new QTableWidgetItem( join->tableDef()->dump() ) );
 
  341     if ( join->onExpr() )
 
  342       mTableJoins->setItem( iRow, 1, 
new QTableWidgetItem( join->onExpr()->dump() ) );
 
  344       mTableJoins->setItem( iRow, 1, 
new QTableWidgetItem( QString() ) );
 
  347   mTableJoins->setItem( iRow, 0, 
new QTableWidgetItem( QString() ) );
 
  348   mTableJoins->setItem( iRow, 1, 
new QTableWidgetItem( QString() ) );
 
  350   mAlreadyModifyingFields = 
false;
 
  355   const auto constList = list;
 
  356   for ( 
const QString &name : constList )
 
  357     mapTableEntryTextToName[name] = name;
 
  358   mTablesCombo->addItems( list );
 
  364   QStringList listCombo;
 
  366   const auto constListNameTitle = listNameTitle;
 
  369     listApi << pair.first;
 
  370     QString entryText( pair.first );
 
  371     if ( !pair.second.isEmpty() && pair.second != pair.first )
 
  373       if ( pair.second.size() < 40 )
 
  374         entryText += 
" (" + pair.second + 
")";
 
  376         entryText += 
" (" + pair.second.mid( 0, 20 ) + QChar( 0x2026 ) + pair.second.mid( pair.second.size() - 20 ) + 
")";
 
  378     listCombo << entryText;
 
  379     mapTableEntryTextToName[entryText] = pair.first;
 
  381   mTablesCombo->addItems( listCombo );
 
  387   QList<PairNameType> listPair;
 
  388   const auto constList = list;
 
  389   for ( 
const QString &name : constList )
 
  394 static QString sanitizeType( QString type )
 
  396   if ( type.startsWith( QLatin1String( 
"xs:" ) ) )
 
  397     return type.mid( 3 );
 
  398   if ( type.startsWith( QLatin1String( 
"xsd:" ) ) )
 
  399     return type.mid( 4 );
 
  400   if ( type == QLatin1String( 
"gml:AbstractGeometryType" ) )
 
  401     return QStringLiteral( 
"geometry" );
 
  407   mAlreadySelectedTables.insert( tableName );
 
  408   if ( mColumnsCombo->count() > 1 )
 
  409     mColumnsCombo->insertSeparator( mColumnsCombo->count() );
 
  411   QStringList listCombo;
 
  413   const auto constList = list;
 
  416     listApi << pair.first;
 
  417     QString entryText( pair.first );
 
  418     if ( !pair.second.isEmpty() )
 
  420       entryText += 
" (" + sanitizeType( pair.second ) + 
")";
 
  422     listCombo << entryText;
 
  423     mapColumnEntryTextToName[entryText] = pair.first;
 
  425   mColumnsCombo->addItems( listCombo );
 
  432   mOperatorsCombo->addItems( list );
 
  440     return QObject::tr( 
"%1 to %2 arguments" ).arg( f.
minArgs ).arg( f.
maxArgs );
 
  448       return QObject::tr( 
"1 argument" );
 
  450       return QObject::tr( 
"%1 arguments" ).arg( f.
minArgs );
 
  455       return QObject::tr( 
"%1 arguments or more" ).arg( f.
minArgs );
 
  457       return QObject::tr( 
"1 argument or more" );
 
  459       return QObject::tr( 
"0 argument or more" );
 
  465 void QgsSQLComposerDialog::getFunctionList( 
const QList<Function> &list,
 
  466     QStringList &listApi,
 
  467     QStringList &listCombo,
 
  468     QMap<QString, QString> &mapEntryTextToName )
 
  470   const auto constList = list;
 
  471   for ( 
const Function &f : constList )
 
  474     QString entryText( f.
name );
 
  475     entryText += QLatin1Char( 
'(' );
 
  480         if ( f.
minArgs >= 0 && i >= f.
minArgs ) entryText += QLatin1Char( 
'[' );
 
  481         if ( i > 0 ) entryText += QLatin1String( 
", " );
 
  489           QString sanitizedType( sanitizeType( f.
argumentList[i].type ) );
 
  493             entryText += QLatin1String( 
": " );
 
  494             entryText += sanitizedType;
 
  497         if ( f.
minArgs >= 0 && i >= f.
minArgs ) entryText += QLatin1Char( 
']' );
 
  499       if ( entryText.size() > 60 )
 
  502         entryText += QLatin1Char( 
'(' );
 
  503         entryText += getFunctionAbbridgedParameters( f );
 
  508       entryText += getFunctionAbbridgedParameters( f );
 
  510     entryText += QLatin1Char( 
')' );
 
  512       entryText += 
": " + sanitizeType( f.
returnType );
 
  513     listCombo << entryText;
 
  514     mapEntryTextToName[entryText] = f.
name + 
"(";
 
  520   QList<Function> listFunction;
 
  521   const auto constList = list;
 
  522   for ( 
const QString &name : constList )
 
  534   QStringList listCombo;
 
  535   getFunctionList( list, listApi, listCombo, mapSpatialPredicateEntryTextToName );
 
  536   mSpatialPredicatesCombo->addItems( listCombo );
 
  537   mSpatialPredicatesCombo->show();
 
  543   QList<Function> listFunction;
 
  544   const auto constList = list;
 
  545   for ( 
const QString &name : constList )
 
  557   QStringList listCombo;
 
  558   getFunctionList( list, listApi, listCombo, mapFunctionEntryTextToName );
 
  559   mFunctionsCombo->addItems( listCombo );
 
  560   mFunctionsCombo->show();
 
  564 void QgsSQLComposerDialog::loadTableColumns( 
const QString &table )
 
  566   if ( mTableSelectedCallback )
 
  568     if ( !mAlreadySelectedTables.contains( table ) )
 
  571       mAlreadySelectedTables.insert( table );
 
  576 static void resetCombo( QComboBox *combo )
 
  583   QMetaObject::invokeMethod( combo, 
"setCurrentIndex", Qt::QueuedConnection, Q_ARG( 
int, 0 ) );
 
  586 void QgsSQLComposerDialog::mTablesCombo_currentIndexChanged( 
int )
 
  588   int index = mTablesCombo->currentIndex();
 
  591   QObject *obj = mFocusedObject;
 
  592   QString newText = mapTableEntryTextToName[mTablesCombo->currentText()];
 
  593   loadTableColumns( newText );
 
  594   if ( obj == mTablesEditor )
 
  596     QString currentText = mTablesEditor->text();
 
  597     if ( currentText.isEmpty() )
 
  598       mTablesEditor->setText( newText );
 
  600       mTablesEditor->setText( currentText + 
", " + newText );
 
  602   else if ( obj == mTableJoins )
 
  604     if ( mTableJoins->selectedItems().size() == 1 )
 
  606       mTableJoins->selectedItems().at( 0 )->setText( newText );
 
  609   else if ( obj == mWhereEditor )
 
  611     mWhereEditor->insertPlainText( newText );
 
  613   else if ( obj == mOrderEditor )
 
  615     mOrderEditor->insertPlainText( newText );
 
  617   else if ( obj == mQueryEdit )
 
  619     mQueryEdit->insertText( newText );
 
  621   resetCombo( mTablesCombo );
 
  624 void QgsSQLComposerDialog::mColumnsCombo_currentIndexChanged( 
int )
 
  626   int index = mColumnsCombo->currentIndex();
 
  629   QObject *obj = mFocusedObject;
 
  630   QString newText = mapColumnEntryTextToName[mColumnsCombo->currentText()];
 
  631   if ( obj == mColumnsEditor )
 
  633     QString currentText = mColumnsEditor->toPlainText();
 
  634     if ( currentText.isEmpty() )
 
  635       mColumnsEditor->insertPlainText( newText );
 
  637       mColumnsEditor->insertPlainText( 
",\n" + newText );
 
  639   else if ( obj == mTableJoins )
 
  641     if ( mTableJoins->selectedItems().size() == 1 &&
 
  642          mTableJoins->selectedItems().at( 0 )->column() == 1 )
 
  644       QString currentText( mTableJoins->selectedItems().at( 0 )->text() );
 
  645       if ( !currentText.isEmpty() && !currentText.contains( QLatin1String( 
"=" ) ) )
 
  646         mTableJoins->selectedItems().at( 0 )->setText( currentText + 
" = " + newText );
 
  648         mTableJoins->selectedItems().at( 0 )->setText( currentText + newText );
 
  651   else if ( obj == mWhereEditor )
 
  653     mWhereEditor->insertPlainText( newText );
 
  655   else if ( obj == mOrderEditor )
 
  657     mOrderEditor->insertPlainText( newText );
 
  659   else if ( obj == mQueryEdit )
 
  661     mQueryEdit->insertText( newText );
 
  663   resetCombo( mColumnsCombo );
 
  666 void QgsSQLComposerDialog::mFunctionsCombo_currentIndexChanged( 
int )
 
  668   functionCurrentIndexChanged( mFunctionsCombo, mapFunctionEntryTextToName );
 
  671 void QgsSQLComposerDialog::mSpatialPredicatesCombo_currentIndexChanged( 
int )
 
  673   functionCurrentIndexChanged( mSpatialPredicatesCombo, mapSpatialPredicateEntryTextToName );
 
  676 void QgsSQLComposerDialog::functionCurrentIndexChanged( QComboBox *combo,
 
  677     const QMap<QString, QString> &mapEntryTextToName )
 
  679   int index = combo->currentIndex();
 
  682   QObject *obj = mFocusedObject;
 
  683   QString newText = mapEntryTextToName[combo->currentText()];
 
  684   if ( obj == mColumnsEditor )
 
  686     mColumnsEditor->insertPlainText( newText );
 
  688   else if ( obj == mWhereEditor )
 
  690     mWhereEditor->insertPlainText( newText );
 
  692   else if ( obj == mQueryEdit )
 
  694     mQueryEdit->insertText( newText );
 
  699 void QgsSQLComposerDialog::mOperatorsCombo_currentIndexChanged( 
int )
 
  701   int index = mOperatorsCombo->currentIndex();
 
  704   QObject *obj = mFocusedObject;
 
  705   QString newText = mOperatorsCombo->currentText();
 
  706   if ( obj == mColumnsEditor )
 
  708     mColumnsEditor->insertPlainText( newText );
 
  710   else if ( obj == mWhereEditor )
 
  712     mWhereEditor->insertPlainText( newText );
 
  714   else if ( obj == mTableJoins )
 
  716     if ( mTableJoins->selectedItems().size() == 1 &&
 
  717          mTableJoins->selectedItems().at( 0 )->column() == 1 )
 
  719       QString currentText( mTableJoins->selectedItems().at( 0 )->text() );
 
  720       mTableJoins->selectedItems().at( 0 )->setText( currentText + newText );
 
  723   else if ( obj == mQueryEdit )
 
  725     mQueryEdit->insertText( newText );
 
  727   resetCombo( mOperatorsCombo );
 
  730 void QgsSQLComposerDialog::mAddJoinButton_clicked()
 
  732   int insertRow = mTableJoins->currentRow();
 
  733   int rowCount = mTableJoins->rowCount();
 
  735     insertRow = rowCount;
 
  736   mTableJoins->setRowCount( rowCount + 1 );
 
  737   for ( 
int row = rowCount ; row > insertRow + 1; row -- )
 
  739     mTableJoins->setItem( row, 0, mTableJoins->takeItem( row - 1, 0 ) );
 
  740     mTableJoins->setItem( row, 1, mTableJoins->takeItem( row - 1, 1 ) );
 
  742   mTableJoins->setItem( ( insertRow == rowCount ) ? insertRow : insertRow + 1, 0, 
new QTableWidgetItem( QString() ) );
 
  743   mTableJoins->setItem( ( insertRow == rowCount ) ? insertRow : insertRow + 1, 1, 
new QTableWidgetItem( QString() ) );
 
  746 void QgsSQLComposerDialog::mRemoveJoinButton_clicked()
 
  748   int row = mTableJoins->currentRow();
 
  751   int rowCount = mTableJoins->rowCount();
 
  752   for ( ; row < rowCount - 1; row ++ )
 
  754     mTableJoins->setItem( row, 0, mTableJoins->takeItem( row + 1, 0 ) );
 
  755     mTableJoins->setItem( row, 1, mTableJoins->takeItem( row + 1, 1 ) );
 
  757   mTableJoins->setRowCount( rowCount - 1 );
 
  759   buildSQLFromFields();
 
  762 void QgsSQLComposerDialog::reset()
 
  764   mQueryEdit->setText( mResetSql );
 
  767 void QgsSQLComposerDialog::mTableJoins_itemSelectionChanged()
 
  769   mRemoveJoinButton->setEnabled( mTableJoins->selectedItems().size() == 1 );
 
  776   delete mQueryEdit->lexer()->apis();
 
  777   QsciAPIs *apis = 
new QsciAPIs( mQueryEdit->lexer() );
 
  779   const auto constMApiList = mApiList;
 
  780   for ( 
const QString &
str : constMApiList )
 
  786   mQueryEdit->lexer()->setAPIs( apis );
 
  791   mJoinsLabels->setVisible( on );
 
  792   mTableJoins->setVisible( on );
 
  793   mAddJoinButton->setVisible( on );
 
  794   mRemoveJoinButton->setVisible( on );
 
  795   mTablesCombo->setVisible( on );
 
  797   QString mainTypenameFormatted;
 
  798   if ( !mainTypename.isEmpty() )
 
  799     mainTypenameFormatted = 
" (" + mainTypename + 
")";
 
  800   mQueryEdit->setToolTip( tr( 
"This is the SQL query editor. The SQL statement can select data from several tables, \n" 
  801                               "but it must compulsory include the main typename%1 in the selected tables, \n" 
  802                               "and only the geometry column of the main typename can be used as the geometry column of the resulting layer." ).arg( mainTypenameFormatted ) );
 
  805 void QgsSQLComposerDialog::showHelp()
 
  807   QgsHelp::openHelp( QStringLiteral( 
"working_with_ogc/ogc_client_support.html#ogc-wfs" ) );
 
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Callback to do validation check on dialog validation.
virtual bool isValid(const QString &sql, QString &errorReason, QString &warningMsg)=0
method should return true if the SQL is valid. Otherwise return false and set the errorReason
Callback to do actions on table selection.
virtual void tableSelected(const QString &name)=0
method called when a table is selected
bool eventFilter(QObject *obj, QEvent *event) override
QgsSQLComposerDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
constructor
void addSpatialPredicates(const QStringList &list)
add a list of spatial predicates
void setSQLValidatorCallback(SQLValidatorCallback *sqlValidatorCallback)
Set a callback that will be called when the OK button is pushed.
void setTableSelectedCallback(TableSelectedCallback *tableSelectedCallback)
Set a callback that will be called when a new table is selected, so that new column names can be adde...
QPair< QString, QString > PairNameType
pair (name, type)
void addOperators(const QStringList &list)
add a list of operators
~QgsSQLComposerDialog() override
void addColumnNames(const QStringList &list, const QString &tableName)
add a list of column names
void setSupportMultipleTables(bool bMultipleTables, const QString &mainTypename=QString())
Sets if multiple tables/joins are supported. Default is false.
void addApis(const QStringList &list)
add a list of API for autocompletion
void setSql(const QString &sql)
initialize the SQL statement
void addFunctions(const QStringList &list)
add a list of functions
void addTableNames(const QStringList &list)
add a list of table names
QPair< QString, QString > PairNameTitle
pair (name, title)
QString sql() const
Gets the SQL statement.
QgsSQLStatement::Node * where() const
Returns the where clause.
bool distinct() const
Returns if the SELECT is DISTINCT.
QList< QgsSQLStatement::NodeSelectedColumn * > columns() const
Returns the list of columns.
QList< QgsSQLStatement::NodeColumnSorted * > orderBy() const
Returns the list of order by columns.
QList< QgsSQLStatement::NodeJoin * > joins() const
Returns the list of joins.
QList< QgsSQLStatement::NodeTableDef * > tables() const
Returns the list of tables.
virtual QString dump() const =0
Abstract virtual dump method.
Class for parsing SQL statements.
static QString quotedIdentifierIfNeeded(const QString &name)
Returns a quoted column reference (in double quotes) if needed, or otherwise the original string.
Interface for a dialog that can edit subset strings.
Represents a vector layer which manages a vector based data sets.
virtual bool setSubsetString(const QString &subset)
Sets the string (typically sql) used to define a subset of the layer.
description of server functions
QString returnType
Returns type, or empty if unknown.
int maxArgs
maximum number of argument (or -1 if unknown)
int minArgs
minimum number of argument (or -1 if unknown)
QList< Argument > argumentList
list of arguments. May be empty despite minArgs > 0