@@ -42,7 +42,7 @@ QgsHtmlAnnotationItem::QgsHtmlAnnotationItem( QgsMapCanvas* canvas, QgsVectorLay
4242 mWidgetContainer = new QGraphicsProxyWidget ( this );
4343 mWidgetContainer ->setWidget ( mWebView );
4444
45- QObject::connect ( mWebView ->page ()->mainFrame (), SIGNAL (javaScriptWindowObjectCleared ()), this , SLOT (javascript ()) );
45+ QObject::connect ( mWebView ->page ()->mainFrame (), SIGNAL ( javaScriptWindowObjectCleared () ), this , SLOT ( javascript () ) );
4646
4747 if ( mVectorLayer && mMapCanvas )
4848 {
@@ -86,36 +86,36 @@ void QgsHtmlAnnotationItem::setMapPosition( const QgsPoint& pos )
8686
8787void QgsHtmlAnnotationItem::paint ( QPainter * painter )
8888{
89- Q_UNUSED ( painter );
89+ Q_UNUSED ( painter );
9090}
9191
9292void QgsHtmlAnnotationItem::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
9393{
9494 Q_UNUSED ( option );
9595 Q_UNUSED ( widget );
96- if ( !painter || !mWidgetContainer )
97- {
98- return ;
99- }
96+ if ( !painter || !mWidgetContainer )
97+ {
98+ return ;
99+ }
100100
101- drawFrame ( painter );
102- if ( mMapPositionFixed )
103- {
104- drawMarkerSymbol ( painter );
105- }
101+ drawFrame ( painter );
102+ if ( mMapPositionFixed )
103+ {
104+ drawMarkerSymbol ( painter );
105+ }
106106
107- mWidgetContainer ->setGeometry ( QRectF ( mOffsetFromReferencePoint .x () + mFrameBorderWidth / 2.0 , mOffsetFromReferencePoint .y ()
108- + mFrameBorderWidth / 2.0 , mFrameSize .width () - mFrameBorderWidth , mFrameSize .height ()
109- - mFrameBorderWidth ) );
110- if (data (1 ).toString () == " composer" )
111- {
112- mWidgetContainer ->widget ()->render ( painter, mOffsetFromReferencePoint .toPoint ());
113- }
107+ mWidgetContainer ->setGeometry ( QRectF ( mOffsetFromReferencePoint .x () + mFrameBorderWidth / 2.0 , mOffsetFromReferencePoint .y ()
108+ + mFrameBorderWidth / 2.0 , mFrameSize .width () - mFrameBorderWidth , mFrameSize .height ()
109+ - mFrameBorderWidth ) );
110+ if ( data ( 1 ).toString () == " composer" )
111+ {
112+ mWidgetContainer ->widget ()->render ( painter, mOffsetFromReferencePoint .toPoint () );
113+ }
114114
115- if ( isSelected () )
116- {
117- drawSelectionBoxes ( painter );
118- }
115+ if ( isSelected () )
116+ {
117+ drawSelectionBoxes ( painter );
118+ }
119119}
120120
121121QSizeF QgsHtmlAnnotationItem::minimumFrameSize () const
@@ -167,7 +167,7 @@ void QgsHtmlAnnotationItem::readXML( const QDomDocument& doc, const QDomElement&
167167 }
168168 mHasAssociatedFeature = itemElem.attribute ( " hasFeature" , " 0" ).toInt ();
169169 mFeatureId = itemElem.attribute ( " feature" , " 0" ).toInt ();
170- mHtmlFile = itemElem.attribute ( " htmlfile" , " " );
170+ mHtmlFile = itemElem.attribute ( " htmlfile" , " " );
171171 QDomElement annotationElem = itemElem.firstChildElement ( " AnnotationItem" );
172172 if ( !annotationElem.isNull () )
173173 {
@@ -210,7 +210,7 @@ void QgsHtmlAnnotationItem::setFeatureForMapPosition()
210210 mFeatureId = currentFeatureId;
211211 mFeature = currentFeature;
212212
213- QString newtext = replaceText ( mHtmlSource , vectorLayer (), mFeature );
213+ QString newtext = QgsExpression::replaceExpressionText ( mHtmlSource , mFeature , vectorLayer () );
214214 mWebView ->setHtml ( newtext );
215215
216216}
@@ -227,51 +227,8 @@ void QgsHtmlAnnotationItem::updateVisibility()
227227
228228void QgsHtmlAnnotationItem::javascript ()
229229{
230- QWebFrame *frame = mWebView ->page ()->mainFrame ();
231- frame->addToJavaScriptWindowObject (" canvas" , mMapCanvas );
232- }
233-
234- QString QgsHtmlAnnotationItem::replaceText ( QString displayText, QgsVectorLayer *layer, QgsFeature &feat )
235- {
236- QString expr_action;
237-
238- int index = 0 ;
239- while ( index < displayText.size () )
240- {
241- QRegExp rx = QRegExp ( " \\ [%([^\\ ]]+)%\\ ]" );
242-
243- int pos = rx.indexIn ( displayText, index );
244- if ( pos < 0 )
245- break ;
246-
247- int start = index;
248- index = pos + rx.matchedLength ();
249-
250- QString to_replace = rx.cap ( 1 ).trimmed ();
251- QgsDebugMsg ( " Found expression: " + to_replace );
252-
253- QgsExpression exp ( to_replace );
254- if ( exp.hasParserError () )
255- {
256- QgsDebugMsg ( " Expression parser error: " + exp.parserErrorString () );
257- expr_action += displayText.mid ( start, index - start );
258- continue ;
259- }
260-
261- QVariant result = exp.evaluate ( &feat, layer->pendingFields () );
262- if ( exp.hasEvalError () )
263- {
264- QgsDebugMsg ( " Expression parser eval error: " + exp.evalErrorString () );
265- expr_action += displayText.mid ( start, index - start );
266- continue ;
267- }
268-
269- QgsDebugMsg ( " Expression result is: " + result.toString () );
270- expr_action += displayText.mid ( start, pos - start ) + result.toString ();
271- }
272-
273- expr_action += displayText.mid ( index );
274- return expr_action;
230+ QWebFrame *frame = mWebView ->page ()->mainFrame ();
231+ frame->addToJavaScriptWindowObject ( " canvas" , mMapCanvas );
275232}
276233
277234
0 commit comments