diff --git a/images/images.qrc b/images/images.qrc index 17a12f2195..a27ba80d03 100644 --- a/images/images.qrc +++ b/images/images.qrc @@ -28,4 +28,7 @@ themes/holodark/cancel.png themes/holodark/edit.png + + themes/holodark/delete_forever.svg + diff --git a/images/themes/holodark/delete_forever.svg b/images/themes/holodark/delete_forever.svg new file mode 100644 index 0000000000..c7c5e7dfea --- /dev/null +++ b/images/themes/holodark/delete_forever.svg @@ -0,0 +1,63 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/feature.cpp b/src/feature.cpp index ec8685db1a..550d18c5be 100644 --- a/src/feature.cpp +++ b/src/feature.cpp @@ -40,6 +40,9 @@ void Feature::setGeometry( const QgsGeometry& geom ) void Feature::create() { + if ( !mLayer ) + return; + mLayer->addFeature( mFeature ); } @@ -53,5 +56,18 @@ QString Feature::displayText() const bool Feature::readOnly() const { + if ( !mLayer ) + return true; + return mLayer->readOnly(); } + +bool Feature::remove() +{ + if ( !mLayer ) + return false; + + mLayer->startEditing(); + mLayer->deleteFeature( mFeature.id() ); + return mLayer->commitChanges(); +} diff --git a/src/feature.h b/src/feature.h index 588396b210..5ed96085b5 100644 --- a/src/feature.h +++ b/src/feature.h @@ -78,6 +78,8 @@ class Feature Q_INVOKABLE bool readOnly() const; + Q_INVOKABLE bool remove(); + private: QgsFeature mFeature; QgsVectorLayer* mLayer; diff --git a/src/featurelistmodel.cpp b/src/featurelistmodel.cpp index b9d958844a..90fb2ff3c9 100644 --- a/src/featurelistmodel.cpp +++ b/src/featurelistmodel.cpp @@ -18,6 +18,8 @@ #include "featurelistmodel.h" #include +#include + #include FeatureListModel::FeatureListModel( QObject *parent ) @@ -46,6 +48,7 @@ void FeatureListModel::setFeatures( const QList( res.mLayer ) ); mFeatures.append( f ); connect( f->layer(), SIGNAL( layerDeleted() ), this, SLOT( layerDeleted() ), Qt::UniqueConnection ); + connect( f->layer(), SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( featureDeleted( QgsFeatureId ) ), Qt::UniqueConnection ); } endResetModel(); @@ -82,6 +85,7 @@ QHash FeatureListModel::roleNames() const roleNames[FeatureIdRole] = "featureId"; roleNames[FeatureRole] = "feature"; roleNames[LayerNameRole] = "layerName"; + roleNames[DeleteFeatureRole] = "deleteFeatureCapability"; return roleNames; } @@ -135,6 +139,10 @@ QVariant FeatureListModel::data( const QModelIndex& index, int role ) const case LayerNameRole: return feature->layer()->name(); + + case DeleteFeatureRole: + bool a = !feature->layer()->readOnly() && ( feature->layer()->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteFeatures ); + return a; } return QVariant(); @@ -207,3 +215,20 @@ void FeatureListModel::layerDeleted() removeRows( firstRowToRemove, count ); } + +void FeatureListModel::featureDeleted( QgsFeatureId fid ) +{ + QgsVectorLayer* l = qobject_cast( sender() ); + Q_ASSERT( l ); + + int i = 0; + Q_FOREACH( Feature* f, mFeatures ) + { + if ( f->layer() == l && f->id() == fid ) + { + removeRows( i, 1 ); + break; + } + ++i; + } +} diff --git a/src/featurelistmodel.h b/src/featurelistmodel.h index 7796b6fc27..bef7e05b6b 100644 --- a/src/featurelistmodel.h +++ b/src/featurelistmodel.h @@ -35,7 +35,8 @@ class FeatureListModel : public QAbstractItemModel { FeatureIdRole = Qt::UserRole + 1, FeatureRole, - LayerNameRole + LayerNameRole, + DeleteFeatureRole }; explicit FeatureListModel( QObject *parent = 0 ); @@ -78,6 +79,8 @@ class FeatureListModel : public QAbstractItemModel private slots: void layerDeleted(); + void featureDeleted( QgsFeatureId fid ); + private: inline Feature* toFeature( const QModelIndex& index ) const { diff --git a/src/featurelistmodelhighlight.cpp b/src/featurelistmodelhighlight.cpp index d18e82d3a1..bb92a8c6b9 100644 --- a/src/featurelistmodelhighlight.cpp +++ b/src/featurelistmodelhighlight.cpp @@ -52,6 +52,7 @@ void FeatureListModelHighlight::onDataChanged() if ( mModel ) { connect( mModel, SIGNAL( modelReset() ), this, SLOT( onModelDataChanged() ) ); + connect( mModel, SIGNAL( rowsRemoved( QModelIndex,int,int ) ), this, SLOT( onModelDataChanged() ) ); } } diff --git a/src/qml/Button.qml b/src/qml/Button.qml index cb7e055f55..90d7979769 100644 --- a/src/qml/Button.qml +++ b/src/qml/Button.qml @@ -8,6 +8,7 @@ Item { property alias iconSource: button.iconSource property alias checked: button.checked property alias checkable: button.checkable + property string style: "dark" signal pressAndHold signal clicked @@ -24,8 +25,8 @@ Item { implicitWidth: 100 implicitHeight: 25 border.width: control.activeFocus ? 2 : 1 - border.color: "#888" - color: "#cc555555" + border.color: style === "dark" ? "#888" : "#ccbbbbbb" + color: style === "dark" ? "#cc555555" : "#ccbbbbbb" } } diff --git a/src/qml/FeatureListForm.qml b/src/qml/FeatureListForm.qml index 6bf9e84d1b..d960392244 100644 --- a/src/qml/FeatureListForm.qml +++ b/src/qml/FeatureListForm.qml @@ -16,7 +16,7 @@ ***************************************************************************/ import QtQuick 2.3 -import QtQuick.Controls 1.2 +import QtQuick.Controls 1.4 as Controls import QtQuick.Layouts 1.1 import org.qgis 1.0 @@ -125,7 +125,7 @@ Rectangle { Text { id: featureText - anchors { leftMargin: 10; left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter } + anchors { leftMargin: 10; left: parent.left; right: deleteButton.left; verticalCenter: parent.verticalCenter } font.bold: true text: display } @@ -143,14 +143,6 @@ Rectangle { } } - /* bottom border */ - Rectangle { - anchors.bottom: parent.bottom - height: 1 - color: "lightGray" - width: parent.width - } - MouseArea { anchors.fill: parent @@ -164,6 +156,33 @@ Rectangle { featureForm.selection.selection = index } } + + Button { + id: deleteButton + + width: 48*dp + height: 48*dp + + visible: deleteFeatureCapability + + anchors { top: parent.top; right: parent.right } + + iconSource: "/themes/holodark/delete_forever.svg" + + style: "light" + + onClicked: { + feature.remove() + } + } + + /* bottom border */ + Rectangle { + anchors.bottom: parent.bottom + height: 1 + color: "lightGray" + width: parent.width + } } /* bottom border */