Skip to content

Commit 90fa6c2

Browse files
committedJul 22, 2017
sub layer dialog: sort by layer id and feature count numerically (fixes #16917)
1 parent 22162b9 commit 90fa6c2

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed
 

‎python/gui/qgssublayersdialog.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class QgsSublayersDialog : QDialog
7070
:rtype: bool
7171
%End
7272

73+
int countColumn() const;
74+
%Docstring
75+
.. versionadded:: 3.0
76+
:rtype: int
77+
%End
78+
7379
public slots:
7480
void on_buttonBox_helpRequested();
7581
int exec();

‎src/gui/qgssublayersdialog.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@
2020
#include <QTableWidgetItem>
2121
#include <QPushButton>
2222

23+
class SubLayerItem : public QTreeWidgetItem
24+
{
25+
public:
26+
SubLayerItem( const QStringList &strings, int type = QTreeWidgetItem::Type )
27+
: QTreeWidgetItem( strings, type )
28+
{}
29+
30+
bool operator <( const QTreeWidgetItem &other ) const
31+
{
32+
QgsSublayersDialog *d = qobject_cast<QgsSublayersDialog *>( treeWidget()->parent() );
33+
int col = treeWidget()->sortColumn();
34+
35+
if ( col == 0 || ( col > 0 && d->countColumn() == col ) )
36+
return text( col ).toInt() < other.text( col ).toInt();
37+
else
38+
return text( col ) < other.text( col );
39+
}
40+
};
2341

2442
QgsSublayersDialog::QgsSublayersDialog( ProviderType providerType, const QString &name,
2543
QWidget *parent, Qt::WindowFlags fl )
@@ -123,7 +141,7 @@ void QgsSublayersDialog::populateLayerTable( const QgsSublayersDialog::LayerDefi
123141
elements << QString::number( item.count );
124142
if ( mShowType )
125143
elements << item.type;
126-
layersTable->addTopLevelItem( new QTreeWidgetItem( elements ) );
144+
layersTable->addTopLevelItem( new SubLayerItem( elements ) );
127145
}
128146

129147
// resize columns

‎src/gui/qgssublayersdialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class GUI_EXPORT QgsSublayersDialog : public QDialog, private Ui::QgsSublayersDi
8080
//! \since QGIS 3.0
8181
bool addToGroupCheckbox() const { return mCheckboxAddToGroup->isChecked(); }
8282

83+
//! Return column with count or -1
84+
//! \since QGIS 3.0
85+
int countColumn() const { return mShowCount ? 2 : -1; }
86+
8387
public slots:
8488
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
8589
int exec();

0 commit comments

Comments
 (0)
Please sign in to comment.