def testGetScenarioTitles(self): """ Test retrieving scenario titles """ layer = make_scenario_layer() mb_electorate_layer = make_meshblock_electorate_layer() reg = ScenarioRegistry(source_layer=layer, id_field='id', name_field='name', meshblock_electorate_layer=mb_electorate_layer) self.assertEqual( reg.scenario_titles(), OrderedDict([('Scenario 1', 1), ('scenario 3', 3), ('scenario B', 2)]))
def __init__(self, scenario_registry: ScenarioRegistry, parent=None): """ Constructor for ScenarioSelectionDialog :param scenario_registry: linked scenario registry :param parent: parent widget """ super().__init__(parent) self.scenario_registry = scenario_registry self.setWindowTitle(self.tr('Select Current Scenario')) layout = QVBoxLayout() self.search = QgsFilterLineEdit() self.search.setShowSearchIcon(True) self.search.setPlaceholderText(self.tr('Search for scenario')) self.search.textChanged.connect(self.filter_changed) layout.addWidget(self.search) self.list = QListWidget() for title, scenario_id in scenario_registry.scenario_titles().items(): item = QListWidgetItem(title) item.setData(Qt.UserRole, scenario_id) self.list.addItem(item) layout.addWidget(self.list, 10) button_box = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel) layout.addWidget(button_box) button_box.rejected.connect(self.reject) button_box.accepted.connect(self.accept) self.setLayout(layout) self.list.itemDoubleClicked.connect( self.accept) # select last scenario by default if self.list.count() > 0: self.list.item(self.list.count() - 1).setSelected(True)