Skip to content

Commit

Permalink
[FEATURE] Add button to toggle between the icon view and a list
Browse files Browse the repository at this point in the history
view for symbols in symbol selector
  • Loading branch information
nyalldawson committed Sep 13, 2018
1 parent 26885e5 commit 454cbda
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 42 deletions.
42 changes: 42 additions & 0 deletions src/gui/symbology/qgssymbolslistwidget.cpp
Expand Up @@ -120,9 +120,17 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style,


double iconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 10; double iconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 10;
viewSymbols->setIconSize( QSize( static_cast< int >( iconSize ), static_cast< int >( iconSize * 0.9 ) ) ); // ~100, 90 on low dpi viewSymbols->setIconSize( QSize( static_cast< int >( iconSize ), static_cast< int >( iconSize * 0.9 ) ) ); // ~100, 90 on low dpi
double treeIconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 2;
mSymbolTreeView->setIconSize( QSize( static_cast< int >( treeIconSize ), static_cast< int >( treeIconSize ) ) );


mModel->addDesiredIconSize( viewSymbols->iconSize() ); mModel->addDesiredIconSize( viewSymbols->iconSize() );
mModel->addDesiredIconSize( mSymbolTreeView->iconSize() );
viewSymbols->setModel( mModel ); viewSymbols->setModel( mModel );
mSymbolTreeView->setModel( mModel );

viewSymbols->setSelectionBehavior( QAbstractItemView::SelectRows );
mSymbolTreeView->setSelectionModel( viewSymbols->selectionModel() );
mSymbolTreeView->setSelectionMode( viewSymbols->selectionMode() );


connect( viewSymbols->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSymbolsListWidget::setSymbolFromStyle ); connect( viewSymbols->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSymbolsListWidget::setSymbolFromStyle );


Expand All @@ -132,6 +140,40 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style,


lblSymbolName->clear(); lblSymbolName->clear();


connect( mButtonIconView, &QToolButton::toggled, this, [ = ]( bool active )
{
if ( active )
{
mSymbolViewStackedWidget->setCurrentIndex( 0 );
// note -- we have to save state here and not in destructor, as new symbol list widgets are created before the previous ones are destroyed
QgsSettings().setValue( QStringLiteral( "UI/symbolsList/lastIconView" ), 0, QgsSettings::Gui );
}
} );
connect( mButtonListView, &QToolButton::toggled, this, [ = ]( bool active )
{
if ( active )
{
QgsSettings().setValue( QStringLiteral( "UI/symbolsList/lastIconView" ), 1, QgsSettings::Gui );
mSymbolViewStackedWidget->setCurrentIndex( 1 );
}
} );

// restore previous view
QgsSettings settings;
const int currentView = settings.value( QStringLiteral( "UI/symbolsList/lastIconView" ), 0, QgsSettings::Gui ).toInt();
if ( currentView == 0 )
mButtonIconView->setChecked( true );
else
mButtonListView->setChecked( true );

mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral( "UI/symbolsList/treeState" ), QByteArray(), QgsSettings::Gui ).toByteArray() );
connect( mSymbolTreeView->header(), &QHeaderView::sectionResized, this, [this]
{
// note -- we have to save state here and not in destructor, as new symbol list widgets are created before the previous ones are destroyed
QgsSettings().setValue( QStringLiteral( "UI/symbolsList/treeState" ), mSymbolTreeView->header()->saveState(), QgsSettings::Gui );
} );


populateGroups(); populateGroups();


if ( mSymbol ) if ( mSymbol )
Expand Down
205 changes: 163 additions & 42 deletions src/ui/symbollayer/widget_symbolslist.ui
Expand Up @@ -36,43 +36,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QListView" name="viewSymbols">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>2</verstretch>
</sizepolicy>
</property>
<property name="iconSize">
<size>
<width>77</width>
<height>70</height>
</size>
</property>
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="spacing">
<number>5</number>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0"> <item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing"> <property name="spacing">
Expand Down Expand Up @@ -113,14 +76,139 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="3" column="0">
<widget class="QStackedWidget" name="mSymbolViewStackedWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QListView" name="viewSymbols">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>2</verstretch>
</sizepolicy>
</property>
<property name="iconSize">
<size>
<width>77</width>
<height>70</height>
</size>
</property>
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="spacing">
<number>5</number>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTreeView" name="mSymbolTreeView"/>
</item>
</layout>
</widget>
</widget>
</item>
<item row="4" column="0"> <item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="topMargin">
<number>2</number>
</property>
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<property name="topMargin">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="mButtonIconView">
<property name="toolTip">
<string>Icon View</string>
</property>
<property name="text">
<string>PushButton</string>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFilterTableFields.svg</normaloff>:/images/themes/default/mActionFilterTableFields.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QToolButton" name="mButtonListView">
<property name="toolTip">
<string>List View</string>
</property>
<property name="text">
<string>PushButton</string>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionOpenTable.svg</normaloff>:/images/themes/default/mActionOpenTable.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="lblSymbolName"> <widget class="QLabel" name="lblSymbolName">
<property name="text"> <property name="text">
Expand Down Expand Up @@ -476,7 +564,6 @@
<tabstop>mWidthDDBtn</tabstop> <tabstop>mWidthDDBtn</tabstop>
<tabstop>groupsCombo</tabstop> <tabstop>groupsCombo</tabstop>
<tabstop>openStyleManagerButton</tabstop> <tabstop>openStyleManagerButton</tabstop>
<tabstop>viewSymbols</tabstop>
<tabstop>btnSaveSymbol</tabstop> <tabstop>btnSaveSymbol</tabstop>
<tabstop>btnAdvanced</tabstop> <tabstop>btnAdvanced</tabstop>
<tabstop>spinSize</tabstop> <tabstop>spinSize</tabstop>
Expand All @@ -486,6 +573,40 @@
<tabstop>spinWidth</tabstop> <tabstop>spinWidth</tabstop>
<tabstop>mWidthDDBtn</tabstop> <tabstop>mWidthDDBtn</tabstop>
</tabstops> </tabstops>
<resources/> <resources>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
</resources>
<connections/> <connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui> </ui>

0 comments on commit 454cbda

Please sign in to comment.