Skip to content

Commit

Permalink
Use button with a menu to add styles instead of input dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Apr 7, 2020
1 parent 9f74ecf commit ff380c5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
27 changes: 8 additions & 19 deletions src/gui/vectortile/qgsvectortilebasicrendererwidget.cpp
Expand Up @@ -24,6 +24,7 @@

#include <QAbstractListModel>
#include <QInputDialog>
#include <QMenu>


///@cond PRIVATE
Expand Down Expand Up @@ -340,7 +341,12 @@ QgsVectorTileBasicRendererWidget::QgsVectorTileBasicRendererWidget( QgsVectorTil
mModel = new QgsVectorTileBasicRendererListModel( mRenderer.get(), viewStyles );
viewStyles->setModel( mModel );

connect( btnAddRule, &QPushButton::clicked, this, &QgsVectorTileBasicRendererWidget::addStyle );
QMenu *menuAddRule = new QMenu( btnAddRule );
menuAddRule->addAction( tr( "Marker" ), this, [this] { addStyle( QgsWkbTypes::PointGeometry ); } );
menuAddRule->addAction( tr( "Line" ), this, [this] { addStyle( QgsWkbTypes::LineGeometry ); } );
menuAddRule->addAction( tr( "Fill" ), this, [this] { addStyle( QgsWkbTypes::PolygonGeometry ); } );
btnAddRule->setMenu( menuAddRule );

connect( btnEditRule, &QPushButton::clicked, this, &QgsVectorTileBasicRendererWidget::editStyle );
connect( btnRemoveRule, &QAbstractButton::clicked, this, &QgsVectorTileBasicRendererWidget::removeStyle );

Expand All @@ -358,25 +364,8 @@ void QgsVectorTileBasicRendererWidget::apply()
mVTLayer->setRenderer( mRenderer->clone() );
}

void QgsVectorTileBasicRendererWidget::addStyle()
void QgsVectorTileBasicRendererWidget::addStyle( QgsWkbTypes::GeometryType geomType )
{
QStringList lst;
lst << tr( "Marker" ) << tr( "Line" ) << tr( "Fill" );
QString type = QInputDialog::getItem( this, tr( "Add style" ), tr( "Please choose symbol type" ), lst, 0, false );
if ( type.isEmpty() )
return;
int index = lst.indexOf( type );

QgsWkbTypes::GeometryType geomType;
if ( index == 0 )
geomType = QgsWkbTypes::PointGeometry;
else if ( index == 1 )
geomType = QgsWkbTypes::LineGeometry;
else if ( index == 2 )
geomType = QgsWkbTypes::PolygonGeometry;
else
return;

QgsVectorTileBasicRendererStyle style( QString(), QString(), geomType );
style.setSymbol( QgsSymbol::defaultSymbol( geomType ) );

Expand Down
4 changes: 3 additions & 1 deletion src/gui/vectortile/qgsvectortilebasicrendererwidget.h
Expand Up @@ -20,6 +20,8 @@

#include "ui_qgsvectortilebasicrendererwidget.h"

#include "qgswkbtypes.h"

#include <memory>

///@cond PRIVATE
Expand Down Expand Up @@ -49,7 +51,7 @@ class GUI_EXPORT QgsVectorTileBasicRendererWidget : public QgsMapLayerConfigWidg
void apply() override;

private slots:
void addStyle();
void addStyle( QgsWkbTypes::GeometryType geomType );
void editStyle();
void editStyleAtIndex( const QModelIndex &index );
void removeStyle();
Expand Down
5 changes: 4 additions & 1 deletion src/ui/qgsvectortilebasicrendererwidget.ui
Expand Up @@ -36,7 +36,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="btnAddRule">
<widget class="QToolButton" name="btnAddRule">
<property name="toolTip">
<string>Add rule</string>
</property>
Expand All @@ -47,6 +47,9 @@
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
<item>
Expand Down

0 comments on commit ff380c5

Please sign in to comment.