37#include <QGraphicsProxyWidget>
43#include "moc_qgsformannotation.cpp"
51 auto c = std::make_unique<QgsFormAnnotation>();
53 c->setDesignerForm( mDesignerForm );
59 mDesignerForm = uiFile;
60 mDesignerWidget.reset( createDesignerWidget( uiFile ) );
61 if ( mDesignerWidget )
63 mMinimumSize = mDesignerWidget->minimumSize();
67 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
76QWidget *QgsFormAnnotation::createDesignerWidget(
const QString &filePath )
78 QFile file( filePath );
79 if ( !file.open( QFile::ReadOnly ) )
85 const QFileInfo fi( file );
86 loader.setWorkingDirectory( fi.dir() );
87 QWidget *widget = loader.load( &file,
nullptr );
91 const QgsAttributeEditorContext context;
92 QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>(
mapLayer() );
95 const QgsFields fields = vectorLayer->
fields();
97 for (
int i = 0; i < attrs.count(); ++i )
99 if ( i < fields.
count() )
101 QWidget *attWidget = widget->findChild<QWidget *>( fields.
at( i ).name() );
108 QVariantList additionalFieldValues;
109 for (
const QString &additionalField : additionalFields )
112 additionalFieldValues.insert( index, attrs.at( index ) );
114 eww->
setValues( attrs.at( i ), additionalFieldValues );
130 const double scaleFactor = context.
painter()->device()->logicalDpiX() / 96.0;
131 context.
painter()->scale( scaleFactor, scaleFactor );
134 mDesignerWidget->setFixedSize( size.toSize() );
135 context.
painter()->setBrush( Qt::NoBrush );
136 context.
painter()->setPen( Qt::NoPen );
137 mDesignerWidget->render( context.
painter(), QPoint( 0, 0 ) );
142 if ( mDesignerWidget )
144 const QSizeF widgetMinSize = mMinimumSize;
149 return QSizeF( 0, 0 );
155 if ( mDesignerWidget )
157 return mDesignerWidget->sizeHint();
161 return QSizeF( 0, 0 );
167 QDomElement formAnnotationElem = doc.createElement( QStringLiteral(
"FormAnnotationItem" ) );
168 formAnnotationElem.setAttribute( QStringLiteral(
"designerForm" ), mDesignerForm );
169 _writeXml( formAnnotationElem, doc, context );
170 elem.appendChild( formAnnotationElem );
175 mDesignerForm = itemElem.attribute( QStringLiteral(
"designerForm" ), QString() );
176 const QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral(
"AnnotationItem" ) );
177 if ( !annotationElem.isNull() )
179 _readXml( annotationElem, context );
182 if ( !
mapLayer() && itemElem.hasAttribute( QStringLiteral(
"vectorLayer" ) ) )
187 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
191 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
201 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
205 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
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.
QgsAnnotation(QObject *parent=nullptr)
Constructor for QgsAnnotation.
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.
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.
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.
A container for the context for various read/write operations on 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.
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