def create_rule_tab(self, rule_id, rule): """ Create a tab in the Rule tab. The tab is added to the left. Args: (int) rule_id: The id of the rule. (list) rule: A list of tuples containing the attributes of the rule. """ tab = QWidget() layout = QVBoxLayout(tab) tab.setLayout(layout) label_field = QLabel(tab) label_field.setGeometry(10, 10, 300, 21) label_field.setText("Measure variable: {}".format(rule[4])) label_field = QLabel(tab) label_field.setGeometry(10, 40, 300, 21) operator = "" if rule[1] == ">": operator = "Bottom up" elif rule[1] == "<": operator = "Top down" label_field.setText("Operator: {}".format(operator)) label_field = QLabel(tab) label_field.setGeometry(310, 10, 300, 21) structure_type = "" if rule[3] == "v2_culvert": structure_type = "culvert" elif rule[3] == "v2_pumpstation": structure_type = "pumpstation" elif rule[3] == "v2_orifice": structure_type = "orifice" elif rule[3] == "v2_weir": structure_type = "weir" label_field.setText("Structure type: {}".format(structure_type)) label_field = QLabel(tab) label_field.setGeometry(310, 40, 300, 21) label_field.setText("Structure id: {}".format(rule[2])) label_field = QLabel(tab) label_field.setGeometry(310, 70, 741, 21) label_field.setText("Action type: {}".format(rule[5])) table_control_table = QTableWidget(tab) table_control_table.setGeometry(10, 100, 741, 181) table_control_table.insertColumn(0) table_control_table.setHorizontalHeaderItem( 0, QTableWidgetItem("measuring_value")) table_control_table.insertColumn(1) table_control_table.setHorizontalHeaderItem( 1, QTableWidgetItem("action_value")) table_control_table.setEditTriggers(QAbstractItemView.NoEditTriggers) self.dockwidget_controlled_structures.table_control_view = table_control_table self.dockwidget_controlled_structures.tab_table_control_view.insertTab( 0, tab, "Table control: {}".format(str(rule_id)))
def show_drawing_analysis(self, planfall=True): ''' open shares of ground cover in dialog with table ''' shares = self.analyse_shares(planfall) l = 'Planfall' if planfall else 'Nullfall' dialog = Dialog(title='Flächenanteile der Bodenbedeckung in ' f'der Zeichnung für den {l}') layout = QVBoxLayout() dialog.setLayout(layout) table_widget = QTableWidget() layout.addWidget(table_widget) table_widget.setColumnCount(2) table_widget.setHorizontalHeaderItem( 0, QTableWidgetItem('Bodenbedeckungstyp')) table_widget.setHorizontalHeaderItem(1, QTableWidgetItem('Anteil')) types = self.bb_types.features() table_widget.setRowCount(len(types)) for i, bb_typ in enumerate(types): share = shares.get(bb_typ.IDBodenbedeckung) or 0 table_widget.setItem(i, 0, QTableWidgetItem(bb_typ.name)) table_widget.setItem(i, 1, QTableWidgetItem(f'{share}%')) table_widget.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents) table_widget.resizeColumnsToContents() dialog.showEvent = lambda e: dialog.adjustSize() dialog.show()
def create_measuring_group_tab(self, measuring_group_id): """ Create a new measuring group in te Measuring group tab. The new tab is added to the left. """ tab = QWidget() layout = QVBoxLayout(tab) tab.setLayout(layout) table_measuring_group = QTableWidget(tab) table_measuring_group.setGeometry(10, 10, 741, 266) table_measuring_group.insertColumn(0) table_measuring_group.setHorizontalHeaderItem( 0, QTableWidgetItem("table")) table_measuring_group.insertColumn(1) table_measuring_group.setHorizontalHeaderItem( 1, QTableWidgetItem("table_id")) table_measuring_group.insertColumn(2) table_measuring_group.setHorizontalHeaderItem( 2, QTableWidgetItem("weight")) table_measuring_group.setEditTriggers(QAbstractItemView.NoEditTriggers) self.dockwidget_controlled_structures.table_measuring_group = ( table_measuring_group) # Set the new tab as the first tab self.dockwidget_controlled_structures.tab_measuring_group_view_2.insertTab( 0, tab, "Group: {}".format(str(measuring_group_id)))
def add_measuring_group_tab_dockwidget(self): """ Create a tab for the measure group within the Measure group tab in the dockwidget. """ tab = QWidget() layout = QVBoxLayout(tab) tab.setLayout(layout) table_measuring_group = QTableWidget(tab) table_measuring_group.setGeometry(10, 10, 741, 266) table_measuring_group.insertColumn(0) table_measuring_group.setHorizontalHeaderItem(0, QTableWidgetItem("table")) table_measuring_group.insertColumn(1) table_measuring_group.setHorizontalHeaderItem(1, QTableWidgetItem("table_id")) table_measuring_group.insertColumn(2) table_measuring_group.setHorizontalHeaderItem(2, QTableWidgetItem("weight")) table_measuring_group.setEditTriggers(QAbstractItemView.NoEditTriggers) self.dockwidget_controlled_structures.table_measuring_group = ( table_measuring_group ) # Add the tab to the left self.dockwidget_controlled_structures.tab_measuring_group_view_2.insertTab( 0, tab, "Group: {}".format(str(self.label_measuring_group_id_info.text())) )
def __init__(self, rows, columns): QWidget.__init__(self) self.table = QTableWidget(rows, columns, self) for column in range(columns): for row in range(rows): item = QTableWidgetItem('Text%d' % row) if row % 2: item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setCheckState(Qt.Unchecked) self.table.setItem(row, column, item) self.table.itemClicked.connect(self.handleItemClicked) layout = QVBoxLayout(self) layout.addWidget(self.table) self._list = []
def setupUi(self): self.resize(800, 600) self.setWindowTitle("Authorship") layout = QVBoxLayout() splitter = QSplitter(self) splitter.setOrientation(Qt.Vertical) self.table = QTableWidget(splitter) self.table.setColumnCount(3) self.table.setShowGrid(False) self.table.verticalHeader().hide() self.table.setHorizontalHeaderLabels(["Attribute", "Author", "Value"]) self.table.setRowCount(len(self.blamedata)) self.table.setSelectionBehavior(QAbstractItemView.SelectRows) self.table.setSelectionMode(QAbstractItemView.SingleSelection); self.table.selectionModel().selectionChanged.connect(self.selectionChanged) for i, name in enumerate(self.blamedata.keys()): values = self.blamedata[name] self.table.setItem(i, 0, QTableWidgetItem(name)); self.table.setItem(i, 1, QTableWidgetItem(values[1].authorname)); self.table.setItem(i, 2, QTableWidgetItem(values[0])); self.table.resizeRowsToContents() self.table.horizontalHeader().setMinimumSectionSize(250) self.table.horizontalHeader().setStretchLastSection(True) self.text = QTextBrowser(splitter) layout.addWidget(splitter) self.setLayout(layout) QMetaObject.connectSlotsByName(self)
def setupUi(self): self.resize(500, 350) self.setWindowTitle("Remote connections manager") self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setSpacing(2) self.horizontalLayout.setMargin(0) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Vertical) self.buttonBox.setStandardButtons(QDialogButtonBox.Close) self.table = QTableWidget() self.table.verticalHeader().setVisible(False) self.table.setSelectionMode(QAbstractItemView.SingleSelection) self.table.setSelectionBehavior(QAbstractItemView.SelectRows) self.addRowButton = QPushButton() self.addRowButton.setText("Add connection") self.editRowButton = QPushButton() self.editRowButton.setText("Edit connection") self.removeRowButton = QPushButton() self.removeRowButton.setText("Remove connection") self.buttonBox.addButton(self.addRowButton, QDialogButtonBox.ActionRole) self.buttonBox.addButton(self.editRowButton, QDialogButtonBox.ActionRole) self.buttonBox.addButton(self.removeRowButton, QDialogButtonBox.ActionRole) self.setTableContent() self.horizontalLayout.addWidget(self.table) self.horizontalLayout.addWidget(self.buttonBox) self.setLayout(self.horizontalLayout) self.buttonBox.rejected.connect(self.close) self.editRowButton.clicked.connect(self.editRow) self.addRowButton.clicked.connect(self.addRow) self.removeRowButton.clicked.connect(self.removeRow) QMetaObject.connectSlotsByName(self) self.editRowButton.setEnabled(False) self.removeRowButton.setEnabled(False)
def show_validation_results(self, results): """ Shows the results of a validation run :param results: validation results """ self.clear() self.table = QTableWidget() self.table.setColumnCount(3) self.table.setHorizontalHeaderLabels(['', 'Electorate', 'Error']) def create_zoom_button(extent: QgsRectangle): """ Creates a zoom to electorate button :param extent: extent to zoom to """ button = QToolButton() button.setToolTip('Zoom to Electorate') button.setIcon(GuiUtils.get_icon('zoom_selected.svg')) button.clicked.connect(partial(self.zoom_to_extent, extent)) return button self.table.setRowCount(0) def add_electorate(electorate_id, name: str, error: str, # pylint: disable=unused-argument extent: QgsRectangle): """ Adds an electorate to the results table :param electorate_id: electorate ID :param name: electorate name :param error: error string :param extent: extent of electorate geometry """ flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled name_item = QTableWidgetItem(name) name_item.setFlags(flags) error_item = QTableWidgetItem(error) error_item.setFlags(flags) row = self.table.rowCount() self.table.setRowCount(row + 1) self.table.setItem(row, 1, name_item) self.table.setItem(row, 2, error_item) self.table.setCellWidget(row, 0, create_zoom_button(extent)) for result in results: add_electorate(electorate_id=result[ValidationTask.ELECTORATE_ID], name=result[ValidationTask.ELECTORATE_NAME], error=result[ValidationTask.ERROR], extent=result[ValidationTask.ELECTORATE_GEOMETRY].boundingBox()) self.table.setColumnWidth(0, 30) self.widget().layout().addWidget(self.table, 1, 0, 1, 1)
def add_table_control_tab_dockwidget(self): """ Create a tab for the measure group within the Rule group tab in the dockwidget. """ tab = QWidget() layout = QVBoxLayout(tab) tab.setLayout(layout) label_field = QLabel(tab) label_field.setGeometry(10, 10, 300, 21) label_field.setText("Measure variable: {}".format( self.combobox_input_rule_measure_variable.currentText())) label_field = QLabel(tab) label_field.setGeometry(10, 40, 300, 21) label_field.setText("Operator: {}".format( self.combobox_input_rule_operator.currentText())) label_field = QLabel(tab) label_field.setGeometry(310, 10, 300, 21) label_field.setText("Structure type: {}".format( self.combobox_input_structure_table.currentText())) label_field = QLabel(tab) label_field.setGeometry(310, 40, 300, 21) label_field.setText("Structure id: {}".format( self.combobox_input_structure_id.currentText())) label_field = QLabel(tab) label_field.setGeometry(310, 70, 741, 21) label_field.setText("Action type: {}".format( self.combobox_input_action_type.currentText())) table_control_table = QTableWidget(tab) table_control_table.setGeometry(10, 100, 741, 181) table_control_table.insertColumn(0) table_control_table.setHorizontalHeaderItem( 0, QTableWidgetItem("measuring_value")) table_control_table.insertColumn(1) table_control_table.setHorizontalHeaderItem( 1, QTableWidgetItem("action_value")) table_control_table.setEditTriggers(QAbstractItemView.NoEditTriggers) self.dockwidget_controlled_structures.table_control_view = table_control_table self.dockwidget_controlled_structures.tab_table_control_view.insertTab( 0, tab, "Table control: {}".format(str(self.table_control_id)))
def create_control_group_tab(self, control_group_id, control_group): """ Create a tab in the Control group tab. The tab is added to the left. Args: (int) control_group_id: The id of the control group. (list) control_group: A list of tuples containing the attributes of the control group. """ tab = QWidget() layout = QVBoxLayout(tab) tab.setLayout(layout) label_field = QLabel(tab) label_field.setGeometry(10, 10, 741, 21) label_field.setText("Name: {}".format(control_group[2])) label_field = QLabel(tab) label_field.setGeometry(10, 40, 741, 51) label_field.setText("Description: {}".format(control_group[0])) control_group_table = QTableWidget(tab) control_group_table.setGeometry(10, 100, 741, 181) control_group_table.insertColumn(0) control_group_table.setHorizontalHeaderItem( 0, QTableWidgetItem("measuring_group_id")) control_group_table.insertColumn(1) control_group_table.setHorizontalHeaderItem( 1, QTableWidgetItem("rule_type")) control_group_table.insertColumn(2) control_group_table.setHorizontalHeaderItem( 2, QTableWidgetItem("rule_id")) control_group_table.insertColumn(3) control_group_table.setHorizontalHeaderItem( 3, QTableWidgetItem("structure")) control_group_table.insertColumn(4) control_group_table.setHorizontalHeaderItem( 4, QTableWidgetItem("structure_id")) control_group_table.setEditTriggers(QAbstractItemView.NoEditTriggers) # Add the tab to the tabwidget in the dockwidget self.dockwidget_controlled_structures.control_group_table = control_group_table self.dockwidget_controlled_structures.tab_control_view.insertTab( 0, tab, "Control group: {}".format(str(control_group_id)))
def add_control_group_tab_dockwidget(self): """ Create a tab for the measure group within the Measure group tab in the dockwidget. """ tab = QWidget() layout = QVBoxLayout(tab) tab.setLayout(layout) label_field = QLabel(tab) label_field.setGeometry(10, 10, 741, 21) label_field.setText("Name: {}".format( self.lineedit_input_control_name.text())) label_field = QLabel(tab) label_field.setGeometry(10, 40, 741, 51) label_field.setText("Description: {}".format( self.textedit_input_control_description.toPlainText())) control_group_table = QTableWidget(tab) control_group_table.setGeometry(10, 100, 741, 181) control_group_table.insertColumn(0) control_group_table.setHorizontalHeaderItem( 0, QTableWidgetItem("measuring_group_id")) control_group_table.insertColumn(1) control_group_table.setHorizontalHeaderItem( 1, QTableWidgetItem("rule_type")) control_group_table.insertColumn(2) control_group_table.setHorizontalHeaderItem( 2, QTableWidgetItem("rule_id")) control_group_table.insertColumn(3) control_group_table.setHorizontalHeaderItem( 3, QTableWidgetItem("structure")) control_group_table.insertColumn(4) control_group_table.setHorizontalHeaderItem( 4, QTableWidgetItem("structure_id")) control_group_table.setEditTriggers(QAbstractItemView.NoEditTriggers) # Add the tab to the tabwidget in the dockwidget self.dockwidget_controlled_structures.control_group_table = control_group_table self.dockwidget_controlled_structures.tab_control_view.insertTab( 0, tab, "Control group: {}".format(str(self.control_group_id)))
def __init__(self, dockwidget, parent, params, edit_type): QDialog.__init__(self, parent) main_lay = QVBoxLayout(self) self.dockwidget = dockwidget self.params = params self.edit_type = edit_type self.x_label = '' self.y_label = '' self.setMinimumWidth(600) self.setMinimumHeight(400) self.setWindowTitle(self.titles[edit_type]) # TODO: softcode self.setWindowModality(QtCore.Qt.ApplicationModal) self.current = None self.current_saved = False # File self.lbl_file = QLabel('File:') self.fra_file = QFrame() self.fra_file.setContentsMargins(0, 0, 0, 0) fra_file_lay = QHBoxLayout(self.fra_file) if edit_type == self.edit_patterns: self.txt_file = QLineEdit(self.params.patterns_file) elif edit_type == self.edit_curves: self.txt_file = QLineEdit(self.params.curves_file) self.txt_file.setReadOnly(True) self.txt_file.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) self.txt_file.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum) fra_file_lay.addWidget(self.txt_file) self.btn_file = QPushButton('Change') # TODO: softcode self.btn_file.clicked.connect(self.import_file) fra_file_lay.addWidget(self.btn_file) fra_file_lay.setContentsMargins(0, 0, 0, 0) self.lbl_list = QLabel(self.labels[edit_type]) self.lst_list = QListWidget() self.lst_list.currentItemChanged.connect(self.list_item_changed) # Form self.fra_form = QFrame() fra_form1_lay = QFormLayout(self.fra_form) fra_form1_lay.setContentsMargins(0, 0, 0, 0) fra_form1_lay.addRow(self.lbl_list, self.lst_list) # Buttons self.fra_buttons = QFrame() fra_buttons_lay = QHBoxLayout(self.fra_buttons) fra_buttons_lay.setContentsMargins(0, 0, 0, 0) if self.edit_type == self.edit_patterns: ele_name = 'pattern' elif self.edit_type == self.edit_curves: ele_name = 'curve' self.btn_new = QPushButton('New ' + ele_name) # TODO: softcode self.btn_new.clicked.connect(self.new_element) fra_buttons_lay.addWidget(self.btn_new) self.btn_import = QPushButton('Import ' + ele_name + 's') # TODO: softcode self.btn_import.clicked.connect(self.import_file) fra_buttons_lay.addWidget(self.btn_import) self.btn_save = QPushButton('Save current ' + ele_name) # TODO: softcode self.btn_save.clicked.connect(self.save) fra_buttons_lay.addWidget(self.btn_save) self.btn_del = QPushButton('Delete current ' + ele_name) # TODO: softcode self.btn_del.clicked.connect(self.del_item) fra_buttons_lay.addWidget(self.btn_del) # ID self.lbl_id = QLabel('ID:') self.txt_id = QLineEdit() self.txt_id.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.MinimumExpanding) self.lbl_desc = QLabel('Desc.:') self.txt_desc = QLineEdit() self.fra_id = QFrame() fra_id_lay = QHBoxLayout(self.fra_id) fra_id_lay.addWidget(self.lbl_id) fra_id_lay.addWidget(self.txt_id) fra_id_lay.addWidget(self.lbl_desc) fra_id_lay.addWidget(self.txt_desc) # Table form self.table = QTableWidget(self) self.rows_nr = 24 self.cols_nr = 2 self.table.setRowCount(self.rows_nr) self.table.setColumnCount(self.cols_nr) self.table.verticalHeader().setVisible(False) # Initialize empty table self.clear_table() self.table.itemChanged.connect(self.data_changed) self.fra_table = QFrame() fra_table_lay = QVBoxLayout(self.fra_table) fra_table_lay.setContentsMargins(0, 0, 0, 0) if edit_type == self.edit_curves: self.fra_pump_type = QFrame() fra_pump_type_lay = QFormLayout(self.fra_pump_type) self.lbl_pump_type = QLabel('Curve type:') # TODO: softcode self.cbo_pump_type = QComboBox() for key, name in Curve.type_names.items(): self.cbo_pump_type.addItem(name, key) fra_pump_type_lay.addRow(self.lbl_pump_type, self.cbo_pump_type) fra_table_lay.addWidget(self.fra_pump_type) self.cbo_pump_type.activated.connect(self.cbo_pump_type_activated) fra_table_lay.addWidget(self.table) self.btn_add_row = QPushButton('Add row') self.btn_add_row.clicked.connect(self.add_row) fra_table_lay.addWidget(self.btn_add_row) # Graph canvas self.fra_graph = QFrame() self.static_canvas = StaticMplCanvas(self.fra_graph, width=5, height=4, dpi=100) fra_graph_lay = QVBoxLayout(self.fra_graph) fra_graph_lay.addWidget(self.static_canvas) # Top frame self.fra_top = QFrame() fra_top_lay = QVBoxLayout(self.fra_top) fra_top_lay.addWidget(self.fra_form) fra_top_lay.addWidget(self.fra_id) fra_top_lay.addWidget(self.fra_buttons) # Bottom frame self.fra_bottom = QFrame() fra_bottom_lay = QHBoxLayout(self.fra_bottom) fra_bottom_lay.addWidget(self.fra_table) fra_bottom_lay.addWidget(self.fra_graph) # Main main_lay.addWidget(self.fra_top) main_lay.addWidget(self.fra_bottom) # Get existing patterns/curves self.need_to_update_graph = False if self.edit_type == self.edit_patterns: for pattern_id, pattern in self.params.patterns.items(): self.lst_list.addItem(pattern.id) elif self.edit_type == self.edit_curves: for curve_id, curve in self.params.curves.items(): self.lst_list.addItem(curve.id) if self.lst_list.count() > 0: self.lst_list.setCurrentRow(0) self.txt_id.setEnabled(True) self.txt_desc.setEnabled(True) self.btn_save.setEnabled(True) self.btn_del.setEnabled(True) self.table.setEnabled(True) self.table.setEditTriggers(QAbstractItemView.AllEditTriggers) else: self.txt_id.setEnabled(False) self.txt_desc.setEnabled(False) self.btn_save.setEnabled(False) self.btn_del.setEnabled(False) self.table.setEnabled(False) self.table.setEditTriggers(QAbstractItemView.NoEditTriggers) self.new_dialog = None self.need_to_update_graph = True
def addLayer(self, layer, headers, types, features): tab = QWidget() tab.layer = layer p1_vertical = QVBoxLayout(tab) p1_vertical.setContentsMargins(0,0,0,0) table = QTableWidget() table.itemSelectionChanged.connect(self.highlight_features) table.title = layer.name() table.crs = layer.crs() table.setColumnCount(len(headers)) if len(features) > 0: table.setRowCount(len(features)) nbrow = len(features) self.loadingWindow.show() self.loadingWindow.setLabelText(table.title) self.loadingWindow.activateWindow() self.loadingWindow.showNormal() # Table population m = 0 for feature in features: n = 0 for cell in feature.attributes(): item = QTableWidgetItem() item.setData(Qt.DisplayRole, cell) item.setFlags(item.flags() ^ Qt.ItemIsEditable) item.feature = feature table.setItem(m, n, item) n += 1 m += 1 self.loadingWindow.setValue(int((float(m)/nbrow)*100)) QApplication.processEvents() else: table.setRowCount(0) table.setHorizontalHeaderLabels(headers) table.horizontalHeader().setSectionsMovable(True) table.types = types table.filter_op = [] table.filters = [] for i in range(0, len(headers)): table.filters.append('') table.filter_op.append(0) header = table.horizontalHeader() header.setContextMenuPolicy(Qt.CustomContextMenu) header.customContextMenuRequested.connect(partial(self.filterMenu, table)) table.setSortingEnabled(True) p1_vertical.addWidget(table) # Status bar to display informations (ie: area) tab.sb = QStatusBar() p1_vertical.addWidget(tab.sb) title = table.title # We reduce the title's length to 20 characters if len(title)>20: title = title[:20]+'...' # We add the number of elements to the tab's title. title += ' ('+str(len(features))+')' self.tabWidget.addTab(tab, title) # Add the tab to the conatiner self.tabWidget.setTabToolTip(self.tabWidget.indexOf(tab), table.title) # Display a tooltip with the layer's full name