Skip to content

Commit

Permalink
Auto update canvas, symbol preview, when project colors change
Browse files Browse the repository at this point in the history
Symbols may be using project colors, so the layers and previews
need to be updated when project color changes occur
  • Loading branch information
nyalldawson committed Jan 12, 2019
1 parent b0de40d commit da53f14
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/symbology/qgsstylemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgsapplication.h"
#include "qgssvgcache.h"
#include "qgsimagecache.h"
#include "qgsproject.h"
#include <QIcon>

const double ICON_PADDING_FACTOR = 0.16;
Expand Down Expand Up @@ -49,6 +50,10 @@ QgsStyleModel::QgsStyleModel( QgsStyle *style, QObject *parent )
// svg
connect( QgsApplication::svgCache(), &QgsSvgCache::remoteSvgFetched, this, &QgsStyleModel::rebuildSymbolIcons );
connect( QgsApplication::imageCache(), &QgsImageCache::remoteImageFetched, this, &QgsStyleModel::rebuildSymbolIcons );

// if project color scheme changes, we need to redraw symbols - they may use project colors and accordingly
// need updating to reflect the new colors
connect( QgsProject::instance(), &QgsProject::projectColorsChanged, this, &QgsStyleModel::rebuildSymbolIcons );
}

QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
// refresh canvas when a remote svg/image has finished downloading
connect( QgsApplication::svgCache(), &QgsSvgCache::remoteSvgFetched, this, &QgsMapCanvas::refreshAllLayers );
connect( QgsApplication::imageCache(), &QgsImageCache::remoteImageFetched, this, &QgsMapCanvas::refreshAllLayers );
// refresh canvas when project color scheme is changed -- if layers use project colors, they need to be redrawn
connect( QgsProject::instance(), &QgsProject::projectColorsChanged, this, &QgsMapCanvas::refreshAllLayers );

//segmentation parameters
QgsSettings settings;
Expand Down
9 changes: 9 additions & 0 deletions src/gui/symbology/qgssymbolselectordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "qgsvectorlayer.h"
#include "qgssvgcache.h"
#include "qgsimagecache.h"
#include "qgsproject.h"

#include <QColorDialog>
#include <QPainter>
Expand Down Expand Up @@ -314,6 +315,14 @@ QgsSymbolSelectorWidget::QgsSymbolSelectorWidget( QgsSymbol *symbol, QgsStyle *s
symbolChanged();
updatePreview();
} );

connect( QgsProject::instance(), &QgsProject::projectColorsChanged, this, [ = ]
{
// if project color scheme changes, we need to redraw symbols - they may use project colors and accordingly
// need updating to reflect the new colors
symbolChanged();
updatePreview();
} );
}

QMenu *QgsSymbolSelectorWidget::advancedMenu()
Expand Down

0 comments on commit da53f14

Please sign in to comment.