-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmapillary_form.py
103 lines (89 loc) · 4.39 KB
/
mapillary_form.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
go2mapillaryDockWidget
A QGIS plugin
mapillary filter
-------------------
begin : 2016-01-21
git sha : $Format:%H$
copyright : (C) 2016 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. *
* *
***************************************************************************/
"""
import os
import sys
import datetime
import json
from PyQt5 import QtWidgets, uic
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QTableWidgetItem
from PyQt5.QtGui import QColor
from qgis.core import QgsPointXY, QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsProject, Qgis, QgsExpressionContextUtils
from qgis.gui import QgsFileWidget
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'mapillary_form_dialog_base.ui'))
class mapillaryForm(QtWidgets.QDialog, FORM_CLASS):
closingPlugin = pyqtSignal()
def __init__(self,parentInstance, parent=None):
"""Constructor."""
super(mapillaryForm, self).__init__(parent)
# 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.parentInstance = parentInstance
self.iface = parentInstance.iface
self.setWindowTitle("go2mapillary sample form")
self.buttonBox.accepted.connect(self.applyForm)
self.deleteButton.clicked.connect(self.deleteFeatureAction)
def open(self,feat):
self.comboBox.clear()
for cat,color in self.parentInstance.sample_settings.settings['categories'].items():
self.comboBox.addItem(cat,color)
self.keyEdit.setText(str(feat['key']))
self.typeEdit.setText(str(feat['type']))
if feat['cat']:
cat_idx = self.comboBox.findText(str(feat['cat']))
else:
cat_idx = 0
self.comboBox.setCurrentIndex(cat_idx)
if feat['note']:
self.noteEdit.setPlainText(str(feat['note']))
else:
self.noteEdit.setPlainText("")
self.currentFeat = feat
super(mapillaryForm, self).open()
def applyForm(self):
cat_idx = self.parentInstance.sample_cursor.samplesLayer.fields().indexFromName('cat')
note_idx = self.parentInstance.sample_cursor.samplesLayer.fields().indexFromName('note')
color_idx = self.parentInstance.sample_cursor.samplesLayer.fields().indexFromName('color')
if self.currentFeat['cat']:
color = self.parentInstance.sample_settings.settings['categories'][str(self.currentFeat['cat'])]
else:
color = '#ffffff'
attrs = {
cat_idx: self.comboBox.currentText(),
note_idx: self.noteEdit.toPlainText()[:99],
color_idx:color
}
self.parentInstance.sample_cursor.samplesLayer.dataProvider().changeAttributeValues({self.currentFeat.id(): attrs})
self.parentInstance.viewer.change_sample(self.currentFeat.id())
def deleteFeatureAction(self):
key = self.currentFeat['key']
id = self.currentFeat['id']
type = self.currentFeat['type']
self.parentInstance.sample_cursor.samplesLayer.dataProvider().deleteFeatures([self.currentFeat.id()])
self.parentInstance.sample_cursor.samplesLayer.triggerRepaint()
self.parentInstance.viewer.removeSample(type,key,id)
self.close()