Skip to content

Commit 191f70a

Browse files
author
mhugent
committed
Remember last annotation form for a layer and store it in project
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13291 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 61ba9cc commit 191f70a

6 files changed

+44
-1
lines changed

python/core/qgsvectorlayer.sip

+9
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,15 @@ public:
444444
*/
445445
void setEditForm( QString ui );
446446

447+
/** get annotation form
448+
@note added in 1.5*/
449+
QString annotationForm() const;
450+
451+
/** set annotation form for layer
452+
@note added in 1.5*/
453+
void setAnnotationForm( const QString& ui );
454+
455+
447456
/** get edit form init function
448457
@note added in 1.4
449458
*/

src/app/qgsformannotationdialog.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "qgsformannotationdialog.h"
22
#include "qgsannotationwidget.h"
3+
#include "qgsvectorlayer.h"
34
#include <QFileDialog>
45
#include <QFileInfo>
56
#include <QGraphicsScene>
@@ -40,6 +41,12 @@ void QgsFormAnnotationDialog::applySettingsToItem()
4041
if ( mItem )
4142
{
4243
mItem->setDesignerForm( mFileLineEdit->text() );
44+
QgsVectorLayer* layer = mItem->vectorLayer();
45+
if ( layer )
46+
{
47+
//set last used annotation form as default for the layer
48+
layer->setAnnotationForm( mFileLineEdit->text() );
49+
}
4350
mItem->update();
4451
}
4552
}

src/core/qgsvectorlayer.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -2797,6 +2797,13 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
27972797
mEditFormInit = editFormInitNode.toElement().text();
27982798
}
27992799

2800+
QDomNode annotationFormNode = node.namedItem( "annotationform" );
2801+
if ( !annotationFormNode.isNull() )
2802+
{
2803+
QDomElement e = annotationFormNode.toElement();
2804+
mAnnotationForm = QgsProject::instance()->readPath( e.text() );
2805+
}
2806+
28002807
mAttributeAliasMap.clear();
28012808
QDomNode aliasesNode = node.namedItem( "aliases" );
28022809
if ( !aliasesNode.isNull() )
@@ -2943,6 +2950,11 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
29432950
efiField.appendChild( efiText );
29442951
node.appendChild( efiField );
29452952

2953+
QDomElement afField = doc.createElement( "annotationform" );
2954+
QDomText afText = doc.createTextNode( QgsProject::instance()->writePath( mAnnotationForm ) );
2955+
afField.appendChild( afText );
2956+
node.appendChild( afField );
2957+
29462958
//attribute aliases
29472959
if ( mAttributeAliasMap.size() > 0 )
29482960
{
@@ -4142,6 +4154,11 @@ void QgsVectorLayer::setEditForm( QString ui )
41424154
mEditForm = ui;
41434155
}
41444156

4157+
void QgsVectorLayer::setAnnotationForm( const QString& ui )
4158+
{
4159+
mAnnotationForm = ui;
4160+
}
4161+
41454162
QString QgsVectorLayer::editFormInit()
41464163
{
41474164
return mEditFormInit;

src/core/qgsvectorlayer.h

+8
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
480480
/** set edit form (added in 1.4) */
481481
void setEditForm( QString ui );
482482

483+
/** get annotation form (added in 1.5)*/
484+
QString annotationForm() const { return mAnnotationForm; }
485+
486+
/** set annotation form for layer (added in 1.5)*/
487+
void setAnnotationForm( const QString& ui );
488+
483489
/** get python function for edit form initialization (added in 1.4) */
484490
QString editFormInit();
485491

@@ -775,6 +781,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
775781
QMap< QString, QPair<QString, QString> > mCheckedStates;
776782

777783
QString mEditForm, mEditFormInit;
784+
//annotation form for this layer
785+
QString mAnnotationForm;
778786

779787
bool mFetching;
780788
QgsRectangle mFetchRect;

src/gui/qgsformannotationitem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ QgsFormAnnotationItem::QgsFormAnnotationItem( QgsMapCanvas* canvas, QgsVectorLay
3939
mWidgetContainer = new QGraphicsProxyWidget( this );
4040
if ( mVectorLayer && mMapCanvas ) //default to the layers edit form
4141
{
42-
mDesignerForm = mVectorLayer->editForm();
42+
mDesignerForm = mVectorLayer->annotationForm();
4343
QObject::connect( mVectorLayer, SIGNAL( layerModified( bool ) ), this, SLOT( setFeatureForMapPosition() ) );
4444
QObject::connect( mMapCanvas, SIGNAL( renderComplete( QPainter* ) ), this, SLOT( setFeatureForMapPosition() ) );
4545
QObject::connect( mMapCanvas, SIGNAL( layersChanged() ), this, SLOT( updateVisibility() ) );

src/gui/qgsformannotationitem.h

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class GUI_EXPORT QgsFormAnnotationItem: public QObject, public QgsAnnotationItem
4949
void writeXML( QDomDocument& doc ) const;
5050
void readXML( const QDomDocument& doc, const QDomElement& itemElem );
5151

52+
QgsVectorLayer* vectorLayer() const { return mVectorLayer; }
53+
5254
private slots:
5355
/**Sets a feature for the current map position and updates the dialog*/
5456
void setFeatureForMapPosition();

0 commit comments

Comments
 (0)