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 ) );
70 QWidget *QgsFormAnnotation::createDesignerWidget(
const QString &filePath )
72 QFile file( filePath );
73 if ( !file.open( QFile::ReadOnly ) )
80 loader.setWorkingDirectory( fi.dir() );
81 QWidget *widget = loader.load( &file,
nullptr );
91 for (
int i = 0; i < attrs.count(); ++i )
93 if ( i < fields.
count() )
95 QWidget *attWidget = widget->findChild<QWidget *>( fields.
at( i ).
name() );
112 if ( !mDesignerWidget )
115 mDesignerWidget->setFixedSize( size.toSize() );
116 context.
painter()->setBrush( Qt::NoBrush );
117 context.
painter()->setPen( Qt::NoPen );
118 mDesignerWidget->render( context.
painter(), QPoint( 0, 0 ) );
123 if ( mDesignerWidget )
125 QSizeF widgetMinSize = mMinimumSize;
131 return QSizeF( 0, 0 );
137 if ( mDesignerWidget )
139 return mDesignerWidget->sizeHint();
143 return QSizeF( 0, 0 );
149 QDomElement formAnnotationElem = doc.createElement( QStringLiteral(
"FormAnnotationItem" ) );
150 formAnnotationElem.setAttribute( QStringLiteral(
"designerForm" ), mDesignerForm );
151 _writeXml( formAnnotationElem, doc, context );
152 elem.appendChild( formAnnotationElem );
157 mDesignerForm = itemElem.attribute( QStringLiteral(
"designerForm" ), QLatin1String(
"" ) );
158 QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral(
"AnnotationItem" ) );
159 if ( !annotationElem.isNull() )
161 _readXml( annotationElem, context );
164 if ( !
mapLayer() && itemElem.hasAttribute( QStringLiteral(
"vectorLayer" ) ) )
169 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
173 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
183 mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
187 newFill->
setColor( mDesignerWidget->palette().color( QPalette::Window ) );
bool isValid() const
Returns the validity of this feature.
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.
void _writeXml(QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes common annotation properties to a DOM element.
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...
void copyCommonProperties(QgsAnnotation *target) const
Copies common annotation properties to the targe annotation.
int count() const
Return number of items.
Abstract base class for annotation items which are drawn over a map.
QgsField at(int i) const
Get field at particular index (must be in range 0..N-1)
QgsMargins contentsMargin() const
Returns the margins (in millimeters) between the outside of the frame and the annotation content...
QgsFields fields() const override
Returns the list of fields of this layer.
QgsFillSymbol * clone() const override
Get a deep copy of this symbol.
double bottom() const
Returns the bottom margin.
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories...
double top() const
Returns the top margin.
void _readXml(const QDomElement &annotationElem, const QgsReadWriteContext &context)
Reads common annotation properties from a DOM element.
void setFrameSize(QSizeF size)
Sets the size of the annotation's frame (the main area in which the annotation's content is drawn)...
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsFeature associatedFeature() const
Returns the feature associated with the annotation, or an invalid feature if none has been set...
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.
QgsFillSymbol * fillSymbol() const
Returns the symbol that is used for rendering the annotation frame.
void setColor(const QColor &color)