37#include <QGraphicsProxyWidget>
44#include "moc_qgsformannotation.cpp"
46using namespace Qt::StringLiterals;
54 auto c = std::make_unique<QgsFormAnnotation>();
56 c->setDesignerForm( mDesignerForm );
62 mDesignerForm = uiFile;
63 mDesignerWidget.reset( createDesignerWidget( uiFile ) );
64 if ( mDesignerWidget )
66 mMinimumSize = mDesignerWidget->minimumSize();
70 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
79QWidget *QgsFormAnnotation::createDesignerWidget(
const QString &filePath )
81 QFile file( filePath );
82 if ( !file.open( QFile::ReadOnly ) )
88 const QFileInfo fi( file );
89 loader.setWorkingDirectory( fi.dir() );
90 QWidget *widget = loader.load( &file,
nullptr );
94 const QgsAttributeEditorContext context;
95 QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>(
mapLayer() );
98 const QgsFields fields = vectorLayer->
fields();
100 for (
int i = 0; i < attrs.count(); ++i )
102 if ( i < fields.
count() )
104 QWidget *attWidget = widget->findChild<QWidget *>( fields.
at( i ).name() );
111 QVariantList additionalFieldValues;
112 for (
const QString &additionalField : additionalFields )
115 additionalFieldValues.insert( index, attrs.at( index ) );
117 eww->
setValues( attrs.at( i ), additionalFieldValues );
133 const double scaleFactor = context.
painter()->device()->logicalDpiX() / 96.0;
134 context.
painter()->scale( scaleFactor, scaleFactor );
137 mDesignerWidget->setFixedSize( size.toSize() );
138 context.
painter()->setBrush( Qt::NoBrush );
139 context.
painter()->setPen( Qt::NoPen );
140 mDesignerWidget->render( context.
painter(), QPoint( 0, 0 ) );
145 if ( mDesignerWidget )
147 const QSizeF widgetMinSize = mMinimumSize;
152 return QSizeF( 0, 0 );
158 if ( mDesignerWidget )
160 return mDesignerWidget->sizeHint();
164 return QSizeF( 0, 0 );
170 QDomElement formAnnotationElem = doc.createElement( u
"FormAnnotationItem"_s );
171 formAnnotationElem.setAttribute( u
"designerForm"_s, mDesignerForm );
172 _writeXml( formAnnotationElem, doc, context );
173 elem.appendChild( formAnnotationElem );
178 mDesignerForm = itemElem.attribute( u
"designerForm"_s, QString() );
179 const QDomElement annotationElem = itemElem.firstChildElement( u
"AnnotationItem"_s );
180 if ( !annotationElem.isNull() )
182 _readXml( annotationElem, context );
185 if ( !
mapLayer() && itemElem.hasAttribute( u
"vectorLayer"_s ) )
190 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
194 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
204 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
208 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