Skip to content

Commit

Permalink
[FEATURE][ux] Use a filter line edit in symbol list tag combo
Browse files Browse the repository at this point in the history
This allows both filtering by selecting existing tags, and also
free-form text searches
  • Loading branch information
nyalldawson committed Sep 13, 2018
1 parent e4fc420 commit 833cdd8
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 55 deletions.
31 changes: 26 additions & 5 deletions src/gui/symbology/qgssymbolslistwidget.cpp
Expand Up @@ -88,7 +88,6 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style,
{
setupUi( this );
connect( mSymbolUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolsListWidget::mSymbolUnitWidget_changed );
connect( groupsCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSymbolsListWidget::groupsCombo_currentIndexChanged );
spinAngle->setClearValue( 0 );

mSymbolUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMetersInMapUnits << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
Expand Down Expand Up @@ -173,8 +172,14 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style,
QgsSettings().setValue( QStringLiteral( "UI/symbolsList/treeState" ), mSymbolTreeView->header()->saveState(), QgsSettings::Gui );
} );


QgsFilterLineEdit *groupEdit = new QgsFilterLineEdit();
groupEdit->setShowSearchIcon( true );
groupEdit->setShowClearButton( true );
groupEdit->setPlaceholderText( tr( "Filter symbols" ) );
groupsCombo->setLineEdit( groupEdit );
populateGroups();
connect( groupsCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSymbolsListWidget::groupsCombo_currentIndexChanged );
connect( groupsCombo, &QComboBox::currentTextChanged, this, &QgsSymbolsListWidget::updateModelFilters );

if ( mSymbol )
{
Expand Down Expand Up @@ -309,6 +314,7 @@ QgsSymbolWidgetContext QgsSymbolsListWidget::context() const

void QgsSymbolsListWidget::populateGroups()
{
mUpdatingGroups = true;
groupsCombo->blockSignals( true );
groupsCombo->clear();

Expand Down Expand Up @@ -344,36 +350,53 @@ void QgsSymbolsListWidget::populateGroups()
index = settings.value( QStringLiteral( "qgis/symbolsListGroupsIndex" ), 0 ).toInt();
groupsCombo->setCurrentIndex( index );

mUpdatingGroups = false;

updateModelFilters();
}

void QgsSymbolsListWidget::updateModelFilters()
{
if ( mUpdatingGroups )
return;

const QString text = groupsCombo->currentText();
const bool isFreeText = text != groupsCombo->itemText( groupsCombo->currentIndex() );

if ( groupsCombo->currentData().toString() == QLatin1String( "favorite" ) )
if ( isFreeText )
{
mModel->setFavoritesOnly( false );
mModel->setTagId( -1 );
mModel->setSmartGroupId( -1 );
mModel->setFilterString( groupsCombo->currentText() );
}
else if ( groupsCombo->currentData().toString() == QLatin1String( "favorite" ) )
{
mModel->setFavoritesOnly( true );
mModel->setTagId( -1 );
mModel->setSmartGroupId( -1 );
mModel->setFilterString( QString() );
}
else if ( groupsCombo->currentData().toString() == QLatin1String( "all" ) )
{
mModel->setFavoritesOnly( false );
mModel->setTagId( -1 );
mModel->setSmartGroupId( -1 );
mModel->setFilterString( QString() );
}
else if ( groupsCombo->currentData().toString() == QLatin1String( "smartgroup" ) )
{
mModel->setFavoritesOnly( false );
mModel->setTagId( -1 );
mModel->setSmartGroupId( mStyle->smartgroupId( text ) );
mModel->setFilterString( QString() );
}
else
{
mModel->setFavoritesOnly( false );
mModel->setTagId( mStyle->tagId( text ) );
mModel->setSmartGroupId( -1 );
mModel->setFilterString( QString() );
}
}

Expand Down Expand Up @@ -709,6 +732,4 @@ void QgsSymbolsListWidget::groupsCombo_currentIndexChanged( int index )
{
QgsSettings settings;
settings.setValue( QStringLiteral( "qgis/symbolsListGroupsIndex" ), index );

updateModelFilters();
}
1 change: 1 addition & 0 deletions src/gui/symbology/qgssymbolslistwidget.h
Expand Up @@ -128,6 +128,7 @@ class GUI_EXPORT QgsSymbolsListWidget : public QWidget, private Ui::SymbolsListW
QgsVectorLayer *mLayer = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
QgsStyleProxyModel *mModel = nullptr;
bool mUpdatingGroups = false;

void updateSymbolColor();
void updateSymbolInfo();
Expand Down
106 changes: 56 additions & 50 deletions src/ui/symbollayer/widget_symbolslist.ui
Expand Up @@ -41,13 +41,6 @@
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Symbols in</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="groupsCombo">
<property name="sizePolicy">
Expand All @@ -62,8 +55,11 @@
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Filter Symbols</string>
</property>
<property name="editable">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
Expand Down Expand Up @@ -164,50 +160,60 @@
<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>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="spacing">
<number>0</number>
</property>
<property name="autoRaise">
<bool>true</bool>
<property name="rightMargin">
<number>0</number>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<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>
</layout>
</item>
<item>
<widget class="QLabel" name="lblSymbolName">
Expand Down

0 comments on commit 833cdd8

Please sign in to comment.