Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
BMG PUBLIC RESOURCES
SIG-TOPO-BMG
Commits
56629b43
Commit
56629b43
authored
Feb 01, 2021
by
Alice Salsé
Browse files
🔨
export fields selection
parent
31c8bd25
Changes
1
Hide whitespace changes
Inline
Side-by-side
python/qgs_plugins/NetworkPlugin/mainPlugin.py
View file @
56629b43
...
...
@@ -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,17 +443,19 @@ 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
:
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;"
)
with
open
(
dir
[
0
],
'w'
,
newline
=
''
)
as
csvfile
:
csvwriter
=
csv
.
writer
(
csvfile
,
delimiter
=
';'
,
quotechar
=
'"'
,
quoting
=
csv
.
QUOTE_MINIMAL
)
csvwriter
.
writerow
(
column_names
)
for
r
in
records
:
csvwriter
.
writerow
(
r
)
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 {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
)
for
r
in
records
:
csvwriter
.
writerow
(
r
)
else
:
self
.
iface
.
messageBar
().
pushMessage
(
"La couche sélectionnée n'est pas une conduite"
,
Qgis
.
Warning
)
return
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment