@@ -32,66 +32,65 @@ QgsUniqueValueDialog::QgsUniqueValueDialog( QgsVectorLayer* vl ): QDialog(), mVe
3232{
3333 setupUi ( this );
3434 setOrientation ( Qt::Vertical );
35+
3536 // find out the fields of mVectorLayer
36- QgsVectorDataProvider *provider;
37- if (( provider = dynamic_cast <QgsVectorDataProvider *>( mVectorLayer ->dataProvider () ) ) )
37+ if (mVectorLayer )
3838 {
39- const QgsFieldMap & fields = provider->fields ();
40- QString str;
41-
42- for ( QgsFieldMap::const_iterator it = fields.begin (); it != fields.end (); ++it )
39+ // we cannot use unique values for not-commited fields because QgsVectorLayer has no 'unique values' method...
40+ QgsVectorDataProvider* provider = mVectorLayer ->dataProvider ();
41+ if (provider)
4342 {
44- str = ( *it ).name ();
45- mClassificationComboBox ->addItem ( str );
43+ const QgsFieldMap & fields = provider->fields ();
44+ QString str;
45+
46+ for ( QgsFieldMap::const_iterator it = fields.begin (); it != fields.end (); ++it )
47+ {
48+ str = ( *it ).name ();
49+ str = mVectorLayer ->attributeDisplayName (it.key ());
50+ mClassificationComboBox ->addItem ( str, it.key () );
51+ }
4652 }
4753 }
48- else
49- {
50- QgsDebugMsg ( " data provider is null" );
51- return ;
52- }
54+
5355
5456 mClassListWidget ->setSelectionMode ( QAbstractItemView::ExtendedSelection );
5557 mClassListWidget ->setEditTriggers ( QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed | QAbstractItemView::AnyKeyPressed );
5658 mClassListWidget ->setSortingEnabled ( true );
5759
58- const QgsUniqueValueRenderer* renderer = dynamic_cast < const QgsUniqueValueRenderer * >( mVectorLayer ->renderer () );
59-
60- if ( renderer )
60+ if (mVectorLayer )
6161 {
62- mClassListWidget ->clear ();
63-
64- // XXX - mloskot - fix for Ticket #31 (bug)
65- // QgsAttributeList attributes = renderer->classificationAttributes();
66- // QgsAttributeList::iterator iter = attributes.begin();
67- // int classattr = *iter;
68- // QString field = provider->fields()[ classattr ].name();
69- QString field = provider->fields ()[ renderer->classificationField ()].name ();
70- mOldClassificationAttribute = field;
71- mClassificationComboBox ->setCurrentIndex ( mClassificationComboBox ->findText ( field ) );
72-
73- const QList<QgsSymbol*> list = renderer->symbols ();
74- // fill the items of the renderer into mValues
75- for ( QList<QgsSymbol*>::const_iterator iter = list.begin (); iter != list.end (); ++iter )
62+ const QgsUniqueValueRenderer* renderer = dynamic_cast < const QgsUniqueValueRenderer * >( mVectorLayer ->renderer () );
63+
64+ if ( renderer )
7665 {
77- QgsSymbol* symbol = ( *iter );
78- QString symbolvalue = symbol->lowerValue ();
79- QgsSymbol* sym = new QgsSymbol ( mVectorLayer ->geometryType (), symbol->lowerValue (), symbol->upperValue (), symbol->label () );
80- sym->setPen ( symbol->pen () );
81- sym->setCustomTexture ( symbol->customTexture () );
82- sym->setBrush ( symbol->brush () );
83- sym->setNamedPointSymbol ( symbol->pointSymbolName () );
84- sym->setPointSize ( symbol->pointSize () );
85- sym->setScaleClassificationField ( symbol->scaleClassificationField () );
86- sym->setRotationClassificationField ( symbol->rotationClassificationField () );
87- mValues .insert ( symbolvalue, sym );
88-
89- QListWidgetItem *item = new QListWidgetItem ( symbolvalue );
90- mClassListWidget ->addItem ( item );
91- updateEntryIcon ( symbol, item );
92- item->setFlags ( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
93- item->setData ( Qt::UserRole, symbol->lowerValue () );
94- item->setToolTip ( symbol->label () );
66+ mClassListWidget ->clear ();
67+ QString field = mVectorLayer ->attributeDisplayName (renderer->classificationField ());
68+ mOldClassificationAttribute = field;
69+ mClassificationComboBox ->setCurrentIndex ( mClassificationComboBox ->findText ( field ) );
70+
71+ const QList<QgsSymbol*> list = renderer->symbols ();
72+ // fill the items of the renderer into mValues
73+ for ( QList<QgsSymbol*>::const_iterator iter = list.begin (); iter != list.end (); ++iter )
74+ {
75+ QgsSymbol* symbol = ( *iter );
76+ QString symbolvalue = symbol->lowerValue ();
77+ QgsSymbol* sym = new QgsSymbol ( mVectorLayer ->geometryType (), symbol->lowerValue (), symbol->upperValue (), symbol->label () );
78+ sym->setPen ( symbol->pen () );
79+ sym->setCustomTexture ( symbol->customTexture () );
80+ sym->setBrush ( symbol->brush () );
81+ sym->setNamedPointSymbol ( symbol->pointSymbolName () );
82+ sym->setPointSize ( symbol->pointSize () );
83+ sym->setScaleClassificationField ( symbol->scaleClassificationField () );
84+ sym->setRotationClassificationField ( symbol->rotationClassificationField () );
85+ mValues .insert ( symbolvalue, sym );
86+
87+ QListWidgetItem *item = new QListWidgetItem ( symbolvalue );
88+ mClassListWidget ->addItem ( item );
89+ updateEntryIcon ( symbol, item );
90+ item->setFlags ( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
91+ item->setData ( Qt::UserRole, symbol->lowerValue () );
92+ item->setToolTip ( symbol->label () );
93+ }
9594 }
9695 }
9796
@@ -149,7 +148,7 @@ void QgsUniqueValueDialog::apply()
149148 QgsVectorDataProvider *provider = dynamic_cast <QgsVectorDataProvider *>( mVectorLayer ->dataProvider () );
150149 if ( provider )
151150 {
152- int fieldIndex = provider-> fieldNameIndex ( mClassificationComboBox ->currentText () );
151+ int fieldIndex = mClassificationComboBox -> itemData ( mClassificationComboBox ->currentIndex () ). toInt ( );
153152 if ( fieldIndex != -1 )
154153 {
155154 renderer->setClassificationField ( fieldIndex );
@@ -292,7 +291,7 @@ void QgsUniqueValueDialog::changeClassificationAttribute()
292291 QgsVectorDataProvider *provider = dynamic_cast <QgsVectorDataProvider *>( mVectorLayer ->dataProvider () );
293292 if ( provider )
294293 {
295- int nr = provider-> fieldNameIndex ( attributeName );
294+ int nr = mClassificationComboBox -> itemData ( mClassificationComboBox -> currentIndex ()). toInt ( );
296295 if ( nr == -1 )
297296 {
298297 return ;
0 commit comments