def testSetColor(self): button = QgsFontButton() s = QgsTextFormat() s.setFont(getTestFont()) s.setNamedStyle('Italic') s.setSize(5) s.setColor(QColor(255, 0, 0)) s.setOpacity(0.5) button.setTextFormat(s) signal_spy = QSignalSpy(button.changed) button.setColor(QColor(0, 255, 0)) self.assertEqual(len(signal_spy), 1) r = button.textFormat() self.assertEqual(r.font().family(), 'QGIS Vera Sans') self.assertEqual(r.namedStyle(), 'Italic') self.assertEqual(r.size(), 5) self.assertEqual(r.color().name(), QColor(0, 255, 0).name()) self.assertEqual(r.opacity(), 0.5) # set same color, should not emit signal button.setColor(QColor(0, 255, 0)) self.assertEqual(len(signal_spy), 1) # color with transparency - should be stripped button.setColor(QColor(0, 255, 0, 100)) r = button.textFormat() self.assertEqual(r.color(), QColor(0, 255, 0))
def testNull(self): button = QgsFontButton() self.assertFalse(button.showNullFormat()) button.setShowNullFormat(True) self.assertTrue(button.showNullFormat()) s = QgsTextFormat() s.setFont(getTestFont()) button.setTextFormat(s) self.assertTrue(button.textFormat().isValid()) button.setToNullFormat() self.assertFalse(button.textFormat().isValid()) button.setTextFormat(s) self.assertTrue(button.textFormat().isValid())
def testSetGetFormat(self): button = QgsFontButton() s = QgsTextFormat() s.setFont(getTestFont()) s.setNamedStyle('Italic') s.setSize(5) s.setColor(QColor(255, 0, 0)) s.setOpacity(0.5) signal_spy = QSignalSpy(button.changed) button.setTextFormat(s) self.assertEqual(len(signal_spy), 1) r = button.textFormat() self.assertEqual(r.font().family(), 'QGIS Vera Sans') self.assertEqual(r.namedStyle(), 'Italic') self.assertEqual(r.size(), 5) self.assertEqual(r.color(), QColor(255, 0, 0)) self.assertEqual(r.opacity(), 0.5)