[QGIS Commit] r12545 - in trunk/qgis/src/app: . attributetable
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Dec 20 13:13:23 EST 2009
Author: jef
Date: 2009-12-20 13:13:22 -0500 (Sun, 20 Dec 2009)
New Revision: 12545
Modified:
trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp
trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h
trunk/qgis/src/app/qgsattributeeditor.cpp
trunk/qgis/src/app/qgsattributetypedialog.cpp
Log:
attribute editor fixes:
- in attribute table: set minimum width of editor to columns width and height
of filename widget to two times the lineedit height
- fix non-editable unique value editor (was editable)
- fix enum support
- add support for symbology-ng categories
Modified: trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp 2009-12-20 18:07:27 UTC (rev 12544)
+++ trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp 2009-12-20 18:13:22 UTC (rev 12545)
@@ -59,10 +59,25 @@
const QModelIndex &index ) const
{
QgsVectorLayer *vl = layer( index.model() );
- if ( vl == NULL )
+ if ( !vl )
return NULL;
- return QgsAttributeEditor::createAttributeEditor( parent, 0, vl, fieldIdx( index ), index.model()->data( index, Qt::EditRole ) );
+ QWidget *w = QgsAttributeEditor::createAttributeEditor( parent, 0, vl, fieldIdx( index ), index.model()->data( index, Qt::EditRole ) );
+
+ if ( parent )
+ {
+ QgsAttributeTableView *tv = dynamic_cast<QgsAttributeTableView *>( parent->parentWidget() );
+ w->setMinimumWidth( tv->columnWidth( index.column() ) );
+
+ if ( vl->editType( fieldIdx( index ) ) == QgsVectorLayer::FileName )
+ {
+ QLineEdit *le = w->findChild<QLineEdit*>();
+ le->adjustSize();
+ w->setMinimumHeight( le->height()*2 ); // FIXME: there must be a better way to do this
+ }
+ }
+
+ return w;
}
void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
@@ -85,7 +100,6 @@
return;
QgsAttributeEditor::setValue( editor, vl, fieldIdx( index ), index.model()->data( index, Qt::EditRole ) );
- editor->adjustSize();
}
void QgsAttributeTableDelegate::paint( QPainter * painter,
Modified: trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h 2009-12-20 18:07:27 UTC (rev 12544)
+++ trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h 2009-12-20 18:13:22 UTC (rev 12545)
@@ -66,7 +66,6 @@
* @param index index of field which is to be retrieved
*/
void setEditorData( QWidget *editor, const QModelIndex &index ) const;
-
};
#endif //QGSATTRIBUTETABLEDELEGATE_H
Modified: trunk/qgis/src/app/qgsattributeeditor.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributeeditor.cpp 2009-12-20 18:07:27 UTC (rev 12544)
+++ trunk/qgis/src/app/qgsattributeeditor.cpp 2009-12-20 18:13:22 UTC (rev 12545)
@@ -20,6 +20,7 @@
#include <qgsvectorlayer.h>
#include <qgsvectordataprovider.h>
#include <qgsuniquevaluerenderer.h>
+#include <qgscategorizedsymbolrendererv2.h>
#include <qgssymbol.h>
#include <QPushButton>
@@ -88,10 +89,10 @@
QComboBox *cb = comboBox( editor, parent );
if ( cb )
{
- cb->setEditable( true );
+ cb->setEditable( false );
for ( QList<QVariant>::iterator it = values.begin(); it != values.end(); it++ )
- cb->addItem( it->toString() );
+ cb->addItem( it->toString(), it->toString() );
myWidget = cb;
}
@@ -109,7 +110,7 @@
QStringList::const_iterator s_it = enumValues.constBegin();
for ( ; s_it != enumValues.constEnd(); ++s_it )
{
- cb->addItem( *s_it );
+ cb->addItem( *s_it, *s_it );
}
myWidget = cb;
@@ -136,14 +137,11 @@
case QgsVectorLayer::Classification:
{
- int classificationField = -1;
QMap<QString, QString> classes;
const QgsUniqueValueRenderer *uvr = dynamic_cast<const QgsUniqueValueRenderer *>( vl->renderer() );
if ( uvr )
{
- classificationField = uvr->classificationField();
-
const QList<QgsSymbol *> symbols = uvr->symbols();
for ( int i = 0; i < symbols.size(); i++ )
@@ -158,6 +156,20 @@
}
}
+ const QgsCategorizedSymbolRendererV2 *csr = dynamic_cast<const QgsCategorizedSymbolRendererV2 *>( vl->rendererV2() );
+ if ( csr )
+ {
+ const QgsCategoryList &categories = (( QgsCategorizedSymbolRendererV2 * )csr )->categories(); // FIXME: QgsCategorizedSymbolRendererV2::categories() should be const
+ for ( int i = 0; i < categories.size(); i++ )
+ {
+ QString label = categories[i].label();
+ QString value = categories[i].value().toString();
+ if ( label.isEmpty() )
+ label = value;
+ classes.insert( label, value );
+ }
+ }
+
QComboBox *cb = comboBox( editor, parent );
if ( cb )
{
Modified: trunk/qgis/src/app/qgsattributetypedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributetypedialog.cpp 2009-12-20 18:07:27 UTC (rev 12544)
+++ trunk/qgis/src/app/qgsattributetypedialog.cpp 2009-12-20 18:13:22 UTC (rev 12545)
@@ -344,61 +344,74 @@
//setPageForIndex( index );
setPageForEditType( editType );
- if ( editType == QgsVectorLayer::ValueMap )
+ switch ( editType )
{
-
- tableWidget->clearContents();
- for ( int i = tableWidget->rowCount() - 1; i > 0; i-- )
+ case QgsVectorLayer::ValueMap:
{
- tableWidget->removeRow( i );
- }
- // if some value map already present use it
- QMap<QString, QVariant> map;
- if ( !mValueMap.empty() )
- {
- map = mValueMap;
- }
- else
- {
- map = mLayer->valueMap( index );
- }
+ tableWidget->clearContents();
+ for ( int i = tableWidget->rowCount() - 1; i > 0; i-- )
+ {
+ tableWidget->removeRow( i );
+ }
- int row = 0;
- for ( QMap<QString, QVariant>::iterator mit = map.begin(); mit != map.end(); mit++, row++ )
- {
- tableWidget->insertRow( row );
- if ( mit.value().isNull() )
+ // if some value map already present use it
+ QMap<QString, QVariant> map;
+ if ( !mValueMap.empty() )
{
- tableWidget->setItem( row, 0, new QTableWidgetItem( mit.key() ) );
+ map = mValueMap;
}
else
{
- tableWidget->setItem( row, 0, new QTableWidgetItem( mit.value().toString() ) );
- tableWidget->setItem( row, 1, new QTableWidgetItem( mit.key() ) );
+ map = mLayer->valueMap( index );
}
+
+ int row = 0;
+ for ( QMap<QString, QVariant>::iterator mit = map.begin(); mit != map.end(); mit++, row++ )
+ {
+ tableWidget->insertRow( row );
+ if ( mit.value().isNull() )
+ {
+ tableWidget->setItem( row, 0, new QTableWidgetItem( mit.key() ) );
+ }
+ else
+ {
+ tableWidget->setItem( row, 0, new QTableWidgetItem( mit.value().toString() ) );
+ tableWidget->setItem( row, 1, new QTableWidgetItem( mit.key() ) );
+ }
+ }
+
}
+ break;
- }
- else if ( editType == QgsVectorLayer::EditRange ||
- editType == QgsVectorLayer::SliderRange )
- {
- if ( mLayer->pendingFields()[mIndex].type() != QVariant::Int )
+ case QgsVectorLayer::EditRange:
+ case QgsVectorLayer::SliderRange:
{
- minimumSpinBox->setValue( mLayer->range( index ).mMin.toInt() );
- maximumSpinBox->setValue( mLayer->range( index ).mMax.toInt() );
- stepSpinBox->setValue( mLayer->range( index ).mStep.toInt() );
+ if ( mLayer->pendingFields()[mIndex].type() != QVariant::Int )
+ {
+ minimumSpinBox->setValue( mLayer->range( index ).mMin.toInt() );
+ maximumSpinBox->setValue( mLayer->range( index ).mMax.toInt() );
+ stepSpinBox->setValue( mLayer->range( index ).mStep.toInt() );
+ }
+ else if ( mLayer->pendingFields()[mIndex].type() == QVariant::Double )
+ {
+ minimumDoubleSpinBox->setValue( mLayer->range( index ).mMin.toDouble() );
+ maximumDoubleSpinBox->setValue( mLayer->range( index ).mMax.toDouble() );
+ stepDoubleSpinBox->setValue( mLayer->range( index ).mStep.toDouble() );
+ }
+ if ( editType == QgsVectorLayer::EditRange )
+ editableRadioButton->setChecked( true );
+ else //slider range
+ sliderRadioButton->setChecked( true );
}
- else if ( mLayer->pendingFields()[mIndex].type() == QVariant::Double )
- {
- minimumDoubleSpinBox->setValue( mLayer->range( index ).mMin.toDouble() );
- maximumDoubleSpinBox->setValue( mLayer->range( index ).mMax.toDouble() );
- stepDoubleSpinBox->setValue( mLayer->range( index ).mStep.toDouble() );
- }
- if ( editType == QgsVectorLayer::EditRange )
- editableRadioButton->setChecked( true );
- else //slider range
- sliderRadioButton->setChecked( true );
+ break;
+
+ case QgsVectorLayer::UniqueValuesEditable:
+ editableUniqueValues->setChecked( editType == QgsVectorLayer::UniqueValuesEditable );
+ break;
+
+ default:
+ break;
}
}
More information about the QGIS-commit
mailing list