Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix sorting of map layer combo box and more const correctness
  • Loading branch information
3nids committed Sep 2, 2014
1 parent 665866f commit 368755a
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion python/gui/qgsmaplayercombobox.sip
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/gui/qgsmaplayermodel.sip
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgsmaplayerproxymodel.sip
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaplayercombobox.cpp
Expand Up @@ -48,7 +48,7 @@ void QgsMapLayerComboBox::setLayer( QgsMapLayer *layer )
emit layerChanged( currentLayer() );
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaplayercombobox.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaplayermodel.cpp
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsmaplayermodel.h
Expand Up @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions src/gui/qgsmaplayerproxymodel.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/gui/qgsmaplayerproxymodel.h
Expand Up @@ -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
Expand Down

0 comments on commit 368755a

Please sign in to comment.