[QGIS Commit] r10992 - in trunk/qgis/src: app app/legend core
core/composer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Wed Jul 1 06:11:34 EDT 2009
Author: mhugent
Date: 2009-07-01 06:11:33 -0400 (Wed, 01 Jul 2009)
New Revision: 10992
Modified:
trunk/qgis/src/app/legend/qgslegendlayer.cpp
trunk/qgis/src/app/qgsattributedialog.cpp
trunk/qgis/src/app/qgscontinuouscolordialog.cpp
trunk/qgis/src/app/qgsgraduatedsymboldialog.cpp
trunk/qgis/src/app/qgsmaptoolidentify.cpp
trunk/qgis/src/app/qgsuniquevaluedialog.cpp
trunk/qgis/src/core/composer/qgslegendmodel.cpp
trunk/qgis/src/core/qgsvectorlayer.cpp
trunk/qgis/src/core/qgsvectorlayer.h
Log:
Added a convenience to retrieve the attribute display name from QgsVectorLayer. Use this function in renderer dialogs, info tool, attribute table and composer legend
Modified: trunk/qgis/src/app/legend/qgslegendlayer.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegendlayer.cpp 2009-07-01 07:51:18 UTC (rev 10991)
+++ trunk/qgis/src/app/legend/qgslegendlayer.cpp 2009-07-01 10:11:33 UTC (rev 10992)
@@ -370,11 +370,14 @@
if ( renderer->needsAttributes() )
{
QgsAttributeList classfieldlist = renderer->classificationAttributes();
- const QgsFieldMap& fields = layer->dataProvider()->fields();
+ const QgsFieldMap& fields = layer->pendingFields();
for ( QgsAttributeList::iterator it = classfieldlist.begin(); it != classfieldlist.end(); ++it )
{
- const QgsField& theField = fields[*it];
- QString classfieldname = theField.name();
+ QString classfieldname = layer->attributeAlias(*it);
+ if(classfieldname.isEmpty())
+ {
+ classfieldname = fields[*it].name();
+ }
itemList.push_front( std::make_pair( classfieldname, QPixmap() ) );
}
}
Modified: trunk/qgis/src/app/qgsattributedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.cpp 2009-07-01 07:51:18 UTC (rev 10991)
+++ trunk/qgis/src/app/qgsattributedialog.cpp 2009-07-01 10:11:33 UTC (rev 10992)
@@ -103,11 +103,7 @@
const QgsField &field = theFieldMap[it.key()];
//show attribute alias if available
- QString myFieldName = vl->attributeAlias(it.key());
- if(myFieldName.isEmpty())
- {
- myFieldName = field.name();
- }
+ QString myFieldName = vl->attributeDisplayName(it.key());
int myFieldType = field.type();
QLabel * mypLabel = new QLabel();
mypInnerLayout->addWidget( mypLabel, index, 0 );
Modified: trunk/qgis/src/app/qgscontinuouscolordialog.cpp
===================================================================
--- trunk/qgis/src/app/qgscontinuouscolordialog.cpp 2009-07-01 07:51:18 UTC (rev 10991)
+++ trunk/qgis/src/app/qgscontinuouscolordialog.cpp 2009-07-01 10:11:33 UTC (rev 10992)
@@ -41,13 +41,15 @@
//find out the numerical fields of mVectorLayer
const QgsFieldMap & fields = mVectorLayer->pendingFields();
+ QString displayName;
for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
{
QVariant::Type type = it->type();
if ( type == QVariant::Int || type == QVariant::Double )
{
- classificationComboBox->addItem( it->name(), it.key() );
+ displayName = mVectorLayer->attributeDisplayName(it.key());
+ classificationComboBox->addItem( displayName, it.key() );
}
}
@@ -144,7 +146,7 @@
}
else
{
- minimumString = QString::number( minimum );
+ minimumString = QString::number( minimum, 'f', 0 );
}
QgsSymbol* minsymbol = new QgsSymbol( mVectorLayer->geometryType(), minimumString, "", "" );
QPen minPen;
@@ -167,7 +169,7 @@
}
else
{
- maximumString = QString::number( maximum );
+ maximumString = QString::number( maximum, 'f', 0 );
}
QgsSymbol* maxsymbol = new QgsSymbol( mVectorLayer->geometryType(), maximumString, "", "" );
QPen maxPen;
Modified: trunk/qgis/src/app/qgsgraduatedsymboldialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsgraduatedsymboldialog.cpp 2009-07-01 07:51:18 UTC (rev 10991)
+++ trunk/qgis/src/app/qgsgraduatedsymboldialog.cpp 2009-07-01 10:11:33 UTC (rev 10992)
@@ -37,15 +37,16 @@
//find out the numerical fields of mVectorLayer
const QgsFieldMap & fields = layer->pendingFields();
- QString str;
+ QString displayName;
for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
{
QVariant::Type type = ( *it ).type();
if ( type == QVariant::Int || type == QVariant::Double )
{
- classificationComboBox->addItem( it->name() );
- mFieldMap.insert( std::make_pair( it->name(), it.key() ) );
+ displayName = layer->attributeDisplayName(it.key());
+ classificationComboBox->addItem( displayName );
+ mFieldMap.insert( std::make_pair( displayName, it.key() ) );
}
}
@@ -350,7 +351,7 @@
}
else
{
- lowerString = QString::number(*last_it);
+ lowerString = QString::number(*last_it, 'f', 0);
}
( *symbol_it )->setLowerValue(lowerString);
@@ -360,7 +361,7 @@
}
else
{
- upperString = QString::number(*it);
+ upperString = QString::number(*it, 'f', 0);
}
( *symbol_it )->setUpperValue(upperString);
@@ -391,7 +392,7 @@
}
else
{
- lowerString = QString::number(lower);
+ lowerString = QString::number(lower, 'f', 0);
}
( *symbol_it )->setLowerValue(lowerString);
@@ -403,7 +404,7 @@
}
else
{
- upperString = QString::number(upper);
+ upperString = QString::number(upper, 'f', 0);
}
( *symbol_it )->setUpperValue(upperString);
Modified: trunk/qgis/src/app/qgsmaptoolidentify.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolidentify.cpp 2009-07-01 07:51:18 UTC (rev 10991)
+++ trunk/qgis/src/app/qgsmaptoolidentify.cpp 2009-07-01 10:11:33 UTC (rev 10992)
@@ -337,11 +337,7 @@
{
featureNode->setText( 1, it->toString() );
}
- QString attributeName = layer->attributeAlias(it.key());
- if(attributeName.isEmpty())
- {
- attributeName = fields[it.key()].name();
- }
+ QString attributeName = layer->attributeDisplayName(it.key());
mResults->addAttribute( featureNode, attributeName, it->isNull() ? "NULL" : it->toString() );
}
Modified: trunk/qgis/src/app/qgsuniquevaluedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsuniquevaluedialog.cpp 2009-07-01 07:51:18 UTC (rev 10991)
+++ trunk/qgis/src/app/qgsuniquevaluedialog.cpp 2009-07-01 10:11:33 UTC (rev 10992)
@@ -32,66 +32,65 @@
{
setupUi( this );
setOrientation( Qt::Vertical );
+
//find out the fields of mVectorLayer
- QgsVectorDataProvider *provider;
- if (( provider = dynamic_cast<QgsVectorDataProvider *>( mVectorLayer->dataProvider() ) ) )
+ if(mVectorLayer)
{
- const QgsFieldMap & fields = provider->fields();
- QString str;
-
- for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
+ //we cannot use unique values for not-commited fields because QgsVectorLayer has no 'unique values' method...
+ QgsVectorDataProvider* provider = mVectorLayer->dataProvider();
+ if(provider)
{
- str = ( *it ).name();
- mClassificationComboBox->addItem( str );
+ const QgsFieldMap & fields = provider->fields();
+ QString str;
+
+ for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
+ {
+ str = ( *it ).name();
+ str = mVectorLayer->attributeDisplayName(it.key());
+ mClassificationComboBox->addItem( str, it.key() );
+ }
}
}
- else
- {
- QgsDebugMsg( "data provider is null" );
- return;
- }
+
mClassListWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
mClassListWidget->setEditTriggers( QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed | QAbstractItemView::AnyKeyPressed );
mClassListWidget->setSortingEnabled( true );
- const QgsUniqueValueRenderer* renderer = dynamic_cast < const QgsUniqueValueRenderer * >( mVectorLayer->renderer() );
-
- if ( renderer )
+ if(mVectorLayer)
{
- mClassListWidget->clear();
+ const QgsUniqueValueRenderer* renderer = dynamic_cast < const QgsUniqueValueRenderer * >( mVectorLayer->renderer() );
- // XXX - mloskot - fix for Ticket #31 (bug)
- //QgsAttributeList attributes = renderer->classificationAttributes();
- //QgsAttributeList::iterator iter = attributes.begin();
- //int classattr = *iter;
- //QString field = provider->fields()[ classattr ].name();
- QString field = provider->fields()[ renderer->classificationField()].name();
- mOldClassificationAttribute = field;
- mClassificationComboBox->setCurrentIndex( mClassificationComboBox->findText( field ) );
-
- const QList<QgsSymbol*> list = renderer->symbols();
- //fill the items of the renderer into mValues
- for ( QList<QgsSymbol*>::const_iterator iter = list.begin(); iter != list.end(); ++iter )
+ if ( renderer )
{
- QgsSymbol* symbol = ( *iter );
- QString symbolvalue = symbol->lowerValue();
- QgsSymbol* sym = new QgsSymbol( mVectorLayer->geometryType(), symbol->lowerValue(), symbol->upperValue(), symbol->label() );
- sym->setPen( symbol->pen() );
- sym->setCustomTexture( symbol->customTexture() );
- sym->setBrush( symbol->brush() );
- sym->setNamedPointSymbol( symbol->pointSymbolName() );
- sym->setPointSize( symbol->pointSize() );
- sym->setScaleClassificationField( symbol->scaleClassificationField() );
- sym->setRotationClassificationField( symbol->rotationClassificationField() );
- mValues.insert( symbolvalue, sym );
+ mClassListWidget->clear();
+ QString field = mVectorLayer->attributeDisplayName(renderer->classificationField());
+ mOldClassificationAttribute = field;
+ mClassificationComboBox->setCurrentIndex( mClassificationComboBox->findText( field ) );
- QListWidgetItem *item = new QListWidgetItem( symbolvalue );
- mClassListWidget->addItem( item );
- updateEntryIcon( symbol, item );
- item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
- item->setData( Qt::UserRole, symbol->lowerValue() );
- item->setToolTip( symbol->label() );
+ const QList<QgsSymbol*> list = renderer->symbols();
+ //fill the items of the renderer into mValues
+ for ( QList<QgsSymbol*>::const_iterator iter = list.begin(); iter != list.end(); ++iter )
+ {
+ QgsSymbol* symbol = ( *iter );
+ QString symbolvalue = symbol->lowerValue();
+ QgsSymbol* sym = new QgsSymbol( mVectorLayer->geometryType(), symbol->lowerValue(), symbol->upperValue(), symbol->label() );
+ sym->setPen( symbol->pen() );
+ sym->setCustomTexture( symbol->customTexture() );
+ sym->setBrush( symbol->brush() );
+ sym->setNamedPointSymbol( symbol->pointSymbolName() );
+ sym->setPointSize( symbol->pointSize() );
+ sym->setScaleClassificationField( symbol->scaleClassificationField() );
+ sym->setRotationClassificationField( symbol->rotationClassificationField() );
+ mValues.insert( symbolvalue, sym );
+
+ QListWidgetItem *item = new QListWidgetItem( symbolvalue );
+ mClassListWidget->addItem( item );
+ updateEntryIcon( symbol, item );
+ item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
+ item->setData( Qt::UserRole, symbol->lowerValue() );
+ item->setToolTip( symbol->label() );
+ }
}
}
@@ -149,7 +148,7 @@
QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider *>( mVectorLayer->dataProvider() );
if ( provider )
{
- int fieldIndex = provider->fieldNameIndex( mClassificationComboBox->currentText() );
+ int fieldIndex = mClassificationComboBox->itemData( mClassificationComboBox->currentIndex() ).toInt();
if ( fieldIndex != -1 )
{
renderer->setClassificationField( fieldIndex );
@@ -292,7 +291,7 @@
QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider *>( mVectorLayer->dataProvider() );
if ( provider )
{
- int nr = provider->fieldNameIndex( attributeName );
+ int nr = mClassificationComboBox->itemData(mClassificationComboBox->currentIndex()).toInt();
if ( nr == -1 )
{
return;
Modified: trunk/qgis/src/core/composer/qgslegendmodel.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgslegendmodel.cpp 2009-07-01 07:51:18 UTC (rev 10991)
+++ trunk/qgis/src/core/composer/qgslegendmodel.cpp 2009-07-01 10:11:33 UTC (rev 10992)
@@ -102,22 +102,17 @@
QSettings settings;
if ( settings.value( "/qgis/showLegendClassifiers", false ).toBool() )
{
- QgsVectorDataProvider* provider = vectorLayer->dataProvider();
-
- if ( provider )
+ QgsFieldMap layerFields = vectorLayer->pendingFields();
+ QgsAttributeList attributes = vectorRenderer->classificationAttributes();
+ QgsAttributeList::const_iterator att_it = attributes.constBegin();
+ for ( ; att_it != attributes.constEnd(); ++att_it )
{
- QgsFieldMap providerFields = provider->fields();
- QgsAttributeList attributes = vectorRenderer->classificationAttributes();
- QgsAttributeList::const_iterator att_it = attributes.constBegin();
- for ( ; att_it != attributes.constEnd(); ++att_it )
+ QgsFieldMap::const_iterator fieldIt = layerFields.find( *att_it );
+ if ( fieldIt != layerFields.constEnd() )
{
- QgsFieldMap::const_iterator fieldIt = providerFields.find( *att_it );
- if ( fieldIt != providerFields.constEnd() )
- {
- QString attributeName = fieldIt.value().name();
- QStandardItem* attributeItem = new QStandardItem( attributeName );
- layerItem->setChild( layerItem->rowCount(), 0, attributeItem );
- }
+ QString attributeName = vectorLayer->attributeDisplayName(fieldIt.key());
+ QStandardItem* attributeItem = new QStandardItem( attributeName );
+ layerItem->setChild( layerItem->rowCount(), 0, attributeItem );
}
}
}
Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp 2009-07-01 07:51:18 UTC (rev 10991)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp 2009-07-01 10:11:33 UTC (rev 10992)
@@ -2732,6 +2732,21 @@
}
}
+QString QgsVectorLayer::attributeDisplayName(int attributeIndex) const
+{
+ QString displayName = attributeAlias(attributeIndex);
+ if(displayName.isEmpty())
+ {
+ const QgsFieldMap& fields = pendingFields();
+ QgsFieldMap::const_iterator fieldIt = fields.find( attributeIndex );
+ if ( fieldIt != fields.constEnd() )
+ {
+ displayName = fieldIt->name();
+ }
+ }
+ return displayName;
+}
+
bool QgsVectorLayer::deleteAttribute( int index )
{
if ( !isEditable() )
Modified: trunk/qgis/src/core/qgsvectorlayer.h
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.h 2009-07-01 07:51:18 UTC (rev 10991)
+++ trunk/qgis/src/core/qgsvectorlayer.h 2009-07-01 10:11:33 UTC (rev 10992)
@@ -409,6 +409,10 @@
@note added in version 1.2*/
QString attributeAlias(int attributeIndex) const;
+ /**Convenience function that returns the attribute alias if defined or the field name else
+ @note added in version 1.2*/
+ QString attributeDisplayName(int attributeIndex) const;
+
/** delete an attribute field (but does not commit it) */
bool deleteAttribute( int attr );
More information about the QGIS-commit
mailing list