Skip to content
Permalink
Browse files

sub layer dialog: sort by layer id and feature count numerically (fixes

  • Loading branch information
jef-n committed Jul 22, 2017
1 parent 22162b9 commit 90fa6c2e9124b555428ab083bf936d28b043539f
Showing with 29 additions and 1 deletion.
  1. +6 −0 python/gui/qgssublayersdialog.sip
  2. +19 −1 src/gui/qgssublayersdialog.cpp
  3. +4 −0 src/gui/qgssublayersdialog.h
@@ -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();
@@ -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 )
@@ -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
@@ -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();

0 comments on commit 90fa6c2

Please sign in to comment.
You can’t perform that action at this time.