Skip to content
Permalink
Browse files

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



git-svn-id: http://svn.osgeo.org/qgis/trunk@12545 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Dec 20, 2009
1 parent cace1e2 commit e863e7d596713b9a06cfe88983bb25d461c4985d
@@ -59,10 +59,25 @@ QWidget *QgsAttributeTableDelegate::createEditor(
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 @@ void QgsAttributeTableDelegate::setEditorData( QWidget *editor, const QModelInde
return;

QgsAttributeEditor::setValue( editor, vl, fieldIdx( index ), index.model()->data( index, Qt::EditRole ) );
editor->adjustSize();
}

void QgsAttributeTableDelegate::paint( QPainter * painter,
@@ -66,7 +66,6 @@ class QgsAttributeTableDelegate : public QItemDelegate
* @param index index of field which is to be retrieved
*/
void setEditorData( QWidget *editor, const QModelIndex &index ) const;

};

#endif //QGSATTRIBUTETABLEDELEGATE_H
@@ -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 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
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 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
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 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed

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 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
}
}

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 )
{
@@ -344,61 +344,74 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
//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() ) );
}
}
}

}
else if ( editType == QgsVectorLayer::EditRange ||
editType == QgsVectorLayer::SliderRange )
{
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 )
break;

case QgsVectorLayer::EditRange:
case QgsVectorLayer::SliderRange:
{
minimumDoubleSpinBox->setValue( mLayer->range( index ).mMin.toDouble() );
maximumDoubleSpinBox->setValue( mLayer->range( index ).mMax.toDouble() );
stepDoubleSpinBox->setValue( mLayer->range( index ).mStep.toDouble() );
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 );
}
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;
}
}

0 comments on commit e863e7d

Please sign in to comment.
You can’t perform that action at this time.