Skip to content
Permalink
Browse files

[Fix #7849] Layer properties > fields delete correct field

  • Loading branch information
m-kuhn committed May 18, 2013
1 parent 094c97b commit 34c85c8724519367ebd7a809a3b3554cba5774aa
Showing with 13 additions and 60 deletions.
  1. +9 −39 src/app/qgsfieldsproperties.cpp
  2. +1 −21 src/app/qgsfieldsproperties.h
  3. +3 −0 src/core/qgsvectorlayer.cpp
@@ -191,7 +191,7 @@ QgsFieldsProperties::QgsFieldsProperties( QgsVectorLayer *layer, QWidget* parent
attrTreeLayout->setMargin( 0 );
attrListLayout->setMargin( 0 );
mAttributesTree = new QgsAttributesTree( mAttributesTreeFrame );
mAttributesList = new QgsAttributesList( mAttributesListFrame );
mAttributesList = new QTableWidget( mAttributesListFrame );
attrTreeLayout->addWidget( mAttributesTree );
attrListLayout->addWidget( mAttributesList );
mAttributesTreeFrame->setLayout( attrTreeLayout );
@@ -536,14 +536,7 @@ void QgsFieldsProperties::attributeAdded( int idx )

void QgsFieldsProperties::attributeDeleted( int idx )
{
for ( int i = 0; i < mAttributesList->rowCount(); i++ )
{
if ( mAttributesList->item( i, 0 )->text().toInt() == idx )
{
mAttributesList->removeRow( i );
break;
}
}
mAttributesList->removeRow( idx );
}

void QgsFieldsProperties::addAttribute()
@@ -580,24 +573,6 @@ bool QgsFieldsProperties::addAttribute( const QgsField &field )
}
}

void QgsFieldsProperties::deleteAttribute()
{
QList<QTableWidgetItem*> items = mAttributesList->selectedItems();
QList<int> idxs;

for ( QList<QTableWidgetItem*>::const_iterator it = items.begin(); it != items.end(); it++ )
{
if (( *it )->column() == 0 )
idxs << ( *it )->text().toInt();
}
for ( QList<int>::const_iterator it = idxs.begin(); it != idxs.end(); it++ )
{
mLayer->beginEditCommand( tr( "Deleted attribute" ) );
mLayer->deleteAttribute( *it );
mLayer->endEditCommand();
}
}

void QgsFieldsProperties::editingToggled()
{
if ( !mLayer->isEditable() )
@@ -626,20 +601,15 @@ void QgsFieldsProperties::on_mAddAttributeButton_clicked()

void QgsFieldsProperties::on_mDeleteAttributeButton_clicked()
{
QList<QTableWidgetItem*> items = mAttributesList->selectedItems();
QList<int> idxs;

for ( QList<QTableWidgetItem*>::const_iterator it = items.begin(); it != items.end(); it++ )
QSet<int> attrs;
foreach ( QTableWidgetItem* item, mAttributesList->selectedItems() )
{
if (( *it )->column() == 0 )
idxs << ( *it )->text().toInt();
}
for ( QList<int>::const_iterator it = idxs.begin(); it != idxs.end(); it++ )
{
mLayer->beginEditCommand( tr( "Deleted attribute" ) );
mLayer->deleteAttribute( *it );
mLayer->endEditCommand();
attrs << mAttributesList->row( item );
}

mLayer->beginEditCommand( tr( "Deleted attribute" ) );
mLayer->deleteAttributes( attrs.toList() );
mLayer->endEditCommand();
}

void QgsFieldsProperties::updateButtons()
@@ -24,20 +24,6 @@
#include "qgsvectorlayer.h"
#include "ui_qgsfieldspropertiesbase.h"

class QgsAttributesList : public QTableWidget
{
Q_OBJECT
public:
QgsAttributesList( QWidget* parent = 0 )
: QTableWidget( parent )
{}

protected:
// virtual void dragMoveEvent( QDragMoveEvent *event );
// QMimeData *mimeData( const QList<QTableWidgetItem *> items ) const;
// Qt::DropActions supportedDropActions() const;
};

class QgsAttributesTree : public QTreeWidget
{
Q_OBJECT
@@ -70,11 +56,6 @@ class QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPropertiesBase
@return false in case of a name conflict, true in case of success */
bool addAttribute( const QgsField &field );

/**Deletes an attribute (but does not commit it)
@param name attribute name
@return false in case of a non-existing attribute.*/
bool deleteAttribute( int attr );

/**Creates the a proper item to save from the tree
* @param item The tree widget item to process
* @return A widget definition. Containing another container or the final field
@@ -103,7 +84,6 @@ class QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPropertiesBase
void on_mEditorLayoutComboBox_currentIndexChanged( int index );

void addAttribute();
void deleteAttribute();
void attributeAdded( int idx );
void attributeDeleted( int idx );
void attributeTypeDialog();
@@ -123,7 +103,7 @@ class QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPropertiesBase
protected:
QgsVectorLayer* mLayer;
QgsAttributesTree* mAttributesTree;
QgsAttributesList* mAttributesList;
QTableWidget* mAttributesList;

QMap<int, bool> mFieldEditables;
QMap<int, QgsVectorLayer::ValueRelationData> mValueRelationData;
@@ -2477,6 +2477,9 @@ bool QgsVectorLayer::deleteAttributes( QList<int> attrs )
{
bool deleted = false;

// Remove multiple occurences of same attribute
attrs = attrs.toSet().toList();

qSort( attrs.begin(), attrs.end(), qGreater<int>() );

foreach ( int attr, attrs )

0 comments on commit 34c85c8

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