30 #include <QDomElement> 34 #include <QGraphicsProxyWidget> 48 c->setDesignerForm( mDesignerForm );
54 mDesignerForm = uiFile;
55 mDesignerWidget.reset( createDesignerWidget( uiFile ) );
56 if ( mDesignerWidget )
58 mMinimumSize = mDesignerWidget->minimumSize();
62 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
71 QWidget *QgsFormAnnotation::createDesignerWidget(
const QString &filePath )
73 QFile file( filePath );
74 if ( !file.open( QFile::ReadOnly ) )
81 loader.setWorkingDirectory( fi.dir() );
82 QWidget *widget = loader.load( &file,
nullptr );
92 for (
int i = 0; i < attrs.count(); ++i )
94 if ( i < fields.
count() )
96 QWidget *attWidget = widget->findChild<QWidget *>( fields.
at( i ).
name() );
113 if ( !mDesignerWidget )
118 const double scaleFactor = context.
painter()->device()->logicalDpiX() / 96.0;
119 context.
painter()->scale( scaleFactor, scaleFactor );
122 mDesignerWidget->setFixedSize( size.toSize() );
123 context.
painter()->setBrush( Qt::NoBrush );
124 context.
painter()->setPen( Qt::NoPen );
125 mDesignerWidget->render( context.
painter(), QPoint( 0, 0 ) );
132 if ( mDesignerWidget )
134 QSizeF widgetMinSize = mMinimumSize;
140 return QSizeF( 0, 0 );
146 if ( mDesignerWidget )
148 return mDesignerWidget->sizeHint();
152 return QSizeF( 0, 0 );
158 QDomElement formAnnotationElem = doc.createElement( QStringLiteral(
"FormAnnotationItem" ) );
159 formAnnotationElem.setAttribute( QStringLiteral(
"designerForm" ), mDesignerForm );
160 _writeXml( formAnnotationElem, doc, context );
161 elem.appendChild( formAnnotationElem );
166 mDesignerForm = itemElem.attribute( QStringLiteral(
"designerForm" ), QString() );
167 QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral(
"AnnotationItem" ) );
168 if ( !annotationElem.isNull() )
170 _readXml( annotationElem, context );
173 if ( !
mapLayer() && itemElem.hasAttribute( QStringLiteral(
"vectorLayer" ) ) )
178 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
182 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
192 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
196 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
QgsFillSymbol * fillSymbol() const
Returns the symbol that is used for rendering the annotation frame.
The class is used as a container of context for various read/write operations on other objects...
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
QgsFeature associatedFeature() const
Returns the feature associated with the annotation, or an invalid feature if none has been set...
bool isValid() const
Returns the validity of this feature.
void setMapLayer(QgsMapLayer *layer)
Sets the map layer associated with the annotation.
This class contains context information for attribute editor widgets.
Container of fields for a vector layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
void _writeXml(QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes common annotation properties to a DOM element.
Abstract base class for annotation items which are drawn over a map.
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
QgsFields fields() const FINAL
Returns the list of fields of this layer.
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...
void copyCommonProperties(QgsAnnotation *target) const
Copies common annotation properties to the targe annotation.
int count() const
Returns number of items.
void setFrameSizeMm(QSizeF size)
Sets the size (in millimeters) of the annotation's frame (the main area in which the annotation's con...
void _readXml(const QDomElement &annotationElem, const QgsReadWriteContext &context)
Reads common annotation properties from a DOM element.
Contains information about the context of a rendering operation.
double bottom() const
Returns the bottom margin.
QPainter * painter()
Returns the destination QPainter for the render operation.
double top() const
Returns the top margin.
QgsMargins contentsMargin() const
Returns the margins (in millimeters) between the outside of the frame and the annotation content...
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
void setFillSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used for rendering the annotation frame.
Represents a vector layer which manages a vector based data sets.
virtual void setAssociatedFeature(const QgsFeature &feature)
Sets the feature associated with the annotation.
void setColor(const QColor &color)
Sets the color for the symbol.