@@ -32,66 +32,65 @@ QgsUniqueValueDialog::QgsUniqueValueDialog( QgsVectorLayer* vl ): QDialog(), mVe
32
32
{
33
33
setupUi ( this );
34
34
setOrientation ( Qt::Vertical );
35
+
35
36
// find out the fields of mVectorLayer
36
- QgsVectorDataProvider *provider;
37
- if (( provider = dynamic_cast <QgsVectorDataProvider *>( mVectorLayer ->dataProvider () ) ) )
37
+ if (mVectorLayer )
38
38
{
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)
43
42
{
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
+ }
46
52
}
47
53
}
48
- else
49
- {
50
- QgsDebugMsg ( " data provider is null" );
51
- return ;
52
- }
54
+
53
55
54
56
mClassListWidget ->setSelectionMode ( QAbstractItemView::ExtendedSelection );
55
57
mClassListWidget ->setEditTriggers ( QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed | QAbstractItemView::AnyKeyPressed );
56
58
mClassListWidget ->setSortingEnabled ( true );
57
59
58
- const QgsUniqueValueRenderer* renderer = dynamic_cast < const QgsUniqueValueRenderer * >( mVectorLayer ->renderer () );
59
-
60
- if ( renderer )
60
+ if (mVectorLayer )
61
61
{
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 )
76
65
{
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
+ }
95
94
}
96
95
}
97
96
@@ -149,7 +148,7 @@ void QgsUniqueValueDialog::apply()
149
148
QgsVectorDataProvider *provider = dynamic_cast <QgsVectorDataProvider *>( mVectorLayer ->dataProvider () );
150
149
if ( provider )
151
150
{
152
- int fieldIndex = provider-> fieldNameIndex ( mClassificationComboBox ->currentText () );
151
+ int fieldIndex = mClassificationComboBox -> itemData ( mClassificationComboBox ->currentIndex () ). toInt ( );
153
152
if ( fieldIndex != -1 )
154
153
{
155
154
renderer->setClassificationField ( fieldIndex );
@@ -292,7 +291,7 @@ void QgsUniqueValueDialog::changeClassificationAttribute()
292
291
QgsVectorDataProvider *provider = dynamic_cast <QgsVectorDataProvider *>( mVectorLayer ->dataProvider () );
293
292
if ( provider )
294
293
{
295
- int nr = provider-> fieldNameIndex ( attributeName );
294
+ int nr = mClassificationComboBox -> itemData ( mClassificationComboBox -> currentIndex ()). toInt ( );
296
295
if ( nr == -1 )
297
296
{
298
297
return ;
0 commit comments