def loadOutputWidget(self, option=None): """ Gets a new instance for the widget that sets output layer loading definitions. :param option: (bool) if output should be loaded. :return: (QWidget) widget for output layer loading behaviour definition. """ cb = QCheckBox() cb.setStyleSheet("margin:auto;") if option is not None: cb.setChecked(option) return cb
class checkableMapLayerList(QWidget): # create a checkable list of the map layers def __init__(self, parent=None): QWidget.__init__(self, parent) layerList = QgsProject.instance().layerTreeRoot().findLayers() self.iface = iface """for layer in layerList: print(layer.name())""" self.selectedLayers = [] layout = QVBoxLayout() self.model = QStandardItemModel() self.select_all_cb = QCheckBox('Check All') self.select_all_cb.setChecked(True) self.select_all_cb.setStyleSheet('margin-left: 5px; font: bold') #self.select_all_cb.stateChanged.connect(lambda: selectAllCheckChanged(select_all_cb, model)) layout.addWidget(self.select_all_cb) self.view = QListView() self.view.setEditTriggers(QAbstractItemView.NoEditTriggers) self.view.setSelectionMode(QAbstractItemView.NoSelection) self.view.setSelectionRectVisible(False) for layer in layerList: item = QStandardItem(layer.name()) # item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) # item.setData(QVariant(Qt.Checked), Qt.CheckStateRole) item.setCheckable(True) item.setSelectable(False) item.setCheckState(QtCore.Qt.Checked) self.model.appendRow(item) self.selectedLayers.append(item) self.view.setModel(self.model) #view.clicked.connect(lambda: listviewCheckChanged(item, model, select_all_cb)) layout.addWidget(self.view) self.setLayout(layout) """if parent: parent.setLayout(layout) else: window = QWidget() window.setLayout(layout)""" #window.show() def selectAllCheckChanged(self, select_all_cb, model): TOMsMessageLog.logMessage("IN selectAllCheckChanged", level=Qgis.Info) for index in range(model.rowCount()): item = model.item(index) if item.isCheckable(): if select_all_cb.isChecked(): item.setCheckState(QtCore.Qt.Checked) self.selectedLayers.append(item) else: item.setCheckState(QtCore.Qt.Unchecked) self.selectedLayers.remove(item) TOMsMessageLog.logMessage( "IN selectAllCheckChanged: len list {}".format( len(self.selectedLayers)), level=Qgis.Info) def listviewCheckChanged(self, model, select_all_cb): ''' updates the select all checkbox based on the listview ''' # model = self.listview.model() TOMsMessageLog.logMessage("IN listviewCheckChanged", level=Qgis.Info) items = [model.item(index) for index in range(model.rowCount())] if all(item.checkState() == QtCore.Qt.Checked for item in items): select_all_cb.setTristate(False) select_all_cb.setCheckState(QtCore.Qt.Checked) elif any(item.checkState() == QtCore.Qt.Checked for item in items): select_all_cb.setTristate(True) select_all_cb.setCheckState(QtCore.Qt.PartiallyChecked) else: select_all_cb.setTristate(False) select_all_cb.setCheckState(QtCore.Qt.Unchecked) def updateSelectedLayers(self, index): #QMessageBox.information(self.iface.mainWindow(), "debug", "IN updateSelectedLayers: {}".format(self.model.itemFromIndex(index))) TOMsMessageLog.logMessage("IN updateSelectedLayers: {}".format(index), level=Qgis.Info) item = self.model.itemFromIndex(index) if item.checkState() == QtCore.Qt.Checked: self.selectedLayers.append(item) else: self.selectedLayers.remove(item) def getSelectedLayers(self): return self.selectedLayers
def __update_available_error_data(self): self.tbw_errors.setUpdatesEnabled( False) # Don't render until we're ready # Save selection before clearing table to restate it later (if needed) self.__update_selected_item() self.tbw_errors.blockSignals( True) # We don't want to get itemSelectionChanged here self.tbw_errors.clear() self.tbw_errors.blockSignals(False) self.tbw_errors.setHorizontalHeaderLabels(self.__column_labels) # Filter by search text list_errors = self.__filter_by_search_text(self.txt_search.text()) self.tbw_errors.setRowCount(len(list_errors)) row = 0 for feature in list_errors: # 1) Fixed error checkbox widget = QWidget() checkbox = QCheckBox() checkbox.setCheckState(Qt.Checked if self.__controller. is_fixed_error(feature) else Qt.Unchecked) checkbox.setStyleSheet('background: white;') checkbox.setEnabled(not self.__controller.is_exception(feature) ) # Exceptions cannot be fixed checkbox.setToolTip( QCoreApplication.translate( "QualityRulesErrorResultsPanelWidget", "Is the error fixed?")) layout = QHBoxLayout(widget) layout.addWidget(checkbox) layout.setAlignment(Qt.AlignCenter) layout.setContentsMargins(0, 0, 0, 0) checkbox.stateChanged.connect( partial(self.__error_state_changed, row)) self.tbw_errors.setCellWidget(row, CHECK_COLUMN, widget) # 2) Object UUIDs uuids = self.__controller.uuid_objs(feature) uuid_item = QTableWidgetItem(uuids) uuid_item.setData(Qt.UserRole, self.__controller.error_t_id(feature)) ili_name = self.__controller.ili_obj_name(feature) uuid_item.setData( Qt.ToolTipRole, "UUIDs ({}):\n{}".format(ili_name, uuids) if ili_name else "UUIDs:\n{}".format(uuids)) self.tbw_errors.setItem(row, UUIDS_COLUMN, uuid_item) # 3) Error type code error_type_code, error_type_display = self.__controller.error_type_code_and_display( feature) error_type_item = QTableWidgetItem(error_type_code) error_type_item.setData( Qt.ToolTipRole, "{}\n({})".format(error_type_display, error_type_code)) self.tbw_errors.setItem(row, QRE_COLUMN, error_type_item) # 4) Details + Values details = self.__controller.error_details_and_values(feature) error_details_item = QTableWidgetItem(details) error_details_item.setData(Qt.ToolTipRole, details) self.tbw_errors.setItem(row, DETAILS_COLUMN, error_details_item) self.__set_row_color_by_state( row, self.__controller.error_state(feature)) row += 1 # Set selection self.tbw_errors.blockSignals( True) # We don't want to get itemSelectionChanged here item = self.__get_item_by_t_id(self.__selected_item) if item: item.setSelected(True) self.tbw_errors.blockSignals(False) self.tbw_errors.setUpdatesEnabled(True) # Now render!