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       const 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           const 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   const 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   const QList<QgsSQLStatement::NodeSelectedColumn *> columns = nodeSelect->
columns();
 
  292   const auto constColumns = columns;
 
  295     if ( !columnText.isEmpty() )
 
  296       columnText += QLatin1String( 
", " );
 
  297     columnText += column->dump();
 
  300   const 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   const QList<QgsSQLStatement::NodeColumnSorted *> orderColumns = nodeSelect->
orderBy();
 
  318   const auto constOrderColumns = orderColumns;
 
  321     if ( !orderText.isEmpty() )
 
  322       orderText += QLatin1String( 
", " );
 
  323     orderText += column->dump();
 
  326   const 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 );
 
  447     return QObject::tr( 
"%n argument(s)", 
nullptr, f.
minArgs );
 
  451     return QObject::tr( 
"%n argument(s) or more", 
nullptr, f.
minArgs );
 
  457 void QgsSQLComposerDialog::getFunctionList( 
const QList<Function> &list,
 
  458     QStringList &listApi,
 
  459     QStringList &listCombo,
 
  460     QMap<QString, QString> &mapEntryTextToName )
 
  462   const auto constList = list;
 
  463   for ( 
const Function &f : constList )
 
  466     QString entryText( f.
name );
 
  467     entryText += QLatin1Char( 
'(' );
 
  472         if ( f.
minArgs >= 0 && i >= f.
minArgs ) entryText += QLatin1Char( 
'[' );
 
  473         if ( i > 0 ) entryText += QLatin1String( 
", " );
 
  481           const QString sanitizedType( sanitizeType( f.
argumentList[i].type ) );
 
  485             entryText += QLatin1String( 
": " );
 
  486             entryText += sanitizedType;
 
  489         if ( f.
minArgs >= 0 && i >= f.
minArgs ) entryText += QLatin1Char( 
']' );
 
  491       if ( entryText.size() > 60 )
 
  494         entryText += QLatin1Char( 
'(' );
 
  495         entryText += getFunctionAbbridgedParameters( f );
 
  500       entryText += getFunctionAbbridgedParameters( f );
 
  502     entryText += QLatin1Char( 
')' );
 
  504       entryText += 
": " + sanitizeType( f.
returnType );
 
  505     listCombo << entryText;
 
  506     mapEntryTextToName[entryText] = f.
name + 
"(";
 
  512   QList<Function> listFunction;
 
  513   const auto constList = list;
 
  514   for ( 
const QString &name : constList )
 
  526   QStringList listCombo;
 
  527   getFunctionList( list, listApi, listCombo, mapSpatialPredicateEntryTextToName );
 
  528   mSpatialPredicatesCombo->addItems( listCombo );
 
  529   mSpatialPredicatesCombo->show();
 
  535   QList<Function> listFunction;
 
  536   const auto constList = list;
 
  537   for ( 
const QString &name : constList )
 
  549   QStringList listCombo;
 
  550   getFunctionList( list, listApi, listCombo, mapFunctionEntryTextToName );
 
  551   mFunctionsCombo->addItems( listCombo );
 
  552   mFunctionsCombo->show();
 
  556 void QgsSQLComposerDialog::loadTableColumns( 
const QString &table )
 
  558   if ( mTableSelectedCallback )
 
  560     if ( !mAlreadySelectedTables.contains( table ) )
 
  563       mAlreadySelectedTables.insert( table );
 
  568 static void resetCombo( QComboBox *combo )
 
  575   QMetaObject::invokeMethod( combo, 
"setCurrentIndex", Qt::QueuedConnection, Q_ARG( 
int, 0 ) );
 
  578 void QgsSQLComposerDialog::mTablesCombo_currentIndexChanged( 
int )
 
  580   const int index = mTablesCombo->currentIndex();
 
  583   QObject *obj = mFocusedObject;
 
  584   const QString newText = mapTableEntryTextToName[mTablesCombo->currentText()];
 
  585   loadTableColumns( newText );
 
  586   if ( obj == mTablesEditor )
 
  588     const QString currentText = mTablesEditor->text();
 
  589     if ( currentText.isEmpty() )
 
  590       mTablesEditor->setText( newText );
 
  592       mTablesEditor->setText( currentText + 
", " + newText );
 
  594   else if ( obj == mTableJoins )
 
  596     if ( mTableJoins->selectedItems().size() == 1 )
 
  598       mTableJoins->selectedItems().at( 0 )->setText( newText );
 
  601   else if ( obj == mWhereEditor )
 
  603     mWhereEditor->insertPlainText( newText );
 
  605   else if ( obj == mOrderEditor )
 
  607     mOrderEditor->insertPlainText( newText );
 
  609   else if ( obj == mQueryEdit )
 
  611     mQueryEdit->insertText( newText );
 
  613   resetCombo( mTablesCombo );
 
  616 void QgsSQLComposerDialog::mColumnsCombo_currentIndexChanged( 
int )
 
  618   const int index = mColumnsCombo->currentIndex();
 
  621   QObject *obj = mFocusedObject;
 
  622   const QString newText = mapColumnEntryTextToName[mColumnsCombo->currentText()];
 
  623   if ( obj == mColumnsEditor )
 
  625     const QString currentText = mColumnsEditor->toPlainText();
 
  626     if ( currentText.isEmpty() )
 
  627       mColumnsEditor->insertPlainText( newText );
 
  629       mColumnsEditor->insertPlainText( 
",\n" + newText );
 
  631   else if ( obj == mTableJoins )
 
  633     if ( mTableJoins->selectedItems().size() == 1 &&
 
  634          mTableJoins->selectedItems().at( 0 )->column() == 1 )
 
  636       const QString currentText( mTableJoins->selectedItems().at( 0 )->text() );
 
  637       if ( !currentText.isEmpty() && !currentText.contains( QLatin1String( 
"=" ) ) )
 
  638         mTableJoins->selectedItems().at( 0 )->setText( currentText + 
" = " + newText );
 
  640         mTableJoins->selectedItems().at( 0 )->setText( currentText + newText );
 
  643   else if ( obj == mWhereEditor )
 
  645     mWhereEditor->insertPlainText( newText );
 
  647   else if ( obj == mOrderEditor )
 
  649     mOrderEditor->insertPlainText( newText );
 
  651   else if ( obj == mQueryEdit )
 
  653     mQueryEdit->insertText( newText );
 
  655   resetCombo( mColumnsCombo );
 
  658 void QgsSQLComposerDialog::mFunctionsCombo_currentIndexChanged( 
int )
 
  660   functionCurrentIndexChanged( mFunctionsCombo, mapFunctionEntryTextToName );
 
  663 void QgsSQLComposerDialog::mSpatialPredicatesCombo_currentIndexChanged( 
int )
 
  665   functionCurrentIndexChanged( mSpatialPredicatesCombo, mapSpatialPredicateEntryTextToName );
 
  668 void QgsSQLComposerDialog::functionCurrentIndexChanged( QComboBox *combo,
 
  669     const QMap<QString, QString> &mapEntryTextToName )
 
  671   const int index = combo->currentIndex();
 
  674   QObject *obj = mFocusedObject;
 
  675   const QString newText = mapEntryTextToName[combo->currentText()];
 
  676   if ( obj == mColumnsEditor )
 
  678     mColumnsEditor->insertPlainText( newText );
 
  680   else if ( obj == mWhereEditor )
 
  682     mWhereEditor->insertPlainText( newText );
 
  684   else if ( obj == mQueryEdit )
 
  686     mQueryEdit->insertText( newText );
 
  691 void QgsSQLComposerDialog::mOperatorsCombo_currentIndexChanged( 
int )
 
  693   const int index = mOperatorsCombo->currentIndex();
 
  696   QObject *obj = mFocusedObject;
 
  697   const QString newText = mOperatorsCombo->currentText();
 
  698   if ( obj == mColumnsEditor )
 
  700     mColumnsEditor->insertPlainText( newText );
 
  702   else if ( obj == mWhereEditor )
 
  704     mWhereEditor->insertPlainText( newText );
 
  706   else if ( obj == mTableJoins )
 
  708     if ( mTableJoins->selectedItems().size() == 1 &&
 
  709          mTableJoins->selectedItems().at( 0 )->column() == 1 )
 
  711       const QString currentText( mTableJoins->selectedItems().at( 0 )->text() );
 
  712       mTableJoins->selectedItems().at( 0 )->setText( currentText + newText );
 
  715   else if ( obj == mQueryEdit )
 
  717     mQueryEdit->insertText( newText );
 
  719   resetCombo( mOperatorsCombo );
 
  722 void QgsSQLComposerDialog::mAddJoinButton_clicked()
 
  724   int insertRow = mTableJoins->currentRow();
 
  725   const int rowCount = mTableJoins->rowCount();
 
  727     insertRow = rowCount;
 
  728   mTableJoins->setRowCount( rowCount + 1 );
 
  729   for ( 
int row = rowCount ; row > insertRow + 1; row -- )
 
  731     mTableJoins->setItem( row, 0, mTableJoins->takeItem( row - 1, 0 ) );
 
  732     mTableJoins->setItem( row, 1, mTableJoins->takeItem( row - 1, 1 ) );
 
  734   mTableJoins->setItem( ( insertRow == rowCount ) ? insertRow : insertRow + 1, 0, 
new QTableWidgetItem( QString() ) );
 
  735   mTableJoins->setItem( ( insertRow == rowCount ) ? insertRow : insertRow + 1, 1, 
new QTableWidgetItem( QString() ) );
 
  738 void QgsSQLComposerDialog::mRemoveJoinButton_clicked()
 
  740   int row = mTableJoins->currentRow();
 
  743   const int rowCount = mTableJoins->rowCount();
 
  744   for ( ; row < rowCount - 1; row ++ )
 
  746     mTableJoins->setItem( row, 0, mTableJoins->takeItem( row + 1, 0 ) );
 
  747     mTableJoins->setItem( row, 1, mTableJoins->takeItem( row + 1, 1 ) );
 
  749   mTableJoins->setRowCount( rowCount - 1 );
 
  751   buildSQLFromFields();
 
  754 void QgsSQLComposerDialog::reset()
 
  756   mQueryEdit->setText( mResetSql );
 
  759 void QgsSQLComposerDialog::mTableJoins_itemSelectionChanged()
 
  761   mRemoveJoinButton->setEnabled( mTableJoins->selectedItems().size() == 1 );
 
  768   delete mQueryEdit->lexer()->apis();
 
  769   QsciAPIs *apis = 
new QsciAPIs( mQueryEdit->lexer() );
 
  771   const auto constMApiList = mApiList;
 
  772   for ( 
const QString &
str : constMApiList )
 
  778   mQueryEdit->lexer()->setAPIs( apis );
 
  783   mJoinsLabels->setVisible( on );
 
  784   mTableJoins->setVisible( on );
 
  785   mAddJoinButton->setVisible( on );
 
  786   mRemoveJoinButton->setVisible( on );
 
  787   mTablesCombo->setVisible( on );
 
  789   QString mainTypenameFormatted;
 
  790   if ( !mainTypename.isEmpty() )
 
  791     mainTypenameFormatted = 
"(" + mainTypename + 
")";
 
  792   mQueryEdit->setToolTip( tr( 
"This is the SQL query editor. The SQL statement can select data from several tables, \n" 
  793                               "but it must compulsory include the main typename %1 in the selected tables, \n" 
  794                               "and only the geometry column of the main typename can be used as the geometry column of the resulting layer." ).arg( mainTypenameFormatted ) );
 
  797 void QgsSQLComposerDialog::showHelp()
 
  799   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