Skip to content
Permalink
Browse files

Use panel widget for data-defined size legend

  • Loading branch information
wonder-sk committed Jun 21, 2017
1 parent 5cff21f commit f33974e9e0b2efb4c290fdac28a6db05ffecdbc7
@@ -239,7 +239,7 @@
%Include symbology-ng/qgscategorizedsymbolrendererwidget.sip
%Include symbology-ng/qgscptcitycolorrampdialog.sip
%Include symbology-ng/qgsdashspacedialog.sip
%Include symbology-ng/qgsdatadefinedsizelegenddialog.sip
%Include symbology-ng/qgsdatadefinedsizelegendwidget.sip
%Include symbology-ng/qgsellipsesymbollayerwidget.sip
%Include symbology-ng/qgsgraduatedhistogramwidget.sip
%Include symbology-ng/qgsgraduatedsymbolrendererwidget.sip
@@ -1,7 +1,7 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/symbology-ng/qgsdatadefinedsizelegenddialog.h *
* src/gui/symbology-ng/qgsdatadefinedsizelegendwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -12,23 +12,23 @@



class QgsDataDefinedSizeLegendDialog : QDialog
class QgsDataDefinedSizeLegendWidget : QgsPanelWidget
{
%Docstring
Dialog for configuration of appearance of legend for marker symbols with data-defined size.
Widget for configuration of appearance of legend for marker symbols with data-defined size.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsdatadefinedsizelegenddialog.h"
#include "qgsdatadefinedsizelegendwidget.h"
%End
public:
explicit QgsDataDefinedSizeLegendDialog( const QgsDataDefinedSizeLegend *ddsLegend, const QgsProperty &ddSize, QgsMarkerSymbol *overrideSymbol /Transfer/, QgsMapCanvas *canvas = 0, QWidget *parent /TransferThis/ = 0 );
explicit QgsDataDefinedSizeLegendWidget( const QgsDataDefinedSizeLegend *ddsLegend, const QgsProperty &ddSize, QgsMarkerSymbol *overrideSymbol /Transfer/, QgsMapCanvas *canvas = 0, QWidget *parent /TransferThis/ = 0 );
%Docstring
when the symbol is given from outside rather than being set inside QgsDataDefinedSizeLegend.
%End
~QgsDataDefinedSizeLegendDialog();
~QgsDataDefinedSizeLegendWidget();

QgsDataDefinedSizeLegend *dataDefinedSizeLegend() const /Factory/;
%Docstring
@@ -43,7 +43,7 @@ Returns configuration as set up in the dialog (may be null). Ownership is passed
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/symbology-ng/qgsdatadefinedsizelegenddialog.h *
* src/gui/symbology-ng/qgsdatadefinedsizelegendwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -86,10 +86,10 @@ and by connecting the slot contextMenuViewCategories(const QPoint&)*
%End
virtual void refreshSymbolView();

QgsDataDefinedSizeLegend *showDataDefinedSizeLegendDialog( const QgsMarkerSymbol *symbol, const QgsDataDefinedSizeLegend *ddsLegend, bool *ok /Out/ ) /Factory/;
QgsDataDefinedSizeLegendWidget *openDataDefinedSizeLegendWidget( const QgsMarkerSymbol *symbol, const QgsDataDefinedSizeLegend *ddsLegend );
%Docstring
.. versionadded:: 3.0
:rtype: QgsDataDefinedSizeLegend
:rtype: QgsDataDefinedSizeLegendWidget
%End

protected slots:
@@ -22,7 +22,7 @@
#include "qgsproject.h"
#include "qgsapplication.h"
#include "qgsdatadefinedsizelegend.h"
#include "qgsdatadefinedsizelegenddialog.h"
#include "qgsdatadefinedsizelegendwidget.h"
#include "qgsdiagramproperties.h"
#include "qgsdiagramrenderer.h"
#include "qgslabelengineconfigdialog.h"
@@ -947,9 +947,15 @@ void QgsDiagramProperties::showSizeLegendDialog()
QgsProperty ddSize = isExpression ? QgsProperty::fromExpression( sizeFieldNameOrExp ) : QgsProperty::fromField( sizeFieldNameOrExp );
ddSize.setTransformer( new QgsSizeScaleTransformer( QgsSizeScaleTransformer::Linear, 0.0, mMaxValueSpinBox->value(), 0.0, mSizeSpinBox->value() ) );

QgsDataDefinedSizeLegendDialog dlg( mSizeLegend.get(), ddSize, nullptr, mMapCanvas );
if ( !dlg.exec() )
return;

mSizeLegend.reset( dlg.dataDefinedSizeLegend() );
QgsDataDefinedSizeLegendWidget *panel = new QgsDataDefinedSizeLegendWidget( mSizeLegend.get(), ddSize, nullptr, mMapCanvas );

QDialog dlg;
dlg.setLayout( new QVBoxLayout() );
dlg.setWindowTitle( panel->panelTitle() );
dlg.layout()->addWidget( panel );
QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok );
connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
dlg.layout()->addWidget( buttonBox );
if ( dlg.exec() )
mSizeLegend.reset( panel->dataDefinedSizeLegend() );
}
@@ -18,7 +18,7 @@ SET(QGIS_GUI_SRCS
symbology-ng/qgscategorizedsymbolrendererwidget.cpp
symbology-ng/qgscptcitycolorrampdialog.cpp
symbology-ng/qgsdashspacedialog.cpp
symbology-ng/qgsdatadefinedsizelegenddialog.cpp
symbology-ng/qgsdatadefinedsizelegendwidget.cpp
symbology-ng/qgsellipsesymbollayerwidget.cpp
symbology-ng/qgsgraduatedhistogramwidget.cpp
symbology-ng/qgsgraduatedsymbolrendererwidget.cpp
@@ -494,7 +494,7 @@ SET(QGIS_GUI_MOC_HDRS
symbology-ng/qgscategorizedsymbolrendererwidget.h
symbology-ng/qgscptcitycolorrampdialog.h
symbology-ng/qgsdashspacedialog.h
symbology-ng/qgsdatadefinedsizelegenddialog.h
symbology-ng/qgsdatadefinedsizelegendwidget.h
symbology-ng/qgsellipsesymbollayerwidget.h
symbology-ng/qgsgraduatedhistogramwidget.h
symbology-ng/qgsgraduatedsymbolrendererwidget.h
@@ -19,6 +19,7 @@
#include "qgscategorizedsymbolrenderer.h"

#include "qgsdatadefinedsizelegend.h"
#include "qgsdatadefinedsizelegendwidget.h"
#include "qgssymbol.h"
#include "qgssymbollayerutils.h"
#include "qgscolorramp.h"
@@ -1044,12 +1045,14 @@ QgsExpressionContext QgsCategorizedSymbolRendererWidget::createExpressionContext

void QgsCategorizedSymbolRendererWidget::dataDefinedSizeLegend()
{
bool ok;
QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( mCategorizedSymbol ); // this should be only enabled for marker symbols
std::unique_ptr<QgsDataDefinedSizeLegend> ddsLegend( showDataDefinedSizeLegendDialog( s, mRenderer->dataDefinedSizeLegend(), &ok ) );
if ( ok )
QgsDataDefinedSizeLegendWidget *panel = openDataDefinedSizeLegendWidget( s, mRenderer->dataDefinedSizeLegend() );
if ( panel )
{
mRenderer->setDataDefinedSizeLegend( ddsLegend.release() ); // ownership is passed from dlg to renderer
emit widgetChanged();
connect( panel, &QgsPanelWidget::widgetChanged, [ = ]
{
mRenderer->setDataDefinedSizeLegend( panel->dataDefinedSizeLegend() );
emit widgetChanged();
} );
}
}
@@ -1,5 +1,5 @@
/***************************************************************************
qgsdatadefinedsizelegenddialog.cpp
qgsdatadefinedsizelegendwidget.cpp
--------------------------------------
Date : June 2017
Copyright : (C) 2017 by Martin Dobias
@@ -13,7 +13,7 @@
* *
***************************************************************************/

#include "qgsdatadefinedsizelegenddialog.h"
#include "qgsdatadefinedsizelegendwidget.h"

#include <QInputDialog>

@@ -28,12 +28,13 @@
#include "qgssymbolselectordialog.h"
#include "qgsvectorlayer.h"

QgsDataDefinedSizeLegendDialog::QgsDataDefinedSizeLegendDialog( const QgsDataDefinedSizeLegend *ddsLegend, const QgsProperty &ddSize, QgsMarkerSymbol *overrideSymbol, QgsMapCanvas *canvas, QWidget *parent )
: QDialog( parent )
QgsDataDefinedSizeLegendWidget::QgsDataDefinedSizeLegendWidget( const QgsDataDefinedSizeLegend *ddsLegend, const QgsProperty &ddSize, QgsMarkerSymbol *overrideSymbol, QgsMapCanvas *canvas, QWidget *parent )
: QgsPanelWidget( parent )
, mSizeProperty( ddSize )
, mMapCanvas( canvas )
{
setupUi( this );
setPanelTitle( tr( "Data-defined size legend" ) );

QgsMarkerSymbol *symbol = nullptr;

@@ -89,9 +90,9 @@ QgsDataDefinedSizeLegendDialog::QgsDataDefinedSizeLegendDialog( const QgsDataDef
mSizeClassesModel->sort( 0 );
}

connect( groupManualSizeClasses, &QGroupBox::clicked, this, &QgsDataDefinedSizeLegendDialog::updatePreview );
connect( btnAddClass, &QToolButton::clicked, this, &QgsDataDefinedSizeLegendDialog::addSizeClass );
connect( btnRemoveClass, &QToolButton::clicked, this, &QgsDataDefinedSizeLegendDialog::removeSizeClass );
connect( groupManualSizeClasses, &QGroupBox::clicked, this, &QgsDataDefinedSizeLegendWidget::updatePreview );
connect( btnAddClass, &QToolButton::clicked, this, &QgsDataDefinedSizeLegendWidget::addSizeClass );
connect( btnRemoveClass, &QToolButton::clicked, this, &QgsDataDefinedSizeLegendWidget::removeSizeClass );

viewSizeClasses->setModel( mSizeClassesModel );

@@ -104,22 +105,23 @@ QgsDataDefinedSizeLegendDialog::QgsDataDefinedSizeLegendDialog( const QgsDataDef
mPreviewModel->setLegendMapViewData( canvas->mapUnitsPerPixel(), canvas->mapSettings().outputDpi(), canvas->scale() );
viewLayerTree->setModel( mPreviewModel );

connect( cboAlignSymbols, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), [ = ] { updatePreview(); } );
connect( radDisabled, &QRadioButton::clicked, this, &QgsDataDefinedSizeLegendDialog::updatePreview );
connect( radSeparated, &QRadioButton::clicked, this, &QgsDataDefinedSizeLegendDialog::updatePreview );
connect( radCollapsed, &QRadioButton::clicked, this, &QgsDataDefinedSizeLegendDialog::updatePreview );
connect( btnChangeSymbol, &QPushButton::clicked, this, &QgsDataDefinedSizeLegendDialog::changeSymbol );
connect( cboAlignSymbols, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), [ = ] { emit widgetChanged(); } );
connect( radDisabled, &QRadioButton::clicked, this, &QgsPanelWidget::widgetChanged );
connect( radSeparated, &QRadioButton::clicked, this, &QgsPanelWidget::widgetChanged );
connect( radCollapsed, &QRadioButton::clicked, this, &QgsPanelWidget::widgetChanged );
connect( btnChangeSymbol, &QPushButton::clicked, this, &QgsDataDefinedSizeLegendWidget::changeSymbol );
connect( this, &QgsPanelWidget::widgetChanged, this, &QgsDataDefinedSizeLegendWidget::updatePreview );
updatePreview();
}

QgsDataDefinedSizeLegendDialog::~QgsDataDefinedSizeLegendDialog()
QgsDataDefinedSizeLegendWidget::~QgsDataDefinedSizeLegendWidget()
{
delete mPreviewModel;
delete mPreviewTree;
delete mPreviewLayer;
}

QgsDataDefinedSizeLegend *QgsDataDefinedSizeLegendDialog::dataDefinedSizeLegend() const
QgsDataDefinedSizeLegend *QgsDataDefinedSizeLegendWidget::dataDefinedSizeLegend() const
{
if ( radDisabled->isChecked() )
return nullptr;
@@ -146,7 +148,7 @@ QgsDataDefinedSizeLegend *QgsDataDefinedSizeLegendDialog::dataDefinedSizeLegend(
return ddsLegend;
}

void QgsDataDefinedSizeLegendDialog::updatePreview()
void QgsDataDefinedSizeLegendWidget::updatePreview()
{
QgsMarkerSymbol *symbol = mSourceSymbol->clone();
symbol->setDataDefinedSize( mSizeProperty );
@@ -157,7 +159,7 @@ void QgsDataDefinedSizeLegendDialog::updatePreview()
viewLayerTree->expandAll();
}

void QgsDataDefinedSizeLegendDialog::changeSymbol()
void QgsDataDefinedSizeLegendWidget::changeSymbol()
{
std::unique_ptr<QgsMarkerSymbol> newSymbol( mSourceSymbol->clone() );
QgsSymbolWidgetContext context;
@@ -188,7 +190,7 @@ void QgsDataDefinedSizeLegendDialog::changeSymbol()
updatePreview();
}

void QgsDataDefinedSizeLegendDialog::addSizeClass()
void QgsDataDefinedSizeLegendWidget::addSizeClass()
{
bool ok;
double v = QInputDialog::getDouble( this, tr( "Add Size Class" ), tr( "Enter value for a new class" ),
@@ -204,7 +206,7 @@ void QgsDataDefinedSizeLegendDialog::addSizeClass()
updatePreview();
}

void QgsDataDefinedSizeLegendDialog::removeSizeClass()
void QgsDataDefinedSizeLegendWidget::removeSizeClass()
{
QModelIndex idx = viewSizeClasses->currentIndex();
if ( !idx.isValid() )
@@ -1,5 +1,5 @@
/***************************************************************************
qgsdatadefinedsizelegenddialog.h
qgsdatadefinedsizelegendwidget.h
--------------------------------------
Date : June 2017
Copyright : (C) 2017 by Martin Dobias
@@ -13,16 +13,16 @@
* *
***************************************************************************/

#ifndef QGSDATADEFINEDSIZELEGENDDIALOG_H
#define QGSDATADEFINEDSIZELEGENDDIALOG_H
#ifndef QGSDATADEFINEDSIZELEGENDWIDGET_H
#define QGSDATADEFINEDSIZELEGENDWIDGET_H

#include "qgis.h"
#include "qgis_gui.h"

#include <memory>
#include <QDialog>
#include <ui_qgsdatadefinedsizelegenddialog.h>
#include <ui_qgsdatadefinedsizelegendwidget.h>

#include "qgspanelwidget.h"
#include "qgsproperty.h"

class QStandardItemModel;
@@ -37,20 +37,20 @@ class QgsProperty;
class QgsVectorLayer;

/** \ingroup gui
* Dialog for configuration of appearance of legend for marker symbols with data-defined size.
* Widget for configuration of appearance of legend for marker symbols with data-defined size.
*
* \since QGIS 3.0
*/
class GUI_EXPORT QgsDataDefinedSizeLegendDialog : public QDialog, private Ui::QgsDataDefinedSizeLegendDialog
class GUI_EXPORT QgsDataDefinedSizeLegendWidget : public QgsPanelWidget, private Ui::QgsDataDefinedSizeLegendWidget
{
Q_OBJECT
public:
//! Creates the dialog and initializes the content to what is passed in the legend configuration (may be null).
//! The ddSize argument determines scaling of the marker symbol - it should have a size scale transformer assigned
//! to know the range of sizes. The overrideSymbol argument may override the source symbol: this is useful in case
//! when the symbol is given from outside rather than being set inside QgsDataDefinedSizeLegend.
explicit QgsDataDefinedSizeLegendDialog( const QgsDataDefinedSizeLegend *ddsLegend, const QgsProperty &ddSize, QgsMarkerSymbol *overrideSymbol SIP_TRANSFER, QgsMapCanvas *canvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
~QgsDataDefinedSizeLegendDialog();
explicit QgsDataDefinedSizeLegendWidget( const QgsDataDefinedSizeLegend *ddsLegend, const QgsProperty &ddSize, QgsMarkerSymbol *overrideSymbol SIP_TRANSFER, QgsMapCanvas *canvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
~QgsDataDefinedSizeLegendWidget();

//! Returns configuration as set up in the dialog (may be null). Ownership is passed to the caller.
QgsDataDefinedSizeLegend *dataDefinedSizeLegend() const SIP_FACTORY;
@@ -75,4 +75,4 @@ class GUI_EXPORT QgsDataDefinedSizeLegendDialog : public QDialog, private Ui::Qg
QStandardItemModel *mSizeClassesModel;
};

#endif // QGSDATADEFINEDSIZELEGENDDIALOG_H
#endif // QGSDATADEFINEDSIZELEGENDWIDGET_H
@@ -16,6 +16,7 @@
#include "qgspanelwidget.h"

#include "qgsdatadefinedsizelegend.h"
#include "qgsdatadefinedsizelegendwidget.h"
#include "qgssymbol.h"
#include "qgssymbollayerutils.h"
#include "qgscolorramp.h"
@@ -1176,12 +1177,14 @@ void QgsGraduatedSymbolRendererWidget::keyPressEvent( QKeyEvent *event )

void QgsGraduatedSymbolRendererWidget::dataDefinedSizeLegend()
{
bool ok;
QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( mGraduatedSymbol ); // this should be only enabled for marker symbols
std::unique_ptr<QgsDataDefinedSizeLegend> ddsLegend( showDataDefinedSizeLegendDialog( s, mRenderer->dataDefinedSizeLegend(), &ok ) );
if ( ok )
QgsDataDefinedSizeLegendWidget *panel = openDataDefinedSizeLegendWidget( s, mRenderer->dataDefinedSizeLegend() );
if ( panel )
{
mRenderer->setDataDefinedSizeLegend( ddsLegend.release() ); // ownership is passed from dlg to renderer
emit widgetChanged();
connect( panel, &QgsPanelWidget::widgetChanged, [ = ]
{
mRenderer->setDataDefinedSizeLegend( panel->dataDefinedSizeLegend() );
emit widgetChanged();
} );
}
}
@@ -14,7 +14,7 @@
***************************************************************************/
#include "qgsrendererwidget.h"

#include "qgsdatadefinedsizelegenddialog.h"
#include "qgsdatadefinedsizelegendwidget.h"
#include "qgssymbol.h"
#include "qgsvectorlayer.h"
#include "qgscolordialog.h"
@@ -275,10 +275,8 @@ void QgsRendererWidget::applyChanges()
apply();
}

QgsDataDefinedSizeLegend *QgsRendererWidget::showDataDefinedSizeLegendDialog( const QgsMarkerSymbol *symbol, const QgsDataDefinedSizeLegend *ddsLegend, bool *ok )
QgsDataDefinedSizeLegendWidget *QgsRendererWidget::openDataDefinedSizeLegendWidget( const QgsMarkerSymbol *symbol, const QgsDataDefinedSizeLegend *ddsLegend )
{
*ok = false;

QgsProperty ddSize = symbol->dataDefinedSize();
if ( !ddSize || !ddSize.isActive() )
{
@@ -291,12 +289,10 @@ QgsDataDefinedSizeLegend *QgsRendererWidget::showDataDefinedSizeLegendDialog( co
return nullptr;
}

QgsDataDefinedSizeLegendDialog dlg( ddsLegend, ddSize, symbol->clone(), mContext.mapCanvas() );
if ( !dlg.exec() )
return nullptr;

*ok = true;
return dlg.dataDefinedSizeLegend();
QgsDataDefinedSizeLegendWidget *panel = new QgsDataDefinedSizeLegendWidget( ddsLegend, ddSize, symbol->clone(), mContext.mapCanvas() );
connect( panel, &QgsPanelWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
openPanel( panel );
return panel;
}


0 comments on commit f33974e

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