68 changes: 68 additions & 0 deletions src/app/qgsguivectorlayertools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/***************************************************************************
qgsfeaturefactory.h
--------------------------------------
Date : 30.5.2013
Copyright : (C) 2013 Matthias Kuhn
Email : matthias dot kuhn at gmx dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSGUIVECTORLAYERTOOLS_H
#define QGSGUIVECTORLAYERTOOLS_H

#include "qgsvectorlayertools.h"

/**
* Implements all the dialogs and actions when editing on a vector layer is toggled
* or a feature is added.
*/

class QgsGuiVectorLayerTools : public QgsVectorLayerTools, public QObject
{
public:
QgsGuiVectorLayerTools();

/**
* This method should be called, whenever a new feature is added to a layer
*
* @param layer The layer to which the feature should be added
* @param defaultValues Default values for the feature to add
* @param defaultGeometry A default geometry to add to the feature
*
* @return True in case of success, False if the operation failed/was aborted
*/
bool addFeature( QgsVectorLayer *layer, QgsAttributeMap defaultValues, const QgsGeometry &defaultGeometry );

/**
* This should be called, whenever a vector layer should be switched to edit mode. If succesful
* the layer is switched to editable and an edit sessions started.
*
* @param layer The layer on which to start an edit session
*
* @return True, if the editing session was started
*/
bool startEditing( QgsVectorLayer* layer );

/**
* Should be called, when an editing session is ended and the features should be commited.
* An appropriate dialog asking the user if he wants to save the edits will be shown if
* allowCancel is set to true.
*
* @param layer The layer to commit
* @param allowCancel True if a cancel button should be offered
*
* @return True if successful
*/
bool stopEditing( QgsVectorLayer* layer , bool allowCancel = true );

private:
void commitError( QgsVectorLayer* vlayer );
};

#endif // QGSGUIVECTORLAYERTOOLS_H
1 change: 1 addition & 0 deletions src/gui/qgsattributeeditorcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "qgsattributeeditorcontext.h"

QgsAttributeEditorContext::QgsAttributeEditorContext()
: mVectorLayerTools( NULL )
{

}
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsattributeeditorcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <qgsdistancearea.h>
#include <qgsvectorlayer.h>
#include <qgsvectorlayertools.h>


/**
Expand All @@ -41,6 +42,9 @@ class GUI_EXPORT QgsAttributeEditorContext
void setDistanceArea( const QgsDistanceArea& distanceArea ) { mDistanceArea = distanceArea; }
inline const QgsDistanceArea& distanceArea() { return mDistanceArea; }

void setVectorLayerTools( QgsVectorLayerTools* vlTools ) { mVectorLayerTools = vlTools; }
QgsVectorLayerTools* vectorLayerTools() { return mVectorLayerTools; }

/**
* When copying the context for another layer, call this.
* Will adjast the distance area for this layer
Expand All @@ -49,7 +53,10 @@ class GUI_EXPORT QgsAttributeEditorContext
*/
void adjustForLayer( QgsVectorLayer* layer );


private:
QgsVectorLayerTools* mVectorLayerTools;

//! vectorlayer => ( fieldIdx, proxyWidget )
QMap<QgsVectorLayer*, QMap<int, QWidget*> > mProxyWidgets;

Expand Down
73 changes: 73 additions & 0 deletions src/gui/qgsvectorlayertools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/***************************************************************************
QgsAbstractFeatureAction.h
--------------------------------------
Date : 29.5.2013
Copyright : (C) 2013 Matthias Kuhn
Email : matthias dot kuhn at gmx dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSVECTORLAYERTOOLS_H
#define QGSVECTORLAYERTOOLS_H

#include "qgsfeature.h"
#include "qgsgeometry.h"

class QgsVectorLayer;

/**
* Methods in this class are used to handle basic operations on vector layers.
* With an implementation of this class, parts of the application can ask for
* an operation to be done and the implementation will then take care of it.
*
* Reimplement this class, if you need to have custom checks or GUI elements
* in your application.
*
*/
class GUI_EXPORT QgsVectorLayerTools
{
public:
QgsVectorLayerTools()
{}

/**
* This method should/will be called, whenever a new feature will be added to the layer
*
* @param layer The layer to which the feature should be added
* @param defaultValues Default values for the feature to add
* @param defaultGeometry A default geometry to add to the feature
* @return True in case of success, False if the operation failed/was aborted
*/
virtual bool addFeature( QgsVectorLayer* layer, QgsAttributeMap defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry() ) = 0;


/**
* This will be called, whenever a vector layer should be switched to edit mode. Check the providers
* capability to edit in here.
* If successful layer->startEditing() will be called and true returned.
*
* @param layer The layer on which to start an edit session
*
* @return True, if the editing session was started
*/
virtual bool startEditing( QgsVectorLayer* layer ) = 0;

/**
* Will be called, when an editing session is ended and the features should be commited.
* Appropriate dialogs should be shown like
*
* @param layer The layer to commit
* @param allowCancel True if a cancel button should be offered
* @return True if successful
*/
virtual bool stopEditing( QgsVectorLayer* layer, bool allowCancel = true ) = 0;

};

#endif // QGSVECTORLAYERTOOLS_H