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()
208 bool featureFound =
false;
210 while ( fit.nextFeature( currentFeature ) )
212 currentFeatureId = currentFeature.
id();
217 mHasAssociatedFeature = featureFound;
218 mFeatureId = currentFeatureId;
219 mFeature = currentFeature;
229 mWebView->setHtml( newtext );
232 void QgsHtmlAnnotationItem::updateVisibility()
242 void QgsHtmlAnnotationItem::javascript()
244 QWebFrame *frame = mWebView->page()->mainFrame();
QgsFeatureId id() const
Get the feature ID for this feature.
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...
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.
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.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
QDomElement documentElement() const
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 x() const
Get the x value of the point.
void drawSelectionBoxes(QPainter *p)
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
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...
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)...
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
void drawMarkerSymbol(QPainter *p)
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.
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...
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 _writeXML(QDomDocument &doc, QDomElement &itemElem) const
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 drawFrame(QPainter *p)
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)
double y() const
Get the y value of the point.
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)