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 const bool isExpression =
static_cast<QgsFieldExpressionWidget *
>( mOrderByTableWidget->cellWidget( i, 0 ) )->isExpression();
67 if ( ! expressionText.isEmpty() )
70 const int ascIndex =
static_cast<QComboBox *
>( mOrderByTableWidget->cellWidget( i, 1 ) )->currentIndex();
74 bool nullsFirst =
false;
75 const int nullsFirstIndex =
static_cast<QComboBox *
>( mOrderByTableWidget->cellWidget( i, 2 ) )->currentIndex();
76 if ( nullsFirstIndex == 1 )
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" ) );
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 data sets.