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 );
46 const auto constOrderBy =
orderBy;
49 setRow( i, orderByClause );
62 for (
int i = 0; i < mOrderByTableWidget->rowCount(); ++i )
64 QString expressionText =
static_cast<QgsFieldExpressionWidget *
>( mOrderByTableWidget->cellWidget( i, 0 ) )->currentText();
65 bool isExpression =
static_cast<QgsFieldExpressionWidget *
>( mOrderByTableWidget->cellWidget( i, 0 ) )->isExpression();
67 if ( ! expressionText.isEmpty() )
70 int ascIndex =
static_cast<QComboBox *
>( mOrderByTableWidget->cellWidget( i, 1 ) )->currentIndex();
74 bool nullsFirst =
false;
75 int nullsFirstIndex =
static_cast<QComboBox *
>( mOrderByTableWidget->cellWidget( i, 2 ) )->currentIndex();
76 if ( nullsFirstIndex == 1 )
84 orderBy << orderByClause;
91 void QgsOrderByDialog::onExpressionChanged(
const QString &expression )
95 for ( row = 0; row < mOrderByTableWidget->rowCount(); ++row )
97 if ( mOrderByTableWidget->cellWidget( row, 0 ) == sender() )
103 if ( expression.isEmpty() && row != mOrderByTableWidget->rowCount() - 1 )
105 mOrderByTableWidget->removeRow( row );
107 else if ( !expression.isEmpty() && row == mOrderByTableWidget->rowCount() - 1 )
109 mOrderByTableWidget->insertRow( mOrderByTableWidget->rowCount() );
117 fieldExpression->
setLayer( mLayer );
121 QComboBox *ascComboBox =
new QComboBox();
122 ascComboBox->addItem( tr(
"Ascending" ) );
123 ascComboBox->addItem( tr(
"Descending" ) );
124 ascComboBox->setCurrentIndex( orderByClause.
ascending() ? 0 : 1 );
126 QComboBox *nullsFirstComboBox =
new QComboBox();
127 nullsFirstComboBox->addItem( tr(
"NULLs last" ) );
128 nullsFirstComboBox->addItem( tr(
"NULLs first" ) );
129 nullsFirstComboBox->setCurrentIndex( orderByClause.
nullsFirst() ? 1 : 0 );
131 mOrderByTableWidget->setCellWidget( row, 0, fieldExpression );
132 mOrderByTableWidget->setCellWidget( row, 1, ascComboBox );
133 mOrderByTableWidget->setCellWidget( row, 2, nullsFirstComboBox );
139 Q_ASSERT( obj == mOrderByTableWidget );
141 if ( e->type() == QEvent::KeyPress )
143 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>( e );
145 if ( keyEvent->key() == Qt::Key_Delete )
147 if ( mOrderByTableWidget->currentRow() != mOrderByTableWidget->rowCount() - 1 )
148 mOrderByTableWidget->removeRow( mOrderByTableWidget->currentRow() );
153 return QDialog::eventFilter( obj, e );
156 void QgsOrderByDialog::showHelp()
158 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#layer-rendering" ) );
bool nullsFirst() const
Set if NULLS should be returned first.
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.
QString expression() const
Returns the original, unmodified expression string.
The OrderByClause class represents an order by clause for a QgsFeatureRequest.
QgsExpression expression() const
The expression.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
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...