Skip to content
Permalink
Browse files

[FEATURE] Make symbol levels dialog a style dock panel widget

  • Loading branch information
nirvn committed Sep 13, 2017
1 parent 5e7dadd commit fe8b751eb53fcebd79055a49d12463f287594ca9
@@ -9,39 +9,69 @@



class QgsSymbolLevelsDialog : QDialog
class QgsSymbolLevelsWidget : QgsPanelWidget
{
%Docstring
A widget which allows the user to modify the rendering order of symbol layers.
.. seealso:: QgsSymbolLevelsDialog
.. versionadded:: 3.0
%End

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

~QgsSymbolLevelsDialog();

bool usingLevels() const;
%Docstring
Returns whether the level ordering is enabled
:rtype: bool
%End

void setForceOrderingEnabled( bool enabled );
%Docstring
Sets whether the level ordering is always forced on and hide the checkbox (used by rule-based renderer)
\param enabled toggle level ordering
%End

public slots:
void updateUi();

void renderingPassChanged( int row, int column );
void apply();
%Docstring
Apply button
%End

protected:




private:
QgsSymbolLevelsDialog();
QgsSymbolLevelsWidget();

};

class QgsSymbolLevelsDialog : QDialog
{
%Docstring
A dialog which allows the user to modify the rendering order of symbol layers.
.. seealso:: QgsSymbolLevelsWidget
%End

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

QgsSymbolLevelsDialog( QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsSymbolLevelsDialog.
%End

void setForceOrderingEnabled( bool enabled );

};

@@ -251,7 +251,18 @@ void QgsRendererWidget::changeSymbolAngle()

void QgsRendererWidget::showSymbolLevelsDialog( QgsFeatureRenderer *r )
{
QgsSymbolLevelsDialog dlg( r, r->usingSymbolLevels(), this );
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsSymbolLevelsWidget *widget = new QgsSymbolLevelsWidget( r, r->usingSymbolLevels(), panel );
widget->setPanelTitle( tr( "Symbol Levels" ) );
connect( widget, &QgsPanelWidget::widgetChanged, widget, &QgsSymbolLevelsWidget::apply );
connect( widget, &QgsPanelWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
panel->openPanel( widget );
return;
}

QgsSymbolLevelsDialog dlg( r, r->usingSymbolLevels(), panel );
if ( dlg.exec() )
{
emit widgetChanged();
@@ -396,7 +396,19 @@ void QgsRuleBasedRendererWidget::keyPressEvent( QKeyEvent *event )

void QgsRuleBasedRendererWidget::setRenderingOrder()
{
QgsSymbolLevelsDialog dlg( mRenderer, true, this );
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsSymbolLevelsWidget *widget = new QgsSymbolLevelsWidget( mRenderer, true, panel );
widget->setForceOrderingEnabled( true );
widget->setPanelTitle( tr( "Symbol Levels" ) );
connect( widget, &QgsPanelWidget::widgetChanged, widget, &QgsSymbolLevelsWidget::apply );
connect( widget, &QgsPanelWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
panel->openPanel( widget );
return;
}

QgsSymbolLevelsDialog dlg( mRenderer, true, panel );
dlg.setForceOrderingEnabled( true );
if ( dlg.exec() )
{
@@ -23,28 +23,23 @@
#include <QTableWidgetItem>
#include <QItemDelegate>
#include <QSpinBox>

#include <QDialogButtonBox>


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

QgsSymbolLevelsDialog::QgsSymbolLevelsDialog( QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent )
: QDialog( parent )
QgsSymbolLevelsWidget::QgsSymbolLevelsWidget( QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent )
: QgsPanelWidget( parent )
, mRenderer( renderer )
, mForceOrderingEnabled( false )
{
setupUi( this );

QgsSettings settings;
restoreGeometry( settings.value( QStringLiteral( "Windows/symbolLevelsDlg/geometry" ) ).toByteArray() );

tableLevels->setItemDelegate( new SpinBoxDelegate( this ) );

chkEnable->setChecked( usingSymbolLevels );

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

if ( mRenderer )
{
@@ -89,16 +84,10 @@ QgsSymbolLevelsDialog::QgsSymbolLevelsDialog( QgsFeatureRenderer *renderer, bool

populateTable();

connect( tableLevels, &QTableWidget::cellChanged, this, &QgsSymbolLevelsDialog::renderingPassChanged );
}

QgsSymbolLevelsDialog::~QgsSymbolLevelsDialog()
{
QgsSettings settings;
settings.setValue( QStringLiteral( "Windows/symbolLevelsDlg/geometry" ), saveGeometry() );
connect( tableLevels, &QTableWidget::cellChanged, this, &QgsSymbolLevelsWidget::renderingPassChanged );
}

void QgsSymbolLevelsDialog::populateTable()
void QgsSymbolLevelsWidget::populateTable()
{
for ( int row = 0; row < mList.count(); row++ )
{
@@ -128,12 +117,13 @@ void QgsSymbolLevelsDialog::populateTable()

}

void QgsSymbolLevelsDialog::updateUi()
void QgsSymbolLevelsWidget::updateUi()
{
tableLevels->setEnabled( chkEnable->isChecked() );
emit widgetChanged();
}

void QgsSymbolLevelsDialog::apply()
void QgsSymbolLevelsWidget::apply()
{
for ( int i = 0; i < mList.count(); i++ )
{
@@ -147,7 +137,7 @@ void QgsSymbolLevelsDialog::apply()
mRenderer->setUsingSymbolLevels( usingLevels() );
}

void QgsSymbolLevelsDialog::setDefaultLevels()
void QgsSymbolLevelsWidget::setDefaultLevels()
{
for ( int i = 0; i < mList.count(); i++ )
{
@@ -159,22 +149,24 @@ void QgsSymbolLevelsDialog::setDefaultLevels()
}
}

bool QgsSymbolLevelsDialog::usingLevels() const
bool QgsSymbolLevelsWidget::usingLevels() const
{
return chkEnable->isChecked();
}

void QgsSymbolLevelsDialog::renderingPassChanged( int row, int column )
void QgsSymbolLevelsWidget::renderingPassChanged( int row, int column )
{
if ( row < 0 || row >= mList.count() )
return;
QgsSymbol *sym = mList.at( row ).symbol();
if ( column < 0 || column > sym->symbolLayerCount() )
return;
sym->symbolLayer( column - 1 )->setRenderingPass( tableLevels->item( row, column )->text().toInt() );

emit widgetChanged();
}

void QgsSymbolLevelsDialog::setForceOrderingEnabled( bool enabled )
void QgsSymbolLevelsWidget::setForceOrderingEnabled( bool enabled )
{
mForceOrderingEnabled = enabled;
if ( enabled )
@@ -186,11 +178,24 @@ void QgsSymbolLevelsDialog::setForceOrderingEnabled( bool enabled )
chkEnable->show();
}

void QgsSymbolLevelsDialog::showHelp()
QgsSymbolLevelsDialog::QgsSymbolLevelsDialog( QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent )
: QDialog( parent )
{
QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#symbols-levels" ) );
QVBoxLayout *vLayout = new QVBoxLayout();
mWidget = new QgsSymbolLevelsWidget( renderer, usingSymbolLevels );
vLayout->addWidget( mWidget );
QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
connect( bbox, &QDialogButtonBox::accepted, mWidget, &QgsSymbolLevelsWidget::apply );
connect( bbox, &QDialogButtonBox::accepted, this, &QgsSymbolLevelsDialog::accept );
connect( bbox, &QDialogButtonBox::rejected, this, &QgsSymbolLevelsDialog::reject );
vLayout->addWidget( bbox );
setLayout( vLayout );
}

void QgsSymbolLevelsDialog::setForceOrderingEnabled( bool enabled )
{
mWidget->setForceOrderingEnabled( enabled );
}

/// @cond PRIVATE

@@ -21,38 +21,41 @@
#include <QItemDelegate>

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

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

/** \ingroup gui
* \class QgsSymbolLevelsDialog
/** \class QgsSymbolLevelsWidget
* \ingroup gui
* A widget which allows the user to modify the rendering order of symbol layers.
* \see QgsSymbolLevelsDialog
* \since QGIS 3.0
*/
class GUI_EXPORT QgsSymbolLevelsDialog : public QDialog, private Ui::QgsSymbolLevelsDialogBase
class GUI_EXPORT QgsSymbolLevelsWidget : public QgsPanelWidget, private Ui::QgsSymbolLevelsDialogBase
{
Q_OBJECT
public:
//! Constructor for QgsSymbolLevelsDialog
QgsSymbolLevelsDialog( QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent = nullptr );

~QgsSymbolLevelsDialog();
//! Constructor for QgsSymbolLevelsWidget
QgsSymbolLevelsWidget( QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent SIP_TRANSFERTHIS = 0 );

//! Returns whether the level ordering is enabled
bool usingLevels() const;

// used by rule-based renderer (to hide checkbox to enable/disable ordering)
/** Sets whether the level ordering is always forced on and hide the checkbox (used by rule-based renderer)
* \param enabled toggle level ordering
*/
void setForceOrderingEnabled( bool enabled );

public slots:
void updateUi();

void renderingPassChanged( int row, int column );

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

void showHelp();
private slots:
void updateUi();

void renderingPassChanged( int row, int column );

protected:
//! \note not available in Python bindings
@@ -71,11 +74,33 @@ class GUI_EXPORT QgsSymbolLevelsDialog : public QDialog, private Ui::QgsSymbolLe

private:
#ifdef SIP_RUN
QgsSymbolLevelsDialog();
QgsSymbolLevelsWidget();

#endif
};

/** \class QgsSymbolLevelsDialog
* \ingroup gui
* A dialog which allows the user to modify the rendering order of symbol layers.
* \see QgsSymbolLevelsWidget
*/
class GUI_EXPORT QgsSymbolLevelsDialog : public QDialog
{
Q_OBJECT
public:

//! Constructor for QgsSymbolLevelsDialog.
QgsSymbolLevelsDialog( QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent SIP_TRANSFERTHIS = 0 );

// used by rule-based renderer (to hide checkbox to enable/disable ordering)
void setForceOrderingEnabled( bool enabled );

private:

QgsSymbolLevelsWidget *mWidget = nullptr;

};

#ifndef SIP_RUN
///@cond PRIVATE

0 comments on commit fe8b751

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