Commit 56629b43 authored by Alice Salsé's avatar Alice Salsé
Browse files

🔨 export fields selection

parent 31c8bd25
......@@ -50,6 +50,37 @@ def executeQuery(provider, query):
print(err.driverText())
return
class MulipleDialog(QDialog):
def __init__(self, title, message, items, parent=None):
super(MulipleDialog, self).__init__(parent=None)
form = QFormLayout(self)
form.addRow(QLabel(message))
self.listView = QListView(self)
form.addRow(self.listView)
model = QStandardItemModel(self.listView)
self.setWindowTitle(title)
for item in items:
# create an item with a caption
standardItem = QStandardItem(item)
standardItem.setCheckable(True)
model.appendRow(standardItem)
self.listView.setModel(model)
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self)
form.addRow(buttonBox)
buttonBox.accepted.connect(self.accept)
buttonBox.rejected.connect(self.reject)
def itemsSelected(self):
selected = []
model = self.listView.model()
i = 0
while model.item(i):
if model.item(i).checkState():
selected.append(model.item(i).text())
i += 1
return selected
class NetworkTools:
def __init__(self, iface):
......@@ -412,12 +443,14 @@ class NetworkTools:
or "start_node" not in layer.fields().names() :
dir = QFileDialog.getSaveFileName(QFileDialog(), "Définir le fichier de destination", filter="CSV (*.csv)")
if dir :
dial = MulipleDialog("Selectionner les attributs à exporter", "Liste des attributs disponibles", layer.fields().names(), self)
if dial.exec_() == QDialog.Accepted:
print(dial.itemsSelected())
l_qtablename=layer.dataProvider().uri().quotedTablename ()
column_names, records = executeQuery(layer.dataProvider()
, "select p.id, p.start_node, p.end_node \
,code_insee, diametre, length \
from utils.fnc_order_pipe('"+l_qtablename+"'::regclass, ARRAY["+','.join([str(i) for i in l_ids])+"]) p \
left outer join "+l_qtablename+" x on p.id = x.id;")
, "select p.id, p.start_node, p.end_node {2} \
from utils.fnc_order_pipe('{0}'::regclass, ARRAY[{1}]) p \
left outer join {0} x on p.id = x.id;".format(l_qtablename, ','.join([str(i) for i in l_ids]), [','+','.join([str(i) for i in dial.itemsSelected()]), ''][len(dial.itemsSelected())==0]))
with open(dir[0], 'w', newline='') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csvwriter.writerow(column_names)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment