29 #include <QDomElement> 33 #include <QGraphicsProxyWidget> 41 , mWidgetContainer( nullptr )
43 , mVectorLayer( vlayer )
44 , mHasAssociatedFeature( hasFeature )
45 , mFeatureId( feature )
53 QObject::connect( mWebView->page()->mainFrame(), SIGNAL( javaScriptWindowObjectCleared() ),
this, SLOT( javascript() ) );
57 QObject::connect( mVectorLayer, SIGNAL( layerModified() ),
this, SLOT( setFeatureForMapPosition() ) );
62 setFeatureForMapPosition();
72 QFile file( htmlFile );
74 if ( !file.
open( QIODevice::ReadOnly | QIODevice::Text ) )
86 setFeatureForMapPosition();
92 setFeatureForMapPosition();
104 if ( !painter || !mWidgetContainer )
145 if ( documentElem.
isNull() )
153 formAnnotationElem.
setAttribute(
"vectorLayer", mVectorLayer->
id() );
155 formAnnotationElem.
setAttribute(
"hasFeature", mHasAssociatedFeature );
156 formAnnotationElem.
setAttribute(
"feature", mFeatureId );
165 mVectorLayer =
nullptr;
171 QObject::connect( mVectorLayer, SIGNAL( layerModified() ),
this, SLOT( setFeatureForMapPosition() ) );
176 mHasAssociatedFeature = itemElem.
attribute(
"hasFeature",
"0" ).
toInt();
178 mHtmlFile = itemElem.
attribute(
"htmlfile",
"" );
180 if ( !annotationElem.
isNull() )
192 void QgsHtmlAnnotationItem::setFeatureForMapPosition()
205 bool featureFound =
false;
207 while ( fit.nextFeature( currentFeature ) )
209 currentFeatureId = currentFeature.
id();
214 mHasAssociatedFeature = featureFound;
215 mFeatureId = currentFeatureId;
216 mFeature = currentFeature;
229 newText = mHtmlSource;
234 void QgsHtmlAnnotationItem::updateVisibility()
244 void QgsHtmlAnnotationItem::javascript()
246 QWebFrame *frame = mWebView->page()->mainFrame();
void readXML(const QDomDocument &doc, const QDomElement &itemElem) override
void setCodec(QTextCodec *codec)
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
The QWebFrame class is a collection of stubs to mimic the API of a QWebFrame on systems where QtWebki...
QList< QgsMapLayer * > layers() const
return list of layers within map canvas.
QgsHtmlAnnotationItem(QgsMapCanvas *canvas, QgsVectorLayer *vlayer=nullptr, bool hasFeature=false, int feature=0)
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.
void setMapPosition(const QgsPoint &pos) override
Reimplemented from QgsAnnotationItem.
QString attribute(const QString &name, const QString &defValue) const
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
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.
void setHtml(const QString &text)
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.
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...
Map canvas is a class for displaying all GIS data types on a canvas.
double y() const
Get the y value of the point.
void addToJavaScriptWindowObject(const QString &name, QObject *object)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
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
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void _writeXML(QDomDocument &doc, QDomElement &itemElem) const
The QgsWebView class is a collection of stubs to mimic the API of QWebView on systems where the real ...
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
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.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
bool mMapPositionFixed
True: the item stays at the same map position, False: the item stays on same screen position...
QVariant data(int key) const
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void paint(QPainter *painter) override
function to be implemented by derived classes
static QgsNetworkAccessManager * instance()
returns a pointer to the single instance
void setHTMLPage(const QString &htmlFile)
QgsMapCanvas * mMapCanvas
pointer to map canvas
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
QDomElement firstChildElement(const QString &tagName) const
void setFlags(QFlags< QGraphicsItem::GraphicsItemFlag > flags)
void writeXML(QDomDocument &doc) const override
static Q_DECL_DEPRECATED QString replaceExpressionText(const QString &action, const QgsFeature *feat, QgsVectorLayer *layer, const QMap< QString, QVariant > *substitutionMap=nullptr, const QgsDistanceArea *distanceArea=nullptr)
This function currently replaces each expression between [% and %] in the string with the result of i...
void setVisible(bool visible)
QSizeF minimumFrameSize() const override
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
QDomElement createElement(const QString &tagName)
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.