27 #include <QDomElement>
31 #include <QGraphicsProxyWidget>
38 :
QgsAnnotationItem( canvas ), mWidgetContainer( 0 ), mWebView( 0 ), mVectorLayer( vlayer ),
39 mHasAssociatedFeature( hasFeature ), mFeatureId( feature )
45 QObject::connect(
mWebView->page()->mainFrame(), SIGNAL( javaScriptWindowObjectCleared() ),
this, SLOT(
javascript() ) );
64 QFile
file( htmlFile );
66 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
72 QTextStream in( &file );
73 in.setCodec(
"UTF-8" );
110 if ( data( 1 ).toString() ==
"composer" )
125 QSizeF widgetMinSize =
mWebView->minimumSize();
130 return QSizeF( 0, 0 );
136 QDomElement documentElem = doc.documentElement();
137 if ( documentElem.isNull() )
142 QDomElement formAnnotationElem = doc.createElement(
"HtmlAnnotationItem" );
145 formAnnotationElem.setAttribute(
"vectorLayer",
mVectorLayer->
id() );
148 formAnnotationElem.setAttribute(
"feature",
mFeatureId );
149 formAnnotationElem.setAttribute(
"htmlfile",
htmlPage() );
152 documentElem.appendChild( formAnnotationElem );
158 if ( itemElem.hasAttribute(
"vectorLayer" ) )
169 mFeatureId = itemElem.attribute(
"feature",
"0" ).toInt();
170 mHtmlFile = itemElem.attribute(
"htmlfile",
"" );
171 QDomElement annotationElem = itemElem.firstChildElement(
"AnnotationItem" );
172 if ( !annotationElem.isNull() )
201 bool featureFound =
false;
203 while ( fit.nextFeature( currentFeature ) )
205 currentFeatureId = currentFeature.
id();
225 setVisible( visible );
230 QWebFrame *frame =
mWebView->page()->mainFrame();
231 frame->addToJavaScriptWindowObject(
"canvas",
mMapCanvas );
232 frame->addToJavaScriptWindowObject(
"layer",
mVectorLayer );
QgsFeatureId id() const
Get the feature id for this feature.
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
QgsVectorLayer * mVectorLayer
Associated vectorlayer (or 0 if attributes are not supposed to be replaced)
QgsVectorLayer * vectorLayer() const
void _readXML(const QDomDocument &doc, const QDomElement &annotationElem)
double mFrameBorderWidth
Width of the frame.
Use exact geometry intersection (slower) instead of bounding boxes.
QgsFeatureId mFeatureId
Associated feature.
QPointF mOffsetFromReferencePoint
Describes the shift of the item content box to the reference point.
void writeXML(QDomDocument &doc) const
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. Added in v1.5
static const double DEFAULT_IDENTIFY_RADIUS
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void readXML(const QDomDocument &doc, const QDomElement &itemElem)
QSizeF minimumFrameSize() const
Map canvas is a class for displaying all GIS data types on a canvas.
QgsHtmlAnnotationItem(QgsMapCanvas *canvas, QgsVectorLayer *vlayer=0, bool hasFeature=false, int feature=0)
void drawSelectionBoxes(QPainter *p)
virtual void setMapPosition(const QgsPoint &pos)
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)
QGraphicsProxyWidget * mWidgetContainer
void updateVisibility()
Sets visibility status based on mVectorLayer visibility.
A class to represent a point geometry.
An annotation item can be either placed either on screen corrdinates or on map coordinates.
void setMapPosition(const QgsPoint &pos)
Reimplemented from QgsAnnotationItem.
bool mMapPositionFixed
True: the item stays at the same map position, False: the item stays on same screen position...
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void _writeXML(QDomDocument &doc, QDomElement &itemElem) const
void setHTMLPage(const QString &htmlFile)
QgsMapCanvas * mMapCanvas
pointer to map canvas
void drawFrame(QPainter *p)
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
void setFeatureForMapPosition()
Sets a feature for the current map position and updates the dialog.
QgsRectangle extent() const
Returns the current zoom exent of the map canvas.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
double width() const
Width of the rectangle.
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)
static QString replaceExpressionText(const QString &action, const QgsFeature *feat, QgsVectorLayer *layer, const QMap< QString, QVariant > *substitutionMap=0)
This function currently replaces each expression between [% and %] in the string with the result of i...
bool mHasAssociatedFeature
True if the item is related to a vector feature.
void paint(QPainter *painter)
function to be implemented by derived classes