class Ui_GHydraulicsResultDialog(object): def setupUi(self, GHydraulicsResultDialog): GHydraulicsResultDialog.setObjectName(_fromUtf8("GHydraulicsResultDialog")) GHydraulicsResultDialog.resize(640, 480) self.buttonBox = QDialogButtonBox(GHydraulicsResultDialog) self.buttonBox.setGeometry(QtCore.QRect(10, 440, 620, 32)) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok) self.buttonBox.setObjectName(_fromUtf8("buttonBox")) self.tabWidget = QTabWidget(GHydraulicsResultDialog) self.tabWidget.setGeometry(QtCore.QRect(10, 10, 620, 390)) self.tabWidget.setObjectName(_fromUtf8("tabWidget")) self.tabOutput = QWidget() self.tabOutput.setObjectName(_fromUtf8("tabOutput")) self.textOutput = QTextBrowser(self.tabOutput) self.textOutput.setGeometry(QtCore.QRect(10, 10, 600, 340)) sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.textOutput.sizePolicy().hasHeightForWidth()) self.textOutput.setSizePolicy(sizePolicy) self.textOutput.setObjectName(_fromUtf8("textOutput")) self.tabWidget.addTab(self.tabOutput, _fromUtf8("")) self.tabReport = QWidget() self.tabReport.setObjectName(_fromUtf8("tabReport")) self.textReport = QTextBrowser(self.tabReport) self.textReport.setGeometry(QtCore.QRect(10, 10, 600, 340)) sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.textReport.sizePolicy().hasHeightForWidth()) self.textReport.setSizePolicy(sizePolicy) self.textReport.setObjectName(_fromUtf8("textReport")) self.tabWidget.addTab(self.tabReport, _fromUtf8("")) self.comboStep = QComboBox(GHydraulicsResultDialog) self.comboStep.setGeometry(QtCore.QRect(150, 410, 80, 27)) self.comboStep.setObjectName(_fromUtf8("comboStep")) self.labelStep = QLabel(GHydraulicsResultDialog) self.labelStep.setGeometry(QtCore.QRect(10, 415, 120, 17)) self.labelStep.setObjectName(_fromUtf8("labelStep")) self.retranslateUi(GHydraulicsResultDialog) self.tabWidget.setCurrentIndex(0) #QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), GHydraulicsResultDialog.accept) self.buttonBox.accepted.connect(GHydraulicsResultDialog.accept) #QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), GHydraulicsResultDialog.reject) self.buttonBox.rejected.connect(GHydraulicsResultDialog.reject) QtCore.QMetaObject.connectSlotsByName(GHydraulicsResultDialog) def retranslateUi(self, GHydraulicsResultDialog): GHydraulicsResultDialog.setWindowTitle(_translate("GHydraulicsResultDialog", "EPANET Results", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabOutput), _translate("GHydraulicsResultDialog", "EPANET Output", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabReport), _translate("GHydraulicsResultDialog", "Report", None)) self.labelStep.setText(_translate("GHydraulicsResultDialog", "Load time step", None))
class GraphDockWidget(QDockWidget): """Main Dock Widget for showing 3Di results in Graphs""" closingWidget = pyqtSignal(int) def __init__( self, iface, parent_widget=None, parent_class=None, nr=0, ts_datasources=None, root_tool=None, ): """Constructor""" super().__init__(parent_widget) self.iface = iface self.parent_class = parent_class self.nr = nr self.ts_datasources = ts_datasources self.root_tool = root_tool self.setup_ui(self) parameter_config = self._get_active_parameter_config() # add graph widgets self.q_graph_widget = GraphWidget( self, self.ts_datasources, parameter_config["q"], "Q graph", QgsWkbTypes.LineString, ) self.h_graph_widget = GraphWidget( self, self.ts_datasources, parameter_config["h"], "H graph", QgsWkbTypes.Point, ) self.graphTabWidget.addTab(self.q_graph_widget, self.q_graph_widget.name) self.graphTabWidget.addTab(self.h_graph_widget, self.h_graph_widget.name) # add listeners self.addSelectedObjectButton.clicked.connect(self.add_objects) # init current layer state and add listener self.selected_layer_changed(self.iface.mapCanvas().currentLayer) self.iface.currentLayerChanged.connect(self.selected_layer_changed) self.root_tool.timeslider_widget.datasource_changed.connect( self.on_active_ts_datasource_change) def on_close(self): """ unloading widget and remove all required stuff :return: """ self.addSelectedObjectButton.clicked.disconnect(self.add_objects) self.iface.currentLayerChanged.disconnect(self.selected_layer_changed) self.root_tool.timeslider_widget.datasource_changed.disconnect( self.on_active_ts_datasource_change) # self.q_graph_widget.close() # self.h_graph_widget.close() def closeEvent(self, event): """ overwrite of QDockWidget class to emit signal :param event: QEvent """ self.on_close() self.closingWidget.emit(self.nr) event.accept() def _get_active_parameter_config(self): active_ts_datasource = self.root_tool.timeslider_widget.active_ts_datasource if active_ts_datasource is not None: # TODO: just taking the first datasource, not sure if correct: threedi_result = active_ts_datasource.threedi_result() available_subgrid_vars = threedi_result.available_subgrid_map_vars available_agg_vars = threedi_result.available_aggregation_vars if not available_agg_vars: messagebar_message("Warning", "No aggregation netCDF was found.", level=1, duration=5) parameter_config = generate_parameter_config( available_subgrid_vars, available_agg_vars) else: parameter_config = {"q": {}, "h": {}} return parameter_config def on_active_ts_datasource_change(self): parameter_config = self._get_active_parameter_config() self.q_graph_widget.set_parameter_list(parameter_config["q"]) self.h_graph_widget.set_parameter_list(parameter_config["h"]) def selected_layer_changed(self, active_layer): tdi_layer = False # get active layer from canvas, otherwise .dataProvider doesn't work canvas = self.iface.mapCanvas() current_layer = canvas.currentLayer() if current_layer: provider = current_layer.dataProvider() valid_object_type = normalized_object_type(current_layer.name()) if provider.name() in VALID_PROVIDERS and valid_object_type: tdi_layer = True elif current_layer.name() in ("flowlines", "nodes"): tdi_layer = True # activate button if 3Di layers found self.addSelectedObjectButton.setEnabled(tdi_layer) def add_objects(self): canvas = self.iface.mapCanvas() current_layer = canvas.currentLayer() if not current_layer: # todo: feedback select layer first return provider = current_layer.dataProvider() if provider.name() not in VALID_PROVIDERS: return if current_layer.name() not in list(LAYER_QH_TYPE_MAPPING.keys()): if current_layer.name() not in ("flowlines", "nodes"): # todo: feedback layer not supported return selected_features = current_layer.selectedFeatures() if current_layer.name() == "flowlines": self.q_graph_widget.add_objects(current_layer, selected_features) self.graphTabWidget.setCurrentIndex( self.graphTabWidget.indexOf(self.q_graph_widget)) return elif current_layer.name() == "nodes": self.h_graph_widget.add_objects(current_layer, selected_features) self.graphTabWidget.setCurrentIndex( self.graphTabWidget.indexOf(self.h_graph_widget)) return if LAYER_QH_TYPE_MAPPING[current_layer.name()] == "q": self.q_graph_widget.add_objects(current_layer, selected_features) self.graphTabWidget.setCurrentIndex( self.graphTabWidget.indexOf(self.q_graph_widget)) else: self.h_graph_widget.add_objects(current_layer, selected_features) self.graphTabWidget.setCurrentIndex( self.graphTabWidget.indexOf(self.h_graph_widget)) def on_btnstate(self, state): """Toggle ``absolute`` state of the GraphPlots""" checked = state == Qt.Checked self.q_graph_widget.graph_plot.absolute = ( self.h_graph_widget.graph_plot.absolute) = checked def setup_ui(self, dock_widget): """ initiate main Qt building blocks of interface :param dock_widget: QDockWidget instance """ dock_widget.setObjectName("dock_widget") dock_widget.setAttribute(Qt.WA_DeleteOnClose) self.dockWidgetContent = QWidget(self) self.dockWidgetContent.setObjectName("dockWidgetContent") self.mainVLayout = QVBoxLayout(self.dockWidgetContent) self.dockWidgetContent.setLayout(self.mainVLayout) # add button to add objects to graphs self.buttonBarHLayout = QHBoxLayout(self) self.addSelectedObjectButton = QPushButton(self.dockWidgetContent) self.addSelectedObjectButton.setObjectName("addSelectedObjectButton") self.checkbox = QCheckBox("Absolute", parent=self.dockWidgetContent) self.checkbox.setChecked(False) self.checkbox.stateChanged.connect(self.on_btnstate) self.buttonBarHLayout.addWidget(self.addSelectedObjectButton) self.buttonBarHLayout.addWidget(self.checkbox) spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.buttonBarHLayout.addItem(spacerItem) self.mainVLayout.addItem(self.buttonBarHLayout) # add tabWidget for graphWidgets self.graphTabWidget = QTabWidget(self.dockWidgetContent) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(6) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.graphTabWidget.sizePolicy().hasHeightForWidth()) self.graphTabWidget.setSizePolicy(sizePolicy) self.graphTabWidget.setObjectName("graphTabWidget") self.mainVLayout.addWidget(self.graphTabWidget) # add dockwidget dock_widget.setWidget(self.dockWidgetContent) self.retranslate_ui(dock_widget) QMetaObject.connectSlotsByName(dock_widget) def retranslate_ui(self, DockWidget): DockWidget.setWindowTitle("3Di result plots %i" % self.nr) self.addSelectedObjectButton.setText("Add")