/
shiftpoints.py
148 lines (123 loc) · 6.72 KB
/
shiftpoints.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
# -*- coding: utf-8 -*-
#******************************************************************************
#
# ShiftPoints
# ---------------------------------------------------------
# Moves overlapped points with same coordinates in a circle around the
# original position.
#
# Copyright (C) 2011-2013 Alexander Bruy (alexander.bruy@gmail.com)
#
# This source 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 3 of the License, or (at your option)
# any later version.
#
# This code is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# A copy of the GNU General Public License is available on the World Wide Web
# at <http://www.gnu.org/licenses/>. You can also obtain it by writing
# to the Free Software Foundation, 51 Franklin Street, Suite 500 Boston,
# MA 02110-1335 USA.
#
#******************************************************************************
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from __init__ import version
import shiftpointsdialog
import resources_rc
class ShiftPointsPlugin(object):
def __init__(self, iface):
self.iface = iface
self.iface = iface
try:
self.QgisVersion = unicode(QGis.QGIS_VERSION_INT)
except:
self.QgisVersion = unicode(QGis.qgisVersion)[0]
# For i18n support
userPluginPath = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/shiftpoints"
systemPluginPath = QgsApplication.prefixPath() + "/python/plugins/shiftpoints"
overrideLocale = QSettings().value("locale/overrideFlag", QVariant(False)).toBool()
if not overrideLocale:
localeFullName = QLocale.system().name()
else:
localeFullName = QSettings().value("locale/userLocale", QVariant("")).toString()
if QFileInfo(userPluginPath).exists():
translationPath = userPluginPath + "/i18n/shiftpoints_" + localeFullName + ".qm"
else:
translationPath = systemPluginPath + "/i18n/shiftpoints_" + localeFullName + ".qm"
self.localePath = translationPath
if QFileInfo(self.localePath).exists():
self.translator = QTranslator()
self.translator.load(self.localePath)
QCoreApplication.installTranslator(self.translator)
def initGui(self):
if int(self.QgisVersion) < 1:
QMessageBox.warning(self.iface.mainWindow(), "Shift Points",
QCoreApplication.translate("Shift Points", "Quantum GIS version detected: ") + unicode(self.QgisVersion) + ".xx\n" +
QCoreApplication.translate("Shift Points", "This version of Shift Points requires at least QGIS version 1.0.0\nPlugin will not be enabled."))
return None
self.actionRun = QAction(QIcon(":/icons/shiftpoints.png"), "Shift points", self.iface.mainWindow())
self.actionRun.setStatusTip(QCoreApplication.translate("ShiftPoints", "Moves overlapped points with same coordinates in a circle"))
self.actionAbout = QAction(QIcon(":/icons/about.png"), "About Shift points", self.iface.mainWindow())
QObject.connect(self.actionRun, SIGNAL("triggered()"), self.run)
QObject.connect(self.actionAbout, SIGNAL("triggered()"), self.about)
if hasattr(self.iface, "addPluginToVectorMenu"):
self.iface.addPluginToVectorMenu(QCoreApplication.translate("ShiftPoints", "Shift points"), self.actionRun)
self.iface.addPluginToVectorMenu(QCoreApplication.translate("ShiftPoints", "Shift points"), self.actionAbout)
self.iface.addVectorToolBarIcon(self.actionRun)
else:
self.iface.addPluginToMenu(QCoreApplication.translate("ShiftPoints", "Shift points"), self.actionRun)
self.iface.addPluginToMenu(QCoreApplication.translate("ShiftPoints", "Shift points"), self.actionAbout)
self.iface.addToolBarIcon(self.actionRun)
def unload(self):
if hasattr(self.iface, "addPluginToVectorMenu"):
self.iface.removePluginVectorMenu(QCoreApplication.translate("ShiftPoints", "Shift points"), self.actionRun)
self.iface.removePluginVectorMenu(QCoreApplication.translate("ShiftPoints", "Shift points"), self.actionAbout)
self.iface.removeVectorToolBarIcon(self.actionRun)
else:
self.iface.removePluginMenu(QCoreApplication.translate("ShiftPoints", "Shift points"), self.actionRun)
self.iface.removePluginMenu(QCoreApplication.translate("ShiftPoints", "Shift points"), self.actionAbout)
self.iface.removeToolBarIcon(self.actionRun)
def about(self):
dlgAbout = QDialog()
dlgAbout.setWindowTitle(QApplication.translate("ShiftPoints", "About Shift Points", "Window title"))
lines = QVBoxLayout(dlgAbout)
title = QLabel(QApplication.translate("ShiftPoints", "<b>Shift Points</b>"))
title.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
lines.addWidget(title)
ver = QLabel(QApplication.translate("ShiftPoints", "Version: %1").arg(version()))
ver.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
lines.addWidget(ver)
lines.addWidget(QLabel(QApplication.translate("ShiftPoints", "Moves overlapped points with same\ncoordinates in a circle around the\noriginal position.")))
lines.addWidget(QLabel(QApplication.translate("ShiftPoints", "<b>Developers:</b>")))
lines.addWidget(QLabel(" Alexander Bruy"))
lines.addWidget(QLabel(QApplication.translate("ShiftPoints", "<b>Homepage:</b>")))
overrideLocale = QSettings().value("locale/overrideFlag", QVariant(False)).toBool()
if not overrideLocale:
localeFullName = QLocale.system().name()
else:
localeFullName = QSettings().value("locale/userLocale", QVariant("")).toString()
localeShortName = localeFullName[0:2]
if localeShortName in ["ru", "uk"]:
link = QLabel("<a href=\"http://gis-lab.info/qa/point-displacement.html\">http://gis-lab.info/qa/point-displacement.html</a>")
else:
link = QLabel("<a href=\"http://gis-lab.info/qa/point-displacement-eng.html\">http://gis-lab.info/qa/point-displacement-eng.html</a>")
link.setOpenExternalLinks(True)
lines.addWidget(link)
lines.addWidget(QLabel(QApplication.translate("ShiftPoints", "<b>Report bugs at:</b>")))
linkBugs = QLabel("<a href=\"http://hub.qgis.org/projects/shiftpoints\">http://hub.qgis.org/projects/shiftpoints</a>")
linkBugs.setOpenExternalLinks(True)
lines.addWidget(linkBugs)
btnClose = QPushButton(QApplication.translate("ShiftPoints", "Close"))
lines.addWidget(btnClose)
QObject.connect(btnClose, SIGNAL("clicked()"), dlgAbout, SLOT("close()"))
dlgAbout.exec_()
def run(self):
dlg = shiftpointsdialog.ShiftPointsDialog(self.iface)
dlg.exec_()