26 #include <QDomElement> 30 #include <QGraphicsProxyWidget> 38 , mWidgetContainer( nullptr )
39 , mDesignerWidget( nullptr )
40 , mVectorLayer( vlayer )
41 , mHasAssociatedFeature( hasFeature )
45 mWidgetContainer->
setData( 0,
"AnnotationItem" );
49 QObject::connect( mVectorLayer, SIGNAL( layerModified() ),
this, SLOT( setFeatureForMapPosition() ) );
54 setFeatureForMapPosition();
59 delete mDesignerWidget;
64 mDesignerForm = uiFile;
66 delete mDesignerWidget;
67 mDesignerWidget = createDesignerWidget( uiFile );
68 if ( mDesignerWidget )
71 mWidgetContainer->
setWidget( mDesignerWidget );
76 QWidget* QgsFormAnnotationItem::createDesignerWidget(
const QString& filePath )
78 QFile file( filePath );
79 if ( !file.
open( QFile::ReadOnly ) )
91 if ( mVectorLayer && mHasAssociatedFeature )
98 for (
int i = 0; i < attrs.
count(); ++i )
100 if ( i < fields.
count() )
117 setFeatureForMapPosition();
129 if ( !painter || !mWidgetContainer )
152 if ( mDesignerWidget )
165 if ( mDesignerWidget )
178 if ( documentElem.
isNull() )
186 formAnnotationElem.
setAttribute(
"vectorLayer", mVectorLayer->
id() );
188 formAnnotationElem.
setAttribute(
"hasFeature", mHasAssociatedFeature );
190 formAnnotationElem.
setAttribute(
"designerForm", mDesignerForm );
197 mVectorLayer =
nullptr;
203 QObject::connect( mVectorLayer, SIGNAL( layerModified() ),
this, SLOT( setFeatureForMapPosition() ) );
208 mHasAssociatedFeature = itemElem.
attribute(
"hasFeature",
"0" ).
toInt();
210 mDesignerForm = itemElem.
attribute(
"designerForm",
"" );
212 if ( !annotationElem.
isNull() )
217 mDesignerWidget = createDesignerWidget( mDesignerForm );
218 if ( mDesignerWidget )
221 mWidgetContainer->
setWidget( mDesignerWidget );
226 void QgsFormAnnotationItem::setFeatureForMapPosition()
241 bool featureFound =
false;
243 while ( fit.nextFeature( currentFeature ) )
245 currentFeatureId = currentFeature.
id();
250 mHasAssociatedFeature = featureFound;
251 mFeature = currentFeatureId;
255 delete mDesignerWidget;
256 mDesignerWidget = createDesignerWidget( mDesignerForm );
257 if ( mDesignerWidget )
260 mWidgetContainer->
setWidget( mDesignerWidget );
264 void QgsFormAnnotationItem::updateVisibility()
QgsFeatureId id() const
Get the feature ID for this feature.
Wrapper for iterator of features from vector data provider or vector layer.
QString annotationForm() const
Get annotation form.
A rectangle specified with double values.
void _readXML(const QDomDocument &doc, const QDomElement &annotationElem)
double mFrameBorderWidth
Width of the frame.
QDomNode appendChild(const QDomNode &newChild)
Use exact geometry intersection (slower) instead of bounding boxes.
QString attribute(const QString &name, const QString &defValue) const
void setData(int key, const QVariant &value)
QgsFields fields() const
Returns the list of fields of this layer.
QPointF mOffsetFromReferencePoint
Describes the shift of the item content box to the reference point.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
QList< QgsMapLayer * > layers() const
return list of layers within map canvas.
Container of fields for a vector layer.
QDomElement documentElement() const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setWorkingDirectory(const QDir &dir)
Map canvas is a class for displaying all GIS data types on a canvas.
double x() const
Get the x value of the point.
void setFrameSize(QSizeF size)
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
virtual void setMapPosition(const QgsPoint &pos)
bool hasAttribute(const QString &name) const
QgsAttributes attributes() const
Returns the feature's attributes.
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void drawMarkerSymbol(QPainter *p) const
Draws the map position marker symbol to a destination painter.
QList< int > QgsAttributeList
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
int count() const
Return number of items.
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
A class to represent a point.
bool contains(const T &value) const
An annotation item can be either placed either on screen corrdinates or on map coordinates.
bool mMapPositionFixed
True: the item stays at the same map position, False: the item stays on same screen position...
static Q_DECL_DEPRECATED QWidget * createAttributeEditor(QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value, QMap< int, QWidget * > &proxyWidgets)
Creates or prepares a attribute editor widget.
const T & at(int i) const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void drawSelectionBoxes(QPainter *p) const
Draws selection handles around the item.
void _writeXML(QDomDocument &doc, QDomElement &itemElem) const
QgsMapCanvas * mMapCanvas
pointer to map canvas
QDomElement firstChildElement(const QString &tagName) const
void setFlags(QFlags< QGraphicsItem::GraphicsItemFlag > flags)
int count(const T &value) const
QWidget * load(QIODevice *device, QWidget *parentWidget)
void setVisible(bool visible)
double y() const
Get the y value of the point.
QColor mFrameBackgroundColor
QDomElement createElement(const QString &tagName)
bool nextFeature(QgsFeature &f)
Geometry is not required. It may still be returned if e.g. required for a filter condition.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
QgsPoint mMapPosition
Map position (in case mMapPositionFixed is true)
QSizeF mFrameSize
Size of the frame (without balloon)
void drawFrame(QPainter *p) const
Draws the annotation frame to a destination painter.
T findChild(const QString &name) const