Skip to content

Commit

Permalink
Merge pull request SistemesInformacioTerritorial#522 from SistemesInf…
Browse files Browse the repository at this point in the history
…ormacioTerritorial/Arreglar-càrrega-gpkg

Arreglar càrrega gpkg
  • Loading branch information
oriolmarti97 authored Apr 16, 2020
2 parents fcfbbef + 83e6e77 commit e35dbec
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
54 changes: 54 additions & 0 deletions moduls/QvCarregadorGPKG.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from qgis.PyQt.QtWidgets import QDialog, QWidget, QVBoxLayout, QHBoxLayout, QCheckBox, QPushButton, QLabel, QFrame, QScrollArea
from qgis.PyQt.QtCore import Qt
from qgis.core import QgsVectorLayer

import os

class QvCarregadorGPKG(QDialog):
def __init__(self, parent=None):
super().__init__(parent,Qt.WindowSystemMenuHint | Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
self._layoutGran = QVBoxLayout()
lblExplicacio=QLabel('Trieu quines capes voleu carregar sobre el mapa')
self._layoutGran.addWidget(lblExplicacio)
fr=QFrame()
sc=QScrollArea()
sc.setWidget(fr)
sc.setWidgetResizable(True)
fr.setFrameShape(QFrame.Box)
fr.setStyleSheet('background: white')
self._layout = QVBoxLayout()
fr.setLayout(self._layout)
self._layoutGran.addWidget(sc)
bAcceptar = QPushButton('Acceptar')
bAcceptar.clicked.connect(self.accept)
bCancelar = QPushButton('Cancelar')
bCancelar.clicked.connect(self.reject)
layBotons = QHBoxLayout()
layBotons.addStretch()
layBotons.addWidget(bAcceptar)
layBotons.addWidget(bCancelar)
self._layoutGran.addLayout(layBotons)
self.setLayout(self._layoutGran)
self.setWindowTitle('Tria de les subcapes a carregar')
def seleccionaTots(self,check):
for x in self._combos:
x.setChecked(check)
def setCapes(self,capes):
self._combos=[QCheckBox(x) for x in capes]
cbTots = QCheckBox('Seleccionar totes les capes')
cbTots.toggled.connect(self.seleccionaTots)
self._layout.addWidget(cbTots)
for x in self._combos:
self._layout.addWidget(x)
def exec_(self):
if super().exec_() == QDialog.Accepted:
return [x.text() for x in filter(lambda x: x.isChecked(),self._combos)]
else:
return []
@classmethod
def triaCapes(cls,nfile, parent=None):
layer = QgsVectorLayer(nfile, os.path.basename(nfile), "ogr")
subLayers = [x.split('!!::!!')[1] for x in layer.dataProvider().subLayers()]
dial=cls(parent)
dial.setCapes(subLayers)
return dial.exec_()
11 changes: 10 additions & 1 deletion qVista.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from moduls.QvSabiesQue import QvSabiesQue
from moduls.QvMemoria import QvMemoria
from moduls.QvBafarada import QvBafarada
from moduls.QvCarregadorGPKG import QvCarregadorGPKG
from moduls.QvVisualitzacioCapa import QvVisualitzacioCapa
# import re
import csv
Expand Down Expand Up @@ -261,11 +262,19 @@ def obrirArxiu(self, llista):
# self.obrirProjecte(nfile)
elif fext == '.qlr':
afegirQlr(nfile)
elif fext in ('.shp', '.gpkg'):
elif fext == '.shp':
layer = QgsVectorLayer(nfile, os.path.basename(nfile), "ogr")
if layer.isValid():
self.project.addMapLayer(layer)
self.setDirtyBit()
elif fext == '.gpkg':
nomsCapes = QvCarregadorGPKG.triaCapes(nfile,self)
uris = map(lambda x: f'{nfile}|layername={x}', nomsCapes)
aux = zip(nomsCapes, uris)
capes = [QgsVectorLayer(y,x,'ogr') for (x,y) in aux]

self.project.addMapLayers(capes)
self.setDirtyBit()
elif fext == '.csv':
carregarLayerCSV(nfile)

Expand Down

0 comments on commit e35dbec

Please sign in to comment.