Skip to content

Commit 454cbda

Browse files
committed
[FEATURE] Add button to toggle between the icon view and a list
view for symbols in symbol selector
1 parent 26885e5 commit 454cbda

File tree

2 files changed

+205
-42
lines changed

2 files changed

+205
-42
lines changed

src/gui/symbology/qgssymbolslistwidget.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,17 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style,
120120

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

124126
mModel->addDesiredIconSize( viewSymbols->iconSize() );
127+
mModel->addDesiredIconSize( mSymbolTreeView->iconSize() );
125128
viewSymbols->setModel( mModel );
129+
mSymbolTreeView->setModel( mModel );
130+
131+
viewSymbols->setSelectionBehavior( QAbstractItemView::SelectRows );
132+
mSymbolTreeView->setSelectionModel( viewSymbols->selectionModel() );
133+
mSymbolTreeView->setSelectionMode( viewSymbols->selectionMode() );
126134

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

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

133141
lblSymbolName->clear();
134142

143+
connect( mButtonIconView, &QToolButton::toggled, this, [ = ]( bool active )
144+
{
145+
if ( active )
146+
{
147+
mSymbolViewStackedWidget->setCurrentIndex( 0 );
148+
// note -- we have to save state here and not in destructor, as new symbol list widgets are created before the previous ones are destroyed
149+
QgsSettings().setValue( QStringLiteral( "UI/symbolsList/lastIconView" ), 0, QgsSettings::Gui );
150+
}
151+
} );
152+
connect( mButtonListView, &QToolButton::toggled, this, [ = ]( bool active )
153+
{
154+
if ( active )
155+
{
156+
QgsSettings().setValue( QStringLiteral( "UI/symbolsList/lastIconView" ), 1, QgsSettings::Gui );
157+
mSymbolViewStackedWidget->setCurrentIndex( 1 );
158+
}
159+
} );
160+
161+
// restore previous view
162+
QgsSettings settings;
163+
const int currentView = settings.value( QStringLiteral( "UI/symbolsList/lastIconView" ), 0, QgsSettings::Gui ).toInt();
164+
if ( currentView == 0 )
165+
mButtonIconView->setChecked( true );
166+
else
167+
mButtonListView->setChecked( true );
168+
169+
mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral( "UI/symbolsList/treeState" ), QByteArray(), QgsSettings::Gui ).toByteArray() );
170+
connect( mSymbolTreeView->header(), &QHeaderView::sectionResized, this, [this]
171+
{
172+
// note -- we have to save state here and not in destructor, as new symbol list widgets are created before the previous ones are destroyed
173+
QgsSettings().setValue( QStringLiteral( "UI/symbolsList/treeState" ), mSymbolTreeView->header()->saveState(), QgsSettings::Gui );
174+
} );
175+
176+
135177
populateGroups();
136178

137179
if ( mSymbol )

src/ui/symbollayer/widget_symbolslist.ui

+163-42
Original file line numberDiff line numberDiff line change
@@ -36,43 +36,6 @@
3636
</property>
3737
</widget>
3838
</item>
39-
<item row="3" column="0">
40-
<widget class="QListView" name="viewSymbols">
41-
<property name="sizePolicy">
42-
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
43-
<horstretch>0</horstretch>
44-
<verstretch>2</verstretch>
45-
</sizepolicy>
46-
</property>
47-
<property name="iconSize">
48-
<size>
49-
<width>77</width>
50-
<height>70</height>
51-
</size>
52-
</property>
53-
<property name="textElideMode">
54-
<enum>Qt::ElideNone</enum>
55-
</property>
56-
<property name="flow">
57-
<enum>QListView::LeftToRight</enum>
58-
</property>
59-
<property name="resizeMode">
60-
<enum>QListView::Adjust</enum>
61-
</property>
62-
<property name="spacing">
63-
<number>5</number>
64-
</property>
65-
<property name="viewMode">
66-
<enum>QListView::IconMode</enum>
67-
</property>
68-
<property name="uniformItemSizes">
69-
<bool>false</bool>
70-
</property>
71-
<property name="wordWrap">
72-
<bool>true</bool>
73-
</property>
74-
</widget>
75-
</item>
7639
<item row="2" column="0">
7740
<layout class="QHBoxLayout" name="horizontalLayout_3">
7841
<property name="spacing">
@@ -113,14 +76,139 @@
11376
</item>
11477
</layout>
11578
</item>
79+
<item row="3" column="0">
80+
<widget class="QStackedWidget" name="mSymbolViewStackedWidget">
81+
<property name="currentIndex">
82+
<number>1</number>
83+
</property>
84+
<widget class="QWidget" name="page">
85+
<layout class="QVBoxLayout" name="verticalLayout_2">
86+
<property name="leftMargin">
87+
<number>0</number>
88+
</property>
89+
<property name="topMargin">
90+
<number>0</number>
91+
</property>
92+
<property name="rightMargin">
93+
<number>0</number>
94+
</property>
95+
<property name="bottomMargin">
96+
<number>0</number>
97+
</property>
98+
<item>
99+
<widget class="QListView" name="viewSymbols">
100+
<property name="sizePolicy">
101+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
102+
<horstretch>0</horstretch>
103+
<verstretch>2</verstretch>
104+
</sizepolicy>
105+
</property>
106+
<property name="iconSize">
107+
<size>
108+
<width>77</width>
109+
<height>70</height>
110+
</size>
111+
</property>
112+
<property name="textElideMode">
113+
<enum>Qt::ElideNone</enum>
114+
</property>
115+
<property name="flow">
116+
<enum>QListView::LeftToRight</enum>
117+
</property>
118+
<property name="resizeMode">
119+
<enum>QListView::Adjust</enum>
120+
</property>
121+
<property name="spacing">
122+
<number>5</number>
123+
</property>
124+
<property name="viewMode">
125+
<enum>QListView::IconMode</enum>
126+
</property>
127+
<property name="uniformItemSizes">
128+
<bool>false</bool>
129+
</property>
130+
<property name="wordWrap">
131+
<bool>true</bool>
132+
</property>
133+
</widget>
134+
</item>
135+
</layout>
136+
</widget>
137+
<widget class="QWidget" name="page2">
138+
<layout class="QVBoxLayout" name="verticalLayout_3">
139+
<property name="leftMargin">
140+
<number>0</number>
141+
</property>
142+
<property name="topMargin">
143+
<number>0</number>
144+
</property>
145+
<property name="rightMargin">
146+
<number>0</number>
147+
</property>
148+
<property name="bottomMargin">
149+
<number>0</number>
150+
</property>
151+
<item>
152+
<widget class="QTreeView" name="mSymbolTreeView"/>
153+
</item>
154+
</layout>
155+
</widget>
156+
</widget>
157+
</item>
116158
<item row="4" column="0">
117159
<layout class="QHBoxLayout" name="horizontalLayout_4">
118-
<property name="topMargin">
119-
<number>2</number>
120-
</property>
121160
<property name="spacing">
122161
<number>6</number>
123162
</property>
163+
<property name="topMargin">
164+
<number>2</number>
165+
</property>
166+
<item>
167+
<widget class="QToolButton" name="mButtonIconView">
168+
<property name="toolTip">
169+
<string>Icon View</string>
170+
</property>
171+
<property name="text">
172+
<string>PushButton</string>
173+
</property>
174+
<property name="icon">
175+
<iconset resource="../../../images/images.qrc">
176+
<normaloff>:/images/themes/default/mActionFilterTableFields.svg</normaloff>:/images/themes/default/mActionFilterTableFields.svg</iconset>
177+
</property>
178+
<property name="checkable">
179+
<bool>true</bool>
180+
</property>
181+
<property name="autoRaise">
182+
<bool>true</bool>
183+
</property>
184+
<attribute name="buttonGroup">
185+
<string notr="true">buttonGroup</string>
186+
</attribute>
187+
</widget>
188+
</item>
189+
<item>
190+
<widget class="QToolButton" name="mButtonListView">
191+
<property name="toolTip">
192+
<string>List View</string>
193+
</property>
194+
<property name="text">
195+
<string>PushButton</string>
196+
</property>
197+
<property name="icon">
198+
<iconset resource="../../../images/images.qrc">
199+
<normaloff>:/images/themes/default/mActionOpenTable.svg</normaloff>:/images/themes/default/mActionOpenTable.svg</iconset>
200+
</property>
201+
<property name="checkable">
202+
<bool>true</bool>
203+
</property>
204+
<property name="autoRaise">
205+
<bool>true</bool>
206+
</property>
207+
<attribute name="buttonGroup">
208+
<string notr="true">buttonGroup</string>
209+
</attribute>
210+
</widget>
211+
</item>
124212
<item>
125213
<widget class="QLabel" name="lblSymbolName">
126214
<property name="text">
@@ -476,7 +564,6 @@
476564
<tabstop>mWidthDDBtn</tabstop>
477565
<tabstop>groupsCombo</tabstop>
478566
<tabstop>openStyleManagerButton</tabstop>
479-
<tabstop>viewSymbols</tabstop>
480567
<tabstop>btnSaveSymbol</tabstop>
481568
<tabstop>btnAdvanced</tabstop>
482569
<tabstop>spinSize</tabstop>
@@ -486,6 +573,40 @@
486573
<tabstop>spinWidth</tabstop>
487574
<tabstop>mWidthDDBtn</tabstop>
488575
</tabstops>
489-
<resources/>
576+
<resources>
577+
<include location="../../../images/images.qrc"/>
578+
<include location="../../../images/images.qrc"/>
579+
<include location="../../../images/images.qrc"/>
580+
<include location="../../../images/images.qrc"/>
581+
<include location="../../../images/images.qrc"/>
582+
<include location="../../../images/images.qrc"/>
583+
<include location="../../../images/images.qrc"/>
584+
<include location="../../../images/images.qrc"/>
585+
<include location="../../../images/images.qrc"/>
586+
<include location="../../../images/images.qrc"/>
587+
<include location="../../../images/images.qrc"/>
588+
<include location="../../../images/images.qrc"/>
589+
<include location="../../../images/images.qrc"/>
590+
<include location="../../../images/images.qrc"/>
591+
<include location="../../../images/images.qrc"/>
592+
<include location="../../../images/images.qrc"/>
593+
<include location="../../../images/images.qrc"/>
594+
<include location="../../../images/images.qrc"/>
595+
<include location="../../../images/images.qrc"/>
596+
<include location="../../../images/images.qrc"/>
597+
<include location="../../../images/images.qrc"/>
598+
<include location="../../../images/images.qrc"/>
599+
<include location="../../../images/images.qrc"/>
600+
<include location="../../../images/images.qrc"/>
601+
<include location="../../../images/images.qrc"/>
602+
<include location="../../../images/images.qrc"/>
603+
<include location="../../../images/images.qrc"/>
604+
<include location="../../../images/images.qrc"/>
605+
<include location="../../../images/images.qrc"/>
606+
<include location="../../../images/images.qrc"/>
607+
</resources>
490608
<connections/>
609+
<buttongroups>
610+
<buttongroup name="buttonGroup"/>
611+
</buttongroups>
491612
</ui>

0 commit comments

Comments
 (0)