Skip to content

Commit

Permalink
[symbology] resurrect symbol levels dialog (fixes #16996)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Sep 13, 2017
1 parent 5796783 commit 5e7dadd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
8 changes: 8 additions & 0 deletions python/gui/symbology/qgssymbollevelsdialog.sip
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@




class QgsSymbolLevelsDialog : QDialog
{

%TypeHeaderCode
#include "qgssymbollevelsdialog.h"
%End
public:
QgsSymbolLevelsDialog( QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent = 0 );
%Docstring
Constructor for QgsSymbolLevelsDialog
%End

~QgsSymbolLevelsDialog();

Expand All @@ -33,8 +38,11 @@ class QgsSymbolLevelsDialog : QDialog
protected:




private:
QgsSymbolLevelsDialog();

};


Expand Down
4 changes: 1 addition & 3 deletions src/gui/symbology/qgsrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,9 @@ void QgsRendererWidget::changeSymbolAngle()

void QgsRendererWidget::showSymbolLevelsDialog( QgsFeatureRenderer *r )
{
QgsSymbolLevelsDialog dlg( r->legendSymbolItems(), r->usingSymbolLevels(), this );

QgsSymbolLevelsDialog dlg( r, r->usingSymbolLevels(), this );
if ( dlg.exec() )
{
r->setUsingSymbolLevels( dlg.usingLevels() );
emit widgetChanged();
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/gui/symbology/qgsrulebasedrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,12 @@ void QgsRuleBasedRendererWidget::keyPressEvent( QKeyEvent *event )

void QgsRuleBasedRendererWidget::setRenderingOrder()
{
QgsSymbolLevelsDialog dlg( mRenderer->legendSymbolItems(), true, this );
QgsSymbolLevelsDialog dlg( mRenderer, true, this );
dlg.setForceOrderingEnabled( true );

dlg.exec();
if ( dlg.exec() )
{
emit widgetChanged();
}
}

void QgsRuleBasedRendererWidget::saveSectionWidth( int section, int oldSize, int newSize )
Expand Down
29 changes: 24 additions & 5 deletions src/gui/symbology/qgssymbollevelsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@

////////////////

QgsSymbolLevelsDialog::QgsSymbolLevelsDialog( const QgsLegendSymbolList &list, bool usingSymbolLevels, QWidget *parent )
QgsSymbolLevelsDialog::QgsSymbolLevelsDialog( QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent )
: QDialog( parent )
, mRenderer( renderer )
, mForceOrderingEnabled( false )
{
setupUi( this );
Expand All @@ -42,13 +43,17 @@ QgsSymbolLevelsDialog::QgsSymbolLevelsDialog( const QgsLegendSymbolList &list, b
chkEnable->setChecked( usingSymbolLevels );

connect( chkEnable, &QAbstractButton::clicked, this, &QgsSymbolLevelsDialog::updateUi );
connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsSymbolLevelsDialog::apply );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsSymbolLevelsDialog::showHelp );

// only consider entries with symbols
Q_FOREACH ( const QgsLegendSymbolItem &item, list )
if ( mRenderer )
{
if ( item.symbol() )
mList << item;
// only consider entries with symbols
Q_FOREACH ( const QgsLegendSymbolItem &item, mRenderer->legendSymbolItems() )
{
if ( item.symbol() )
mList << item;
}
}

int maxLayers = 0;
Expand Down Expand Up @@ -128,6 +133,20 @@ void QgsSymbolLevelsDialog::updateUi()
tableLevels->setEnabled( chkEnable->isChecked() );
}

void QgsSymbolLevelsDialog::apply()
{
for ( int i = 0; i < mList.count(); i++ )
{
QgsSymbol *sym = mList.at( i ).symbol();
for ( int layer = 0; layer < sym->symbolLayerCount(); layer++ )
{
mRenderer->setLegendSymbolItem( mList.at( i ).ruleKey(), sym->clone() );
}
}

mRenderer->setUsingSymbolLevels( usingLevels() );
}

void QgsSymbolLevelsDialog::setDefaultLevels()
{
for ( int i = 0; i < mList.count(); i++ )
Expand Down
14 changes: 11 additions & 3 deletions src/gui/symbology/qgssymbollevelsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
#include <QList>
#include <QItemDelegate>

#include "qgsrenderer.h"
#include "qgshelp.h"
#include "qgsrenderer.h"

#include "ui_qgssymbollevelsdialogbase.h"
#include "qgis_gui.h"

Expand All @@ -32,8 +33,8 @@ class GUI_EXPORT QgsSymbolLevelsDialog : public QDialog, private Ui::QgsSymbolLe
{
Q_OBJECT
public:
//! \note not available in Python bindings
QgsSymbolLevelsDialog( const QgsLegendSymbolList &list, bool usingSymbolLevels, QWidget *parent = nullptr ) SIP_SKIP;
//! Constructor for QgsSymbolLevelsDialog
QgsSymbolLevelsDialog( QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent = nullptr );

~QgsSymbolLevelsDialog();

Expand All @@ -48,6 +49,9 @@ class GUI_EXPORT QgsSymbolLevelsDialog : public QDialog, private Ui::QgsSymbolLe
void renderingPassChanged( int row, int column );

private slots:
//! Apply button
void apply();

void showHelp();

protected:
Expand All @@ -58,13 +62,17 @@ class GUI_EXPORT QgsSymbolLevelsDialog : public QDialog, private Ui::QgsSymbolLe

//! maximal number of layers from all symbols
int mMaxLayers;

QgsFeatureRenderer *mRenderer;
QgsLegendSymbolList mList;

//! whether symbol layers always should be used (default false)
bool mForceOrderingEnabled;

private:
#ifdef SIP_RUN
QgsSymbolLevelsDialog();

#endif
};

Expand Down

0 comments on commit 5e7dadd

Please sign in to comment.