Example #1
0
    def testPathWriter(self):
        readerId = QgsPathResolver.setPathPreprocessor(self.__test_path_reader)
        writerId = QgsPathResolver.setPathWriter(self.__test__path_writer)

        lines_shp_path = os.path.join(TEST_DATA_DIR, 'lines.shp')

        lines_layer = QgsVectorLayer(lines_shp_path, 'Lines', 'ogr')
        self.assertTrue(lines_layer.isValid())
        p = QgsProject()
        p.addMapLayer(lines_layer)
        # save project to a temporary file
        temp_path = tempfile.mkdtemp()
        temp_project_path = os.path.join(temp_path, 'temp.qgs')
        self.assertTrue(p.write(temp_project_path))

        with open(temp_project_path) as f:
            self.assertTrue("@TEST_DATA_DIR@" in f.read())

        p2 = QgsProject()
        self.assertTrue(p2.read(temp_project_path))
        l = p2.mapLayersByName('Lines')[0]
        self.assertEqual(l.isValid(), True)
        self.assertEqual(l.source(), lines_shp_path)

        QgsPathResolver.removePathPreprocessor(readerId)
        QgsPathResolver.removePathWriter(writerId)
    def unload(self):
        try:
            self.iface.layoutDesignerOpened.disconnect()
        except Exception:
            pass
        try:
            self.iface.layoutDesignerClosed.disconnect()
        except Exception:
            pass
        try:
            self.actionCreateLayout.triggered.disconnect()
        except Exception:
            pass
        if self.pathPreprocessorId is not None:
            QgsPathResolver.removePathPreprocessor(self.pathPreprocessorId)
        # remove toolBar
        self.iface.removeToolBarIcon(self.actionCreateLayout)
        self.iface.mainWindow().removeToolBar(self.toolBar)
        del self.toolBar

        self.removeIconPath()
        self.removeColorScheme()
        self.removeWorldLayer()