Skip to content
Permalink
Browse files

fix sorting of map layer combo box and more const correctness

  • Loading branch information
3nids committed Sep 2, 2014
1 parent 665866f commit 368755a51a20824689a69419cafce604f9c4ec87
@@ -23,7 +23,7 @@ class QgsMapLayerComboBox : QComboBox
QgsMapLayerProxyModel::Filters filters() const;

//! currentLayer returns the current layer selected in the combo box
QgsMapLayer* currentLayer();
QgsMapLayer* currentLayer() const;

public slots:
//! setLayer set the current layer selected in the combo
@@ -37,12 +37,12 @@ class QgsMapLayerModel : QAbstractItemModel
*/
QList<QgsMapLayer*> layersChecked( Qt::CheckState checkState = Qt::Checked );
//! returns if the items can be checked or not
bool itemsCheckable();
bool itemsCheckable() const;

/**
* @brief indexFromLayer returns the model index for a given layer
*/
QModelIndex indexFromLayer( QgsMapLayer* layer );
QModelIndex indexFromLayer( QgsMapLayer* layer ) const;


protected slots:
@@ -33,7 +33,7 @@ class QgsMapLayerProxyModel : QSortFilterProxyModel
/**
* @brief layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
*/
QgsMapLayerModel* sourceLayerModel();
QgsMapLayerModel* sourceLayerModel() const;

/**
* @brief setFilters set flags that affect how layers are filtered
@@ -48,7 +48,7 @@ void QgsMapLayerComboBox::setLayer( QgsMapLayer *layer )
emit layerChanged( currentLayer() );
}

QgsMapLayer* QgsMapLayerComboBox::currentLayer()
QgsMapLayer* QgsMapLayerComboBox::currentLayer() const
{
int i = currentIndex();

@@ -47,7 +47,7 @@ class GUI_EXPORT QgsMapLayerComboBox : public QComboBox
QgsMapLayerProxyModel::Filters filters() const { return mProxyModel->filters(); }

//! currentLayer returns the current layer selected in the combo box
QgsMapLayer* currentLayer();
QgsMapLayer* currentLayer() const;

public slots:
//! setLayer set the current layer selected in the combo
@@ -70,7 +70,7 @@ QList<QgsMapLayer *> QgsMapLayerModel::layersChecked( Qt::CheckState checkState
return layers;
}

QModelIndex QgsMapLayerModel::indexFromLayer( QgsMapLayer *layer )
QModelIndex QgsMapLayerModel::indexFromLayer( QgsMapLayer *layer ) const
{
int r = mLayers.indexOf( layer );
return index( r, 0 );
@@ -57,12 +57,12 @@ class GUI_EXPORT QgsMapLayerModel : public QAbstractItemModel
*/
QList<QgsMapLayer*> layersChecked( Qt::CheckState checkState = Qt::Checked );
//! returns if the items can be checked or not
bool itemsCheckable() { return mItemCheckable; }
bool itemsCheckable() const { return mItemCheckable; }

/**
* @brief indexFromLayer returns the model index for a given layer
*/
QModelIndex indexFromLayer( QgsMapLayer* layer );
QModelIndex indexFromLayer( QgsMapLayer* layer ) const;


protected slots:
@@ -21,9 +21,13 @@
QgsMapLayerProxyModel::QgsMapLayerProxyModel( QObject *parent )
: QSortFilterProxyModel( parent )
, mFilters( All )
, mModel( new QgsMapLayerModel( this ) )
, mModel( new QgsMapLayerModel( parent ) )
{
setSourceModel( mModel );
setDynamicSortFilter( true );
setSortLocaleAware( true );
setFilterCaseSensitivity( Qt::CaseInsensitive );
sort( 0 );
}

QgsMapLayerProxyModel *QgsMapLayerProxyModel::setFilters( Filters filters )
@@ -79,7 +83,7 @@ bool QgsMapLayerProxyModel::filterAcceptsRow( int source_row, const QModelIndex
bool QgsMapLayerProxyModel::lessThan( const QModelIndex &left, const QModelIndex &right ) const
{
// default mode is alphabetical order
QString leftId = sourceModel()->data( left ).toString();
QString rightId = sourceModel()->data( right ).toString();
return QString::localeAwareCompare( leftId, rightId ) < 0;
QString leftStr = sourceModel()->data( left ).toString();
QString rightStr = sourceModel()->data( right ).toString();
return QString::localeAwareCompare( leftStr, rightStr ) < 0;
}
@@ -52,7 +52,7 @@ class GUI_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
/**
* @brief layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
*/
QgsMapLayerModel* sourceLayerModel() { return mModel; }
QgsMapLayerModel* sourceLayerModel() const { return mModel; }

/**
* @brief setFilters set flags that affect how layers are filtered

0 comments on commit 368755a

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