Skip to content

Commit

Permalink
Support for readonly layer property
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Mar 29, 2016
1 parent 71a53c4 commit 107ab34
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/feature.cpp
Expand Up @@ -50,3 +50,8 @@ QString Feature::displayText() const
else
return mFeature.attribute( mLayer->displayField() ).toString();
}

bool Feature::readOnly() const
{
return mLayer->readOnly();
}
11 changes: 7 additions & 4 deletions src/feature.h
Expand Up @@ -15,14 +15,16 @@
* *
***************************************************************************/

#ifndef QGSEXTENDEDFEATURE_H
#define QGSEXTENDEDFEATURE_H
#ifndef FEATURE_H
#define FEATURE_H

#include <qgsfeature.h>
#include <qgsvectorlayer.h>

class Feature
{
Q_GADGET

public:
Feature( const QgsFeature& feature, QgsVectorLayer* layer );
Feature();
Expand Down Expand Up @@ -74,12 +76,13 @@ class Feature

QString displayText() const;

Q_INVOKABLE bool readOnly() const;

private:
// TODO: Use implicity sharing for this
QgsFeature mFeature;
QgsVectorLayer* mLayer;
};

Q_DECLARE_METATYPE( Feature )

#endif // QGSEXTENDEDFEATURE_H
#endif // FEATURE_H
2 changes: 1 addition & 1 deletion src/featurelistextentcontroller.cpp
Expand Up @@ -37,7 +37,7 @@ void FeatureListExtentController::zoomToSelected() const
{
if ( mModel && mSelection && mMapSettings )
{
Feature feat = mSelection->selectedFeature().value<Feature>();
Feature feat = mSelection->selectedFeature();

QgsCoordinateTransform transf( feat.layer()->crs(), mMapSettings->crs()->crs() );
QgsGeometry geom( *feat.qgsFeature().constGeometry() );
Expand Down
6 changes: 3 additions & 3 deletions src/featurelistmodelselection.cpp
Expand Up @@ -62,11 +62,11 @@ void FeatureListModelSelection::setModel( FeatureListModel* model )
}
}

const QVariant FeatureListModelSelection::selectedFeature() const
const Feature FeatureListModelSelection::selectedFeature() const
{
if ( mSelection->selectedIndexes().count() )
{
return mModel->data( mSelection->selectedIndexes().first(), FeatureListModel::FeatureRole );
return mModel->data( mSelection->selectedIndexes().first(), FeatureListModel::FeatureRole ).value<Feature>();
}
return QVariant();
return Feature();
}
4 changes: 2 additions & 2 deletions src/featurelistmodelselection.h
Expand Up @@ -28,7 +28,7 @@ class FeatureListModelSelection : public QObject
Q_OBJECT
Q_PROPERTY( FeatureListModel* model READ model WRITE setModel NOTIFY modelChanged )
Q_PROPERTY( int selection READ selection WRITE setSelection NOTIFY selectionChanged )
Q_PROPERTY( QVariant selectedFeature READ selectedFeature NOTIFY selectionChanged )
Q_PROPERTY( Feature selectedFeature READ selectedFeature NOTIFY selectionChanged )

public:
explicit FeatureListModelSelection( QObject *parent = 0 );
Expand All @@ -39,7 +39,7 @@ class FeatureListModelSelection : public QObject
FeatureListModel* model() const;
void setModel( FeatureListModel* model );

const QVariant selectedFeature() const;
const Feature selectedFeature() const;

signals:
void modelChanged();
Expand Down
1 change: 0 additions & 1 deletion src/qml/FeatureForm.qml
Expand Up @@ -113,7 +113,6 @@ Rectangle {
anchors { leftMargin: 5; right: parent.right; left: txtAttributeName.right }
height: childrenRect.height

visible: EditorWidget !== "Hidden"

/* attribute value */
Loader {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/LayerSelector.qml
Expand Up @@ -14,7 +14,7 @@ ComboBox {
ModelHelper {
id: modelHelper
model: MapLayerModel {
filters: MapLayerModel.PointLayer
filters: MapLayerModel.PointLayer | MapLayerModel.WritableLayer
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/qml/NavigationBar.qml
Expand Up @@ -158,9 +158,11 @@ Rectangle {
Button {
id: editButton

property bool readOnly: false

anchors.right: nextButton.left

width: ( parent.state == "Navigation" ? 48*dp : 0 )
width: ( parent.state == "Navigation" && !readOnly ? 48*dp : 0 )
height: 48*dp
clip: true

Expand All @@ -175,6 +177,15 @@ Rectangle {
easing.type: Easing.InQuart
}
}

Connections {
target: selection

onSelectionChanged:
{
editButton.readOnly = selection.selectedFeature.readOnly()
}
}
}

Button {
Expand Down

0 comments on commit 107ab34

Please sign in to comment.