Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Implement saving paletted raster renderer color tables
Use the .clr/gdal file format, but add the labels on the ends of the lines. Seems other importers like ArcMap just ignore these.
- Loading branch information
1 parent
d0566f7
commit 7eb63d9
Showing
7 changed files
with
106 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,9 +326,11 @@ QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromStr | |
break; | ||
} | ||
|
||
case 4: | ||
case 5: | ||
default: | ||
{ | ||
if ( lineParts.count() < 4 ) | ||
continue; | ||
|
||
int value = lineParts.at( 0 ).toInt( &ok ); | ||
if ( !ok ) | ||
continue; | ||
|
@@ -346,14 +348,20 @@ QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromStr | |
c = QColor( r, g, b ); | ||
} | ||
|
||
if ( lineParts.count() == 5 ) | ||
if ( lineParts.count() >= 5 ) | ||
{ | ||
double alpha = lineParts.at( 4 ).toDouble( &ok ); | ||
if ( ok ) | ||
c.setAlpha( alpha ); | ||
} | ||
|
||
classes << Class( value, c ); | ||
QString label; | ||
if ( lineParts.count() > 5 ) | ||
{ | ||
label = lineParts.mid( 5 ).join( ' ' ); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nyalldawson
Author
Collaborator
|
||
} | ||
|
||
classes << Class( value, c, label ); | ||
break; | ||
} | ||
} | ||
|
@@ -375,6 +383,24 @@ QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromFil | |
return classDataFromString( input ); | ||
} | ||
|
||
QString QgsPalettedRasterRenderer::classDataToString( const QgsPalettedRasterRenderer::ClassData &classes ) | ||
{ | ||
QStringList out; | ||
// must be sorted | ||
QgsPalettedRasterRenderer::ClassData cd = classes; | ||
std::sort( cd.begin(), cd.end(), []( const Class & a, const Class & b ) -> bool | ||
{ | ||
return a.value < b.value; | ||
} ); | ||
|
||
Q_FOREACH ( const Class &c, cd ) | ||
{ | ||
out << QString( "%1 %2 %3 %4 %5 %6" ).arg( c.value ).arg( c.color.red() ) | ||
.arg( c.color.green() ).arg( c.color.blue() ).arg( c.color.alpha() ).arg( c.label ); | ||
} | ||
return out.join( '\n' ); | ||
} | ||
|
||
void QgsPalettedRasterRenderer::updateArrays() | ||
{ | ||
// find maximum color index | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
1 0 0 0 | ||
2 200 200 200 | ||
3 0 110 0 | ||
4 110 65 0 | ||
5 0 0 255 | ||
6 0 89 255 | ||
7 0 174 255 | ||
8 0 255 246 | ||
9 238 255 0 | ||
10 255 182 0 |
This line gives me compilation error:
no member named 'join' in 'QList<QString>'
which seems to be right, because mid() returns QList, not QStringList which has join().
How can you compile that line?