-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialogSelectFaune.py
More file actions
187 lines (131 loc) · 7.66 KB
/
DialogSelectFaune.py
File metadata and controls
187 lines (131 loc) · 7.66 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
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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
DialogSelectFaune
A QGIS plugin
export
-------------------
begin : 2016-04-19
git sha : $Format:%H$
copyright : (C) 2016 by Loic Martel
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
from PyQt4 import QtGui, uic
from PyQt4.QtCore import *
from PyQt4.Qt import QTableWidget, QAbstractItemView, QTableWidgetItem, QMessageBox
from PyQt4.QtGui import QIcon
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'ModuleExport_dialog_faune.ui'))
class DialogSelectFaune(QtGui.QDialog, FORM_CLASS):
def __init__(self, parent=None):
"""Constructor."""
super(DialogSelectFaune, 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.setWindowTitle("Selection de la faune.")
#définir les titres de mes colonnes
header_labels = ["espece_id", "taxons", "nomcommun", 'class', 'ordre', "cd_nom", "cd_ref", "rarete", "menace" ]
self.matablewidget.setHorizontalHeaderLabels(header_labels)
#On cache la colonne d espece
for i in range(3,9):
self.matablewidget.setColumnHidden(i, True)
#La selection sur la vue wref ne pourra se faire que par lignes
self.matablewidget.setSelectionBehavior(QAbstractItemView.SelectRows)
#Notre table ne doit pas être éditable
self.matablewidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
header_labels = ["espece_id", "taxon", "nomcommun"]
self.tab_faune_selected.setHorizontalHeaderLabels(header_labels)
#On cache la colonne d espece
self.tab_faune_selected.setColumnHidden(2, True)
#La selection sur la vue wref ne pourra se faire que par lignes
self.tab_faune_selected.setSelectionBehavior(QAbstractItemView.SelectRows)
#Notre table ne doit pas être éditable
self.tab_faune_selected.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.plugin_dir = os.path.dirname(__file__)
self.btn_ajoutfaune.setIcon(QIcon(self.plugin_dir+"/btn_add.png"))
self.btn_rmfaune.setIcon(QIcon(self.plugin_dir+"/btn_remove.png"))
self.vider_faune.setIcon(QIcon(self.plugin_dir+"/btn_suppr.png"))
self.unselect.setIcon(QIcon(self.plugin_dir+"/unselect.png"))
self.btn_visible.setIcon(QIcon(self.plugin_dir+"/visible.png"))
self.btn_invisible.setIcon(QIcon(self.plugin_dir+"/invisible.png"))
self.searchButton.setStyleSheet('QPushButton {background-color: #CCF390;font-weight: bold}')
def visibilite(self, bool = False):
if bool == False:
for i in range(3,9):
self.matablewidget.setColumnHidden(i, True)
self.tab_faune_selected.setColumnHidden(2, True)
if bool == True:
for i in range(3,9):
self.matablewidget.setColumnHidden(i, False)
self.tab_faune_selected.setColumnHidden(2, False)
#Méthode d'ajout d'éspèce dans les colonnes de selection
#On supprime les doublons également
def transvasajout__espece_faune(self):
#CREATION D UNE LISTE ANTI DOUBLON
#Variables qui contiennt les elements des cellules dans les rows selectionnés
#Quadriliste de non-doublons
compterow = self.tab_faune_selected.rowCount()
old_maliste0=[]
for i in xrange(0,compterow):
old_maliste0.append(self.tab_faune_selected.item(i,0).text())
#MON TRANSVASAGE
#Controle
if self.matablewidget.selectionModel().hasSelection() != True:
QMessageBox.information(self,'Information',u'Veuillez selectionner des entites a transferer.')
else:
#Variables qui contiennt les elements des cellules dans les rows selectionnés
mesrows0 = self.matablewidget.selectionModel().selectedRows(0)
mesrows1 = self.matablewidget.selectionModel().selectedRows(1)
mesrows2 = self.matablewidget.selectionModel().selectedRows(2)
#Quadriliste
maliste0 = []
for i in mesrows0:
if i.data() not in old_maliste0:
maliste0.append(i.data())
maliste1 = []
for i in mesrows1:
maliste1.append(i.data())
maliste2 = []
for i in mesrows2:
maliste2.append(i.data())
#On réparti les listes dans des QTableWidget!
for i in xrange(0, len(maliste0)):
self.tab_faune_selected.insertRow(self.tab_faune_selected.rowCount())
self.tab_faune_selected.setItem(self.tab_faune_selected.rowCount()-1,0 ,QTableWidgetItem(self.tr(maliste0[i])))
self.tab_faune_selected.setItem(self.tab_faune_selected.rowCount()-1,1 ,QTableWidgetItem(maliste1[i]))
self.tab_faune_selected.setItem(self.tab_faune_selected.rowCount()-1,2 ,QTableWidgetItem(self.tr(maliste2[i])))
#Méthode de retrait d'éspèce dans la colonne de selection
def transvasretrait_espece_faune(self):
rows = self.tab_faune_selected.selectionModel().selectedRows()
#liste inversée pour régler les pb d'index.
rows = sorted(rows, reverse = True)
for r in rows:
self.tab_faune_selected.removeRow(r.row())
#SLOT pour déselectionner tout les éléments des 2 tableaux.
def clear(self):
#deselection tableau
self.matablewidget.clearSelection()
self.tab_faune_selected.clearSelection()
def peupler_table_from_base(self,tableurcible, iter):
tableurcible.insertRow(tableurcible.rowCount())
for i in range(0,9):
tableurcible.setItem(tableurcible.rowCount()-1,i ,QTableWidgetItem(unicode(iter[i])))
def peupler_table_from_base_selected(self,tableurcible, iter):
tableurcible.insertRow(tableurcible.rowCount())
tableurcible.setItem(tableurcible.rowCount()-1,0 ,QTableWidgetItem(unicode(iter[0])))
tableurcible.setItem(tableurcible.rowCount()-1,1 ,QTableWidgetItem((iter[1])))
tableurcible.setItem(tableurcible.rowCount()-1,2 ,QTableWidgetItem((iter[2])))