Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
vector editing update:
- show mapped value instead of attribute value for value maps in attribute table and identify results.
- alternating background color in identify results
- allow hiding of attributes
- add actions (including edit action) into identify results



git-svn-id: http://svn.osgeo.org/qgis/trunk@11681 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 19, 2009
1 parent 793a32f commit 9f1622c
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 98 deletions.
36 changes: 31 additions & 5 deletions src/app/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -34,8 +34,29 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayer *theLayer, QObjec
mLastRow = NULL;
mLayer = theLayer;
mFeatureCount = mLayer->pendingFeatureCount();
mFieldCount = mLayer->pendingFields().size();
mAttributes = mLayer->pendingAllAttributesList();

mFieldCount = 0;
mAttributes.clear();
mValueMaps.clear();

for ( QgsFieldMap::const_iterator it = theLayer->pendingFields().constBegin(); it != theLayer->pendingFields().end(); it++ )
{
switch ( mLayer->editType( it.key() ) )
{
case QgsVectorLayer::Hidden:
continue;

case QgsVectorLayer::ValueMap:
mValueMaps.insert( it.key(), &mLayer->valueMap( it.key() ) );
break;

default:
break;
}

mFieldCount++;
mAttributes << it.key();
}

connect( mLayer, SIGNAL( layerModified( bool ) ), this, SLOT( layerModified( bool ) ) );
//connect(mLayer, SIGNAL(attributeAdded(int)), this, SLOT( attributeAdded(int)));
Expand Down Expand Up @@ -173,7 +194,7 @@ void QgsAttributeTableModel::loadLayer()
// QgsDebugMsg(QString("%1, %2").arg(mFeatureCount).arg(mLayer->pendingFeatureCount() -1));
}

mLayer->select( QgsAttributeList(), QgsRectangle(), false );
mLayer->select( mAttributes, QgsRectangle(), false );

// preallocate data before inserting
mRowIdMap.reserve( pendingFeatureCount + 50 );
Expand All @@ -187,7 +208,7 @@ void QgsAttributeTableModel::loadLayer()

// not needed when we have featureAdded signal
mFeatureCount = pendingFeatureCount;
mFieldCount = mLayer->pendingFields().size();
mFieldCount = mAttributes.size();

if ( ins )
{
Expand Down Expand Up @@ -369,7 +390,7 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
if ( !mLastRow )
return QVariant( "ERROR" );

QVariant &val = ( *mLastRow )[ mAttributes[index.column()] ];
const QVariant &val = ( *mLastRow )[ mAttributes[index.column()] ];

if ( val.isNull() )
{
Expand All @@ -384,6 +405,11 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
}
}

if ( role == Qt::DisplayRole && mValueMaps.contains( index.column() ) )
{
return mValueMaps[ index.column()]->key( val.toString(), QString( "(%1)" ).arg( val.toString() ) );
}

// force also numeric data for EditRole to be strings
// otherwise it creates spinboxes instead of line edits
// (probably not what we do want)
Expand Down
1 change: 1 addition & 0 deletions src/app/attributetable/qgsattributetablemodel.h
Expand Up @@ -188,6 +188,7 @@ class QgsAttributeTableModel: public QAbstractTableModel

mutable QgsAttributeMap *mLastRow;
QgsAttributeList mAttributes;
QMap< int, const QMap<QString, QVariant> * > mValueMaps;

QList<QgsAttributeTableIdColumnPair> mSortList;
QHash<int, int> mIdRowMap;
Expand Down
3 changes: 0 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -3667,9 +3667,6 @@ void QgisApp::openProject( const QString & fileName )
{
QgsDebugMsg( "unable to load project " + fileName );
}
else
{
}
}
catch ( QgsIOException & io_exception )
{
Expand Down
17 changes: 10 additions & 7 deletions src/app/qgsattributedialog.cpp
Expand Up @@ -43,7 +43,8 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat

const QgsFieldMap &theFieldMap = vl->pendingFields();

if ( theFieldMap.isEmpty() ) return;
if ( theFieldMap.isEmpty() )
return;

QgsAttributeMap myAttributes = mpFeature->attributeMap();
//
Expand All @@ -64,8 +65,6 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
mypScrollArea->setWidgetResizable( true );
QGridLayout * mypInnerLayout = new QGridLayout( mypInnerFrame );



int index = 0;
for ( QgsAttributeMap::const_iterator it = myAttributes.begin();
it != myAttributes.end();
Expand All @@ -77,6 +76,10 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
QString myFieldName = vl->attributeDisplayName( it.key() );
int myFieldType = field.type();

QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, vl, it.key(), it.value() );
if ( !myWidget )
continue;

QLabel * mypLabel = new QLabel();
mypInnerLayout->addWidget( mypLabel, index, 0 );
if ( myFieldType == QVariant::Int )
Expand All @@ -93,9 +96,8 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
mypLabel->setText( myFieldName + tr( " (txt)" ) );
}

QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, vl, it.key(), it.value() );

mypInnerLayout->addWidget( myWidget, index, 1 );
mpIndizes << it.key();
mpWidgets << myWidget;
++index;
}
Expand Down Expand Up @@ -124,8 +126,9 @@ void QgsAttributeDialog::accept()
{
QVariant value;

if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, it.key(), value ) )
mpFeature->changeAttribute( it.key(), value );
int idx = mpIndizes.value( myIndex );
if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, idx, value ) )
mpFeature->changeAttribute( idx, value );

++myIndex;
}
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsattributedialog.h
Expand Up @@ -55,6 +55,7 @@ class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
private:
QString mSettingsPath;
QList<QWidget *> mpWidgets;
QList<int> mpIndizes;
QgsVectorLayer *mLayer;
QgsFeature * mpFeature;

Expand Down
13 changes: 12 additions & 1 deletion src/app/qgsattributeeditor.cpp
Expand Up @@ -228,6 +228,10 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QgsVectorLa
}
break;

case QgsVectorLayer::Hidden:
myWidget = NULL;
break;

case QgsVectorLayer::FileName:
{
QLineEdit *le = new QLineEdit();
Expand All @@ -252,6 +256,9 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QgsVectorLa

bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value )
{
if ( !widget )
return false;

const QgsField &theField = vl->pendingFields()[idx];
QgsVectorLayer::EditType editType = vl->editType( idx );
bool modified = false;
Expand Down Expand Up @@ -349,6 +356,9 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int

bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value )
{
if ( !editor )
return false;

QgsVectorLayer::EditType editType = vl->editType( idx );
const QgsField &field = vl->pendingFields()[idx];
QVariant::Type myFieldType = field.type();
Expand All @@ -362,7 +372,8 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
QComboBox *cb = dynamic_cast<QComboBox *>( editor );
if ( cb == NULL )
return false;
int idx = cb->findText( value.toString() );

int idx = cb->findData( value );
if ( idx < 0 )
return false;

Expand Down
7 changes: 7 additions & 0 deletions src/app/qgsattributetypedialog.cpp
Expand Up @@ -226,6 +226,10 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy
setPage( 7 );
break;

case QgsVectorLayer::Hidden:
setPage( 8 );
break;

case QgsVectorLayer::LineEdit:
setPage( 0 );
break;
Expand Down Expand Up @@ -501,6 +505,9 @@ void QgsAttributeTypeDialog::accept()
case 7:
mEditType = QgsVectorLayer::Immutable;
break;
case 8:
mEditType = QgsVectorLayer::Hidden;
break;
default:
mEditType = QgsVectorLayer::LineEdit;
}
Expand Down

0 comments on commit 9f1622c

Please sign in to comment.