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()
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
QgsAttributes attributes() const
Returns the feature's attributes.
QList< QgsMapLayer * > layers() const
return list of layers within map canvas.
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)
QPointF mOffsetFromReferencePoint
Describes the shift of the item content box to the reference point.
QgsMapLayer * mapLayer(const QString &theLayerId) const
Retrieve a pointer to a registered layer by layer ID.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
void drawMarkerSymbol(QPainter *p) const
Draws the map position marker symbol to a destination painter.
Container of fields for a vector layer.
QDomElement documentElement() const
void drawSelectionBoxes(QPainter *p) const
Draws selection handles around the item.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setWorkingDirectory(const QDir &dir)
int count() const
Return number of items.
Map canvas is a class for displaying all GIS data types on a canvas.
void setFrameSize(QSizeF size)
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
double y() const
Get the y value of the point.
QgsFields fields() const
Returns the list of fields of this layer.
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.
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
virtual void setMapPosition(const QgsPoint &pos)
bool hasAttribute(const QString &name) const
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)...
QList< int > QgsAttributeList
void _writeXML(QDomDocument &doc, QDomElement &itemElem) const
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QString annotationForm() const
Get annotation form.
A class to represent a point.
QgsFeatureId id() const
Get the feature ID for this feature.
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...
const T & at(int i) const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
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)
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)
double x() const
Get the x value of the point.
void drawFrame(QPainter *p) const
Draws the annotation frame to a destination painter.
T findChild(const QString &name) const