Skip to content

Commit

Permalink
sub layer dialog: sort by layer id and feature count numerically (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jul 22, 2017
1 parent 22162b9 commit 90fa6c2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions python/gui/qgssublayersdialog.sip
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class QgsSublayersDialog : QDialog
:rtype: bool
%End

int countColumn() const;
%Docstring
.. versionadded:: 3.0
:rtype: int
%End

public slots:
void on_buttonBox_helpRequested();
int exec();
Expand Down
20 changes: 19 additions & 1 deletion src/gui/qgssublayersdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@
#include <QTableWidgetItem>
#include <QPushButton>

class SubLayerItem : public QTreeWidgetItem
{
public:
SubLayerItem( const QStringList &strings, int type = QTreeWidgetItem::Type )
: QTreeWidgetItem( strings, type )
{}

bool operator <( const QTreeWidgetItem &other ) const
{
QgsSublayersDialog *d = qobject_cast<QgsSublayersDialog *>( treeWidget()->parent() );
int col = treeWidget()->sortColumn();

if ( col == 0 || ( col > 0 && d->countColumn() == col ) )
return text( col ).toInt() < other.text( col ).toInt();
else
return text( col ) < other.text( col );
}
};

QgsSublayersDialog::QgsSublayersDialog( ProviderType providerType, const QString &name,
QWidget *parent, Qt::WindowFlags fl )
Expand Down Expand Up @@ -123,7 +141,7 @@ void QgsSublayersDialog::populateLayerTable( const QgsSublayersDialog::LayerDefi
elements << QString::number( item.count );
if ( mShowType )
elements << item.type;
layersTable->addTopLevelItem( new QTreeWidgetItem( elements ) );
layersTable->addTopLevelItem( new SubLayerItem( elements ) );
}

// resize columns
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgssublayersdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class GUI_EXPORT QgsSublayersDialog : public QDialog, private Ui::QgsSublayersDi
//! \since QGIS 3.0
bool addToGroupCheckbox() const { return mCheckboxAddToGroup->isChecked(); }

//! Return column with count or -1
//! \since QGIS 3.0
int countColumn() const { return mShowCount ? 2 : -1; }

public slots:
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
int exec();
Expand Down

0 comments on commit 90fa6c2

Please sign in to comment.