def test_settings_entry_enum(self): settingsKey = "settingsEntryEnum/enumValue" settingsKeyComplete = self.pluginName + "/" + settingsKey # Make sure settings does not exists QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins) defaultValue = QgsUnitTypes.LayoutMeters description = "Enum value functionality test" settingsEntryEnum = QgsSettingsEntryEnumFlag(settingsKey, self.pluginName, defaultValue, description) # Check default value self.assertEqual(settingsEntryEnum.defaultValue(), QgsUnitTypes.LayoutMeters) # Check set value success = settingsEntryEnum.setValue(QgsUnitTypes.LayoutFeet) self.assertEqual(success, True) qgsSettingsValue = QgsSettings().enumValue(settingsKeyComplete, QgsUnitTypes.LayoutMeters, QgsSettings.Plugins) self.assertEqual(qgsSettingsValue, QgsUnitTypes.LayoutFeet) # Check get value QgsSettings().setEnumValue(settingsKeyComplete, QgsUnitTypes.LayoutPicas, QgsSettings.Plugins) self.assertEqual(settingsEntryEnum.value(), QgsUnitTypes.LayoutPicas) # Check settings type self.assertEqual(settingsEntryEnum.settingsType(), QgsSettingsEntryBase.SettingsType.EnumFlag) # assign to inexisting value success = settingsEntryEnum.setValue(-1) self.assertEqual(success, False) # Current value should not have changed qgsSettingsValue = QgsSettings().enumValue(settingsKeyComplete, QgsUnitTypes.LayoutMeters, QgsSettings.Plugins) self.assertEqual(qgsSettingsValue, QgsUnitTypes.LayoutPicas)
def test_settings_entry_flag(self): settingsKey = "settingsEntryFlag/flagValue" settingsKeyComplete = self.pluginName + "/" + settingsKey pointAndLine = QgsMapLayerProxyModel.Filters( QgsMapLayerProxyModel.PointLayer | QgsMapLayerProxyModel.LineLayer) pointAndPolygon = QgsMapLayerProxyModel.Filters( QgsMapLayerProxyModel.PointLayer | QgsMapLayerProxyModel.PolygonLayer) hasGeometry = QgsMapLayerProxyModel.Filters( QgsMapLayerProxyModel.HasGeometry) # Make sure settings does not exists QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins) description = "Flag value functionality test" settingsEntryFlag = QgsSettingsEntryEnumFlag(settingsKey, self.pluginName, pointAndLine, description) # Check default value self.assertEqual(settingsEntryFlag.defaultValue(), pointAndLine) # Check set value success = settingsEntryFlag.setValue(hasGeometry) self.assertEqual(success, True) qgsSettingsValue = QgsSettings().flagValue(settingsKeyComplete, pointAndLine, QgsSettings.Plugins) self.assertEqual(qgsSettingsValue, hasGeometry) # Check get value QgsSettings().setValue(settingsKeyComplete, 'PointLayer|PolygonLayer', QgsSettings.Plugins) self.assertEqual(settingsEntryFlag.value(), pointAndPolygon) # Check settings type self.assertEqual(settingsEntryFlag.settingsType(), QgsSettingsEntryBase.SettingsType.EnumFlag)
def test_settings_entry_enum(self): settingsKey = "settingsEntryEnum/enumValue" settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKey) # Make sure settings does not exists QgsSettings().remove(settingsKeyComplete) defaultValue = QgsUnitTypes.LayoutMeters description = "Enum value functionality test" settingsEntryEnum = QgsSettingsEntryEnumFlag(settingsKey, self.pluginName, defaultValue, description) # Check default value self.assertEqual(settingsEntryEnum.defaultValue(), QgsUnitTypes.LayoutMeters) # Check set value success = settingsEntryEnum.setValue(QgsUnitTypes.LayoutFeet) self.assertEqual(success, True) qgsSettingsValue = QgsSettings().enumValue(settingsKeyComplete, QgsUnitTypes.LayoutMeters) self.assertEqual(qgsSettingsValue, QgsUnitTypes.LayoutFeet) # Check get value QgsSettings().setEnumValue(settingsKeyComplete, QgsUnitTypes.LayoutPicas) self.assertEqual(settingsEntryEnum.value(), QgsUnitTypes.LayoutPicas) # Check settings type self.assertEqual(settingsEntryEnum.settingsType(), Qgis.SettingsType.EnumFlag) # assign to inexisting value success = settingsEntryEnum.setValue(-1) self.assertEqual(success, False) # Current value should not have changed qgsSettingsValue = QgsSettings().enumValue(settingsKeyComplete, QgsUnitTypes.LayoutMeters) self.assertEqual(qgsSettingsValue, QgsUnitTypes.LayoutPicas) # With save as integer option settingsEntryEnumAsInteger = QgsSettingsEntryEnumFlag( settingsKey, self.pluginName, defaultValue, description, Qgis.SettingsOption.SaveEnumFlagAsInt) settingsEntryEnumAsInteger.remove() self.assertEqual(settingsEntryEnumAsInteger.value(), defaultValue) success = settingsEntryEnumAsInteger.setValue(QgsUnitTypes.LayoutFeet) self.assertEqual(success, True) qgsSettingsValue = QgsSettings().value(settingsKeyComplete, int(QgsUnitTypes.LayoutMeters)) self.assertEqual(qgsSettingsValue, int(QgsUnitTypes.LayoutFeet))