23 #include <QTableWidget> 32 mOrderByTableWidget->horizontalHeader()->setSectionResizeMode( QHeaderView::Stretch );
33 mOrderByTableWidget->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::ResizeToContents );
34 mOrderByTableWidget->horizontalHeader()->setSectionResizeMode( 2, QHeaderView::ResizeToContents );
36 mOrderByTableWidget->installEventFilter(
this );
38 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsOrderByDialog::showHelp );
43 mOrderByTableWidget->setRowCount( orderBy.length() + 1 );
48 setRow( i, orderByClause );
61 for (
int i = 0; i < mOrderByTableWidget->rowCount(); ++i )
63 QString expressionText =
static_cast<QgsFieldExpressionWidget *
>( mOrderByTableWidget->cellWidget( i, 0 ) )->currentText();
64 bool isExpression =
static_cast<QgsFieldExpressionWidget *
>( mOrderByTableWidget->cellWidget( i, 0 ) )->isExpression();
66 if ( ! expressionText.isEmpty() )
69 int ascIndex =
static_cast<QComboBox *
>( mOrderByTableWidget->cellWidget( i, 1 ) )->currentIndex();
73 bool nullsFirst =
false;
74 int nullsFirstIndex =
static_cast<QComboBox *
>( mOrderByTableWidget->cellWidget( i, 2 ) )->currentIndex();
75 if ( nullsFirstIndex == 1 )
83 orderBy << orderByClause;
90 void QgsOrderByDialog::onExpressionChanged(
const QString &expression )
94 for ( row = 0; row < mOrderByTableWidget->rowCount(); ++row )
96 if ( mOrderByTableWidget->cellWidget( row, 0 ) == sender() )
102 if ( expression.isEmpty() && row != mOrderByTableWidget->rowCount() - 1 )
104 mOrderByTableWidget->removeRow( row );
106 else if ( !expression.isEmpty() && row == mOrderByTableWidget->rowCount() - 1 )
108 mOrderByTableWidget->insertRow( mOrderByTableWidget->rowCount() );
116 fieldExpression->
setLayer( mLayer );
120 QComboBox *ascComboBox =
new QComboBox();
121 ascComboBox->addItem( tr(
"Ascending" ) );
122 ascComboBox->addItem( tr(
"Descending" ) );
123 ascComboBox->setCurrentIndex( orderByClause.
ascending() ? 0 : 1 );
125 QComboBox *nullsFirstComboBox =
new QComboBox();
126 nullsFirstComboBox->addItem( tr(
"NULLs last" ) );
127 nullsFirstComboBox->addItem( tr(
"NULLs first" ) );
128 nullsFirstComboBox->setCurrentIndex( orderByClause.
nullsFirst() ? 1 : 0 );
130 mOrderByTableWidget->setCellWidget( row, 0, fieldExpression );
131 mOrderByTableWidget->setCellWidget( row, 1, ascComboBox );
132 mOrderByTableWidget->setCellWidget( row, 2, nullsFirstComboBox );
138 Q_ASSERT( obj == mOrderByTableWidget );
140 if ( e->type() == QEvent::KeyPress )
142 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>( e );
144 if ( keyEvent->key() == Qt::Key_Delete )
146 if ( mOrderByTableWidget->currentRow() != mOrderByTableWidget->rowCount() - 1 )
147 mOrderByTableWidget->removeRow( mOrderByTableWidget->currentRow() );
152 return QDialog::eventFilter( obj, e );
155 void QgsOrderByDialog::showHelp()
157 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#layer-rendering" ) );
bool eventFilter(QObject *obj, QEvent *e) override
void setOrderBy(const QgsFeatureRequest::OrderBy &orderBy)
Set the order by to manage.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
bool ascending() const
Order ascending.
QgsExpression expression() const
The expression.
bool nullsFirst() const
Set if NULLS should be returned first.
The OrderByClause class represents an order by clause for a QgsFeatureRequest.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
QString expression() const
Returns the original, unmodified expression string.
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 data sets.
Represents a list of OrderByClauses, with the most important first and the least important last...