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 )
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" ) );