-
Notifications
You must be signed in to change notification settings - Fork 2
/
SchedaEdificio.py
620 lines (498 loc) · 21.2 KB
/
SchedaEdificio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
# -*- coding: utf-8 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
import qgis.gui
from ui.mainSchedaEdificio_ui import Ui_SchedaEdificio
from AutomagicallyUpdater import *
class SchedaEdificio(QMainWindow, MappingOne2One, Ui_SchedaEdificio):
def __init__(self, parent=None, schedaID=None):
QMainWindow.__init__(self, parent)
MappingOne2One.__init__(self, "SCHEDA_EDIFICIO")
self.setAttribute(Qt.WA_DeleteOnClose)
self.setupUi(self)
self.sectionsStacked.setCurrentIndex(0)
# carica i widget multivalore con i valori delle relative tabelle
tablesDict = {
self.LOCALIZZAZIONE_EDIFICIOIDLOCALIZZ.ZZ_PROPRIETAID: AutomagicallyUpdater.ZZTable( "ZZ_PROPRIETA" )
}
self.setupTablesUpdater(tablesDict)
self.loadTables()
# mappa i widget con i campi delle tabelle
childrenList = [
self.PRINCIPALE,
self.LOCALIZZAZIONE_EDIFICIOIDLOCALIZZ,
self.LOCALIZZAZIONE_EDIFICIOIDLOCALIZZ.ZZ_PROPRIETAID,
self.LOCALIZZAZIONE_EDIFICIOIDLOCALIZZ.NUM_UNITA_IMMOBILIARI,
self.LOCALIZZAZIONE_EDIFICIOIDLOCALIZZ.PARTICELLE_CATASTALI,
self.UNITA_VOLUMETRICHE,
self.INTERVENTI,
self.STATO_UTILIZZO_EDIFICIOID,
self.CARATTERISTICHE_STRUTTURALI,
self.CARATTERISTICHE_ARCHITETTONICHE_EDIFICIOID,
self.FOTO
]
self.setupValuesUpdater(childrenList)
self.connect(self.sectionsList, SIGNAL("itemSelectionChanged()"), self.currentSectionChanged)
self.connect(self.PRINCIPALE.printBtn, SIGNAL("clicked()"), self.stampaScheda)
# aggiorna il titolo della scheda con l'indirizzo del primo tab indirizzi
indirizzo = self.LOCALIZZAZIONE_EDIFICIOIDLOCALIZZ.LOCALIZZAZIONE_EDIFICIO_INDIRIZZO_VIA.firstTab
self.connect(indirizzo, SIGNAL("indirizzoChanged"), self.aggiornaTitolo)
# carica i dati della scheda
self.setupLoader( schedaID )
self.aggiornaTitolo()
def currentSectionChanged(self):
if self.sectionsList.currentRow() < 0:
return
self.sectionsStacked.setCurrentIndex(self.sectionsList.currentRow())
def aggiornaTitolo(self):
indirizzo = self.LOCALIZZAZIONE_EDIFICIOIDLOCALIZZ.LOCALIZZAZIONE_EDIFICIO_INDIRIZZO_VIA.firstTab
comune = indirizzo.ZZ_COMUNIISTATCOM.currentText()
provincia = indirizzo.ZZ_PROVINCEISTATPROV.currentText()
via = indirizzo.VIA.currentText()
civico = indirizzo.NUMERI_CIVICI.rowToString()
from WdgLocalizzazioneIndirizzi import WdgLocalizzazioneIndirizzi
indirizzo_non_valido = WdgLocalizzazioneIndirizzi.INDIRIZZO_NON_VALIDO
indirizzo_non_inserito = WdgLocalizzazioneIndirizzi.INDIRIZZO_NON_INSERITO
if comune != '':
via = u"%s, %s" % (via, civico) if via != '' and civico != '' else indirizzo_non_inserito
titolo = u"%s - %s (%s)" % (via, comune, provincia)
else:
titolo = indirizzo_non_valido
self.setWindowTitle( titolo )
def getTitoloStampa(self):
indirizzo = self.LOCALIZZAZIONE_EDIFICIOIDLOCALIZZ.LOCALIZZAZIONE_EDIFICIO_INDIRIZZO_VIA.firstTab
istatcom = self.getValue(indirizzo.ZZ_COMUNIISTATCOM)
via = indirizzo.VIA.currentText()
civico = indirizzo.NUMERI_CIVICI.rowToString()
if istatcom != None and via != '' and civico != '':
return u"%s - %s - %s" % ( istatcom, via, civico )
return self._ID
def stampaScheda(self, preview=True):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.PRINCIPALE.printBtn.setEnabled( False )
self._previewOnPrinting = preview
self._printMode, _ = AutomagicallyUpdater.printBehavior()
if self._printMode in (QPrinter.PdfFormat, QPrinter.NativeFormat):
# create a webview to load the HTML
from PyQt4.QtWebKit import QWebView
self._webView = QWebView(self)
self._webView.setVisible(False)
QObject.connect(self._webView, SIGNAL("loadFinished(bool)"), self.webViewLoadFinished)
# generate the HTML and load it into the webview
html = self.toHtml()
self._webView.setHtml( html )
else: # print to HTML files
outputDir = AutomagicallyUpdater._getLastUsedDir( 'pdf' )
if preview:
QApplication.restoreOverrideCursor()
outputDir = QFileDialog.getExistingDirectory(self, "Salvataggio scheda", outputDir, QFileDialog.ShowDirsOnly)
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
if outputDir == "":
return self.onPrintFinished( True )
AutomagicallyUpdater._setLastUsedDir( 'pdf', outputDir )
# create the dir that will contain the html file within the output dir
outputDir = QDir( outputDir )
outputPath = outputDir.filePath( self._ID )
if not outputDir.exists( self._ID ) and not outputDir.mkdir( self._ID ):
QMessageBox.warning( self, "RT Omero", u"Impossibile creare il percorso '%s'" % outputPath )
return self.onPrintFinished( False )
# generate the HTML using outputPath as directory for the images/resources
html = self.toHtml( outputPath )
htmlFile = unicode( QDir( outputPath ).filePath( "index.html" ) )
with open( htmlFile, 'w' ) as fout:
fout.write( html.encode('utf8') )
self.onPrintFinished(True)
#if preview:
# QDesktopServices.openUrl( QUrl.fromLocalFile( htmlFile ) )
def webViewLoadFinished(self, ok):
if not ok:
return self.onPrintFinished( False )
# get the instance of the printer
from ManagerWindow import ManagerWindow
printer = ManagerWindow.instance.getPrinter()
printer.setDocName( self.getTitoloStampa() )
if self._printMode == QPrinter.PdfFormat:
# set the output format and filename
lastDir = AutomagicallyUpdater._getLastUsedDir( 'pdf' )
outFn = QDir( lastDir ).filePath( u"%s.pdf" % self.getTitoloStampa() )
printer.setOutputFileName( outFn )
if self._previewOnPrinting:
printDlg = QPrintPreviewDialog(printer, self)
QObject.connect(printDlg, SIGNAL("paintRequested(QPrinter *)"), self._webView.print_)
QApplication.restoreOverrideCursor()
ret = printDlg.exec_()
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
if ret:
if self._printMode == QPrinter.PdfFormat:
AutomagicallyUpdater._setLastUsedDir( 'pdf', printer.outputFileName() )
printDlg.deleteLater()
del printDlg
elif self._printMode == QPrinter.NativeFormat:
printDlg = QPrintDialog(printer, self)
QApplication.restoreOverrideCursor()
ret = printDlg.exec_()
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
if ret:
self._webView.print_(printer)
else: # print to PDF without asking to the user
self._webView.print_(printer)
return self.onPrintFinished( ok )
def onPrintFinished(self, ok):
# remove temporary files, i.e. images/resources used in the HTML
from Utils import TemporaryFile
TemporaryFile.delAllFiles( TemporaryFile.KEY_SCHEDAEDIFICIO2HTML )
if self._printMode in (QPrinter.PdfFormat, QPrinter.NativeFormat):
self._webView.deleteLater()
del self._webView
self.PRINCIPALE.printBtn.setEnabled( True )
QApplication.restoreOverrideCursor()
self.emit( SIGNAL("printFinished"), ok, self._ID )
return ok
def creaStralcioCartografico( self, size, scale, ext="png", factor=1, outpath=None):
from ManagerWindow import ManagerWindow
def renderScaleLabel(painter, scale, factor=1):
text = "1:%s" % (scale*factor)
fontSize = 10*factor
font = QFont( "helvetica", fontSize )
painter.setFont( font )
fontMetrics = QFontMetrics( font )
margin = 20*factor
bufferSize = 1
backColor = Qt.white
foreColor = Qt.black
# first the buffer
painter.setPen( backColor )
fontWidth = fontMetrics.width( text )
fontHeight = fontMetrics.height()
for i in range(-bufferSize, bufferSize+1):
for j in range(-bufferSize, bufferSize+1):
painter.drawText( i + margin, j + margin, text )
# then the text itself
painter.setPen( foreColor );
painter.drawText( margin, margin, text )
def createStralcioUsingCanvas(filename, size, scale, ext="png", factor=1):
# get the reference to the main canvas and its renderer
mainCanvas = ManagerWindow.instance.iface.mapCanvas()
mainRenderer = mainCanvas.mapRenderer()
# create a new map canvas and setup it
canvas = qgis.gui.QgsMapCanvas( ManagerWindow.instance.iface.mainWindow() )
canvas.setCanvasColor( Qt.white )
canvas.setFixedSize( size.width(), size.height() )
canvas.setRenderFlag( False )
settings = QSettings()
canvas.enableAntiAliasing( settings.value( "/qgis/enable_anti_aliasing", False, type=bool ) )
canvas.useImageToRender( settings.value( "/qgis/use_qimage_to_render", False, type=bool ) )
canvas.mapRenderer().setDestinationCrs( mainRenderer.destinationCrs() )
canvas.mapRenderer().setMapUnits( mainRenderer.mapUnits() )
try:
canvasLayers = []
# add WMS layers
for order, rlid in sorted( ManagerWindow.RLID_WMS.iteritems() ):
layer = QgsMapLayerRegistry.instance().mapLayer( rlid )
if layer != None and ManagerWindow.instance.iface.legendInterface().isLayerVisible( layer ):
cl = qgis.gui.QgsMapCanvasLayer(layer)
canvasLayers.insert(0, cl)
# add other layers
layers = [ManagerWindow.VLID_GEOM_ORIG, ManagerWindow.VLID_GEOM_MODIF, ManagerWindow.VLID_FOTO]
for vlid in layers:
layer = QgsMapLayerRegistry.instance().mapLayer( vlid )
if layer != None:
layer.removeSelection()
cl = qgis.gui.QgsMapCanvasLayer(layer)
canvasLayers.insert(0, cl)
canvas.setLayerSet( canvasLayers )
# XXX: why? it's needed to update the extent of the other canvas
canvas.show()
mainCanvas.setRenderFlag( True )
# select the geometries
layerModif = QgsMapLayerRegistry.instance().mapLayer( ManagerWindow.VLID_GEOM_MODIF )
if layerModif != None:
query = AutomagicallyUpdater.Query( "SELECT gmod.ROWID FROM GEOMETRIE_RILEVATE_NUOVE_O_MODIFICATE AS gmod JOIN SCHEDA_UNITA_VOLUMETRICA AS suv ON gmod.ID_UV_NEW = suv.GEOMETRIE_RILEVATE_NUOVE_O_MODIFICATEID_UV_NEW WHERE SCHEDA_EDIFICIOID = ?", [ self._ID ] ).getQuery()
if query.exec_():
selIds = []
while query.next():
selIds.append( query.value(0) )
layerModif.setSelectedFeatures( selIds )
canvas.zoomToSelected( layerModif )
# zoom to scale
canvas.zoomScale( scale )
# save the map to a file
eventLoopHandler = [ QEventLoop(self) ]
def savePainter(p, scale, evlHandler):
renderScaleLabel(p, scale)
evlHandler[0].quit()
evlHandler[0].deleteLater()
del evlHandler[0]
onRenderFunc = lambda x: savePainter(x, scale, eventLoopHandler)
QObject.connect(canvas, SIGNAL("renderComplete(QPainter *)"), onRenderFunc)
canvas.setRenderFlag( True )
if len(eventLoopHandler) > 0:
eventLoopHandler[0].exec_( QEventLoop.ExcludeUserInputEvents )
QObject.disconnect(canvas, SIGNAL("renderComplete(QPainter *)"), onRenderFunc)
canvas.saveAsImage( filename, None, ext.upper() )
extent = canvas.extent()
# remove the wordfile create by canvas.saveAsImage()
wordfile = QFile( filename[:-4] + filename[-4:].upper() + "w" )
if wordfile.exists():
wordfile.remove()
finally:
canvas.hide()
canvas.deleteLater()
del canvas
return filename, extent
def createStralcioUsingRenderer(filename, size, scale, ext="png", factor=1):
# create the output image and pre-fill it
image = QPixmap( size )
image.fill( QColor(255, 255, 255, 255) )
# get the reference to the main canvas and its renderer
mainCanvas = ManagerWindow.instance.iface.mapCanvas()
mainRenderer = mainCanvas.mapRenderer()
# create a new renderer and setup it
mapRenderer = qgis.core.QgsMapRenderer()
mapRenderer.setOutputSize( size, image.logicalDpiX() )
mapRenderer.setDestinationCrs( mainRenderer.destinationCrs() )
mapRenderer.setMapUnits( mainRenderer.mapUnits() )
mapRenderer.setProjectionsEnabled( mainRenderer.hasCrsTransformEnabled() )
# add layers to renderer layer set
layerIds = []
# add WMS layers
for order, rlid in sorted( ManagerWindow.RLID_WMS.iteritems() ):
layer = QgsMapLayerRegistry.instance().mapLayer( rlid )
if layer != None and ManagerWindow.instance.iface.legendInterface().isLayerVisible( layer ):
lid = layer.id() if hasattr(layer, 'id') else layer.getLayerID() # old API compatibility
layerIds.insert(0, lid)
# add other layers
layers = [ManagerWindow.VLID_GEOM_ORIG, ManagerWindow.VLID_GEOM_MODIF, ManagerWindow.VLID_FOTO]
for vlid in layers:
layer = QgsMapLayerRegistry.instance().mapLayer( vlid )
if layer != None:
layer.removeSelection()
lid = layer.id() if hasattr(layer, 'id') else layer.getLayerID() # old API compatibility
layerIds.insert(0, lid)
mapRenderer.setLayerSet( layerIds )
# select the geometries
layerModif = QgsMapLayerRegistry.instance().mapLayer( ManagerWindow.VLID_GEOM_MODIF )
if layerModif != None:
query = AutomagicallyUpdater.Query( "SELECT gmod.ROWID FROM GEOMETRIE_RILEVATE_NUOVE_O_MODIFICATE AS gmod JOIN SCHEDA_UNITA_VOLUMETRICA AS suv ON gmod.ID_UV_NEW = suv.GEOMETRIE_RILEVATE_NUOVE_O_MODIFICATEID_UV_NEW WHERE SCHEDA_EDIFICIOID = ?", [ self._ID ] ).getQuery()
if query.exec_():
selIds = []
while query.next():
selIds.append( query.value(0) )
layerModif.setSelectedFeatures( selIds )
mapRenderer.setExtent( layerModif.boundingBoxOfSelected() )
# zoom at the scale
extent = mapRenderer.extent()
extent.scale( float(scale) / mapRenderer.scale() )
mapRenderer.setExtent( extent )
# render now!
painter = QPainter()
painter.begin( image )
#settings = QSettings()
#antiAliasingEnabled = settings.value( "/qgis/enable_anti_aliasing", False ).toBool()
#painter.setRenderHints( QPainter.RenderHints() | (QPainter.Antialiasing if antiAliasingEnabled else 0) )
mapRenderer.render( painter )
renderScaleLabel(painter, scale)
painter.end()
del painter
mapRenderer.deleteLater()
del mapRenderer
# save the image to a file
image.save( filename, ext.upper() )
del image
return filename, extent
if outpath is None:
# get a new temp file
from Utils import TemporaryFile
tmp = TemporaryFile.getNewFile( TemporaryFile.KEY_SCHEDAEDIFICIO2HTML, ext )
if not tmp.open():
TemporaryFile.delFile( TemporaryFile.KEY_SCHEDAEDIFICIO2HTML, ext )
return "", None
filename = unicode( tmp.fileName() )
tmp.close()
else:
filename = u"%s/stralcio.%s" % (outpath, ext)
# override the canvas render flag
mainCanvas = ManagerWindow.instance.iface.mapCanvas()
prevRenderFlag = mainCanvas.renderFlag()
mainCanvas.setRenderFlag( False )
# override the selection color
#prevColor = QgsRenderer.selectionColor()
#newColor = QColor( Qt.yellow )
#newColor.setAlpha(127)
#QgsRenderer.setSelectionColor( newColor )
prevColor = qgis.core.QgsMapRenderer().rendererContext().selectionColor()
newColor = QColor( Qt.yellow )
newColor.setAlpha(127)
qgis.core.QgsMapRenderer().rendererContext().setSelectionColor( newColor )
# set layers visible
legend = ManagerWindow.instance.iface.legendInterface()
layerOrig = QgsMapLayerRegistry.instance().mapLayer( ManagerWindow.VLID_GEOM_ORIG )
if layerOrig != None:
prevOrigState = ManagerWindow.instance.iface.legendInterface().isLayerVisible( layerOrig )
ManagerWindow.instance.iface.legendInterface().setLayerVisible( layerOrig, True )
layerModif = QgsMapLayerRegistry.instance().mapLayer( ManagerWindow.VLID_GEOM_MODIF )
if layerModif != None:
prevModifState = ManagerWindow.instance.iface.legendInterface().isLayerVisible( layerModif )
prevSelection = layerModif.selectedFeaturesIds()
ManagerWindow.instance.iface.legendInterface().setLayerVisible( layerModif, True )
try:
if True:
# XXX: why? the output image seems to be generated at a wrong scale using a new renderer
filename, extent = createStralcioUsingCanvas(filename, size, scale, ext, factor)
else:
filename, extent = createStralcioUsingRenderer(filename, size, scale, ext, factor)
finally:
# restore the original layers' state and selection
if layerOrig != None:
legend.setLayerVisible( layerOrig, prevOrigState )
if layerModif != None:
legend.setLayerVisible( layerModif, prevModifState )
layerModif.setSelectedFeatures( prevSelection )
# restore the canvas original state and selection color
#QgsRenderer.setSelectionColor( prevColor )
qgis.core.QgsMapRenderer().rendererContext().setSelectionColor( prevColor )
mainCanvas.setRenderFlag( prevRenderFlag )
return filename, extent
def setMinimized(self, minimize=True):
if minimize:
self.setWindowState( self.windowState() | Qt.WindowMinimized )
else:
self.setWindowState( self.windowState() & ~Qt.WindowMinimized )
self.raise_()
def closeEvent(self, event):
# rimuovi i file temporanei collegati alla scheda
from Utils import TemporaryFile
TemporaryFile.delAllFiles( TemporaryFile.KEY_SCHEDAEDIFICIO )
try:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
ConnectionManager.startTransaction()
# effettua il salvataggio della scheda
self.save()
except ConnectionManager.AbortedException, e:
QMessageBox.critical(self, "Errore", Porting.str(e))
return
finally:
ConnectionManager.endTransaction()
QApplication.restoreOverrideCursor()
self.onClosing()
self.emit( SIGNAL("closed()") )
# carica il layer delle foto
from ManagerWindow import ManagerWindow
ManagerWindow.instance.aggiornaLayerFoto()
def toHtml(self, prefix=None):
import os.path
currentPath = os.path.dirname(__file__)
# path to css file
css_orig = os.path.join( currentPath, "docs", "default.css" )
if prefix is None:
css = css_orig
else:
# copy the css file to the output folder
css = QDir( prefix ).filePath( "default.css" )
if not QFile.exists( css ) and not QFile.copy( css_orig, css ):
css = css_orig
css = QUrl.fromLocalFile(css).toString()
# path to the omero banner
banner_orig = os.path.join( currentPath, "docs", "banner_omero.gif" )
if prefix is None:
banner = banner_orig
else:
# copy the omero banner file to the output folder
banner = QDir( prefix ).filePath( "banner_omero.gif" )
if not QFile.exists( banner ) and not QFile.copy( banner_orig, banner ):
banner = banner_orig
banner = QUrl.fromLocalFile(banner).toString()
# path to the logo
if prefix is None:
logoDir = QDir( AutomagicallyUpdater._getPathToDb() )
else:
logoDir = QDir( prefix )
logo = logoDir.filePath( "omero_stampa_logo.jpg" )
if not QFile.exists( logo ):
logo_orig = os.path.join( currentPath, "docs", "omero_stampa_logo.jpg" )
if not QFile.copy( logo_orig, logo ):
logo = logo_orig
logo = QUrl.fromLocalFile(logo).toString()
comune = AutomagicallyUpdater.Query( "SELECT NOME FROM ZZ_COMUNI WHERE ISTATCOM = ?", [AutomagicallyUpdater._getIDComune()] ).getFirstResult()
indirizzo = self.LOCALIZZAZIONE_EDIFICIOIDLOCALIZZ.LOCALIZZAZIONE_EDIFICIO_INDIRIZZO_VIA.firstTab
via = indirizzo.VIA.currentText()
civico = indirizzo.NUMERI_CIVICI.rowToString()
if via != '' and civico != '':
via = u"%s, %s" % (via, civico)
else:
via = ''
nome_edificio = self.getValue( self.PRINCIPALE.NOME_EDIFICIO )
data = QDate.currentDate().toString( "dd/MM/yyyy" )
return u"""
<html>
<head>
<title>Scheda di rilevamento</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<link media="all" href="%s" type="text/css" rel="stylesheet">
</head>
<body>
<div id="header">
<div id="omero">
<img src="%s" alt="Omero">
</div>
<div id="logo">
<img src="%s" alt="Logo">
</div>
<p id="comune">Comune di %s</p>
<p id="titolo">Scheda edificio</p>
<div id="edificio">
<p id="nomeedificio">%s</p>
<p id="via">%s</p>
</div>
<p id="idscheda">Scheda: %s</p>
<p id="data">scheda stampata il %s</p>
<p id="info">(QuantumGIS - Omero - Regione Toscana - S.I.T.A.)</p>
</div>
%s %s %s %s %s %s %s
<div id="sez8" class="block">
<p class="section">SEZIONE A8 - FOTOGRAFIE</p>
%s %s
</div>
</body>
</html>
""" % (css, banner, logo, comune, nome_edificio if nome_edificio != None else '', via, self._ID, data, self.PRINCIPALE.toHtml(), self.LOCALIZZAZIONE_EDIFICIOIDLOCALIZZ.toHtml(), self.UNITA_VOLUMETRICHE.toHtml(), self.INTERVENTI.toHtml(), self.STATO_UTILIZZO_EDIFICIOID.toHtml(), self.CARATTERISTICHE_STRUTTURALI.toHtml(), self.CARATTERISTICHE_ARCHITETTONICHE_EDIFICIOID.toHtml(), self.stralcioToHtml(prefix), self.FOTO.toHtml(prefix))
def stralcioToHtml(self, prefix=None):
xmin = ymin = xmax = ymax = ""
# dimensioni e scala originali
realwidth = 700
realscale = 1000
# TRICK! aumenta la risoluzione dell'immagine
# riduce la scala e ingrandisce le dimensioni dell'immagine in output
factor = 1
# size and scale will be passed to the map renderer
renderwidth = realwidth * factor
renderscale = realscale / factor
# create the image
filename, extent = self.creaStralcioCartografico( QSize(renderwidth, renderwidth), renderscale, "png", factor, outpath=prefix )
filename = QUrl.fromLocalFile(filename).toString()
if extent != None:
xmin = extent.xMinimum()
ymin = extent.yMinimum()
xmax = extent.xMaximum()
ymax = extent.yMaximum()
# size of the image displayed in the HTML page
printwidth = realwidth*1.25
return u"""
<table class="border">
<tr>
<td colspan="4">Stralcio cartografico dell'edificio</td>
</tr>
<tr>
<td colspan="4" class="mapContainer"><img class="map border" style="width: %spx; height: %spx;" src="%s" alt="stralcio cartografico"></td>
</tr>
<tr>
<td>xmin</td><td class="value">%s</td>
<td>ymin</td><td class="value">%s</td>
</tr>
<tr>
<td>xmax</td><td class="value">%s</td>
<td>ymax</td><td class="value">%s</td>
</tr>
</table>
""" % (printwidth, printwidth, filename, xmin, ymin, xmax, ymax)