Skip to content
Permalink
Browse files

Paletted: fix ordering from proxy model

  • Loading branch information
elpaso committed Nov 9, 2020
1 parent b3a0ff8 commit 58ce77f19aea54d98cb526453af69facf49a50de
Showing with 19 additions and 3 deletions.
  1. +15 −3 src/gui/raster/qgspalettedrendererwidget.cpp
  2. +4 −0 src/gui/raster/qgspalettedrendererwidget.h
@@ -141,7 +141,7 @@ QgsPalettedRendererWidget::~QgsPalettedRendererWidget()

QgsRasterRenderer *QgsPalettedRendererWidget::renderer()
{
QgsPalettedRasterRenderer::ClassData classes = mModel->classData();
QgsPalettedRasterRenderer::ClassData classes = mProxyModel->classData();
int bandNumber = mBandComboBox->currentBand();

QgsPalettedRasterRenderer *r = new QgsPalettedRasterRenderer( mRasterLayer->dataProvider(), bandNumber, classes );
@@ -342,7 +342,7 @@ void QgsPalettedRendererWidget::applyColorRamp()

disconnect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );

QgsPalettedRasterRenderer::ClassData data = mModel->classData();
QgsPalettedRasterRenderer::ClassData data = mProxyModel->classData();
QgsPalettedRasterRenderer::ClassData::iterator cIt = data.begin();

double numberOfEntries = data.count();
@@ -407,7 +407,7 @@ void QgsPalettedRendererWidget::saveColorTable()
if ( outputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
{
QTextStream outputStream( &outputFile );
outputStream << QgsPalettedRasterRenderer::classDataToString( mModel->classData() );
outputStream << QgsPalettedRasterRenderer::classDataToString( mProxyModel->classData() );
outputStream.flush();
outputFile.close();

@@ -876,4 +876,16 @@ void QgsPalettedRendererClassGatherer::run()
emit collectedClasses();
}


QgsPalettedRasterRenderer::ClassData QgsPalettedRendererProxyModel::classData() const
{
QgsPalettedRasterRenderer::ClassData data;
for ( int i = 0; i < rowCount( ); ++i )
{
data.push_back( qobject_cast<QgsPalettedRendererModel *>( sourceModel() )->classAtIndex( mapToSource( index( i, 0 ) ) ) );
}
return data;
}


///@endcond PRIVATE
@@ -112,6 +112,7 @@ class QgsPalettedRendererModel : public QAbstractItemModel
void setClassData( const QgsPalettedRasterRenderer::ClassData &data );

QgsPalettedRasterRenderer::ClassData classData() const { return mData; }
QgsPalettedRasterRenderer::Class classAtIndex( const QModelIndex &index ) const { return mData.at( index.row() ); }

QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
QModelIndex parent( const QModelIndex &index ) const override;
@@ -156,6 +157,9 @@ class QgsPalettedRendererProxyModel: public QSortFilterProxyModel
{
}

//! Return sorted class data
QgsPalettedRasterRenderer::ClassData classData() const;

protected:

bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override

0 comments on commit 58ce77f

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