Showing with 18 additions and 64 deletions.
  1. +9 −39 src/app/qgsfieldsproperties.cpp
  2. +1 −21 src/app/qgsfieldsproperties.h
  3. +3 −0 src/core/qgsvectorlayer.cpp
  4. +5 −4 src/gui/attributetable/qgsattributetablemodel.cpp
48 changes: 9 additions & 39 deletions src/app/qgsfieldsproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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()
Expand Down
22 changes: 1 addition & 21 deletions src/app/qgsfieldsproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
9 changes: 5 additions & 4 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* *
***************************************************************************/

#include "qgsapplication.h"
#include "qgsattributetablemodel.h"
#include "qgsattributetablefiltermodel.h"

Expand Down Expand Up @@ -262,15 +263,15 @@ void QgsAttributeTableModel::loadAttributes()
attributes << idx;
}

if ( columnCount() < attributes.size() )
if ( mFieldCount < attributes.size() )
{
ins = true;
beginInsertColumns( QModelIndex(), columnCount(), attributes.size() - 1 );
beginInsertColumns( QModelIndex(), mFieldCount, attributes.size() - 1 );
}
else if ( attributes.size() < columnCount() )
else if ( attributes.size() < mFieldCount )
{
rm = true;
beginRemoveColumns( QModelIndex(), attributes.size(), columnCount() - 1 );
beginRemoveColumns( QModelIndex(), attributes.size(), mFieldCount - 1 );
}

mFieldCount = attributes.size();
Expand Down