Skip to content
Permalink
Browse files
[symbology] Add a thumbnail size slider to style manager dialog
Cos sometimes the thumbnail sizes are just too small to get a good
representation of a symbol!

Sponsored by North Road
  • Loading branch information
nyalldawson committed Nov 2, 2021
1 parent 9272035 commit 9693f8d2c351e9457947685aa8be1df43f235f74
Showing with 52 additions and 10 deletions.
  1. +20 −5 src/gui/symbology/qgsstylemanagerdialog.cpp
  2. +2 −0 src/gui/symbology/qgsstylemanagerdialog.h
  3. +2 −3 src/ui/qgsstyleitemslistwidgetbase.ui
  4. +28 −2 src/ui/qgsstylemanagerdialogbase.ui
@@ -278,17 +278,12 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,
connect( exportAction, &QAction::triggered, this, &QgsStyleManagerDialog::exportItems );
btnShare->setMenu( shareMenu );

double iconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 10;
listItems->setIconSize( QSize( static_cast< int >( iconSize ), static_cast< int >( iconSize * 0.9 ) ) ); // ~100, 90 on low dpi
// set a grid size which allows sufficient vertical spacing to fit reasonably sized entity names
listItems->setGridSize( QSize( static_cast< int >( listItems->iconSize().width() * 1.4 ), static_cast< int >( listItems->iconSize().height() * 1.7 ) ) );
listItems->setTextElideMode( Qt::TextElideMode::ElideRight );
double treeIconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 2;
mSymbolTreeView->setIconSize( QSize( static_cast< int >( treeIconSize ), static_cast< int >( treeIconSize ) ) );

mModel = mStyle == QgsStyle::defaultStyle() ? new QgsCheckableStyleModel( QgsApplication::defaultStyleModel(), this, mReadOnly )
: new QgsCheckableStyleModel( mStyle, this, mReadOnly );
mModel->addDesiredIconSize( listItems->iconSize() );
mModel->addDesiredIconSize( mSymbolTreeView->iconSize() );
listItems->setModel( mModel );
mSymbolTreeView->setModel( mModel );
@@ -515,6 +510,11 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,
QgsSettings().setValue( QStringLiteral( "Windows/StyleV2Manager/treeState" ), mSymbolTreeView->header()->saveState(), QgsSettings::Gui );
} );

const int thumbnailSize = settings.value( QStringLiteral( "Windows/StyleV2Manager/thumbnailSize" ), 0, QgsSettings::Gui ).toInt();
mSliderIconSize->setValue( thumbnailSize );
connect( mSliderIconSize, &QSlider::valueChanged, this, &QgsStyleManagerDialog::setThumbnailSize );
setThumbnailSize( thumbnailSize );

// set initial disabled state for actions requiring a selection
selectedSymbolsChanged( QItemSelection(), QItemSelection() );
}
@@ -734,6 +734,21 @@ void QgsStyleManagerDialog::pasteItem()
}
}

void QgsStyleManagerDialog::setThumbnailSize( int value )
{
// value ranges from 0-10
const double iconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * ( value * 2.5 + 10 );
// set a grid size which allows sufficient vertical spacing to fit reasonably sized entity names
const double spacing = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * ( value * 2.2 + 14 );
const double verticalSpacing = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 7
+ iconSize * 0.8;
listItems->setIconSize( QSize( static_cast< int >( iconSize ), static_cast< int >( iconSize * 0.9 ) ) );
listItems->setGridSize( QSize( static_cast< int >( spacing ), static_cast< int >( verticalSpacing ) ) );
mModel->addDesiredIconSize( listItems->iconSize() );

QgsSettings().setValue( QStringLiteral( "Windows/StyleV2Manager/thumbnailSize" ), value, QgsSettings::Gui );
}

int QgsStyleManagerDialog::selectedItemType()
{
QModelIndex index = listItems->selectionModel()->currentIndex();
@@ -347,6 +347,8 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan

void pasteItem();

void setThumbnailSize( int );

private:
int selectedItemType();

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>386</width>
<height>619</height>
<width>563</width>
<height>633</height>
</rect>
</property>
<property name="windowTitle">
@@ -267,7 +267,6 @@
</tabstops>
<resources>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
</resources>
<connections/>
<buttongroups>
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>867</width>
<height>410</height>
<width>950</width>
<height>419</height>
</rect>
</property>
<property name="windowTitle">
@@ -212,6 +212,31 @@
</property>
</spacer>
</item>
<item>
<widget class="QSlider" name="mSliderIconSize">
<property name="toolTip">
<string>Thumbnail size</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>10</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>0</number>
</property>
<property name="tracking">
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="spacing">
@@ -672,6 +697,7 @@
<tabstop>btnRemoveItem</tabstop>
<tabstop>btnEditItem</tabstop>
<tabstop>mCopyToDefaultButton</tabstop>
<tabstop>mSliderIconSize</tabstop>
<tabstop>mButtonIconView</tabstop>
<tabstop>mButtonListView</tabstop>
<tabstop>searchBox</tabstop>

0 comments on commit 9693f8d

Please sign in to comment.