def finished(self, result): if result == True: self.dlg.geoClassListModel.clear() self.dlg.comboBox.setCurrentIndex(0) self.maindlg.currentgraph = self.graph self.dlg.layercount.setText("[" + str(len(self.geoconcepts)) + "]") for geo in self.geoconcepts: item = QStandardItem() item.setData(geo, 1) item.setText(geo[geo.rfind('/') + 1:]) self.dlg.geoClassListModel.appendRow(item) #comp=QCompleter(self.dlg.layerconcepts) #comp.setCompletionMode(QCompleter.PopupCompletion) #comp.setModel(self.dlg.layerconcepts.model()) #self.dlg.layerconcepts.setCompleter(comp) self.dlg.inp_sparql2.setPlainText( self.triplestoreconf[0]["querytemplate"][0]["query"].replace( "%%concept%%", self.geoconcepts[0])) self.dlg.inp_sparql2.columnvars = {} self.maindlg.loadedfromfile = True self.maindlg.justloadingfromfile = False self.loadgraphdlg.close() else: msgBox = QMessageBox() msgBox.setText(self.exception) msgBox.exec() self.progress.close()
def initModel(self): self.model = QStandardItemModel(self.listView) state = self.checkBox.isChecked() for key in list(self.feat.keys()): if state == False or self.feat[key] > 0: item = QStandardItem() item.setText(key) item.setCheckable(True) item.setSelectable(False) self.model.appendRow(item) self.listView.setModel(self.model) self.listView.show()
def loadAdditionalItems(self, items): """Add some additional layers to this NafiTreeViewModel.""" additionalItemsGroup = QStandardItem() additionalItemsGroup.setFlags(Qt.ItemIsEnabled) additionalItemsGroup.setText("Additional layers") additionalItemsGroup.setIcon(QIcon(":/plugins/nafi/images/folder.png")) for item in items: assert isinstance(item, QStandardItem) additionalItemsGroup.appendRow(item) self.appendRow(additionalItemsGroup)
def finished(self, result): self.geoClassList.clear() if self.examplequery != None: self.sparql.setPlainText(self.examplequery) self.sparql.columnvars = {} if len(self.resultlist) > 0: first = True for concept in self.resultlist: #self.layerconcepts.addItem(concept) item = QStandardItem() item.setData(concept, 1) item.setText(concept[concept.rfind('/') + 1:]) self.geoClassList.appendRow(item) if self.triplestoreconf["name"] == "Wikidata": self.completerClassList["completerClassList"][ concept[concept.rfind('/') + 1:]] = "wd:" + concept.split("(")[1].replace( " ", "_").replace(")", "") else: self.completerClassList["completerClassList"][ concept[concept.rfind('/') + 1:]] = "<" + concept + ">" self.sparql.updateNewClassList() self.geoClassListGui.selectionModel().setCurrentIndex( self.geoClassList.index(0, 0), QItemSelectionModel.SelectCurrent) self.dlg.viewselectaction() elif len(self.viewlist) > 0: for concept in self.viewlist: #self.layerconcepts.addItem(concept) item = QStandardItem() item.setData(concept, 1) item.setText(concept[concept.rfind('/') + 1:]) self.geoClassList.appendRow(item) if self.triplestoreconf["name"] == "Wikidata": self.completerClassList["completerClassList"][ concept[concept.rfind('/') + 1:]] = "wd:" + concept.split("(")[1].replace( " ", "_").replace(")", "") else: self.completerClassList["completerClassList"][ concept[concept.rfind('/') + 1:]] = "<" + concept + ">" #item=QListWidgetItem() #item.setData(1,concept) #item.setText(concept[concept.rfind('/')+1:]) #self.geoClassList.addItem(item) self.sparql.updateNewClassList() self.geoClassListGui.selectionModel().setCurrentIndex( self.geoClassList.index(0, 0), QItemSelectionModel.SelectCurrent) self.dlg.viewselectaction() if self.amountoflabels != -1: self.layercount.setText("[" + str(self.amountoflabels) + "]")
def fill_lst_stations(self, id=None): """ Fill stations table in function of :param id: id of station :return: """ model = QStandardItemModel() model.setColumnCount(3) model.setHorizontalHeaderLabels(['Station', 'H', 'Q']) self.ui.tab_stations.setModel(model) self.ui.tab_stations.setColumnWidth(0, 140) self.ui.tab_stations.setColumnWidth(1, 10) self.ui.tab_stations.setColumnWidth(2, 10) self.ui.tab_stations.selectionModel().selectionChanged.connect( self.station_changed) sql = "SELECT DISTINCT sta.code, not cnt_h isNull as h, not cnt_q isNull as q " \ "FROM ({0}.observations as sta LEFT JOIN (SELECT code, count(*) as cnt_h FROM {0}.observations " \ "WHERE type = 'H' GROUP BY code) as sta_h ON sta.code = sta_h.code) " \ "LEFT JOIN (SELECT code, count(*) as cnt_q FROM {0}.observations " \ "WHERE type = 'Q' GROUP BY code) as sta_q ON sta.code = sta_q.code " \ "ORDER BY sta.code".format(self.mdb.SCHEMA) rows = self.mdb.run_query(sql, fetch=True) for i, row in enumerate(rows): for j, field in enumerate(row): new_itm = QStandardItem() if j == 0: new_itm.setTextAlignment(Qt.AlignLeft | Qt.AlignVCenter) txt = str(row[j]).strip() else: new_itm.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter) if row[j] is True: txt = "X" else: txt = "" new_itm.setText(txt) new_itm.setEditable(False) self.ui.tab_stations.model().setItem(i, j, new_itm) if id: for r in range(self.ui.tab_stations.model().rowCount()): if str(self.ui.tab_stations.model().item(r, 0).text()) == str( id): self.ui.tab_stations.setCurrentIndex( self.ui.tab_stations.model().item(r, 0).index()) break else: self.station_changed()
def set_values(self, data): """ Get alist and match on the Combobox items, if value exist, ensure it is checked :param data: :return: """ for val in (data.split(',')): item = QStandardItem() item.setText(val) index = self.model().indexFromItem(item) if index.data() is not None: pass else: item.setCheckState(Qt.Unchecked) self.model().appendRow(item)
def endpointselectaction(self): endpointIndex = self.dlg.comboBox.currentIndex() self.dlg.queryTemplates.clear() print("changing endpoint") conceptlist = [] self.dlg.geoClassListModel.clear() self.dlg.savedQueries.clear() if "endpoint" in self.triplestoreconf[ endpointIndex] and self.triplestoreconf[endpointIndex][ "endpoint"] in self.savedQueriesJSON: for item in self.savedQueriesJSON[ self.triplestoreconf[endpointIndex]["endpoint"]]: self.dlg.savedQueries.addItem(item["label"]) if "endpoint" in self.triplestoreconf[ endpointIndex] and self.triplestoreconf[endpointIndex][ "endpoint"] != "" and ( not "staticconcepts" in self.triplestoreconf[endpointIndex] or "staticconcepts" in self.triplestoreconf[endpointIndex] and self.triplestoreconf[endpointIndex]["staticconcepts"] == []) and "geoconceptquery" in self.triplestoreconf[ endpointIndex] and self.triplestoreconf[ endpointIndex]["geoconceptquery"] != "": item = QStandardItem() item.setText("Loading...") self.dlg.geoClassListModel.appendRow(item) if "examplequery" in self.triplestoreconf[endpointIndex]: conceptlist = self.getGeoConcepts( self.triplestoreconf[endpointIndex]["endpoint"], self.triplestoreconf[endpointIndex]["geoconceptquery"], "class", None, True, self.triplestoreconf[endpointIndex]["examplequery"]) else: conceptlist = self.getGeoConcepts( self.triplestoreconf[endpointIndex]["endpoint"], self.triplestoreconf[endpointIndex]["geoconceptquery"], "class", None, True, None) elif "staticconcepts" in self.triplestoreconf[ endpointIndex] and self.triplestoreconf[endpointIndex][ "staticconcepts"] != []: conceptlist = self.triplestoreconf[endpointIndex]["staticconcepts"] self.dlg.autocomplete["completerClassList"] = {} for concept in conceptlist: item = QStandardItem() item.setData(concept, 1) item.setText(concept[concept.rfind('/') + 1:]) self.dlg.autocomplete["completerClassList"][ concept[concept.rfind('/') + 1:]] = "<" + concept + ">" self.dlg.geoClassListModel.appendRow(item) self.dlg.inp_sparql2.updateNewClassList() if len(conceptlist) > 0: self.dlg.geoClassList.selectionModel().setCurrentIndex( self.dlg.geoClassList.model().index(0, 0), QItemSelectionModel.SelectCurrent) if "examplequery" in self.triplestoreconf[endpointIndex]: self.dlg.inp_sparql2.setPlainText( self.triplestoreconf[endpointIndex]["examplequery"]) self.dlg.inp_sparql2.columnvars = {} if "areaconcepts" in self.triplestoreconf[ endpointIndex] and self.triplestoreconf[endpointIndex][ "areaconcepts"]: conceptlist2 = self.triplestoreconf[endpointIndex]["areaconcepts"] for concept in conceptlist2: self.dlg.areaconcepts.addItem(concept["concept"]) if "querytemplate" in self.triplestoreconf[endpointIndex]: for concept in self.triplestoreconf[endpointIndex][ "querytemplate"]: self.dlg.queryTemplates.addItem(concept["label"])
def _recurse_tree(self, bl_el=None, proj_el=None, parent: QStandardItem = None): if self.business_logic is None: return if bl_el is None: bl_el = self.business_logic.find('Node') is_root = proj_el is None bl_attr = bl_el.attrib if proj_el is None: proj_el = self.project new_proj_el = proj_el if 'xpath' in bl_el.attrib: new_proj_el = xpathone_withref(self.project, proj_el, bl_el.attrib['xpath']) if new_proj_el is None: # We just ignore layers we can't find. Log them though return # The label is either explicit or it's an xpath lookup curr_label = '<unknown>' if 'label' in bl_el.attrib: curr_label = bl_el.attrib['label'] elif 'xpathlabel' in bl_el.attrib: found = new_proj_el.xpath(bl_el.attrib['xpathlabel']) curr_label = found[0].text if found is not None and len( found) > 0 else '<unknown>' curr_item = QStandardItem() curr_item.setText(curr_label) children_container = bl_el.find('Children') # If there are children then this is a branch if children_container: curr_item.setIcon( QIcon(':/plugins/qrave_toolbar/BrowseFolder.png')) if is_root is True: curr_item.setData( ProjectTreeData(QRaveTreeTypes.PROJECT_ROOT, project=self, data=dict(children_container.attrib)), Qt.UserRole), else: curr_item.setData( ProjectTreeData(QRaveTreeTypes.PROJECT_FOLDER, project=self, data=dict(children_container.attrib)), Qt.UserRole), for child_node in children_container.xpath('*'): # Handle any explicit <Node> children if child_node.tag == 'Node': self._recurse_tree(child_node, new_proj_el, curr_item) # Repeaters are a separate case elif child_node.tag == 'Repeater': qrepeater = QStandardItem( QIcon(':/plugins/qrave_toolbar/BrowseFolder.png'), child_node.attrib['label']) qrepeater.setData( ProjectTreeData(QRaveTreeTypes.PROJECT_REPEATER_FOLDER, project=self, data=dict(children_container.attrib)), Qt.UserRole), curr_item.appendRow(qrepeater) repeat_xpath = child_node.attrib['xpath'] repeat_node = child_node.find('Node') if repeat_node is not None: for repeater_el in new_proj_el.xpath(repeat_xpath): self._recurse_tree(repeat_node, repeater_el, qrepeater) # Otherwise this is a leaf else: bl_type = bl_el.attrib['type'] if bl_type == 'polygon': curr_item.setIcon( QIcon(':/plugins/qrave_toolbar/layers/Polygon.png')) elif bl_type == 'line': curr_item.setIcon( QIcon(':/plugins/qrave_toolbar/layers/Polyline.png')) elif bl_type == 'point': curr_item.setIcon( QIcon(':/plugins/qrave_toolbar/layers/MultiDot.png')) elif bl_type == 'raster': curr_item.setIcon( QIcon(':/plugins/qrave_toolbar/layers/Raster.png')) else: curr_item.setIcon( QIcon(':/plugins/qrave_toolbar/RaveAddIn_16px.png')) # Couldn't find this node. Ignore it. meta = { meta.attrib['name']: meta.text for meta in new_proj_el.findall('MetaData/Meta') } new_proj_el.find('Path') layer_name = None layer_uri = os.path.join(self.project_dir, new_proj_el.find('Path').text) # If this is a geopackage it's special if new_proj_el.getparent().tag == 'Layers': layer_name = new_proj_el.find('Path').text layer_uri = os.path.join( self.project_dir, new_proj_el.getparent().getparent().find('Path').text) layer_type = bl_attr['type'] if 'type' in bl_attr else 'unknown' map_layer = QRaveMapLayer(curr_label, layer_type, layer_uri, bl_attr, meta, layer_name) curr_item.setData( ProjectTreeData(QRaveTreeTypes.LEAF, project=self, data=map_layer), Qt.UserRole) if not map_layer.exists: curr_item.setData(QBrush(Qt.red), Qt.ForegroundRole) curr_item_font = curr_item.font() curr_item_font.setItalic(True) curr_item.setFont(curr_item_font) curr_item.setToolTip('File not found: {}'.format( map_layer.layer_uri)) elif map_layer.layer_uri: curr_item.setToolTip(map_layer.layer_uri) if parent: parent.appendRow(curr_item) return curr_item