Пример #1
0
    def testProjectStyle(self):
        project = QgsProject()
        settings = project.styleSettings()
        self.assertIsInstance(settings.projectStyle(), QgsStyle)
        self.assertEqual(settings.projectStyle().name(), 'Project Styles')

        text_format = QgsTextFormat()
        text_format.setColor(QColor(255, 0, 0))
        self.assertTrue(settings.projectStyle().addTextFormat(
            'my text format', text_format))
        self.assertTrue(settings.projectStyle().saveTextFormat(
            'my text format', text_format, True, []))
        self.assertEqual(settings.projectStyle().textFormatCount(), 1)

        tmp_dir = QTemporaryDir()
        tmp_project_file = "{}/project.qgs".format(tmp_dir.path())
        self.assertTrue(project.write(tmp_project_file))

        project.deleteLater()
        del project
        QCoreApplication.sendPostedEvents(None, QEvent.DeferredDelete)

        project2 = QgsProject()
        self.assertTrue(project2.read(tmp_project_file))
        self.assertEqual(
            project2.styleSettings().projectStyle().textFormatCount(), 1)
        self.assertEqual(
            project2.styleSettings().projectStyle().textFormat(
                'my text format').color().name(), '#ff0000')

        project2.clear()
        self.assertEqual(
            project2.styleSettings().projectStyle().textFormatCount(), 0)
Пример #2
0
    def testColorScheme(self):
        p = QgsProject.instance()
        spy = QSignalSpy(p.projectColorsChanged)
        p.setProjectColors([[QColor(255, 0, 0), 'red'], [QColor(0, 255, 0), 'green']])
        self.assertEqual(len(spy), 1)
        scheme = [s for s in QgsApplication.colorSchemeRegistry().schemes() if isinstance(s, QgsProjectColorScheme)][0]
        self.assertEqual([[c[0].name(), c[1]] for c in scheme.fetchColors()], [['#ff0000', 'red'], ['#00ff00', 'green']])
        # except color changed signal when clearing project
        p.clear()
        self.assertEqual(len(spy), 2)
        self.assertEqual([[c[0].name(), c[1]] for c in scheme.fetchColors()], [])

        # should be no signal on project destruction -- can cause a crash
        p = QgsProject()
        spy = QSignalSpy(p.projectColorsChanged)
        p.deleteLater()
        del p
        self.assertEqual(len(spy), 0)
Пример #3
0
    def testColorScheme(self):
        p = QgsProject.instance()
        spy = QSignalSpy(p.projectColorsChanged)
        p.setProjectColors([[QColor(255, 0, 0), 'red'], [QColor(0, 255, 0), 'green']])
        self.assertEqual(len(spy), 1)
        scheme = [s for s in QgsApplication.colorSchemeRegistry().schemes() if isinstance(s, QgsProjectColorScheme)][0]
        self.assertEqual([[c[0].name(), c[1]] for c in scheme.fetchColors()], [['#ff0000', 'red'], ['#00ff00', 'green']])
        # except color changed signal when clearing project
        p.clear()
        self.assertEqual(len(spy), 2)
        self.assertEqual([[c[0].name(), c[1]] for c in scheme.fetchColors()], [])

        # should be no signal on project destruction -- can cause a crash
        p = QgsProject()
        spy = QSignalSpy(p.projectColorsChanged)
        p.deleteLater()
        del p
        self.assertEqual(len(spy), 0)