18#include "moc_qgsorderbydialog.cpp" 
   24#include <QTableWidget> 
   33  mOrderByTableWidget->horizontalHeader()->setSectionResizeMode( QHeaderView::Stretch );
 
   34  mOrderByTableWidget->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::ResizeToContents );
 
   35  mOrderByTableWidget->horizontalHeader()->setSectionResizeMode( 2, QHeaderView::ResizeToContents );
 
   37  mOrderByTableWidget->installEventFilter( 
this );
 
   39  connect( buttonBox, &QDialogButtonBox::helpRequested, 
this, &QgsOrderByDialog::showHelp );
 
 
   44  mOrderByTableWidget->setRowCount( 
orderBy.length() + 1 );
 
   47  const auto constOrderBy = 
orderBy;
 
   50    setRow( i, orderByClause );
 
 
   63  for ( 
int i = 0; i < mOrderByTableWidget->rowCount(); ++i )
 
   65    QString expressionText = 
static_cast<QgsFieldExpressionWidget *
>( mOrderByTableWidget->cellWidget( i, 0 ) )->currentText();
 
   66    const bool isExpression = 
static_cast<QgsFieldExpressionWidget *
>( mOrderByTableWidget->cellWidget( i, 0 ) )->isExpression();
 
   68    if ( !expressionText.isEmpty() )
 
   71      const int ascIndex = 
static_cast<QComboBox *
>( mOrderByTableWidget->cellWidget( i, 1 ) )->currentIndex();
 
   75      bool nullsFirst = 
false;
 
   76      const int nullsFirstIndex = 
static_cast<QComboBox *
>( mOrderByTableWidget->cellWidget( i, 2 ) )->currentIndex();
 
   77      if ( nullsFirstIndex == 1 )
 
 
   92void QgsOrderByDialog::onExpressionChanged( 
const QString &expression )
 
   96  for ( row = 0; row < mOrderByTableWidget->rowCount(); ++row )
 
   98    if ( mOrderByTableWidget->cellWidget( row, 0 ) == sender() )
 
  104  if ( expression.isEmpty() && row != mOrderByTableWidget->rowCount() - 1 )
 
  106    mOrderByTableWidget->removeRow( row );
 
  108  else if ( !expression.isEmpty() && row == mOrderByTableWidget->rowCount() - 1 )
 
  110    mOrderByTableWidget->insertRow( mOrderByTableWidget->rowCount() );
 
  118  fieldExpression->
setLayer( mLayer );
 
  122  QComboBox *ascComboBox = 
new QComboBox();
 
  123  ascComboBox->addItem( tr( 
"Ascending" ) );
 
  124  ascComboBox->addItem( tr( 
"Descending" ) );
 
  125  ascComboBox->setCurrentIndex( orderByClause.
ascending() ? 0 : 1 );
 
  127  QComboBox *nullsFirstComboBox = 
new QComboBox();
 
  128  nullsFirstComboBox->addItem( tr( 
"NULLs Last" ) );
 
  129  nullsFirstComboBox->addItem( tr( 
"NULLs First" ) );
 
  130  nullsFirstComboBox->setCurrentIndex( orderByClause.
nullsFirst() ? 1 : 0 );
 
  132  mOrderByTableWidget->setCellWidget( row, 0, fieldExpression );
 
  133  mOrderByTableWidget->setCellWidget( row, 1, ascComboBox );
 
  134  mOrderByTableWidget->setCellWidget( row, 2, nullsFirstComboBox );
 
  140  Q_ASSERT( obj == mOrderByTableWidget );
 
  142  if ( e->type() == QEvent::KeyPress )
 
  144    QKeyEvent *keyEvent = 
static_cast<QKeyEvent *
>( e );
 
  146    if ( keyEvent->key() == Qt::Key_Delete )
 
  148      if ( mOrderByTableWidget->currentRow() != mOrderByTableWidget->rowCount() - 1 )
 
  149        mOrderByTableWidget->removeRow( mOrderByTableWidget->currentRow() );
 
  154  return QDialog::eventFilter( obj, e );
 
 
  157void QgsOrderByDialog::showHelp()
 
  159  QgsHelp::openHelp( QStringLiteral( 
"working_with_vector/vector_properties.html#layer-rendering" ) );
 
QString expression() const
Returns the original, unmodified expression string.
 
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
 
The OrderByClause class represents an order by clause for a QgsFeatureRequest.
 
QgsExpression expression() const
The expression.
 
bool ascending() const
Order ascending.
 
bool nullsFirst() const
Set if NULLS should be returned first.
 
Represents a list of OrderByClauses, with the most important first and the least important last.
 
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
 
bool eventFilter(QObject *obj, QEvent *e) override
 
void setOrderBy(const QgsFeatureRequest::OrderBy &orderBy)
Set the order by to manage.
 
QgsOrderByDialog(QgsVectorLayer *layer, QWidget *parent=nullptr)
Create a new order by dialog.
 
QgsFeatureRequest::OrderBy orderBy()
Gets the order by defined in the dialog.
 
Represents a vector layer which manages a vector based dataset.