Skip to content

Commit

Permalink
Make style model refresh icons when svg cache fetches a remote image
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 14, 2018
1 parent 57f89c9 commit 8c899d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/core/symbology/qgsstylemodel.cpp
Expand Up @@ -16,6 +16,8 @@
#include "qgsstylemodel.h"
#include "qgsstyle.h"
#include "qgssymbollayerutils.h"
#include "qgsapplication.h"
#include "qgssvgcache.h"
#include <QIcon>

const double ICON_PADDING_FACTOR = 0.16;
Expand All @@ -38,6 +40,13 @@ QgsStyleModel::QgsStyleModel( QgsStyle *style, QObject *parent )
connect( mStyle, &QgsStyle::rampRenamed, this, &QgsStyleModel::onRampRename );

connect( mStyle, &QgsStyle::entityTagsChanged, this, &QgsStyleModel::onTagsChanged );

// when a remote svg has been fetched, update the model's decorations.
// this is required if a symbol utilizes remote svgs, and the current icons
// have been generated using the temporary "downloading" svg. In this case
// we require the preview to be regenerated to use the correct fetched
// svg
connect( QgsApplication::svgCache(), &QgsSvgCache::remoteSvgFetched, this, &QgsStyleModel::rebuildSymbolIcons );
}

QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const
Expand Down Expand Up @@ -403,6 +412,12 @@ void QgsStyleModel::onTagsChanged( int entity, const QString &name, const QStrin
emit dataChanged( i, i );
}

void QgsStyleModel::rebuildSymbolIcons()
{
mSymbolIconCache.clear();
emit dataChanged( index( 0, 0 ), index( mSymbolNames.count() - 1, 0 ), QVector<int>() << Qt::DecorationRole );
}

//
// QgsStyleProxyModel
//
Expand Down
1 change: 1 addition & 0 deletions src/core/symbology/qgsstylemodel.h
Expand Up @@ -96,6 +96,7 @@ class CORE_EXPORT QgsStyleModel: public QAbstractItemModel
void onRampChanged( const QString &name );
void onRampRename( const QString &oldName, const QString &newName );
void onTagsChanged( int entity, const QString &name, const QStringList &tags );
void rebuildSymbolIcons();

private:

Expand Down
8 changes: 0 additions & 8 deletions src/gui/symbology/qgssymbolslistwidget.cpp
Expand Up @@ -29,7 +29,6 @@
#include "qgssettings.h"
#include "qgsnewauxiliarylayerdialog.h"
#include "qgsauxiliarystorage.h"
#include "qgssvgcache.h"
#include "qgsstylemodel.h"

#include <QAction>
Expand Down Expand Up @@ -210,13 +209,6 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style,
connect( btnSaveSymbol, &QPushButton::clicked, this, &QgsSymbolsListWidget::saveSymbol );

connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsSymbolsListWidget::opacityChanged );

// when a remote svg has been fetched, update the widget's previews
// this is required if the symbol utilizes remote svgs, and the current previews
// have been generated using the temporary "downloading" svg. In this case
// we require the preview to be regenerated to use the correct fetched
// svg
connect( QgsApplication::svgCache(), &QgsSvgCache::remoteSvgFetched, this, &QgsSymbolsListWidget::updateModelFilters );
}

QgsSymbolsListWidget::~QgsSymbolsListWidget()
Expand Down

0 comments on commit 8c899d8

Please sign in to comment.