Skip to content

Commit

Permalink
Remember last annotation form for a layer and store it in project
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@13291 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 9, 2010
1 parent 6b44aab commit f930a16
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
9 changes: 9 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -444,6 +444,15 @@ public:
*/
void setEditForm( QString ui );

/** get annotation form
@note added in 1.5*/
QString annotationForm() const;

/** set annotation form for layer
@note added in 1.5*/
void setAnnotationForm( const QString& ui );


/** get edit form init function
@note added in 1.4
*/
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgsformannotationdialog.cpp
@@ -1,5 +1,6 @@
#include "qgsformannotationdialog.h"
#include "qgsannotationwidget.h"
#include "qgsvectorlayer.h"
#include <QFileDialog>
#include <QFileInfo>
#include <QGraphicsScene>
Expand Down Expand Up @@ -40,6 +41,12 @@ void QgsFormAnnotationDialog::applySettingsToItem()
if ( mItem )
{
mItem->setDesignerForm( mFileLineEdit->text() );
QgsVectorLayer* layer = mItem->vectorLayer();
if ( layer )
{
//set last used annotation form as default for the layer
layer->setAnnotationForm( mFileLineEdit->text() );
}
mItem->update();
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2797,6 +2797,13 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
mEditFormInit = editFormInitNode.toElement().text();
}

QDomNode annotationFormNode = node.namedItem( "annotationform" );
if ( !annotationFormNode.isNull() )
{
QDomElement e = annotationFormNode.toElement();
mAnnotationForm = QgsProject::instance()->readPath( e.text() );
}

mAttributeAliasMap.clear();
QDomNode aliasesNode = node.namedItem( "aliases" );
if ( !aliasesNode.isNull() )
Expand Down Expand Up @@ -2943,6 +2950,11 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
efiField.appendChild( efiText );
node.appendChild( efiField );

QDomElement afField = doc.createElement( "annotationform" );
QDomText afText = doc.createTextNode( QgsProject::instance()->writePath( mAnnotationForm ) );
afField.appendChild( afText );
node.appendChild( afField );

//attribute aliases
if ( mAttributeAliasMap.size() > 0 )
{
Expand Down Expand Up @@ -4142,6 +4154,11 @@ void QgsVectorLayer::setEditForm( QString ui )
mEditForm = ui;
}

void QgsVectorLayer::setAnnotationForm( const QString& ui )
{
mAnnotationForm = ui;
}

QString QgsVectorLayer::editFormInit()
{
return mEditFormInit;
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -480,6 +480,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** set edit form (added in 1.4) */
void setEditForm( QString ui );

/** get annotation form (added in 1.5)*/
QString annotationForm() const { return mAnnotationForm; }

/** set annotation form for layer (added in 1.5)*/
void setAnnotationForm( const QString& ui );

/** get python function for edit form initialization (added in 1.4) */
QString editFormInit();

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

QString mEditForm, mEditFormInit;
//annotation form for this layer
QString mAnnotationForm;

bool mFetching;
QgsRectangle mFetchRect;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsformannotationitem.cpp
Expand Up @@ -39,7 +39,7 @@ QgsFormAnnotationItem::QgsFormAnnotationItem( QgsMapCanvas* canvas, QgsVectorLay
mWidgetContainer = new QGraphicsProxyWidget( this );
if ( mVectorLayer && mMapCanvas ) //default to the layers edit form
{
mDesignerForm = mVectorLayer->editForm();
mDesignerForm = mVectorLayer->annotationForm();
QObject::connect( mVectorLayer, SIGNAL( layerModified( bool ) ), this, SLOT( setFeatureForMapPosition() ) );
QObject::connect( mMapCanvas, SIGNAL( renderComplete( QPainter* ) ), this, SLOT( setFeatureForMapPosition() ) );
QObject::connect( mMapCanvas, SIGNAL( layersChanged() ), this, SLOT( updateVisibility() ) );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsformannotationitem.h
Expand Up @@ -49,6 +49,8 @@ class GUI_EXPORT QgsFormAnnotationItem: public QObject, public QgsAnnotationItem
void writeXML( QDomDocument& doc ) const;
void readXML( const QDomDocument& doc, const QDomElement& itemElem );

QgsVectorLayer* vectorLayer() const { return mVectorLayer; }

private slots:
/**Sets a feature for the current map position and updates the dialog*/
void setFeatureForMapPosition();
Expand Down

0 comments on commit f930a16

Please sign in to comment.