forked from enricofer/redLayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
note_class_dialog.py
109 lines (92 loc) · 3.62 KB
/
note_class_dialog.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
idtVen - class idtVen_albero
A QGIS plugin
compilazione assistita metadati regione veneto
-------------------
begin : 2014-12-04
git sha : $Format:%H$
copyright : (C) 2014 by Enrico Ferreguti
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
#from PyQt4 import QtCore, QtGui
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from ui_note_dialog import Ui_noteDialog
from qgis.core import *
from qgis.utils import *
from qgis.gui import *
# create the dialog for zoom to point
class sketchNoteDialog(QDialog, Ui_noteDialog):
def __init__(self, iface):
QDialog.__init__(self)
# Set up the user interface from Designer.
# After setupUI you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect
self.setupUi(self)
self.hide()
self.buttonBox.accepted.connect(self.mkNote)
self.buttonBox.rejected.connect(self.cancel)
self.note = None
self.iface = iface
def setPoint(self,segment):
self.point = self.midPoint(segment)
def getNote(self):
return self.note
def getAnnotation(self):
try:
return self.textItem
except:
return None
def cancel(self):
self.note = ""
#self.hide()
pass
def mkNote(self):
self.textItem = self.mkAnnotation(self.noteText.toPlainText())
self.note = self.noteText.toPlainText()
self.noteText.clear()
def mkAnnotation(self,doc):
if self.point:
TD =QTextDocument(doc)
item = QgsTextAnnotationItem( self.iface.mapCanvas() )
item.setMapPosition(self.point)
item.setFrameSize(TD.size())
item.setDocument(TD)
item.update()
return item
else:
print "invalin insert point"
return None
def midPoint(self,s):
x = (s.vertexAt(0).x() + s.vertexAt(1).x())/2
y = (s.vertexAt(0).y() + s.vertexAt(1).y())/2
return QgsPoint(x,y)
@staticmethod
def newPoint(iface,segment,txt = None):
dialog = sketchNoteDialog(iface)
dialog.setPoint(segment)
if not txt:
print "interactive"
result = dialog.exec_()
dialog.show()
if QDialog.Accepted:
return dialog.getAnnotation()
else:
return None
else:
print "non interactive"
return dialog.mkAnnotation(txt)