Skip to content

Commit 9a64569

Browse files
committed
Fix orderby table headers and use combobox
1 parent 09cc9e4 commit 9a64569

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

src/gui/qgsorderbydialog.cpp

+24-12
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "qgsfieldexpressionwidget.h"
2121

2222
#include <QTableWidget>
23-
#include <QCheckBox>
2423
#include <QKeyEvent>
2524

2625
QgsOrderByDialog::QgsOrderByDialog( QgsVectorLayer* layer, QWidget* parent )
@@ -30,15 +29,14 @@ QgsOrderByDialog::QgsOrderByDialog( QgsVectorLayer* layer, QWidget* parent )
3029
setupUi( this );
3130

3231
mOrderByTableWidget->horizontalHeader()->setResizeMode( QHeaderView::Stretch );
33-
mOrderByTableWidget->horizontalHeader()->setResizeMode( 1, QHeaderView::Interactive );
34-
mOrderByTableWidget->horizontalHeader()->setResizeMode( 2, QHeaderView::Interactive );
32+
mOrderByTableWidget->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents );
33+
mOrderByTableWidget->horizontalHeader()->setResizeMode( 2, QHeaderView::ResizeToContents );
3534

3635
mOrderByTableWidget->installEventFilter( this );
3736
}
3837

3938
void QgsOrderByDialog::setOrderBy( const QgsFeatureRequest::OrderBy& orderBy )
4039
{
41-
mOrderByTableWidget->clear();
4240
mOrderByTableWidget->setRowCount( orderBy.length() + 1 );
4341

4442
int i = 0;
@@ -63,8 +61,16 @@ QgsFeatureRequest::OrderBy QgsOrderByDialog::orderBy()
6361

6462
if ( ! expressionText.isEmpty() )
6563
{
66-
bool asc = static_cast<QCheckBox*>( mOrderByTableWidget->cellWidget( i, 1 ) )->checkState();
67-
bool nullsFirst = static_cast<QCheckBox*>( mOrderByTableWidget->cellWidget( i, 2 ) )->checkState();
64+
bool asc = true;
65+
int ascIndex = static_cast<QComboBox*>( mOrderByTableWidget->cellWidget( i, 1 ) )->currentIndex();
66+
if ( ascIndex == 1 )
67+
asc = false;
68+
69+
bool nullsFirst = false;
70+
int nullsFirstIndex = static_cast<QComboBox*>( mOrderByTableWidget->cellWidget( i, 2 ) )->currentIndex();
71+
if ( nullsFirstIndex == 1 )
72+
nullsFirst = true;
73+
6874
QgsFeatureRequest::OrderByClause orderByClause( expressionText, asc, nullsFirst );
6975

7076
orderBy << orderByClause;
@@ -103,14 +109,20 @@ void QgsOrderByDialog::setRow( int row, const QgsFeatureRequest::OrderByClause&
103109
fieldExpression->setLayer( mLayer );
104110
fieldExpression->setField( orderByClause.expression().expression() );
105111
connect( fieldExpression, SIGNAL( fieldChanged( QString ) ), this, SLOT( onExpressionChanged( QString ) ) );
106-
QCheckBox* ascCheckBox = new QCheckBox();
107-
ascCheckBox->setChecked( orderByClause.ascending() );
108-
QCheckBox* nullsFirstCheckBox = new QCheckBox();
109-
nullsFirstCheckBox->setChecked( orderByClause.nullsFirst() );
112+
113+
QComboBox* ascComboBox = new QComboBox();
114+
ascComboBox->addItem( tr( "Ascending" ) );
115+
ascComboBox->addItem( tr( "Descencing" ) );
116+
ascComboBox->setCurrentIndex( orderByClause.ascending() ? 0 : 1 );
117+
118+
QComboBox* nullsFirstComboBox = new QComboBox();
119+
nullsFirstComboBox->addItem( tr( "NULLs last" ) );
120+
nullsFirstComboBox->addItem( tr( "NULLs first" ) );
121+
nullsFirstComboBox->setCurrentIndex( orderByClause.nullsFirst() ? 1 : 0 );
110122

111123
mOrderByTableWidget->setCellWidget( row, 0, fieldExpression );
112-
mOrderByTableWidget->setCellWidget( row, 1, ascCheckBox );
113-
mOrderByTableWidget->setCellWidget( row, 2, nullsFirstCheckBox );
124+
mOrderByTableWidget->setCellWidget( row, 1, ascComboBox );
125+
mOrderByTableWidget->setCellWidget( row, 2, nullsFirstComboBox );
114126
}
115127

116128
bool QgsOrderByDialog::eventFilter( QObject* obj, QEvent* e )

src/ui/qgsorderbydialogbase.ui

+2-8
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,19 @@
2626
</item>
2727
<item row="0" column="0">
2828
<widget class="QTableWidget" name="mOrderByTableWidget">
29-
<property name="selectionMode">
30-
<enum>QAbstractItemView::SingleSelection</enum>
31-
</property>
32-
<property name="selectionBehavior">
33-
<enum>QAbstractItemView::SelectRows</enum>
34-
</property>
3529
<column>
3630
<property name="text">
3731
<string>Expression</string>
3832
</property>
3933
</column>
4034
<column>
4135
<property name="text">
42-
<string>Ascending</string>
36+
<string>Asc / Desc</string>
4337
</property>
4438
</column>
4539
<column>
4640
<property name="text">
47-
<string>Nulls First</string>
41+
<string>NULLs handling</string>
4842
</property>
4943
</column>
5044
</widget>

0 commit comments

Comments
 (0)