diff --git a/actions/ed.py b/actions/ed.py index fe51e1cb3..c829c772b 100644 --- a/actions/ed.py +++ b/actions/ed.py @@ -6,10 +6,8 @@ ''' # -*- coding: utf-8 -*- - from PyQt4.QtGui import QCompleter, QLineEdit, QStringListModel, QDateTimeEdit, QFileDialog, QPushButton from qgis.gui import QgsMessageBar -from qgis.core import QgsExpression import os import sys @@ -113,7 +111,7 @@ def ed_search_plus(self): try: if self.search_plus is not None: self.search_plus.dlg.setVisible(True) - except RuntimeError as e: + except RuntimeError: pass @@ -256,9 +254,9 @@ def get_date(self): # Check if interval is valid if (date_from < date_to): - expr = QgsExpression('format_date("date",\'yyyyMMdd\') > ' + self.date_document_from.date().toString('yyyyMMdd')+'AND format_date("date",\'yyyyMMdd\') < ' + self.date_document_to.date().toString('yyyyMMdd')+ ' AND "arc_id" ='+ self.arc_id_selected+'' ) + pass else : - message="Valid interval!" + message = "Date interval not valid!" self.iface.messageBar().pushMessage(message, QgsMessageBar.WARNING, 5) return @@ -302,7 +300,13 @@ def ed_add_element_accept(self): rotation = utils_giswater.getWidgetText("rotation") link = utils_giswater.getWidgetText("link") verified = utils_giswater.getWidgetText("verified") - + + if element_id == 'null': + # Show warning message + message = "You need to insert element_id" + self.controller.show_warning(message, context_name='ui_message') + return + # Check if we already have data with selected element_id sql = "SELECT DISTINCT(element_id) FROM "+self.schema_name+".element WHERE element_id = '"+element_id+"'" row = self.dao.get_row(sql) @@ -567,6 +571,12 @@ def ed_add_file_accept(self): observ = utils_giswater.getWidgetText("observ") path = utils_giswater.getWidgetText("path") + + if doc_id == 'null': + # Show warning message + message = "You need to insert doc_id" + self.controller.show_warning(message, context_name='ui_message' ) + return # Check if this document already exists sql = "SELECT DISTINCT(id) FROM "+self.schema_name+".doc WHERE id = '"+doc_id+"'" row = self.dao.get_row(sql) @@ -641,4 +651,6 @@ def open_web_browser(self, widget): url = 'www.giswater.org' webbrowser.open(url) else : - webbrowser.open(url) \ No newline at end of file + webbrowser.open(url) + + \ No newline at end of file diff --git a/actions/mg.py b/actions/mg.py index 230124406..f614695ea 100644 --- a/actions/mg.py +++ b/actions/mg.py @@ -1,7 +1,13 @@ +''' +This file is part of Giswater 2.0 +The 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 3 of the License, +or (at your option) any later version. +''' + # -*- coding: utf-8 -*- from PyQt4.QtCore import Qt, QSettings -from PyQt4.QtGui import QFileDialog, QMessageBox, QCheckBox, QLineEdit, QCommandLinkButton, QTableView, QMenu, QPushButton -from qgis.gui import QgsMessageBar +from PyQt4.QtGui import QFileDialog, QMessageBox, QCheckBox, QLineEdit, QTableView, QMenu, QPushButton from PyQt4.QtSql import QSqlTableModel import os @@ -101,9 +107,7 @@ def mg_arc_topo_repair_accept(self): sql = "SELECT "+self.schema_name+".gw_fct_anl_node_sink();" self.controller.execute_sql(sql) - # Show message and close the dialog - #message = "Selected functions have been executed" - #self.controller.show_info(message, context_name='ui_message') + # Close the dialog self.close_dialog() # Refresh map canvas @@ -329,9 +333,7 @@ def mg_go2epa_accept(self): self.gsw_settings.setValue('FILE_RPT', self.file_rpt) self.gsw_settings.setValue('PROJECT_NAME', self.project_name) - # Show message and close form -# message = "Values has been updated" -# self.controller.show_info(message, context_name='ui_message') + # Close form self.close_dialog(self.dlg) @@ -418,21 +420,18 @@ def mg_result_selector_accept(self): rpt_selector_result_id = utils_giswater.getWidgetText("rpt_selector_result_id") rpt_selector_compare_id = utils_giswater.getWidgetText("rpt_selector_compare_id") - # Set project user - user = self.controller.set_project_user() - # Delete previous values - # Set new values to tables 'rpt_selector_result' and 'rpt_selector_compare' sql = "DELETE FROM "+self.schema_name+".rpt_selector_result" self.controller.execute_sql(sql) sql = "DELETE FROM "+self.schema_name+".rpt_selector_compare" self.controller.execute_sql(sql) + + # Set new values to tables 'rpt_selector_result' and 'rpt_selector_compare' sql = "INSERT INTO "+self.schema_name+".rpt_selector_result (result_id, cur_user)" - sql+= " VALUES ('"+rpt_selector_result_id+"', '"+user+"')" + sql+= " VALUES ('"+rpt_selector_result_id+"', '"+rpt_selector_compare_id+"')" self.controller.execute_sql(sql) - #sql = "INSERT INTO "+self.schema_name+".rpt_selector_compare VALUES ('"+rpt_selector_compare_id+"');" sql = "INSERT INTO "+self.schema_name+".rpt_selector_compare (result_id, cur_user)" - sql+= " VALUES ('"+rpt_selector_compare_id+"', '"+user+"')" + sql+= " VALUES ('"+rpt_selector_compare_id+"', '"+rpt_selector_compare_id+"')" self.controller.execute_sql(sql) # Show message to user @@ -458,7 +457,6 @@ def mg_change_elem_type(self): Combo to select new node_type.type Combo to select new node_type.id Combo to select new cat_node.id - TODO: Trigger 'gw_trg_edit_node' has to be disabled temporarily ''' # Uncheck all actions (buttons) except this one @@ -561,7 +559,7 @@ def mg_change_elem_type_accept(self): message = "Node type has been update!" self.controller.show_info(message, context_name='ui_message' ) - # Close dialog + # Close form self.close_dialog() @@ -589,8 +587,6 @@ def mg_config(self): self.om_visit_absolute_path = self.dlg.findChild(QLineEdit, "om_visit_absolute_path") self.doc_absolute_path = self.dlg.findChild(QLineEdit, "doc_absolute_path") - - self.om_visit_path = self.dlg.findChild(QLineEdit, "om_visit_absolute_path") self.doc_path = self.dlg.findChild(QLineEdit, "doc_absolute_path") @@ -605,8 +601,7 @@ def mg_config(self): row = self.dao.get_row(sql) if row : path = str(row['value']) - self.om_visit_absolute_path.setText(path) - #self.om_visit_absolute_path.clicked.connect(partial(self.geth_path, path)) + self.om_visit_absolute_path.setText(path) sql = "SELECT value FROM "+self.schema_name+".config_param_text" sql +=" WHERE id = 'doc_absolute_path'" @@ -614,8 +609,6 @@ def mg_config(self): if row : path = str(row['value']) self.doc_absolute_path.setText(path) - #self.doc_absolute_path.clicked.connect(partial(self.geth_path, path)) - # Set values from widgets of type QComboBox sql = "SELECT DISTINCT(type) FROM "+self.schema_name+".node_type ORDER BY type" @@ -785,17 +778,14 @@ def fill_insert_menu(self,table): if row == None: self.menu.addAction(elem,partial(self.insert, elem,table)) - #self.menu.activated.connect(self.insert) - - def insert(self,id_action,table): + def insert(self, id_action, table): ''' On action(select value from menu) execute SQL ''' # Insert value into database sql = "INSERT INTO "+self.schema_name+"."+table+" (id) " sql+= " VALUES ('"+id_action+"')" self.controller.execute_sql(sql) - self.fill_table(self.tbl, self.schema_name+"."+table) diff --git a/dao/controller.py b/dao/controller.py index ff3412a20..01b34afbf 100644 --- a/dao/controller.py +++ b/dao/controller.py @@ -1,3 +1,10 @@ +''' +This file is part of Giswater 2.0 +The 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 3 of the License, +or (at your option) any later version. +''' + # -*- coding: utf-8 -*- from PyQt4.QtCore import QCoreApplication, QSettings from PyQt4.QtGui import QCheckBox, QLabel, QMessageBox, QPushButton @@ -358,15 +365,5 @@ def get_layer_source_key(self): return uri_schema - - def set_project_user(self): - # TODO: Set user - pass - ''' - sql = "UPDATE "+self.schema_name+".rpt_selector_result" - sql+= " SET cur_user = '"+self.user+"'" - sql+= " WHERE id = '1'" - self.dao.execute_sql(sql) - ''' \ No newline at end of file diff --git a/giswater.py b/giswater.py index 9b3232cff..6732e6134 100644 --- a/giswater.py +++ b/giswater.py @@ -6,7 +6,6 @@ ''' # -*- coding: utf-8 -*- - from PyQt4.QtCore import QCoreApplication, QObject, QSettings, QTranslator from PyQt4.QtGui import QAction, QActionGroup, QIcon diff --git a/init/ud_arc_init.py b/init/ud_arc_init.py index f0d0cd0cf..06c1eca6a 100644 --- a/init/ud_arc_init.py +++ b/init/ud_arc_init.py @@ -1,3 +1,10 @@ +''' +This file is part of Giswater 2.0 +The 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 3 of the License, +or (at your option) any later version. +''' + # -*- coding: utf-8 -*- from PyQt4.QtGui import QPushButton, QTableView, QTabWidget diff --git a/init/ud_connec_init.py b/init/ud_connec_init.py index 0fa65275c..d466833d5 100644 --- a/init/ud_connec_init.py +++ b/init/ud_connec_init.py @@ -1,3 +1,10 @@ +''' +This file is part of Giswater 2.0 +The 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 3 of the License, +or (at your option) any later version. +''' + # -*- coding: utf-8 -*- from PyQt4.QtGui import QPushButton, QTableView, QTabWidget diff --git a/init/ud_gully_init.py b/init/ud_gully_init.py index 96e9371ba..4f1f44f36 100644 --- a/init/ud_gully_init.py +++ b/init/ud_gully_init.py @@ -1,3 +1,10 @@ +''' +This file is part of Giswater 2.0 +The 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 3 of the License, +or (at your option) any later version. +''' + # -*- coding: utf-8 -*- from PyQt4.QtGui import QPushButton, QTableView, QTabWidget diff --git a/init/ud_man_arc_init.py b/init/ud_man_arc_init.py index d721737a2..85c902852 100644 --- a/init/ud_man_arc_init.py +++ b/init/ud_man_arc_init.py @@ -6,7 +6,6 @@ ''' # -*- coding: utf-8 -*- - from PyQt4.QtGui import QPushButton, QTableView, QTabWidget, QLineEdit from PyQt4.QtCore import Qt from functools import partial @@ -77,9 +76,6 @@ def init_config_form(self): # Load data from related tables self.load_data() - # Set layer in editing mode - # self.layer.startEditing() - # Manage tab visibility self.set_tabs_visibility(4) diff --git a/init/ud_man_connec_init.py b/init/ud_man_connec_init.py index f5c72c4da..dabf42c53 100644 --- a/init/ud_man_connec_init.py +++ b/init/ud_man_connec_init.py @@ -6,15 +6,12 @@ ''' # -*- coding: utf-8 -*- - -from PyQt4.QtGui import QComboBox, QDateEdit, QPushButton, QTableView, QTabWidget, QLineEdit +from PyQt4.QtGui import QPushButton, QTableView, QTabWidget from functools import partial import utils_giswater from parent_init import ParentDialog -from ui.add_sum import Add_sum # @UnresolvedImport -from PyQt4.Qt import QDialogButtonBox def formOpen(dialog, layer, feature): @@ -56,7 +53,6 @@ def init_config_form(self): table_element = "v_ui_element_x_connec" table_document = "v_ui_doc_x_connec" - #table_event_connec = "v_ui_doc_x_connec" table_event_connec = "v_ui_om_visit_x_connec" table_hydrometer = "v_rtc_hydrometer" table_hydrometer_value = "v_edit_rtc_hydro_data_x_connec" @@ -80,9 +76,6 @@ def init_config_form(self): # Load data from related tables self.load_data() - # Set layer in editing mode - #self.layer.startEditing() - # Fill the info table self.fill_table(self.tbl_info, self.schema_name+"."+table_element, self.filter) @@ -114,15 +107,10 @@ def init_config_form(self): # Configuration of table hydrometer | hydrometer value self.set_configuration(self.tbl_hydrometer_value, table_hydrometer_value) - # Set signals self.dialog.findChild(QPushButton, "btn_doc_delete").clicked.connect(partial(self.delete_records, self.tbl_document, table_document)) self.dialog.findChild(QPushButton, "delete_row_info").clicked.connect(partial(self.delete_records, self.tbl_info, table_element)) self.dialog.findChild(QPushButton, "btn_delete_hydrometer").clicked.connect(partial(self.delete_records_hydro, self.tbl_hydrometer)) self.dialog.findChild(QPushButton, "btn_add_hydrometer").clicked.connect(self.insert_records) - - #self.dialog.findChild(QPushButton, "buttonBox").clicked.connect(self.save) - - - \ No newline at end of file + \ No newline at end of file diff --git a/init/ud_man_gully_init.py b/init/ud_man_gully_init.py index 144f53afb..b1fb3c64e 100644 --- a/init/ud_man_gully_init.py +++ b/init/ud_man_gully_init.py @@ -6,7 +6,6 @@ ''' # -*- coding: utf-8 -*- - from PyQt4.QtGui import QPushButton, QTableView, QTabWidget from functools import partial diff --git a/init/ud_man_node_init.py b/init/ud_man_node_init.py index 03ef4fe6e..34878a76d 100644 --- a/init/ud_man_node_init.py +++ b/init/ud_man_node_init.py @@ -6,7 +6,6 @@ ''' # -*- coding: utf-8 -*- - from PyQt4.QtGui import QPushButton, QTableView, QTabWidget from functools import partial @@ -52,7 +51,6 @@ def init_config_form(self): table_event_node = "v_ui_om_visit_x_node" table_scada = "v_rtc_scada" table_scada_value = "v_rtc_scada_value" - table_price_node = "v_price_x_node" self.table_chamber = self.schema_name+'."v_edit_man_chamber"' diff --git a/init/ud_node_init.py b/init/ud_node_init.py index 5473b8ddd..6c1f8e6b0 100644 --- a/init/ud_node_init.py +++ b/init/ud_node_init.py @@ -1,3 +1,10 @@ +''' +This file is part of Giswater 2.0 +The 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 3 of the License, +or (at your option) any later version. +''' + # -*- coding: utf-8 -*- from PyQt4.QtGui import QPushButton, QTableView, QTabWidget diff --git a/init/ws_arc_init.py b/init/ws_arc_init.py index 7a063b251..76207a7b6 100644 --- a/init/ws_arc_init.py +++ b/init/ws_arc_init.py @@ -1,6 +1,15 @@ +''' +This file is part of Giswater 2.0 +The 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 3 of the License, +or (at your option) any later version. +''' + # -*- coding: utf-8 -*- from PyQt4.QtGui import QComboBox, QPushButton, QTableView, QTabWidget +from functools import partial + import utils_giswater from parent_init import ParentDialog @@ -97,7 +106,6 @@ def init_config_form(self): # Set signals btn_element_delete = self.dialog.findChild(QPushButton, "btn_element_delete") btn_doc_delete = self.dialog.findChild(QPushButton, "btn_doc_delete") - # TODO if btn_element_delete: btn_element_delete.clicked.connect(partial(self.delete_records, self.tbl_info, table_element)) if btn_doc_delete: diff --git a/init/ws_connec_init.py b/init/ws_connec_init.py index 2d38bccd9..0f7fa8694 100644 --- a/init/ws_connec_init.py +++ b/init/ws_connec_init.py @@ -1,3 +1,10 @@ +''' +This file is part of Giswater 2.0 +The 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 3 of the License, +or (at your option) any later version. +''' + # -*- coding: utf-8 -*- from PyQt4.QtGui import QComboBox, QDateEdit, QPushButton, QTableView, QTabWidget, QLineEdit diff --git a/init/ws_man_connec_init.py b/init/ws_man_connec_init.py index 6fefe478f..304539696 100644 --- a/init/ws_man_connec_init.py +++ b/init/ws_man_connec_init.py @@ -6,8 +6,8 @@ ''' # -*- coding: utf-8 -*- - from PyQt4.QtGui import QPushButton, QTableView, QTabWidget + from functools import partial import utils_giswater diff --git a/init/ws_man_node_init.py b/init/ws_man_node_init.py index 346b27b15..82b1ab9e4 100644 --- a/init/ws_man_node_init.py +++ b/init/ws_man_node_init.py @@ -6,7 +6,6 @@ ''' # -*- coding: utf-8 -*- - from PyQt4.QtGui import QPushButton, QTableView, QTabWidget from functools import partial diff --git a/init/ws_node_init.py b/init/ws_node_init.py index d0c90cf17..1ff8d493a 100644 --- a/init/ws_node_init.py +++ b/init/ws_node_init.py @@ -1,3 +1,10 @@ +''' +This file is part of Giswater 2.0 +The 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 3 of the License, +or (at your option) any later version. +''' + # -*- coding: utf-8 -*- from PyQt4.QtGui import QComboBox, QPushButton, QTableView, QTabWidget @@ -229,7 +236,6 @@ def save_tab_add_info(self): self.controller.execute_sql(sql) total = self.dao.get_rowcount() # Perform an INSERT if any record has been updated - # TODO: If trigger was working correctly this wouldn't be necessary! if total == 0: sql = "INSERT INTO " + self.schema_name + ".man_tank (node_id, vmax, area) VALUES" sql += " ('" + self.id + "', " + str(vmax) + ", " + str(area) + ");" diff --git a/map_tools/add_element.py b/map_tools/add_element.py deleted file mode 100644 index f89e489e8..000000000 --- a/map_tools/add_element.py +++ /dev/null @@ -1,466 +0,0 @@ -""" -/*************************************************************************** - begin : 2016-01-05 - copyright : (C) 2016 by BGEO SL - email : vicente.medina@gits.ws - git sha : $Format:%H$ - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -""" - -# -*- coding: utf-8 -*- -from qgis.core import QgsPoint, QgsVectorLayer, QgsRectangle, QGis,QgsExpression -from qgis.gui import QgsRubberBand, QgsVertexMarker -from PyQt4.QtCore import QPoint, QRect, Qt -from PyQt4.QtGui import QApplication, QColor, QLineEdit, QCompleter, QDateTimeEdit, QStringListModel -from qgis.gui import QgsMessageBar - -from map_tools.parent import ParentMapTool -from ..ui.add_element import Add_element # @UnresolvedImport - -import utils_giswater - - -class AddElementMapTool(ParentMapTool): - ''' Button 33. Add_element ''' - - def __init__(self, iface, settings, action, index_action): - ''' Class constructor ''' - - # Call ParentMapTool constructor - super(AddElementMapTool, self).__init__(iface, settings, action, index_action) - - self.dragging = False - - # Vertex marker - self.vertexMarker = QgsVertexMarker(self.canvas) - self.vertexMarker.setColor(QColor(255, 25, 25)) - self.vertexMarker.setIconSize(11) - self.vertexMarker.setIconType(QgsVertexMarker.ICON_BOX) # or ICON_CROSS, ICON_X - self.vertexMarker.setPenWidth(5) - - # Rubber band - self.rubberBand = QgsRubberBand(self.canvas, True) - mFillColor = QColor(100, 0, 0); - self.rubberBand.setColor(mFillColor) - self.rubberBand.setWidth(3) - mBorderColor = QColor(254, 58, 29) - self.rubberBand.setBorderColor(mBorderColor) - - # Select rectangle - self.selectRect = QRect() - - - def reset(self): - ''' Clear selected features ''' - layer = self.layer_connec - if layer is not None: - layer.removeSelection() - - # Graphic elements - self.rubberBand.reset() - - - ''' QgsMapTools inherited event functions ''' - - def canvasMoveEvent(self, event): - ''' With left click the digitizing is finished ''' - - #Plugin reloader bug, MapTool should be deactivated - if not hasattr(Qt, 'LeftButton'): - self.iface.actionPan().trigger() - return - - if event.buttons() == Qt.LeftButton: - - if not self.dragging: - self.dragging = True - self.selectRect.setTopLeft(event.pos()) - - self.selectRect.setBottomRight(event.pos()) - self.set_rubber_band() - - else: - - # Hide highlight - self.vertexMarker.hide() - - # Get the click - x = event.pos().x() - y = event.pos().y() - eventPoint = QPoint(x, y) - - # Snapping - (retval, result) = self.snapper.snapToBackgroundLayers(eventPoint) #@UnusedVariable - - # That's the snapped point - if result <> []: - - # Check Arc or Node - for snapPoint in result: - layer = self.iface.activeLayer() - #exist=self.snapperManager.check_connec_group(snapPoint.layer) - #if exist : - if snapPoint.layer == layer: - - # Get the point - point = QgsPoint(result[0].snappedVertex) - - # Add marker - self.vertexMarker.setCenter(point) - self.vertexMarker.show() - - break - - - def canvasPressEvent(self, event): #@UnusedVariable - - self.selectRect.setRect(0, 0, 0, 0) - self.rubberBand.reset() - - - def canvasReleaseEvent(self, event): - ''' With left click the digitizing is finished ''' - - if event.button() == Qt.LeftButton: - - # Get the click - x = event.pos().x() - y = event.pos().y() - eventPoint = QPoint(x, y) - - # Not dragging, just simple selection - if not self.dragging: - - # Snap to node - (retval, result) = self.snapper.snapToBackgroundLayers(eventPoint) #@UnusedVariable - - # That's the snapped point - if result <> [] : - - for snapPoint in result: - layer = self.iface.activeLayer() - if snapPoint.layer == layer: - point = QgsPoint(result[0].snappedVertex) #@UnusedVariable - #layer.removeSelection() - #layer.select([result[0].snappedAtGeometry]) - result[0].layer.removeSelection() - result[0].layer.select([result[0].snappedAtGeometry]) - - # Create link - #self.link_connec() - self.ed_add_element() - - # Hide highlight - self.vertexMarker.hide() - - else: - - # Set valid values for rectangle's width and height - if self.selectRect.width() == 1: - self.selectRect.setLeft( self.selectRect.left() + 1 ) - - if self.selectRect.height() == 1: - self.selectRect.setBottom( self.selectRect.bottom() + 1 ) - - self.set_rubber_band() - selectGeom = self.rubberBand.asGeometry() #@UnusedVariable - self.select_multiple_features(self.selectRectMapCoord) - self.dragging = False - self.ed_add_element() - - elif event.button() == Qt.RightButton: - - # Check selected records - numberFeatures = 0 - - layer = self.iface.activeLayer() - #for layer in self.layer_connec_man: - numberFeatures += layer.selectedFeatureCount() - - if numberFeatures > 0: - answer = self.controller.ask_question("There are " + str(numberFeatures) + " features selected in the connec group, do you want to update values on them?", "Interpolate value") - if answer: - self.ed_add_element() - - - def activate(self): - - # Check button - self.action().setChecked(True) - - # Rubber band - self.rubberBand.reset() - - # Store user snapping configuration - self.snapperManager.storeSnappingOptions() - - # Clear snapping - self.snapperManager.clearSnapping() - - layer = self.iface.activeLayer() - exist = self.snapperManager.check_connec_group(layer) - if exist: - # Set snapping to connec - self.snapperManager.snapToConnec() - - exist = self.snapperManager.check_node_group(layer) - if exist: - # Set snapping to node - self.snapperManager.snapToNode() - - exist = self.snapperManager.check_arc_group(layer) - if exist: - # Set snapping to arc - self.snapperManager.snapToArc() - - # Change cursor - self.canvas.setCursor(self.cursor) - - # Show help message when action is activated - if self.show_help: - message = "Right click to use current selection, select connec points by clicking or dragging (selection box)" - self.controller.show_info(message, context_name='ui_message') - - # Control current layer (due to QGIS bug in snapping system) - if self.canvas.currentLayer() == None: - self.iface.setActiveLayer(self.layer_node_man[0]) - - - def deactivate(self): - - # Check button - self.action().setChecked(False) - - # Rubber band - self.rubberBand.reset() - - # Restore previous snapping - self.snapperManager.recoverSnappingOptions() - - # Recover cursor - self.canvas.setCursor(self.stdCursor) - - - def set_rubber_band(self): - - # Coordinates transform - transform = self.canvas.getCoordinateTransform() - - # Coordinates - ll = transform.toMapCoordinates(self.selectRect.left(), self.selectRect.bottom()) - lr = transform.toMapCoordinates(self.selectRect.right(), self.selectRect.bottom()) - ul = transform.toMapCoordinates(self.selectRect.left(), self.selectRect.top()) - ur = transform.toMapCoordinates(self.selectRect.right(), self.selectRect.top()) - - # Rubber band - self.rubberBand.reset() - self.rubberBand.addPoint(ll, False) - self.rubberBand.addPoint(lr, False) - self.rubberBand.addPoint(ur, False) - self.rubberBand.addPoint(ul, False) - self.rubberBand.addPoint(ll, True) - - self.selectRectMapCoord = QgsRectangle(ll, ur) - - - def select_multiple_features(self, selectGeometry): - - if self.layer_connec_man is None: - return - - # Change cursor - QApplication.setOverrideCursor(Qt.WaitCursor) - - if QGis.QGIS_VERSION_INT >= 21600: - - # Default choice - behaviour = QgsVectorLayer.SetSelection - - # Selection for all connec group layers - layer = self.iface.activeLayer - exist=self.snapperManager.check_connec_group(layer) - if exist : - for layer in self.layer_connec_man: - layer.selectByRect(selectGeometry, behaviour) - exist=self.snapperManager.check_node_group(layer) - if exist : - for layer in self.layer_node_man: - layer.selectByRect(selectGeometry, behaviour) - exist=self.snapperManager.check_arc_group(layer) - if exist : - for layer in self.layer_arc_man: - layer.selectByRect(selectGeometry, behaviour) - - else: - layer = self.iface.activeLayer - exist=self.snapperManager.check_connec_group(layer) - if exist : - for layer in self.layer_connec_man: - layer.removeSelection() - layer.select(selectGeometry, True) - exist=self.snapperManager.check_node_group(layer) - if exist : - for layer in self.layer_node_man: - layer.removeSelection() - layer.select(selectGeometry, True) - exist=self.snapperManager.check_arc_group(layer) - if exist : - for layer in self.layer_arc_man: - layer.removeSelection() - layer.select(selectGeometry, True) - - - # Old cursor - QApplication.restoreOverrideCursor() - - - def ed_add_element(self): - ''' Button 33. Add element ''' - - # Create the dialog and signals - self.dlg = Add_element() - utils_giswater.setDialog(self.dlg) - self.dlg.btn_accept.pressed.connect(self.ed_add_element_accept) - self.dlg.btn_cancel.pressed.connect(self.close_dialog) - - # Manage i18n of the form - self.controller.translate_form(self.dlg, 'element') - - # Check if we have at least one feature selected - if not self.ed_check(): - return - - # Fill combo boxes - self.populate_combo("elementcat_id", "cat_element") - self.populate_combo("state", "value_state") - self.populate_combo("location_type", "man_type_location") - self.populate_combo("workcat_id", "cat_work") - self.populate_combo("buildercat_id", "cat_builder") - self.populate_combo("ownercat_id", "cat_owner") - self.populate_combo("verified", "value_verified") - self.populate_combo("workcat_id_end", "cat_work") - - # Adding auto-completion to a QLineEdit - self.edit = self.dlg.findChild(QLineEdit, "element_id") - self.completer = QCompleter() - self.edit.setCompleter(self.completer) - model = QStringListModel() - sql = "SELECT DISTINCT(element_id) FROM "+self.schema_name+".element " - row = self.dao.get_rows(sql) - for i in range(0,len(row)): - aux = row[i] - row[i] = str(aux[0]) - - #self.get_date() - model.setStringList(row) - self.completer.setModel(model) - - # Set signal to reach selected value from QCompleter - self.completer.activated.connect(self.ed_add_el_autocomplete) - - # Open the dialog - self.dlg.exec_() - - - def get_date(self): - ''' Get date_from and date_to from ComboBoxes - Filter the table related on selected value - ''' - - self.date_document_from = self.dlg.findChild(QDateTimeEdit, "builtdate") - self.date_document_to = self.dlg.findChild(QDateTimeEdit, "enddate") - - date_from=self.date_document_from.date() - date_to=self.date_document_to.date() - - # TODO: - if (date_from < date_to): - expr = QgsExpression('format_date("date",\'yyyyMMdd\') > ' + self.date_document_from.date().toString('yyyyMMdd')+'AND format_date("date",\'yyyyMMdd\') < ' + self.date_document_to.date().toString('yyyyMMdd')+ ' AND "arc_id" ='+ self.arc_id_selected+'' ) - - else: - message = "Valid interval!" - self.iface.messageBar().pushMessage(message, QgsMessageBar.WARNING, 5) - return - - - def ed_add_el_autocomplete(self): - ''' Once we select 'element_id' using autocomplete, fill widgets with current values ''' - - self.dlg.element_id.setCompleter(self.completer) - element_id = utils_giswater.getWidgetText("element_id") - - # Get values from database - sql = "SELECT elementcat_id, location_type, ownercat_id, state, workcat_id," - sql+= " buildercat_id, annotation, observ, comment, link, verified, rotation" - sql+= " FROM "+self.schema_name+".element" - sql+= " WHERE element_id = '"+element_id+"'" - row = self.dao.get_row(sql) - - # Fill widgets - columns_length = self.dao.get_columns_length() - for i in range(0, columns_length): - column_name = self.dao.get_column_name(i) - utils_giswater.setWidgetText(column_name, row[column_name]) - - - def ed_add_element_accept(self): - - # Get values from dialog - element_id = utils_giswater.getWidgetText("element_id") - elementcat_id = utils_giswater.getWidgetText("elementcat_id") - workcat_id_end = utils_giswater.getWidgetText("workcat_id_end") - state = utils_giswater.getWidgetText("state") - annotation = utils_giswater.getWidgetText("annotation") - observ = utils_giswater.getWidgetText("observ") - comment = utils_giswater.getWidgetText("comment") - location_type = utils_giswater.getWidgetText("location_type") - workcat_id = utils_giswater.getWidgetText("workcat_id") - buildercat_id = utils_giswater.getWidgetText("buildercat_id") - ownercat_id = utils_giswater.getWidgetText("ownercat_id") - rotation = utils_giswater.getWidgetText("rotation") - link = utils_giswater.getWidgetText("link") - verified = utils_giswater.getWidgetText("verified") - - # Check if we already have data with selected element_id - sql = "SELECT DISTINCT(element_id) FROM "+self.schema_name+".element WHERE element_id = '"+element_id+"'" - row = self.dao.get_row(sql) - if row: - answer = self.controller.ask_question("Are you sure you want change the data?") - if answer: - sql = "UPDATE "+self.schema_name+".element" - sql+= " SET element_id = '"+element_id+"', elementcat_id= '"+elementcat_id+"',state = '"+state+"', location_type = '"+location_type+"'" - sql+= ", workcat_id_end= '"+workcat_id_end+"', workcat_id= '"+workcat_id+"',buildercat_id = '"+buildercat_id+"', ownercat_id = '"+ownercat_id+"'" - sql+= ", rotation= '"+rotation+"',comment = '"+comment+"', annotation = '"+annotation+"', observ= '"+observ+"',link = '"+link+"', verified = '"+verified+"'" - sql+= " WHERE element_id = '"+element_id+"'" - self.dao.execute_sql(sql) - else: - self.close_dialog(self.dlg) - else: - sql = "INSERT INTO "+self.schema_name+".element (element_id, elementcat_id, state, location_type" - sql+= ", workcat_id, buildercat_id, ownercat_id, rotation, comment, annotation, observ, link, verified,workcat_id_end) " - sql+= " VALUES ('"+element_id+"', '"+elementcat_id+"', '"+state+"', '"+location_type+"', '" - sql+= workcat_id+"', '"+buildercat_id+"', '"+ownercat_id+"', '"+rotation+"', '"+comment+"', '" - sql+= annotation+"','"+observ+"','"+link+"','"+verified+"','"+workcat_id_end+"')" - status = self.controller.execute_sql(sql) - if not status: - message = "Error inserting element in table, you need to review data" - self.controller.show_warning(message, context_name='ui_message') - return - - # Add document to selected feature - self.ed_add_to_feature("element", element_id) - - # Show message to user - message = "Values has been updated" - self.controller.show_info(message, context_name='ui_message') - self.close_dialog() \ No newline at end of file diff --git a/map_tools/point.py b/map_tools/point.py index 22b219dd0..9517759ca 100644 --- a/map_tools/point.py +++ b/map_tools/point.py @@ -1,3 +1,10 @@ +''' +This file is part of Giswater 2.0 +The 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 3 of the License, +or (at your option) any later version. +''' + # -*- coding: utf-8 -*- from qgis.gui import QgsMapTool @@ -90,13 +97,11 @@ def canvasPressEvent(self, e): def canvasReleaseEvent(self, e): - # TODO: Get clicked point and current layer + # Get clicked point and current layer self.point = self.toMapCoordinates(e.pos()) - layer = self.iface.activeLayer() - # Insert new node into selected point. Open its feature form - last_id = self.insert_node(self.point.x(), self.point.y()) - + # Insert new node into selected point + self.insert_node(self.point.x(), self.point.y()) self.iface.mapCanvas().refreshAllLayers() for layerRefresh in self.iface.mapCanvas().layers(): diff --git a/metadata.txt b/metadata.txt index edc750694..dff300331 100644 --- a/metadata.txt +++ b/metadata.txt @@ -3,10 +3,10 @@ [general] name=giswater -qgisMinimumVersion=2.8 +qgisMinimumVersion=2.14 description=Plugin to enable additional features and capabilities of Giswater working together with QGIS and PostgreSQL about=Giswater is a open source tool with the goal to move from acquired knowledge to shared knowledge in the areas of water management, such as supply, sewerage, urban drainage or flood risk assessment with to communicate any water simulation software through any Spatial database with any Geographic Information System (GIS) in order to give everybody a real way of open solution of water management. -version=1.2 +version=2.1 author=David Erill, Vicente Medina, Xavi Torret # End of mandatory metadata diff --git a/parent_init.py b/parent_init.py index 2d7820b47..afba8fdd5 100644 --- a/parent_init.py +++ b/parent_init.py @@ -6,7 +6,6 @@ ''' # -*- coding: utf-8 -*- - from qgis.utils import iface from qgis.gui import QgsMessageBar from PyQt4.Qt import QTableView, QDate diff --git a/utils_giswater.py b/utils_giswater.py index a7a1b3eee..58e7a999a 100644 --- a/utils_giswater.py +++ b/utils_giswater.py @@ -2,7 +2,7 @@ """ /*************************************************************************** * * - * This file is part of Giswater 2.0 * * + * This file is part of Giswater 2.0 * * 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 3 of the License, or *