[projects] Add signals for background color and selection color change

This commit is contained in:
nirvn 2019-10-07 12:01:57 +07:00 committed by Mathieu Pellerin
parent 6b1e31170e
commit 23cc659a05
4 changed files with 42 additions and 0 deletions

View File

@ -1412,6 +1412,24 @@ Emitted whenever the project's color scheme has been changed.
.. versionadded:: 3.6
%End
void backgroundColorChanged();
%Docstring
Emitted whenever the project's canvas background color has been changed.
.. seealso:: :py:func:`setBackgroundColor`
.. versionadded:: 3.10
%End
void selectionColorChanged();
%Docstring
Emitted whenever the project's selection color has been changed.
.. seealso:: :py:func:`setSelectionColor`
.. versionadded:: 3.10
%End
void layersWillBeRemoved( const QStringList &layerIds );
%Docstring

View File

@ -3206,6 +3206,8 @@ void QgsProject::setBackgroundColor( const QColor &color )
writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorRedPart" ), color.red() );
writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), color.green() );
writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), color.blue() );
emit backgroundColorChanged();
}
QColor QgsProject::backgroundColor() const
@ -3221,6 +3223,8 @@ void QgsProject::setSelectionColor( const QColor &color )
writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorGreenPart" ), color.green() );
writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorBluePart" ), color.blue() );
writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorAlphaPart" ), color.alpha() );
emit selectionColorChanged();
}
QColor QgsProject::selectionColor() const

View File

@ -1421,6 +1421,22 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
void projectColorsChanged();
/**
* Emitted whenever the project's canvas background color has been changed.
* \see setBackgroundColor()
* \since QGIS 3.10
*/
void backgroundColorChanged();
/**
* Emitted whenever the project's selection color has been changed.
* \see setSelectionColor()
* \since QGIS 3.10
*/
void selectionColorChanged();
//
// signals from QgsMapLayerRegistry
//

View File

@ -1242,7 +1242,9 @@ class TestQgsProject(unittest.TestCase):
blue = int(s.value("qgis/default_canvas_color_blue", 255))
# test default canvas backgroud color
self.assertEqual(p.backgroundColor(), QColor(red, green, blue))
spy = QSignalSpy(p.backgroundColorChanged)
p.setBackgroundColor(QColor(0, 0, 0))
self.assertEqual(len(spy), 1)
# test customized canvas background color
self.assertEqual(p.backgroundColor(), QColor(0, 0, 0))
@ -1256,7 +1258,9 @@ class TestQgsProject(unittest.TestCase):
alpha = int(s.value("qgis/default_selection_color_alpha", 255))
# test default feature selection color
self.assertEqual(p.selectionColor(), QColor(red, green, blue, alpha))
spy = QSignalSpy(p.selectionColorChanged)
p.setSelectionColor(QColor(0, 0, 0, 50))
self.assertEqual(len(spy), 1)
# test customized feature selection color
self.assertEqual(p.selectionColor(), QColor(0, 0, 0, 50))