-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathqnote.py
More file actions
81 lines (67 loc) · 2.8 KB
/
qnote.py
File metadata and controls
81 lines (67 loc) · 2.8 KB
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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
qNote
A QGIS plugin
Save notes in QGIS projects
-------------------
begin : 2012-03-31
copyright : (C) 2012 by Piotr Pociask
email : opengis84 (at) gmail (dot) com
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
# Import the PyQt and QGIS libraries
from builtins import object
from qgis.PyQt.QtCore import Qt
from qgis.core import QgsProject
from qgis.PyQt import uic
from os import path
from .qnote_panel import MainPanel
class qNote(object):
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
def initGui(self):
proj = QgsProject.instance()
proj.readProject.connect(self.loadData)
proj.writeProject.connect(self.saveData)
self.iface.newProjectCreated.connect(self.clearEdit)
self.dock = MainPanel()
self.iface.addDockWidget(Qt.BottomDockWidgetArea, self.dock)
self.loadData()
def unload(self):
self.iface.removeDockWidget(self.dock)
del self.dock
def run(self):
self.iface.addDockWidget(Qt.BottomDockWidgetArea, self.dock)
self.loadData()
def saveData(self):
proj = QgsProject.instance()
if self.dock.edit.toPlainText():
proj.writeEntry('qnote', 'data', self.dock.edit.toHtml())
proj.writeEntryBool('qnote', 'is_html', True)
else:
proj.removeEntry('qnote', 'data')
proj.removeEntry('qnote', 'is_html')
def loadData(self):
proj = QgsProject.instance()
text, has_note = proj.readEntry('qnote', 'data', '')
is_html = proj.readEntry('qnote', 'is_html', "false")[0]
if is_html == "true":
self.dock.edit.setHtml( text )
else:
self.dock.edit.setText( text )
self.dock.undo.setEnabled( False )
self.dock.redo.setEnabled( False )
if has_note:
self.dock.show()
def clearEdit(self):
self.dock.edit.setHtml('')