@@ -39,35 +39,7 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer* layer ): Q
3939 mBandComboBox ->addItem ( provider->colorInterpretationName ( i ), i );
4040 }
4141
42- QgsPalettedRasterRenderer* r = dynamic_cast <QgsPalettedRasterRenderer*>( mRasterLayer ->renderer () );
43- if ( r )
44- {
45- // read values and colors and fill into tree widget
46- int nColors = r->nColors ();
47- QColor* colors = r->colors ();
48- for ( int i = 0 ; i < nColors; ++i )
49- {
50- QTreeWidgetItem* item = new QTreeWidgetItem ( mTreeWidget );
51- item->setText ( 0 , QString::number ( i ) );
52- item->setBackground ( 1 , QBrush ( colors[i] ) );
53- }
54- delete[] colors;
55- }
56- else
57- {
58- // read default palette settings from layer
59- QList<QgsColorRampShader::ColorRampItem>* itemList =
60- mRasterLayer ->colorTable ( mBandComboBox ->itemData ( mBandComboBox ->currentIndex () ).toInt () );
61- QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList->constBegin ();
62- int index = 0 ;
63- for ( ; itemIt != itemList->constEnd (); ++itemIt )
64- {
65- QTreeWidgetItem* item = new QTreeWidgetItem ( mTreeWidget );
66- item->setText ( 0 , QString::number ( index ) );
67- item->setBackground ( 1 , QBrush ( itemIt->color ) );
68- ++index;
69- }
70- }
42+ setFromRenderer ( mRasterLayer ->renderer () );
7143 }
7244}
7345
@@ -99,3 +71,36 @@ void QgsPalettedRendererWidget::on_mTreeWidget_itemDoubleClicked( QTreeWidgetIte
9971 }
10072 }
10173}
74+
75+ void QgsPalettedRendererWidget::setFromRenderer ( const QgsRasterRenderer* r )
76+ {
77+ const QgsPalettedRasterRenderer* pr = dynamic_cast <const QgsPalettedRasterRenderer*>( r );
78+ if ( pr )
79+ {
80+ // read values and colors and fill into tree widget
81+ int nColors = pr->nColors ();
82+ QColor* colors = pr->colors ();
83+ for ( int i = 0 ; i < nColors; ++i )
84+ {
85+ QTreeWidgetItem* item = new QTreeWidgetItem ( mTreeWidget );
86+ item->setText ( 0 , QString::number ( i ) );
87+ item->setBackground ( 1 , QBrush ( colors[i] ) );
88+ }
89+ delete[] colors;
90+ }
91+ else
92+ {
93+ // read default palette settings from layer
94+ QList<QgsColorRampShader::ColorRampItem>* itemList =
95+ mRasterLayer ->colorTable ( mBandComboBox ->itemData ( mBandComboBox ->currentIndex () ).toInt () );
96+ QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList->constBegin ();
97+ int index = 0 ;
98+ for ( ; itemIt != itemList->constEnd (); ++itemIt )
99+ {
100+ QTreeWidgetItem* item = new QTreeWidgetItem ( mTreeWidget );
101+ item->setText ( 0 , QString::number ( index ) );
102+ item->setBackground ( 1 , QBrush ( itemIt->color ) );
103+ ++index;
104+ }
105+ }
106+ }
0 commit comments