def tesRegisterSameProviderTwice(self): """Test that a provider cannot be registered twice""" r = QgsProviderRegistry.instance() metadata = QgsProviderMetadata(PyProvider.providerKey(), PyProvider.description(), PyProvider.createProvider) self.assertFalse(r.registerProvider(metadata))
def setUpClass(cls): """Run before all tests""" # Register the provider r = QgsProviderRegistry.instance() metadata = QgsProviderMetadata(PyProvider.providerKey(), PyProvider.description(), PyProvider.createProvider) assert r.registerProvider(metadata) assert r.providerMetadata(PyProvider.providerKey()) == metadata # Create test layer cls.vl = cls.createLayer() assert (cls.vl.isValid()) cls.source = cls.vl.dataProvider() # poly layer cls.poly_vl = QgsVectorLayer('Polygon?crs=epsg:4326&field=pk:integer&key=pk', 'test', 'pythonprovider') assert (cls.poly_vl.isValid()) cls.poly_provider = cls.poly_vl.dataProvider() f1 = QgsFeature() f1.setAttributes([1]) f1.setGeometry(QgsGeometry.fromWkt('Polygon ((-69.03664108 81.35818902, -69.09237722 80.24346619, -73.718477 80.1319939, -73.718477 76.28620011, -74.88893598 76.34193625, -74.83319983 81.35818902, -69.03664108 81.35818902))')) f2 = QgsFeature() f2.setAttributes([2]) f2.setGeometry(QgsGeometry.fromWkt('Polygon ((-67.58750139 81.1909806, -66.30557012 81.24671674, -66.30557012 76.89929767, -67.58750139 76.89929767, -67.58750139 81.1909806))')) f3 = QgsFeature() f3.setAttributes([3]) f3.setGeometry(QgsGeometry.fromWkt('Polygon ((-68.36780737 75.78457483, -67.53176524 72.60761475, -68.64648808 73.66660144, -70.20710006 72.9420316, -68.36780737 75.78457483))')) f4 = QgsFeature() f4.setAttributes([4]) cls.poly_provider.addFeatures([f1, f2, f3, f4])
def register_data_provider(): metadata = QgsProviderMetadata( EarthEngineRasterDateProvider.providerKey(), EarthEngineRasterDateProvider.description(), EarthEngineRasterDateProvider.createProvider) registry = qgis.core.QgsProviderRegistry.instance() registry.registerProvider(metadata) QgsMessageLog.logMessage('EE provider registered')
def register_django_provider(): registry = QgsProviderRegistry.instance() if registry.providerMetadata(DjangoProvider.providerKey()): # already registered return metadata = QgsProviderMetadata(DjangoProvider.providerKey(), DjangoProvider.description(), DjangoProvider.createProvider) if not registry.registerProvider(metadata) or registry.providerMetadata( DjangoProvider.providerKey()) != metadata: raise Exception('Cannot register Django provider')
def setUp(self): model = Point generate_data(model=model, count=5) print('QGIS settings: %s' % QgsApplication.showSettings()) registry = QgsProviderRegistry.instance() metadata = QgsProviderMetadata(DjangoProvider.providerKey(), DjangoProvider.description(), DjangoProvider.createProvider) self.assertTrue(registry.registerProvider(metadata)) self.assertTrue( registry.providerMetadata(DjangoProvider.providerKey()) == metadata)
def __init__(self, iface): self.iface = iface self.plugin_dir = os.path.dirname(__file__) # Register all actions for cleanup on plugin unload. self.actions = [] self.menu = 'QGIS-ROS' self.toolbar = self.iface.addToolBar('QGIS-ROS') self.toolbar.setObjectName('QGIS-ROS') # Register the ROS vector data provider. metadata = QgsProviderMetadata(ROSVectorProvider.providerKey(), ROSVectorProvider.description(), ROSVectorProvider.createProvider) QgsProviderRegistry.instance().registerProvider(metadata) # Eager init dialogs and preserve state when re-opened in the future. self.bagFileDialog = BagfileDialog() self.rosMasterDialog = ROSMasterDialog()