Skip to content
Permalink
Browse files

Make style model refresh icons when svg cache fetches a remote image

  • Loading branch information
nyalldawson committed Sep 14, 2018
1 parent 57f89c9 commit 8c899d8f917c64cd06af57b5fda15acaae95e856
@@ -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;
@@ -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
@@ -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
//
@@ -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:

@@ -29,7 +29,6 @@
#include "qgssettings.h"
#include "qgsnewauxiliarylayerdialog.h"
#include "qgsauxiliarystorage.h"
#include "qgssvgcache.h"
#include "qgsstylemodel.h"

#include <QAction>
@@ -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()

0 comments on commit 8c899d8

Please sign in to comment.
You can’t perform that action at this time.