def testFindParentPanel(self): """ test QgsPanelWidget.findParentPanel """ # no widget self.assertFalse(QgsPanelWidget.findParentPanel(None)) # widget with no parent w = QWidget() self.assertFalse(QgsPanelWidget.findParentPanel(w)) # widget with no panel parent w2 = QWidget(w) self.assertFalse(QgsPanelWidget.findParentPanel(w2)) # panel widget itself w3 = QgsPanelWidget() self.assertEqual(QgsPanelWidget.findParentPanel(w3), w3) # widget with direct QgsPanelWidget parent w4 = QWidget(w3) self.assertEqual(QgsPanelWidget.findParentPanel(w4), w3) # widget with QgsPanelWidget grandparent w5 = QWidget(w4) self.assertEqual(QgsPanelWidget.findParentPanel(w5), w3) # chain should be broken when a new window is encountered n = QgsPanelWidget() n2 = QDialog(n) n3 = QWidget(n2) self.assertFalse(QgsPanelWidget.findParentPanel(n3))
def testTakeMainAcceptsAll(self): """ test that taking the main panel accepts all open child panels""" s = QgsPanelWidgetStack() mp = QgsPanelWidget() s.setMainPanel(mp) p1 = QgsPanelWidget() s.showPanel(p1) p1_accept_spy = QSignalSpy(p1.panelAccepted) p2 = QgsPanelWidget() s.showPanel(p2) p2_accept_spy = QSignalSpy(p2.panelAccepted) p3 = QgsPanelWidget() s.showPanel(p3) p3_accept_spy = QSignalSpy(p3.panelAccepted) # take main s.takeMainPanel() self.assertEqual(len(p1_accept_spy), 1) self.assertEqual(len(p2_accept_spy), 1) self.assertEqual(len(p3_accept_spy), 1)
def testClear(self): """ test clearing stack """ s = QgsPanelWidgetStack() # call on empty stack s.clear() # add panels mp = QgsPanelWidget() s.setMainPanel(mp) p1 = QgsPanelWidget() s.showPanel(p1) p2 = QgsPanelWidget() s.showPanel(p2) p3 = QgsPanelWidget() s.showPanel(p3) # clear s.clear() self.assertFalse(s.currentPanel()) self.assertFalse(s.mainPanel())
def __init__(self, parent, controller): QgsPanelWidget.__init__(self, parent) self.setupUi(self) self.parent = parent self._controller = controller self.logger = Logger() self.app = AppInterface() self.setDockMode(True) self.setPanelTitle(QCoreApplication.translate("BaseSplitDataForReceiversPanelWidget", "Convert to offline")) self.parent.setWindowTitle(QCoreApplication.translate("BaseSplitDataForReceiversPanelWidget", "Allocate parcels")) self.mQgsFileWidget.lineEdit().setPlaceholderText(QCoreApplication.translate("BaseSplitDataForReceiversPanelWidget", "Choose the output folder...")) self.mQgsFileWidget.setDefaultRoot(self.app.settings.export_dir_field_data) self.panelAccepted.connect(self.panel_accepted) self._controller.export_field_data_progress.connect(self.update_progress) self.btn_split_data.clicked.connect(self.export_field_data) self.fill_data()
def testFindParentPanel(self): """ test QgsPanelWidget.findParentPanel """ # no widget self.assertFalse(QgsPanelWidget.findParentPanel(None)) # widget with no parent w = QWidget() self.assertFalse(QgsPanelWidget.findParentPanel(w)) # widget with no panel parent w2 = QWidget(w) self.assertFalse(QgsPanelWidget.findParentPanel(w2)) # panel widget itself w3 = QgsPanelWidget() self.assertEqual(QgsPanelWidget.findParentPanel(w3), w3) # widget with direct QgsPanelWidget parent w4 = QWidget(w3) self.assertEqual(QgsPanelWidget.findParentPanel(w4), w3) # widget with QgsPanelWidget grandparent w5 = QWidget(w4) self.assertEqual(QgsPanelWidget.findParentPanel(w5), w3)
def __init__(self, task_id, parent): QgsPanelWidget.__init__(self, parent) self.setupUi(self) self.session = STSession() self._task = self.session.task_manager.get_task(task_id) self.parent = parent self.logger = Logger() self.setDockMode(True) self.setPanelTitle( QCoreApplication.translate("TaskPanelWidget", "Task details")) self.trw_task_steps.itemDoubleClicked.connect(self.trigger_action) self.trw_task_steps.itemChanged.connect(self.update_step_controls) self.session.task_manager.task_started.connect(self.update_task) self.session.task_manager.task_canceled.connect(self.acceptPanel) self.session.task_manager.task_closed.connect(self.acceptPanel) self.btn_start_task.clicked.connect(self.start_task) self.btn_cancel_task.clicked.connect(self.cancel_task) self.btn_close_task.clicked.connect(self.close_task) self.initialize_gui()
def testMainPanel(self): """ test mainPanel methods """ s = QgsPanelWidgetStack() # no main panel self.assertFalse(s.mainPanel()) self.assertFalse(s.takeMainPanel()) # set main panel p1 = QgsPanelWidget() s.setMainPanel(p1) self.assertEqual(s.mainPanel(), p1) # takeMainPanel() self.assertEqual(s.takeMainPanel(), p1) self.assertFalse(s.mainPanel()) self.assertFalse(s.takeMainPanel())
class ColorsDock(QgsDockWidget): """ Custom dock widget for modfication of project colors """ def __init__(self, iface): super().__init__() self.iface = iface stack = QgsPanelWidgetStack() self.main_panel = QgsPanelWidget() self.main_panel.setDockMode(True) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setMargin(0) # pylint: disable=no-value-for-parameter self.main_panel.setLayout(layout) self.setWindowTitle(self.tr('Project Colors')) self.setObjectName('project_colors_dock') scheme = [ s for s in QgsApplication.colorSchemeRegistry().schemes() if isinstance(s, QgsProjectColorScheme) ] self.color_list = QgsColorSchemeList(None, scheme[0]) layout.addWidget(self.color_list) # defer updates for a short timeout -- prevents flooding with signals # when doing lots of color changes, improving app responsiveness self.timer = QTimer(self) self.timer.setSingleShot(True) self.timer.setInterval(100) self.block_updates = False def apply_colors(): """ Applies color changes to canvas and project """ self.block_updates = True self.color_list.saveColorsToScheme() self.block_updates = False self.iface.mapCanvas().refreshAllLayers() self.timer.timeout.connect(apply_colors) def colors_changed(): """ Triggers a deferred update of the project colors """ if self.timer.isActive(): return self.timer.start() self.color_list.model().dataChanged.connect(colors_changed) stack.setMainPanel(self.main_panel) self.setWidget(stack) QgsProject.instance().projectColorsChanged.connect( self.repopulate_list) def repopulate_list(self): """ Rebuild the colors list when project colors are changed """ if self.block_updates: return scheme = [ s for s in QgsApplication.colorSchemeRegistry().schemes() if isinstance(s, QgsProjectColorScheme) ][0] self.color_list.setScheme(scheme)
def __init__(self, controller, parent=None): QgsPanelWidget.__init__(self, parent) self.setupUi(self) self.__controller = controller self.parent = parent self.logger = Logger() self.__selected_item = None # t_id of the qr error self.txt_search.addAction( QIcon(":/Asistente-LADM-COL/resources/images/search.png"), QLineEdit.LeadingPosition) self.setDockMode(True) self.setPanelTitle( QCoreApplication.translate("QualityRulesErrorResultsPanelWidget", "Errors")) self.tbw_errors.setColumnCount(4) self.tbw_errors.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) self.tbw_errors.horizontalHeader().setSectionResizeMode( CHECK_COLUMN, QHeaderView.ResizeToContents) self.tbw_errors.horizontalHeader().setSectionResizeMode( QRE_COLUMN, QHeaderView.ResizeToContents) # TODO: uncomment the following block when implemented self.btn_exception.setEnabled(False) self.btn_fix_error.setEnabled(False) self.txt_search.textChanged.connect(self.__search_text_changed) #self.btn_open_report.clicked.connect(self.__controller.open_report) #self.btn_view_error_results.clicked.connect(self.__view_error_results_clicked) self.btn_help.clicked.connect(self.__show_help) self.tbw_errors.itemSelectionChanged.connect(self.__selection_changed) # Set icon and QR name in the panel header qr = self.__controller.get_selected_qr() icon_names = [ 'schema.png', 'points.png', 'lines.png', 'polygons.png', 'relationships.svg' ] icon_name = icon_names[qr.type().value] icon = QIcon( ":/Asistente-LADM-COL/resources/images/{}".format(icon_name)) self.lbl_icon_type.setPixmap(icon.pixmap(QSize(24, 24))) self.lbl_icon_type.setToolTip( self.__controller.get_tr_string(qr.type())) self.lbl_qr_name.setText(qr.name()) self.lbl_qr_name.setToolTip(qr.id()) self.__column_labels = [ "", self.__controller.get_uuids_display_name(), QCoreApplication.translate("QualityRulesErrorResultsPanelWidget", "Error"), QCoreApplication.translate("QualityRulesErrorResultsPanelWidget", "Details") ] # Load available rules for current role and current db models self.__load_available_errors()