22#include "moc_qgssqlcomposerdialog.cpp" 
   30#include <Qsci/qscilexer.h> 
   41  connect( mTablesCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsSQLComposerDialog::mTablesCombo_currentIndexChanged );
 
   42  connect( mColumnsCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsSQLComposerDialog::mColumnsCombo_currentIndexChanged );
 
   43  connect( mSpatialPredicatesCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsSQLComposerDialog::mSpatialPredicatesCombo_currentIndexChanged );
 
   44  connect( mFunctionsCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsSQLComposerDialog::mFunctionsCombo_currentIndexChanged );
 
   45  connect( mOperatorsCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsSQLComposerDialog::mOperatorsCombo_currentIndexChanged );
 
   46  connect( mAddJoinButton, &QPushButton::clicked, 
this, &QgsSQLComposerDialog::mAddJoinButton_clicked );
 
   47  connect( mRemoveJoinButton, &QPushButton::clicked, 
this, &QgsSQLComposerDialog::mRemoveJoinButton_clicked );
 
   48  connect( mTableJoins, &QTableWidget::itemSelectionChanged, 
this, &QgsSQLComposerDialog::mTableJoins_itemSelectionChanged );
 
   50  mQueryEdit->setWrapMode( QsciScintilla::WrapWord );
 
   51  mQueryEdit->installEventFilter( 
this );
 
   52  mColumnsEditor->installEventFilter( 
this );
 
   53  mTablesEditor->installEventFilter( 
this );
 
   54  mTableJoins->installEventFilter( 
this );
 
   55  mWhereEditor->installEventFilter( 
this );
 
   56  mOrderEditor->installEventFilter( 
this );
 
   57  mTablesCombo->view()->installEventFilter( 
this );
 
   60  connect( mButtonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked, 
this, &QgsSQLComposerDialog::reset );
 
   62  connect( mQueryEdit, &QsciScintilla::textChanged, 
this, &QgsSQLComposerDialog::splitSQLIntoFields );
 
   63  connect( mColumnsEditor, &QTextEdit::textChanged, 
this, &QgsSQLComposerDialog::buildSQLFromFields );
 
   64  connect( mTablesEditor, &QLineEdit::textChanged, 
this, &QgsSQLComposerDialog::buildSQLFromFields );
 
   65  connect( mWhereEditor, &QTextEdit::textChanged, 
this, &QgsSQLComposerDialog::buildSQLFromFields );
 
   66  connect( mOrderEditor, &QTextEdit::textChanged, 
this, &QgsSQLComposerDialog::buildSQLFromFields );
 
   67  connect( mTableJoins, &QTableWidget::cellChanged, 
this, &QgsSQLComposerDialog::buildSQLFromFields );
 
   68  connect( mButtonBox, &QDialogButtonBox::helpRequested, 
this, &QgsSQLComposerDialog::showHelp );
 
   71  baseList << QStringLiteral( 
"SELECT" );
 
   72  baseList << QStringLiteral( 
"FROM" );
 
   73  baseList << QStringLiteral( 
"JOIN" );
 
   74  baseList << QStringLiteral( 
"ON" );
 
   75  baseList << QStringLiteral( 
"USING" );
 
   76  baseList << QStringLiteral( 
"WHERE" );
 
   77  baseList << QStringLiteral( 
"AND" );
 
   78  baseList << QStringLiteral( 
"OR" );
 
   79  baseList << QStringLiteral( 
"NOT" );
 
   80  baseList << QStringLiteral( 
"IS" );
 
   81  baseList << QStringLiteral( 
"NULL" );
 
   82  baseList << QStringLiteral( 
"LIKE" );
 
   83  baseList << QStringLiteral( 
"ORDER" );
 
   84  baseList << QStringLiteral( 
"BY" );
 
   87  QStringList operatorsList;
 
   88  operatorsList << QStringLiteral( 
"AND" );
 
   89  operatorsList << QStringLiteral( 
"OR" );
 
   90  operatorsList << QStringLiteral( 
"NOT" );
 
   91  operatorsList << QStringLiteral( 
"=" );
 
   92  operatorsList << QStringLiteral( 
"<" );
 
   93  operatorsList << QStringLiteral( 
"<=" );
 
   94  operatorsList << QStringLiteral( 
">" );
 
   95  operatorsList << QStringLiteral( 
">=" );
 
   96  operatorsList << QStringLiteral( 
"<>" );
 
   97  operatorsList << QStringLiteral( 
"BETWEEN" );
 
   98  operatorsList << QStringLiteral( 
"NOT BETWEEN" );
 
   99  operatorsList << QStringLiteral( 
"IS" );
 
  100  operatorsList << QStringLiteral( 
"IS NOT" );
 
  101  operatorsList << QStringLiteral( 
"IN" );
 
  102  operatorsList << QStringLiteral( 
"LIKE" );
 
  105  mAggregatesCombo->hide();
 
  106  mFunctionsCombo->hide();
 
  107  mSpatialPredicatesCombo->hide();
 
  108  mStringFunctionsCombo->hide();
 
  110  delete mPageColumnsValues;
 
  111  mPageColumnsValues = 
nullptr;
 
  113  mRemoveJoinButton->setEnabled( 
false );
 
  115  mTableJoins->setRowCount( 0 );
 
  116  mTableJoins->setItem( 0, 0, 
new QTableWidgetItem( QString() ) );
 
  117  mTableJoins->setItem( 0, 1, 
new QTableWidgetItem( QString() ) );
 
 
  125  delete mQueryEdit->lexer()->apis();
 
  126  mQueryEdit->lexer()->setAPIs( 
nullptr );
 
 
  131  if ( event->type() == QEvent::FocusIn )
 
  133    if ( obj == mTablesCombo->view() )
 
  134      lastSearchedText.clear();
 
  136      mFocusedObject = obj;
 
  140  if ( event->type() == QEvent::KeyPress && obj == mTablesCombo->view() )
 
  142    QString currentString = ( ( QKeyEvent * ) event )->text();
 
  143    if ( !currentString.isEmpty() && ( ( currentString[0] >= 
'a' && currentString[0] <= 
'z' ) || ( currentString[0] >= 
'A' && currentString[0] <= 
'Z' ) || ( currentString[0] >= 
'0' && currentString[0] <= 
'9' ) || currentString[0] == 
':' || currentString[0] == 
'_' || currentString[0] == 
' ' || currentString[0] == 
'(' || currentString[0] == 
')' ) )
 
  147      const int attemptCount = ( lastSearchedText.isEmpty() ) ? 1 : 2;
 
  148      for ( 
int attempt = 0; attempt < attemptCount; attempt++ )
 
  151          lastSearchedText += currentString;
 
  153          lastSearchedText = currentString;
 
  158        int iBestCandidate = 0;
 
  159        int idxInTextOfBestCandidate = 1000;
 
  160        for ( 
int i = 1; i < mTablesCombo->count(); i++ )
 
  162          const int idxInText = mTablesCombo->itemText( i ).indexOf( lastSearchedText, Qt::CaseInsensitive );
 
  163          if ( idxInText >= 0 && idxInText < idxInTextOfBestCandidate )
 
  166            idxInTextOfBestCandidate = idxInText;
 
  169        if ( iBestCandidate > 0 )
 
  171          mTablesCombo->view()->setCurrentIndex( mTablesCombo->model()->index( 0, 0 ).sibling( iBestCandidate, 0 ) );
 
  175      lastSearchedText.clear();
 
  179  return QDialog::eventFilter( obj, event );
 
 
  184  mTableSelectedCallback = tableSelectedCallback;
 
 
  189  mSQLValidatorCallback = sqlValidatorCallback;
 
 
  195  mQueryEdit->setText( 
sql );
 
 
  200  return mQueryEdit->text();
 
 
  203void QgsSQLComposerDialog::accept()
 
  205  if ( mSQLValidatorCallback )
 
  207    QString errorMsg, warningMsg;
 
  208    if ( !mSQLValidatorCallback->
isValid( 
sql(), errorMsg, warningMsg ) )
 
  210      if ( errorMsg.isEmpty() )
 
  211        errorMsg = tr( 
"An error occurred during evaluation of the SQL statement." );
 
  212      QMessageBox::critical( 
this, tr( 
"SQL Evaluation" ), errorMsg );
 
  215    if ( !warningMsg.isEmpty() )
 
  217      QMessageBox::warning( 
this, tr( 
"SQL Evaluation" ), warningMsg );
 
  227void QgsSQLComposerDialog::buildSQLFromFields()
 
  229  if ( mAlreadyModifyingFields )
 
  231  mAlreadyModifyingFields = 
true;
 
  232  QString 
sql( QStringLiteral( 
"SELECT " ) );
 
  234    sql += QLatin1String( 
"DISTINCT " );
 
  235  sql += mColumnsEditor->toPlainText();
 
  236  sql += QLatin1String( 
" FROM " );
 
  237  sql += mTablesEditor->text();
 
  239  const int rows = mTableJoins->rowCount();
 
  240  for ( 
int i = 0; i < rows; i++ )
 
  242    QTableWidgetItem *itemTable = mTableJoins->item( i, 0 );
 
  243    QTableWidgetItem *itemOn = mTableJoins->item( i, 1 );
 
  244    if ( itemTable && !itemTable->text().isEmpty() && itemOn && !itemOn->text().isEmpty() )
 
  246      sql += QLatin1String( 
" JOIN " );
 
  247      sql += itemTable->text();
 
  248      sql += QLatin1String( 
" ON " );
 
  249      sql += itemOn->text();
 
  253  if ( !mWhereEditor->toPlainText().isEmpty() )
 
  255    sql += QLatin1String( 
" WHERE " );
 
  256    sql += mWhereEditor->toPlainText();
 
  258  if ( !mOrderEditor->toPlainText().isEmpty() )
 
  260    sql += QLatin1String( 
" ORDER BY " );
 
  261    sql += mOrderEditor->toPlainText();
 
  263  mQueryEdit->setText( 
sql );
 
  265  mAlreadyModifyingFields = 
false;
 
  268void QgsSQLComposerDialog::splitSQLIntoFields()
 
  270  if ( mAlreadyModifyingFields )
 
  273  if ( 
sql.hasParserError() )
 
  279  const QList<QgsSQLStatement::NodeSelectedColumn *> columns = nodeSelect->
columns();
 
  281  const auto constColumns = columns;
 
  284    if ( !columnText.isEmpty() )
 
  285      columnText += QLatin1String( 
", " );
 
  286    columnText += column->dump();
 
  289  const QList<QgsSQLStatement::NodeTableDef *> tables = nodeSelect->
tables();
 
  291  const auto constTables = tables;
 
  294    if ( !tablesText.isEmpty() )
 
  295      tablesText += QLatin1String( 
", " );
 
  297    tablesText += table->dump();
 
  303    whereText = where->
dump();
 
  306  const QList<QgsSQLStatement::NodeColumnSorted *> orderColumns = nodeSelect->
orderBy();
 
  307  const auto constOrderColumns = orderColumns;
 
  310    if ( !orderText.isEmpty() )
 
  311      orderText += QLatin1String( 
", " );
 
  312    orderText += column->dump();
 
  315  const QList<QgsSQLStatement::NodeJoin *> joins = nodeSelect->
joins();
 
  317  mAlreadyModifyingFields = 
true;
 
  318  mColumnsEditor->setPlainText( columnText );
 
  319  mTablesEditor->setText( tablesText );
 
  320  mWhereEditor->setPlainText( whereText );
 
  321  mOrderEditor->setPlainText( orderText );
 
  323  mTableJoins->setRowCount( joins.size() + 1 );
 
  325  const auto constJoins = joins;
 
  329    mTableJoins->setItem( iRow, 0, 
new QTableWidgetItem( join->tableDef()->dump() ) );
 
  330    if ( join->onExpr() )
 
  331      mTableJoins->setItem( iRow, 1, 
new QTableWidgetItem( join->onExpr()->dump() ) );
 
  333      mTableJoins->setItem( iRow, 1, 
new QTableWidgetItem( QString() ) );
 
  336  mTableJoins->setItem( iRow, 0, 
new QTableWidgetItem( QString() ) );
 
  337  mTableJoins->setItem( iRow, 1, 
new QTableWidgetItem( QString() ) );
 
  339  mAlreadyModifyingFields = 
false;
 
  344  const auto constList = list;
 
  345  for ( 
const QString &name : constList )
 
  346    mapTableEntryTextToName[name] = name;
 
  347  mTablesCombo->addItems( list );
 
 
  353  QStringList listCombo;
 
  355  const auto constListNameTitle = listNameTitle;
 
  358    listApi << pair.first;
 
  359    QString entryText( pair.first );
 
  360    if ( !pair.second.isEmpty() && pair.second != pair.first )
 
  362      if ( pair.second.size() < 40 )
 
  363        entryText += 
" (" + pair.second + 
")";
 
  365        entryText += 
" (" + pair.second.mid( 0, 20 ) + QChar( 0x2026 ) + pair.second.mid( pair.second.size() - 20 ) + 
")";
 
  367    listCombo << entryText;
 
  368    mapTableEntryTextToName[entryText] = pair.first;
 
  370  mTablesCombo->addItems( listCombo );
 
 
  376  QList<PairNameType> listPair;
 
  377  const auto constList = list;
 
  378  for ( 
const QString &name : constList )
 
 
  383static QString sanitizeType( QString type )
 
  385  if ( type.startsWith( QLatin1String( 
"xs:" ) ) )
 
  386    return type.mid( 3 );
 
  387  if ( type.startsWith( QLatin1String( 
"xsd:" ) ) )
 
  388    return type.mid( 4 );
 
  389  if ( type == QLatin1String( 
"gml:AbstractGeometryType" ) )
 
  390    return QStringLiteral( 
"geometry" );
 
  396  mAlreadySelectedTables.insert( tableName );
 
  397  if ( mColumnsCombo->count() > 1 )
 
  398    mColumnsCombo->insertSeparator( mColumnsCombo->count() );
 
  400  QStringList listCombo;
 
  402  const auto constList = list;
 
  405    listApi << pair.first;
 
  406    QString entryText( pair.first );
 
  407    if ( !pair.second.isEmpty() )
 
  409      entryText += 
" (" + sanitizeType( pair.second ) + 
")";
 
  411    listCombo << entryText;
 
  412    mapColumnEntryTextToName[entryText] = pair.first;
 
  414  mColumnsCombo->addItems( listCombo );
 
 
  421  mOperatorsCombo->addItems( list );
 
 
  429    return QObject::tr( 
"%1 to %n argument(s)", 
nullptr, f.
maxArgs ).arg( f.
minArgs );
 
  436    return QObject::tr( 
"%n argument(s)", 
nullptr, f.
minArgs );
 
  440    return QObject::tr( 
"%n argument(s) or more", 
nullptr, f.
minArgs );
 
  446void QgsSQLComposerDialog::getFunctionList( 
const QList<Function> &list, QStringList &listApi, QStringList &listCombo, QMap<QString, QString> &mapEntryTextToName )
 
  448  const auto constList = list;
 
  449  for ( 
const Function &f : constList )
 
  452    QString entryText( f.
name );
 
  453    entryText += QLatin1Char( 
'(' );
 
  459          entryText += QLatin1Char( 
'[' );
 
  461          entryText += QLatin1String( 
", " );
 
  469          const QString sanitizedType( sanitizeType( f.
argumentList[i].type ) );
 
  472            entryText += QLatin1String( 
": " );
 
  473            entryText += sanitizedType;
 
  477          entryText += QLatin1Char( 
']' );
 
  479      if ( entryText.size() > 60 )
 
  482        entryText += QLatin1Char( 
'(' );
 
  483        entryText += getFunctionAbbridgedParameters( f );
 
  488      entryText += getFunctionAbbridgedParameters( f );
 
  490    entryText += QLatin1Char( 
')' );
 
  492      entryText += 
": " + sanitizeType( f.
returnType );
 
  493    listCombo << entryText;
 
  494    mapEntryTextToName[entryText] = f.
name + 
"(";
 
  500  QList<Function> listFunction;
 
  501  const auto constList = list;
 
  502  for ( 
const QString &name : constList )
 
 
  514  QStringList listCombo;
 
  515  getFunctionList( list, listApi, listCombo, mapSpatialPredicateEntryTextToName );
 
  516  mSpatialPredicatesCombo->addItems( listCombo );
 
  517  mSpatialPredicatesCombo->show();
 
 
  523  QList<Function> listFunction;
 
  524  const auto constList = list;
 
  525  for ( 
const QString &name : constList )
 
 
  537  QStringList listCombo;
 
  538  getFunctionList( list, listApi, listCombo, mapFunctionEntryTextToName );
 
  539  mFunctionsCombo->addItems( listCombo );
 
  540  mFunctionsCombo->show();
 
 
  544void QgsSQLComposerDialog::loadTableColumns( 
const QString &table )
 
  546  if ( mTableSelectedCallback )
 
  548    if ( !mAlreadySelectedTables.contains( table ) )
 
  551      mAlreadySelectedTables.insert( table );
 
  556static void resetCombo( QComboBox *combo )
 
  563  QMetaObject::invokeMethod( combo, 
"setCurrentIndex", Qt::QueuedConnection, Q_ARG( 
int, 0 ) );
 
  566void QgsSQLComposerDialog::mTablesCombo_currentIndexChanged( 
int )
 
  568  const int index = mTablesCombo->currentIndex();
 
  571  QObject *obj = mFocusedObject;
 
  572  const QString newText = mapTableEntryTextToName[mTablesCombo->currentText()];
 
  573  loadTableColumns( newText );
 
  574  if ( obj == mTablesEditor )
 
  576    const QString currentText = mTablesEditor->text();
 
  577    if ( currentText.isEmpty() )
 
  578      mTablesEditor->setText( newText );
 
  580      mTablesEditor->setText( currentText + 
", " + newText );
 
  582  else if ( obj == mTableJoins )
 
  584    if ( mTableJoins->selectedItems().size() == 1 )
 
  586      mTableJoins->selectedItems().at( 0 )->setText( newText );
 
  589  else if ( obj == mWhereEditor )
 
  591    mWhereEditor->insertPlainText( newText );
 
  593  else if ( obj == mOrderEditor )
 
  595    mOrderEditor->insertPlainText( newText );
 
  597  else if ( obj == mQueryEdit )
 
  599    mQueryEdit->insertText( newText );
 
  601  resetCombo( mTablesCombo );
 
  604void QgsSQLComposerDialog::mColumnsCombo_currentIndexChanged( 
int )
 
  606  const int index = mColumnsCombo->currentIndex();
 
  609  QObject *obj = mFocusedObject;
 
  610  const QString newText = mapColumnEntryTextToName[mColumnsCombo->currentText()];
 
  611  if ( obj == mColumnsEditor )
 
  613    const QString currentText = mColumnsEditor->toPlainText();
 
  614    if ( currentText.isEmpty() )
 
  615      mColumnsEditor->insertPlainText( newText );
 
  617      mColumnsEditor->insertPlainText( 
",\n" + newText );
 
  619  else if ( obj == mTableJoins )
 
  621    if ( mTableJoins->selectedItems().size() == 1 && mTableJoins->selectedItems().at( 0 )->column() == 1 )
 
  623      const QString currentText( mTableJoins->selectedItems().at( 0 )->text() );
 
  624      if ( !currentText.isEmpty() && !currentText.contains( QLatin1String( 
"=" ) ) )
 
  625        mTableJoins->selectedItems().at( 0 )->setText( currentText + 
" = " + newText );
 
  627        mTableJoins->selectedItems().at( 0 )->setText( currentText + newText );
 
  630  else if ( obj == mWhereEditor )
 
  632    mWhereEditor->insertPlainText( newText );
 
  634  else if ( obj == mOrderEditor )
 
  636    mOrderEditor->insertPlainText( newText );
 
  638  else if ( obj == mQueryEdit )
 
  640    mQueryEdit->insertText( newText );
 
  642  resetCombo( mColumnsCombo );
 
  645void QgsSQLComposerDialog::mFunctionsCombo_currentIndexChanged( 
int )
 
  647  functionCurrentIndexChanged( mFunctionsCombo, mapFunctionEntryTextToName );
 
  650void QgsSQLComposerDialog::mSpatialPredicatesCombo_currentIndexChanged( 
int )
 
  652  functionCurrentIndexChanged( mSpatialPredicatesCombo, mapSpatialPredicateEntryTextToName );
 
  655void QgsSQLComposerDialog::functionCurrentIndexChanged( QComboBox *combo, 
const QMap<QString, QString> &mapEntryTextToName )
 
  657  const int index = combo->currentIndex();
 
  660  QObject *obj = mFocusedObject;
 
  661  const QString newText = mapEntryTextToName[combo->currentText()];
 
  662  if ( obj == mColumnsEditor )
 
  664    mColumnsEditor->insertPlainText( newText );
 
  666  else if ( obj == mWhereEditor )
 
  668    mWhereEditor->insertPlainText( newText );
 
  670  else if ( obj == mQueryEdit )
 
  672    mQueryEdit->insertText( newText );
 
  677void QgsSQLComposerDialog::mOperatorsCombo_currentIndexChanged( 
int )
 
  679  const int index = mOperatorsCombo->currentIndex();
 
  682  QObject *obj = mFocusedObject;
 
  683  const QString newText = mOperatorsCombo->currentText();
 
  684  if ( obj == mColumnsEditor )
 
  686    mColumnsEditor->insertPlainText( newText );
 
  688  else if ( obj == mWhereEditor )
 
  690    mWhereEditor->insertPlainText( newText );
 
  692  else if ( obj == mTableJoins )
 
  694    if ( mTableJoins->selectedItems().size() == 1 && mTableJoins->selectedItems().at( 0 )->column() == 1 )
 
  696      const QString currentText( mTableJoins->selectedItems().at( 0 )->text() );
 
  697      mTableJoins->selectedItems().at( 0 )->setText( currentText + newText );
 
  700  else if ( obj == mQueryEdit )
 
  702    mQueryEdit->insertText( newText );
 
  704  resetCombo( mOperatorsCombo );
 
  707void QgsSQLComposerDialog::mAddJoinButton_clicked()
 
  709  int insertRow = mTableJoins->currentRow();
 
  710  const int rowCount = mTableJoins->rowCount();
 
  712    insertRow = rowCount;
 
  713  mTableJoins->setRowCount( rowCount + 1 );
 
  714  for ( 
int row = rowCount; row > insertRow + 1; row-- )
 
  716    mTableJoins->setItem( row, 0, mTableJoins->takeItem( row - 1, 0 ) );
 
  717    mTableJoins->setItem( row, 1, mTableJoins->takeItem( row - 1, 1 ) );
 
  719  mTableJoins->setItem( ( insertRow == rowCount ) ? insertRow : insertRow + 1, 0, new QTableWidgetItem( QString() ) );
 
  720  mTableJoins->setItem( ( insertRow == rowCount ) ? insertRow : insertRow + 1, 1, new QTableWidgetItem( QString() ) );
 
  723void QgsSQLComposerDialog::mRemoveJoinButton_clicked()
 
  725  int row = mTableJoins->currentRow();
 
  728  const int rowCount = mTableJoins->rowCount();
 
  729  for ( ; row < rowCount - 1; row++ )
 
  731    mTableJoins->setItem( row, 0, mTableJoins->takeItem( row + 1, 0 ) );
 
  732    mTableJoins->setItem( row, 1, mTableJoins->takeItem( row + 1, 1 ) );
 
  734  mTableJoins->setRowCount( rowCount - 1 );
 
  736  buildSQLFromFields();
 
  739void QgsSQLComposerDialog::reset()
 
  741  mQueryEdit->setText( mResetSql );
 
  744void QgsSQLComposerDialog::mTableJoins_itemSelectionChanged()
 
  746  mRemoveJoinButton->setEnabled( mTableJoins->selectedItems().size() == 1 );
 
  753  delete mQueryEdit->lexer()->apis();
 
  754  QsciAPIs *apis = 
new QsciAPIs( mQueryEdit->lexer() );
 
  756  const auto constMApiList = mApiList;
 
  757  for ( 
const QString &str : constMApiList )
 
  763  mQueryEdit->lexer()->setAPIs( apis );
 
 
  768  mJoinsLabels->setVisible( on );
 
  769  mTableJoins->setVisible( on );
 
  770  mAddJoinButton->setVisible( on );
 
  771  mRemoveJoinButton->setVisible( on );
 
  772  mTablesCombo->setVisible( on );
 
  774  QString mainTypenameFormatted;
 
  775  if ( !mainTypename.isEmpty() )
 
  776    mainTypenameFormatted = 
"(" + mainTypename + 
")";
 
  777  mQueryEdit->setToolTip( tr( 
"This is the SQL query editor. The SQL statement can select data from several tables, \n" 
  778                              "but it must compulsory include the main typename %1 in the selected tables, \n" 
  779                              "and only the geometry column of the main typename can be used as the geometry column of the resulting layer." )
 
  780                            .arg( mainTypenameFormatted ) );
 
 
  783void QgsSQLComposerDialog::showHelp()
 
  785  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.
 
QList< QgsSQLStatement::NodeColumnSorted * > orderBy() const
Returns the list of order by columns.
 
QList< QgsSQLStatement::NodeSelectedColumn * > columns() const
Returns the list of columns.
 
bool distinct() const
Returns if the SELECT is DISTINCT.
 
QList< QgsSQLStatement::NodeJoin * > joins() const
Returns the list of joins.
 
QgsSQLStatement::Node * where() const
Returns the where clause.
 
QList< QgsSQLStatement::NodeTableDef * > tables() const
Returns the list of tables.
 
Abstract node class for SQL statement nodes.
 
virtual QString dump() const =0
Abstract virtual dump method.
 
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 dataset.
 
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