19#include "moc_qgsformannotation.cpp"
37#include <QGraphicsProxyWidget>
51 c->setDesignerForm( mDesignerForm );
57 mDesignerForm = uiFile;
58 mDesignerWidget.reset( createDesignerWidget( uiFile ) );
59 if ( mDesignerWidget )
61 mMinimumSize = mDesignerWidget->minimumSize();
65 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
74QWidget *QgsFormAnnotation::createDesignerWidget(
const QString &filePath )
76 QFile file( filePath );
77 if ( !file.open( QFile::ReadOnly ) )
83 const QFileInfo fi( file );
84 loader.setWorkingDirectory( fi.dir() );
85 QWidget *widget = loader.load( &file,
nullptr );
95 for (
int i = 0; i < attrs.count(); ++i )
97 if ( i < fields.
count() )
99 QWidget *attWidget = widget->findChild<QWidget *>( fields.
at( i ).
name() );
106 QVariantList additionalFieldValues;
107 for (
const QString &additionalField : additionalFields )
110 additionalFieldValues.insert( index, attrs.at( index ) );
112 eww->
setValues( attrs.at( i ), additionalFieldValues );
128 const double scaleFactor = context.
painter()->device()->logicalDpiX() / 96.0;
129 context.
painter()->scale( scaleFactor, scaleFactor );
132 mDesignerWidget->setFixedSize( size.toSize() );
133 context.
painter()->setBrush( Qt::NoBrush );
134 context.
painter()->setPen( Qt::NoPen );
135 mDesignerWidget->render( context.
painter(), QPoint( 0, 0 ) );
140 if ( mDesignerWidget )
142 const QSizeF widgetMinSize = mMinimumSize;
148 return QSizeF( 0, 0 );
154 if ( mDesignerWidget )
156 return mDesignerWidget->sizeHint();
160 return QSizeF( 0, 0 );
166 QDomElement formAnnotationElem = doc.createElement( QStringLiteral(
"FormAnnotationItem" ) );
167 formAnnotationElem.setAttribute( QStringLiteral(
"designerForm" ), mDesignerForm );
168 _writeXml( formAnnotationElem, doc, context );
169 elem.appendChild( formAnnotationElem );
174 mDesignerForm = itemElem.attribute( QStringLiteral(
"designerForm" ), QString() );
175 const QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral(
"AnnotationItem" ) );
176 if ( !annotationElem.isNull() )
178 _readXml( annotationElem, context );
181 if ( !
mapLayer() && itemElem.hasAttribute( QStringLiteral(
"vectorLayer" ) ) )
186 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
190 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
200 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
204 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
Abstract base class for annotation items which are drawn over a map.
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
void setFillSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used for rendering the annotation frame.
QgsMargins contentsMargin() const
Returns the margins (in millimeters) between the outside of the frame and the annotation content.
void _writeXml(QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes common annotation properties to a DOM element.
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
void setFrameSizeMm(QSizeF size)
Sets the size (in millimeters) of the annotation's frame (the main area in which the annotation's con...
virtual void setAssociatedFeature(const QgsFeature &feature)
Sets the feature associated with the annotation.
QgsFeature associatedFeature() const
Returns the feature associated with the annotation, or an invalid feature if none has been set.
void _readXml(const QDomElement &annotationElem, const QgsReadWriteContext &context)
Reads common annotation properties from a DOM element.
void copyCommonProperties(QgsAnnotation *target) const
Copies common annotation properties to the targe annotation.
QgsFillSymbol * fillSymbol() const
Returns the symbol that is used for rendering the annotation frame.
void setMapLayer(QgsMapLayer *layer)
Sets the map layer associated with the annotation.
This class contains context information for attribute editor widgets.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isCanceled() const
Tells whether the operation has been canceled already.
Container of fields for a vector layer.
Q_INVOKABLE int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
static QgsProject * instance()
Returns the QgsProject singleton instance.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly during rendering to check if rendering shou...
Scoped object for saving and restoring a QPainter object's state.
void setColor(const QColor &color) const
Sets the color for the symbol.
Represents a vector layer which manages a vector based data sets.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c