Skip to content

Commit

Permalink
Allow adding/editing 3d symbols in style manager dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 29, 2020
1 parent ae3f2c3 commit d8e4453
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 7 deletions.
34 changes: 34 additions & 0 deletions python/gui/auto_generated/qgs3dsymbolwidget.sip.in
Expand Up @@ -40,6 +40,40 @@ Caller takes ownership of the returned symbol.
%End
};



class Qgs3DSymbolDialog : QDialog
{
%Docstring
A dialog for configuring a 3D symbol.

.. versionadded:: 3.16
%End

%TypeHeaderCode
#include "qgs3dsymbolwidget.h"
%End
public:

Qgs3DSymbolDialog( const QgsAbstract3DSymbol *symbol, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for Qgs3DSymbolDialog, initially showing the specified ``symbol``.
%End

QgsAbstract3DSymbol *symbol() const /Factory/;
%Docstring
Returns a new instance of the symbol defined by the dialog.

Caller takes ownership of the returned symbol.
%End

QDialogButtonBox *buttonBox() const;
%Docstring
Returns a reference to the dialog's button box.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
40 changes: 40 additions & 0 deletions src/gui/qgs3dsymbolwidget.cpp
Expand Up @@ -14,7 +14,47 @@
***************************************************************************/

#include "qgs3dsymbolwidget.h"
#include "qgsapplication.h"
#include "qgs3dsymbolregistry.h"
#include "qgsabstract3dsymbol.h"
#include "qgsgui.h"
#include <QVBoxLayout>
#include <QDialogButtonBox>

Qgs3DSymbolWidget::Qgs3DSymbolWidget( QWidget *parent )
: QWidget( parent )
{}

Qgs3DSymbolDialog::Qgs3DSymbolDialog( const QgsAbstract3DSymbol *symbol, QWidget *parent )
: QDialog( parent )
{
Q_ASSERT( symbol );

QgsGui::enableAutoGeometryRestore( this );

QVBoxLayout *vLayout = new QVBoxLayout();

if ( Qgs3DSymbolAbstractMetadata *metadata = QgsApplication::symbol3DRegistry()->symbolMetadata( symbol->type() ) )
{
mWidget = metadata->createSymbolWidget( nullptr );
vLayout->addWidget( mWidget );
mWidget->setSymbol( symbol, nullptr );
}

mButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok, Qt::Horizontal );
connect( mButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
connect( mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
vLayout->addWidget( mButtonBox );
setLayout( vLayout );
setWindowTitle( tr( "3D Symbol" ) );
}

QgsAbstract3DSymbol *Qgs3DSymbolDialog::symbol() const
{
return mWidget ? mWidget->symbol() : nullptr;
}

QDialogButtonBox *Qgs3DSymbolDialog::buttonBox() const
{
return mButtonBox;
}
39 changes: 39 additions & 0 deletions src/gui/qgs3dsymbolwidget.h
Expand Up @@ -17,11 +17,13 @@
#define QGS3DSYMBOLWIDGET_H

#include <QWidget>
#include <QDialog>
#include "qgis_gui.h"
#include "qgis_sip.h"

class QgsAbstract3DSymbol;
class QgsVectorLayer;
class QDialogButtonBox;

/**
* \ingroup gui
Expand Down Expand Up @@ -53,4 +55,41 @@ class GUI_EXPORT Qgs3DSymbolWidget : public QWidget
virtual QgsAbstract3DSymbol *symbol() = 0 SIP_FACTORY;
};



/**
* \ingroup gui
* \brief A dialog for configuring a 3D symbol.
* \since QGIS 3.16
*/
class GUI_EXPORT Qgs3DSymbolDialog : public QDialog
{
Q_OBJECT

public:

/**
* Constructor for Qgs3DSymbolDialog, initially showing the specified \a symbol.
*/
Qgs3DSymbolDialog( const QgsAbstract3DSymbol *symbol, QWidget *parent SIP_TRANSFERTHIS = nullptr );

/**
* Returns a new instance of the symbol defined by the dialog.
*
* Caller takes ownership of the returned symbol.
*/
QgsAbstract3DSymbol *symbol() const SIP_FACTORY;

/**
* Returns a reference to the dialog's button box.
*/
QDialogButtonBox *buttonBox() const;

private:

Qgs3DSymbolWidget *mWidget = nullptr;
QDialogButtonBox *mButtonBox = nullptr;

};

#endif // QGS3DSYMBOLWIDGET_H

0 comments on commit d8e4453

Please sign in to comment.