Skip to content
Permalink
Browse files

Show 3d symbol library selector in 3d symbol widget

  • Loading branch information
nyalldawson committed Jul 29, 2020
1 parent 396540a commit 680e0952f0d5890172e87ec73ab6398a835a49ba
Showing with 71 additions and 2 deletions.
  1. +63 −2 src/app/3d/qgssymbol3dwidget.cpp
  2. +8 −0 src/app/3d/qgssymbol3dwidget.h
@@ -23,13 +23,16 @@
#include "qgspoint3dsymbolwidget.h"
#include "qgspolygon3dsymbolwidget.h"
#include "qgsabstractmaterialsettings.h"

#include "qgsstyleitemslistwidget.h"
#include "qgsstylesavedialog.h"
#include "qgsvectorlayer.h"

#include <QStackedWidget>
#include <QMessageBox>


QgsSymbol3DWidget::QgsSymbol3DWidget( QWidget *parent ) : QWidget( parent )
QgsSymbol3DWidget::QgsSymbol3DWidget( QWidget *parent )
: QWidget( parent )
{
widgetUnsupported = new QLabel( tr( "Sorry, this symbol is not supported." ), this );
widgetLine = new QgsLine3DSymbolWidget( this );
@@ -46,6 +49,15 @@ QgsSymbol3DWidget::QgsSymbol3DWidget( QWidget *parent ) : QWidget( parent )
layout->setContentsMargins( 0, 0, 0, 0 );
layout->addWidget( widgetStack );

mStyleWidget = new QgsStyleItemsListWidget( this );
mStyleWidget->setStyle( QgsStyle::defaultStyle() );
mStyleWidget->setEntityType( QgsStyle::Symbol3DEntity );

connect( mStyleWidget, &QgsStyleItemsListWidget::selectionChanged, this, &QgsSymbol3DWidget::setSymbolFromStyle );
connect( mStyleWidget, &QgsStyleItemsListWidget::saveEntity, this, &QgsSymbol3DWidget::saveSymbol );

layout->addWidget( mStyleWidget );

connect( widgetLine, &QgsLine3DSymbolWidget::changed, this, &QgsSymbol3DWidget::widgetChanged );
connect( widgetPoint, &QgsPoint3DSymbolWidget::changed, this, &QgsSymbol3DWidget::widgetChanged );
connect( widgetPolygon, &QgsPolygon3DSymbolWidget::changed, this, &QgsSymbol3DWidget::widgetChanged );
@@ -118,3 +130,52 @@ void QgsSymbol3DWidget::setSymbol( const QgsAbstract3DSymbol *symbol, QgsVectorL
}
widgetStack->setCurrentIndex( pageIndex );
}

void QgsSymbol3DWidget::setSymbolFromStyle( const QString &name )
{
// get new instance of symbol from style
std::unique_ptr< QgsAbstract3DSymbol > s( QgsStyle::defaultStyle()->symbol3D( name ) );
if ( !s )
return;

if ( s->type() == QStringLiteral( "point" ) )
widgetPoint->setSymbol( s.release(), nullptr );
else if ( s->type() == QStringLiteral( "line" ) )
widgetLine->setSymbol( s.release(), nullptr );
else if ( s->type() == QStringLiteral( "polygon" ) )
widgetPolygon->setSymbol( s.release(), nullptr );
}

void QgsSymbol3DWidget::saveSymbol()
{
QgsStyleSaveDialog saveDlg( this, QgsStyle::Symbol3DEntity );
saveDlg.setDefaultTags( mStyleWidget->currentTagFilter() );
if ( !saveDlg.exec() )
return;

if ( saveDlg.name().isEmpty() )
return;

// check if there is no symbol with same name
if ( QgsStyle::defaultStyle()->symbol3DNames().contains( saveDlg.name() ) )
{
int res = QMessageBox::warning( this, tr( "Save 3D Symbol" ),
tr( "A 3D symbol with the name '%1' already exists. Overwrite?" )
.arg( saveDlg.name() ),
QMessageBox::Yes | QMessageBox::No );
if ( res != QMessageBox::Yes )
{
return;
}
QgsStyle::defaultStyle()->removeEntityByName( QgsStyle::Symbol3DEntity, saveDlg.name() );
}

QStringList symbolTags = saveDlg.tags().split( ',' );

// add new symbol to style and re-populate the list
QgsAbstract3DSymbol *newSymbol = symbol();
QgsStyle::defaultStyle()->addSymbol3D( saveDlg.name(), newSymbol );

// make sure the symbol is stored
QgsStyle::defaultStyle()->saveSymbol3D( saveDlg.name(), newSymbol, saveDlg.isFavorite(), symbolTags );
}
@@ -26,6 +26,7 @@ class QgsAbstract3DSymbol;
class QgsLine3DSymbolWidget;
class QgsPoint3DSymbolWidget;
class QgsPolygon3DSymbolWidget;
class QgsStyleItemsListWidget;

class QgsVectorLayer;

@@ -48,6 +49,11 @@ class QgsSymbol3DWidget : public QWidget
signals:
void widgetChanged();

private slots:

void setSymbolFromStyle( const QString &name );
void saveSymbol();

private:

QStackedWidget *widgetStack = nullptr;
@@ -56,6 +62,8 @@ class QgsSymbol3DWidget : public QWidget
QgsPolygon3DSymbolWidget *widgetPolygon = nullptr;
QLabel *widgetUnsupported = nullptr;

QgsStyleItemsListWidget *mStyleWidget = nullptr;

};


0 comments on commit 680e095

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