22 #include <QTableWidget> 31 mOrderByTableWidget->horizontalHeader()->setResizeMode( QHeaderView::Stretch );
32 mOrderByTableWidget->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents );
33 mOrderByTableWidget->horizontalHeader()->setResizeMode( 2, QHeaderView::ResizeToContents );
35 mOrderByTableWidget->installEventFilter(
this );
40 mOrderByTableWidget->setRowCount( orderBy.
length() + 1 );
45 setRow( i, orderByClause );
58 for (
int i = 0; i < mOrderByTableWidget->rowCount(); ++i )
61 bool isExpression =
static_cast<QgsFieldExpressionWidget*
>( mOrderByTableWidget->cellWidget( i, 0 ) )->isExpression();
63 if ( ! expressionText.
isEmpty() )
66 int ascIndex =
static_cast<QComboBox*
>( mOrderByTableWidget->cellWidget( i, 1 ) )->currentIndex();
70 bool nullsFirst =
false;
71 int nullsFirstIndex =
static_cast<QComboBox*
>( mOrderByTableWidget->cellWidget( i, 2 ) )->currentIndex();
72 if ( nullsFirstIndex == 1 )
80 orderBy << orderByClause;
87 void QgsOrderByDialog::onExpressionChanged(
const QString& expression )
91 for ( row = 0; row < mOrderByTableWidget->rowCount(); ++row )
93 if ( mOrderByTableWidget->cellWidget( row, 0 ) ==
sender() )
99 if ( expression.
isEmpty() && row != mOrderByTableWidget->rowCount() - 1 )
101 mOrderByTableWidget->removeRow( row );
103 else if ( !expression.
isEmpty() && row == mOrderByTableWidget->rowCount() - 1 )
105 mOrderByTableWidget->insertRow( mOrderByTableWidget->rowCount() );
113 fieldExpression->
setLayer( mLayer );
115 connect( fieldExpression, SIGNAL( fieldChanged(
QString ) ),
this, SLOT( onExpressionChanged(
QString ) ) );
118 ascComboBox->
addItem(
tr(
"Ascending" ) );
119 ascComboBox->
addItem(
tr(
"Descending" ) );
123 nullsFirstComboBox->
addItem(
tr(
"NULLs last" ) );
124 nullsFirstComboBox->
addItem(
tr(
"NULLs first" ) );
127 mOrderByTableWidget->setCellWidget( row, 0, fieldExpression );
128 mOrderByTableWidget->setCellWidget( row, 1, ascComboBox );
129 mOrderByTableWidget->setCellWidget( row, 2, nullsFirstComboBox );
135 Q_ASSERT( obj == mOrderByTableWidget );
137 if ( e->
type() == QEvent::KeyPress )
141 if ( keyEvent->
key() == Qt::Key_Delete )
143 if ( mOrderByTableWidget->currentRow() != mOrderByTableWidget->rowCount() - 1 )
144 mOrderByTableWidget->removeRow( mOrderByTableWidget->currentRow() );
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 tr(const char *sourceText, const char *disambiguation, int n)
void addItem(const QString &text, const QVariant &userData)
QString expression() const
Return the original, unmodified expression string.
The OrderByClause class represents an order by clause for a QgsFeatureRequest.
QgsExpression expression() const
The expression.
void setCurrentIndex(int index)
QgsOrderByDialog(QgsVectorLayer *layer, QWidget *parent=nullptr)
Create a new order by dialog.
QgsFeatureRequest::OrderBy orderBy()
Get the order by defined in the dialog.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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...