Skip to content

Commit c0f190d

Browse files
committed
Address Nyall's point from review
1 parent ca65717 commit c0f190d

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

src/core/mesh/qgsmeshlayer.cpp

+23-7
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
#include "qgsmaplayerlegend.h"
2626
#include "qgsmeshdataprovider.h"
2727
#include "qgsmeshlayer.h"
28+
#include "qgsmeshlayerinterpolator.h"
2829
#include "qgsmeshlayerrenderer.h"
2930
#include "qgsmeshlayerutils.h"
3031
#include "qgsproviderregistry.h"
3132
#include "qgsreadwritecontext.h"
33+
#include "qgsstyle.h"
3234
#include "qgstriangularmesh.h"
33-
#include "qgsmeshlayerinterpolator.h"
3435

3536

3637
QgsMeshLayer::QgsMeshLayer( const QString &meshLayerPath,
@@ -182,13 +183,28 @@ void QgsMeshLayer::onDatasetGroupsAdded( int count )
182183
assignDefaultStyleToDatasetGroup( i );
183184
}
184185

185-
static QgsGradientColorRamp *_createDefaultColorRamp()
186+
static QgsColorRamp *_createDefaultColorRamp()
186187
{
187-
QgsGradientStopsList stops;
188-
stops << QgsGradientStop( 0.25, QColor( 0, 255, 255 ) );
189-
stops << QgsGradientStop( 0.5, QColor( 0, 255, 0 ) );
190-
stops << QgsGradientStop( 0.75, QColor( 255, 255, 0 ) );
191-
return new QgsGradientColorRamp( QColor( 0, 0, 255 ), QColor( 255, 0, 0 ), false, stops );
188+
QgsColorRamp *ramp = QgsStyle::defaultStyle()->colorRamp( QStringLiteral( "Plasma" ) );
189+
if ( ramp )
190+
return ramp;
191+
192+
// definition of "Plasma" color ramp (in case it is not available in the style for some reason)
193+
QgsStringMap props;
194+
props["color1"] = "13,8,135,255";
195+
props["color2"] = "240,249,33,255";
196+
props["stops"] =
197+
"0.0196078;27,6,141,255:0.0392157;38,5,145,255:0.0588235;47,5,150,255:0.0784314;56,4,154,255:0.0980392;65,4,157,255:"
198+
"0.117647;73,3,160,255:0.137255;81,2,163,255:0.156863;89,1,165,255:0.176471;97,0,167,255:0.196078;105,0,168,255:"
199+
"0.215686;113,0,168,255:0.235294;120,1,168,255:0.254902;128,4,168,255:0.27451;135,7,166,255:0.294118;142,12,164,255:"
200+
"0.313725;149,17,161,255:0.333333;156,23,158,255:0.352941;162,29,154,255:0.372549;168,34,150,255:0.392157;174,40,146,255:"
201+
"0.411765;180,46,141,255:0.431373;186,51,136,255:0.45098;191,57,132,255:0.470588;196,62,127,255:0.490196;201,68,122,255:"
202+
"0.509804;205,74,118,255:0.529412;210,79,113,255:0.54902;214,85,109,255:0.568627;218,91,105,255:0.588235;222,97,100,255:"
203+
"0.607843;226,102,96,255:0.627451;230,108,92,255:0.647059;233,114,87,255:0.666667;237,121,83,255:0.686275;240,127,79,255:"
204+
"0.705882;243,133,75,255:0.72549;245,140,70,255:0.745098;247,147,66,255:0.764706;249,154,62,255:0.784314;251,161,57,255:"
205+
"0.803922;252,168,53,255:0.823529;253,175,49,255:0.843137;254,183,45,255:0.862745;254,190,42,255:0.882353;253,198,39,255:"
206+
"0.901961;252,206,37,255:0.921569;251,215,36,255:0.941176;248,223,37,255:0.960784;246,232,38,255:0.980392;243,240,39,255";
207+
return QgsGradientColorRamp::create( props );
192208
}
193209

194210
void QgsMeshLayer::assignDefaultStyleToDatasetGroup( int groupIndex )

tests/src/core/testqgsmeshlayerrenderer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ void TestQgsMeshRenderer::initTestCase()
110110
mMapSettings->setLayers(
111111
QList<QgsMapLayer *>() << mMemoryLayer );
112112

113-
// here we check that datasets automatically get some default style applied
113+
// here we check that datasets automatically get our default color ramp applied ("Plasma")
114114
QgsMeshDatasetIndex ds( 0, 0 );
115115
QgsMeshRendererScalarSettings scalarSettings = mMemoryLayer->rendererSettings().scalarSettings( ds.group() );
116116
QgsColorRampShader shader = scalarSettings.colorRampShader();
117117
QList<QgsColorRampShader::ColorRampItem> lst = shader.colorRampItemList();
118-
QCOMPARE( lst.count(), 5 );
118+
QCOMPARE( lst.count(), 52 );
119119
QCOMPARE( lst.at( 0 ).value, 1. ); // min group value
120-
QCOMPARE( lst.at( 4 ).value, 4. ); // max group value
120+
QCOMPARE( lst.at( lst.count() - 1 ).value, 4. ); // max group value
121121
}
122122

123123
void TestQgsMeshRenderer::cleanupTestCase()

0 commit comments

Comments
 (0)