Skip to content
Permalink
Browse files

[FEATURE] Add list view mode to style manager dialog

This was added to the symbol list widget in 3.4, and now it's
available in the style manager dialog too.
  • Loading branch information
nyalldawson committed Jan 14, 2019
1 parent b72e01f commit cd96ecd88cef311bb56b121c7df69879eeb00b96
Showing with 188 additions and 29 deletions.
  1. +48 −2 src/gui/symbology/qgsstylemanagerdialog.cpp
  2. +140 −27 src/ui/qgsstylemanagerdialogbase.ui
@@ -97,7 +97,7 @@ QVariant QgsCheckableStyleModel::data( const QModelIndex &index, int role ) cons

case Qt::CheckStateRole:
{
if ( !mCheckable )
if ( !mCheckable || index.column() != 0 )
return QVariant();

const QStringList tags = data( index, QgsStyleModel::TagRole ).toStringList();
@@ -194,11 +194,19 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,

double iconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 10;
listItems->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 = new QgsCheckableStyleModel( mStyle, this );
mModel->addDesiredIconSize( listItems->iconSize() );
mModel->addDesiredIconSize( mSymbolTreeView->iconSize() );
listItems->setModel( mModel );
mSymbolTreeView->setModel( mModel );

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

//connect( model, &QStandardItemModel::itemChanged, this, &QgsStyleManagerDialog::itemChanged );
connect( listItems->selectionModel(), &QItemSelectionModel::currentChanged,
@@ -237,6 +245,9 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,
listItems->setContextMenuPolicy( Qt::CustomContextMenu );
connect( listItems, &QWidget::customContextMenuRequested,
this, &QgsStyleManagerDialog::listitemsContextMenu );
mSymbolTreeView->setContextMenuPolicy( Qt::CustomContextMenu );
connect( mSymbolTreeView, &QWidget::customContextMenuRequested,
this, &QgsStyleManagerDialog::listitemsContextMenu );

// Menu for the "Add item" toolbutton when in colorramp mode
QStringList rampTypes;
@@ -286,6 +297,37 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,

connect( mStyle, &QgsStyle::symbolSaved, this, &QgsStyleManagerDialog::populateList );
connect( mStyle, &QgsStyle::groupsModified, this, &QgsStyleManagerDialog::populateGroups );

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( "Windows/StyleV2Manager/lastIconView" ), 0, QgsSettings::Gui );
}
} );
connect( mButtonListView, &QToolButton::toggled, this, [ = ]( bool active )
{
if ( active )
{
QgsSettings().setValue( QStringLiteral( "Windows/StyleV2Manager/lastIconView" ), 1, QgsSettings::Gui );
mSymbolViewStackedWidget->setCurrentIndex( 1 );
}
} );
// restore previous view
const int currentView = settings.value( QStringLiteral( "Windows/StyleV2Manager/lastIconView" ), 0, QgsSettings::Gui ).toInt();
if ( currentView == 0 )
mButtonIconView->setChecked( true );
else
mButtonListView->setChecked( true );

mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral( "Windows/StyleV2Manager/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( "Windows/StyleV2Manager/treeState" ), mSymbolTreeView->header()->saveState(), QgsSettings::Gui );
} );
}

void QgsStyleManagerDialog::onFinished()
@@ -1205,6 +1247,7 @@ void QgsStyleManagerDialog::tagSymbolsAction()

// Reset the selection mode
listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
mSymbolTreeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
}
else
{
@@ -1244,6 +1287,7 @@ void QgsStyleManagerDialog::tagSymbolsAction()

// No selection should be possible
listItems->setSelectionMode( QAbstractItemView::NoSelection );
mSymbolTreeView->setSelectionMode( QAbstractItemView::NoSelection );
}
}

@@ -1363,7 +1407,9 @@ void QgsStyleManagerDialog::grouptreeContextMenu( QPoint point )

void QgsStyleManagerDialog::listitemsContextMenu( QPoint point )
{
QPoint globalPos = listItems->viewport()->mapToGlobal( point );
QPoint globalPos = mSymbolViewStackedWidget->currentIndex() == 0
? listItems->viewport()->mapToGlobal( point )
: mSymbolTreeView->viewport()->mapToGlobal( point );

// Clear all actions and create new actions for every group
mGroupListMenu->clear();
@@ -209,6 +209,62 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="spacing">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</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/mActionIconView.svg</normaloff>:/images/themes/default/mActionIconView.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>
</layout>
</item>
</layout>
</item>
<item row="3" column="0">
@@ -284,34 +340,85 @@
</widget>
</item>
<item>
<widget class="QListView" name="listItems">
<property name="editTriggers">
<set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</property>
<property name="iconSize">
<size>
<width>77</width>
<height>70</height>
</size>
</property>
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>
<property name="movement">
<enum>QListView::Static</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="wordWrap">
<bool>true</bool>
<widget class="QStackedWidget" name="mSymbolViewStackedWidget">
<property name="currentIndex">
<number>0</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="listItems">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>2</verstretch>
</sizepolicy>
</property>
<property name="editTriggers">
<set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</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>
</layout>
@@ -506,10 +613,13 @@
<tabstop>btnShare</tabstop>
<tabstop>tabItemType</tabstop>
<tabstop>listItems</tabstop>
<tabstop>mSymbolTreeView</tabstop>
<tabstop>btnAddItem</tabstop>
<tabstop>btnRemoveItem</tabstop>
<tabstop>btnEditItem</tabstop>
<tabstop>searchBox</tabstop>
<tabstop>mButtonIconView</tabstop>
<tabstop>mButtonListView</tabstop>
</tabstops>
<resources>
<include location="../../images/images.qrc"/>
@@ -596,4 +706,7 @@
</hints>
</connection>
</connections>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

0 comments on commit cd96ecd

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