38#include <QGraphicsProxyWidget>
45#include "moc_qgsformannotation.cpp"
47using namespace Qt::StringLiterals;
55 auto c = std::make_unique<QgsFormAnnotation>();
57 c->setDesignerForm( mDesignerForm );
63 mDesignerForm = uiFile;
64 mDesignerWidget.reset( createDesignerWidget( uiFile ) );
65 if ( mDesignerWidget )
67 mMinimumSize = mDesignerWidget->minimumSize();
71 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
80QWidget *QgsFormAnnotation::createDesignerWidget(
const QString &filePath )
82 QFile file( filePath );
83 if ( !file.open( QFile::ReadOnly ) )
89 const QFileInfo fi( file );
90 loader.setWorkingDirectory( fi.dir() );
91 QWidget *widget = loader.load( &file,
nullptr );
95 const QgsAttributeEditorContext context;
96 QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>(
mapLayer() );
99 const QgsFields fields = vectorLayer->
fields();
101 for (
int i = 0; i < attrs.count(); ++i )
103 if ( i < fields.
count() )
105 QWidget *attWidget = widget->findChild<QWidget *>( fields.
at( i ).name() );
112 QVariantList additionalFieldValues;
113 for (
const QString &additionalField : additionalFields )
116 additionalFieldValues.insert( index, attrs.at( index ) );
118 eww->
setValues( attrs.at( i ), additionalFieldValues );
134 const double scaleFactor = context.
painter()->device()->logicalDpiX() / 96.0;
135 context.
painter()->scale( scaleFactor, scaleFactor );
138 mDesignerWidget->setFixedSize( size.toSize() );
139 context.
painter()->setBrush( Qt::NoBrush );
140 context.
painter()->setPen( Qt::NoPen );
141 mDesignerWidget->render( context.
painter(), QPoint( 0, 0 ) );
146 if ( mDesignerWidget )
148 const QSizeF widgetMinSize = mMinimumSize;
153 return QSizeF( 0, 0 );
159 if ( mDesignerWidget )
161 return mDesignerWidget->sizeHint();
165 return QSizeF( 0, 0 );
171 QDomElement formAnnotationElem = doc.createElement( u
"FormAnnotationItem"_s );
172 formAnnotationElem.setAttribute( u
"designerForm"_s, mDesignerForm );
173 _writeXml( formAnnotationElem, doc, context );
174 elem.appendChild( formAnnotationElem );
179 mDesignerForm = itemElem.attribute( u
"designerForm"_s, QString() );
180 const QDomElement annotationElem = itemElem.firstChildElement( u
"AnnotationItem"_s );
181 if ( !annotationElem.isNull() )
183 _readXml( annotationElem, context );
186 if ( !
mapLayer() && itemElem.hasAttribute( u
"vectorLayer"_s ) )
191 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
195 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
205 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
209 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