Skip to content

Commit

Permalink
[styledock] inline effects widget
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Jun 6, 2016
1 parent ad5f970 commit 4556a0d
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 20 deletions.
13 changes: 13 additions & 0 deletions python/gui/effects/qgseffectstackpropertieswidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class QgsEffectStackPropertiesWidget : QWidget
*/
void changeEffect( QgsPaintEffect* newEffect );

signals:
/**
* Emiited when something in the widget changes.
*/
void widgetChanged();

protected:

/** Refreshes the widget to reflect the current state of the stack.
Expand Down Expand Up @@ -182,6 +188,13 @@ class QgsEffectStackCompactWidget : QWidget
*/
void setPreviewPicture( const QPicture& picture );

/**
* Set the widget in dock mode. In dock mode the widget will emit a signal
* to show the effects selector instead of opening a dialog.
* @param dockMode True to enable dock mode.
*/
void setDockMode( bool dockMode );

signals:

/** Emitted when the paint effect properties change
Expand Down
12 changes: 12 additions & 0 deletions python/gui/symbology-ng/qgsrendererv2propertiesdialog.sip
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ class QgsRendererV2PropertiesDialog : QDialog
//! Apply and accept the changes for the dialog.
void onOK();

/** Shows a panel widget inside the renderer widget.
* @param container widget panel to show
* @note added in QGIS 2.16
*/
void showPanel( QgsRendererWidgetContainer *container );

/**
* Closes the given panel in the stack of panels.
* @param container The container widget to close.
*/
void closePanel( QgsRendererWidgetContainer *container );

protected:
/**
* Connect the given slot to the value changed event for the set of widgets
Expand Down
11 changes: 5 additions & 6 deletions python/gui/symbology-ng/qgsrendererv2widget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ class QgsRendererV2Widget : QWidget
*/
void applyChanges();

/** Shows a panel widget inside the renderer widget.
* @param container widget panel to show
* @note added in QGIS 2.16
*/
void showPanel( QWidget *container );

signals:
/**
* Emitted when expression context variables on the associated
Expand All @@ -59,7 +53,12 @@ class QgsRendererV2Widget : QWidget
*/
void widgetChanged();

/** Shows a panel widget inside the renderer widget.
* @param container widget panel to show
* @note added in QGIS 2.16
*/
void panelOpened( bool opened );

protected:
/** Subclasses may provide the capability of changing multiple symbols at once by implementing the following two methods
and by connecting the slot contextMenuViewCategories(const QPoint&)*/
Expand Down
23 changes: 22 additions & 1 deletion python/gui/symbology-ng/qgsrendererwidgetcontainer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,32 @@ class QgsRendererWidgetContainer : QWidget
QWidget* widget();

signals:

/**
* @brief Emitted when the container is accpeted and closed.
* Listen to this to clean up the callers state.
*/
void accepted();
void accepted( QgsRendererWidgetContainer* container );

/**
* Emiited when the internal widget changes state.
* @param conatiner The container holding the widget that changed state.
*/
void widgetChanged( QgsRendererWidgetContainer* conatiner );

public slots:

/**
* Accept the container. Causes accepted to be emiited.
*/
void accept();

/**
* Fire the widgetChanged event on the container. Connect your widgets dirty signal to
* this slot to fire the and listen to widgetChanged to handle the event.
*/
void emitWidgetChanged();


protected:
void keyPressEvent( QKeyEvent* event );
Expand Down
50 changes: 42 additions & 8 deletions src/gui/effects/qgseffectstackpropertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qgspainteffectwidget.h"
#include "qgsapplication.h"
#include "qgssymbollayerv2utils.h"
#include "qgsrendererwidgetcontainer.h"

#include <QPicture>
#include <QPainter>
Expand Down Expand Up @@ -219,6 +220,7 @@ void QgsEffectStackPropertiesWidget::updatePreview()
painter.end();

lblPreview->setPixmap( QPixmap::fromImage( previewImage ) );
emit widgetChanged();
}

EffectItem* QgsEffectStackPropertiesWidget::currentEffectItem()
Expand Down Expand Up @@ -378,6 +380,7 @@ void QgsEffectStackPropertiesDialog::setPreviewPicture( const QPicture &picture

QgsEffectStackCompactWidget::QgsEffectStackCompactWidget( QWidget *parent , QgsPaintEffect *effect )
: QWidget( parent )
, mDockMode( false )
, mEnabledCheckBox( nullptr )
, mButton( nullptr )
, mPreviewPicture( nullptr )
Expand Down Expand Up @@ -447,18 +450,34 @@ void QgsEffectStackCompactWidget::showDialog()
return;

QgsEffectStack* clone = static_cast<QgsEffectStack*>( mStack->clone() );
QgsEffectStackPropertiesDialog dialog( clone, this );
if ( mPreviewPicture )
if ( mDockMode )
{
dialog.setPreviewPicture( *mPreviewPicture );
QgsEffectStackPropertiesWidget* widget = new QgsEffectStackPropertiesWidget( clone, nullptr );
if ( mPreviewPicture )
{
widget->setPreviewPicture( *mPreviewPicture );
}
QgsRendererWidgetContainer* container = new QgsRendererWidgetContainer( widget, tr( "Effects Properties" ), nullptr );
connect( widget, SIGNAL( widgetChanged() ), container, SLOT( emitWidgetChanged() ) );
connect( container, SIGNAL( widgetChanged( QgsRendererWidgetContainer* ) ), this, SLOT( updateFromContainer( QgsRendererWidgetContainer* ) ) );
connect( container, SIGNAL( accepted( QgsRendererWidgetContainer* ) ), this, SLOT( cleanUpContainer( QgsRendererWidgetContainer* ) ) );
emit showPanel( container );
}
if ( dialog.exec() == QDialog::Accepted )
else
{
*mStack = *clone;
emit changed();
}
QgsEffectStackPropertiesDialog dialog( clone, this );
if ( mPreviewPicture )
{
dialog.setPreviewPicture( *mPreviewPicture );
}
if ( dialog.exec() == QDialog::Accepted )
{
*mStack = *clone;
emit changed();
}

delete clone;
delete clone;
}
}

void QgsEffectStackCompactWidget::enableToggled( bool checked )
Expand All @@ -472,3 +491,18 @@ void QgsEffectStackCompactWidget::enableToggled( bool checked )
mButton->setEnabled( checked );
emit changed();
}

void QgsEffectStackCompactWidget::cleanUpContainer( QgsRendererWidgetContainer *container )
{
QgsEffectStackPropertiesWidget* widget = qobject_cast<QgsEffectStackPropertiesWidget*>( container->widget() );
*mStack = *widget->stack();
emit changed();
// delete widget->stack();
}

void QgsEffectStackCompactWidget::updateFromContainer( QgsRendererWidgetContainer *container )
{
QgsEffectStackPropertiesWidget* widget = qobject_cast<QgsEffectStackPropertiesWidget*>( container->widget() );
*mStack = *widget->stack();
emit changed();
}
22 changes: 21 additions & 1 deletion src/gui/effects/qgseffectstackpropertieswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class EffectItem;
class QgsPaintEffect;
class QCheckBox;
class QToolButton;
class QgsRendererWidgetContainer;

/** \ingroup gui
* \class QgsEffectStackPropertiesWidget
Expand Down Expand Up @@ -63,6 +64,12 @@ class GUI_EXPORT QgsEffectStackPropertiesWidget : public QWidget, private Ui::Qg
*/
void setPreviewPicture( const QPicture& picture );

signals:
/**
* Emiited when something in the widget changes.
*/
void widgetChanged();

public slots:

/** Moves the currently selected effect down in the stack.
Expand Down Expand Up @@ -198,7 +205,7 @@ class GUI_EXPORT QgsEffectStackCompactWidget: public QWidget
QgsEffectStackCompactWidget( QWidget* parent = nullptr, QgsPaintEffect* effect = nullptr );
~QgsEffectStackCompactWidget();

/** Sets paint effect attached to the widget
/** Sets paint effect attached to the widget,
* @param effect QgsPaintEffect for modification by the widget. If the effect
* is not a QgsEffectStack, it will be automatically converted to an effect
* stack consisting of the original effect
Expand All @@ -217,19 +224,32 @@ class GUI_EXPORT QgsEffectStackCompactWidget: public QWidget
*/
void setPreviewPicture( const QPicture &picture );

/**
* Set the widget in dock mode. In dock mode the widget will emit a signal
* to show the effects selector instead of opening a dialog.
* @param dockMode True to enable dock mode.
*/
void setDockMode( bool dockMode ) { mDockMode = dockMode; }

signals:

/** Emitted when the paint effect properties change
*/
void changed();

void showPanel( QgsRendererWidgetContainer* widget );

private slots:

void showDialog();

void enableToggled( bool checked );

void cleanUpContainer( QgsRendererWidgetContainer* container );
void updateFromContainer( QgsRendererWidgetContainer *container );

private:
bool mDockMode;

QgsEffectStack* mStack;
QCheckBox* mEnabledCheckBox;
Expand Down
3 changes: 3 additions & 0 deletions src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog( QgsVectorLayer* la
connect( checkboxEnableOrderBy, SIGNAL( toggled( bool ) ), btnOrderBy, SLOT( setEnabled( bool ) ) );
connect( checkboxEnableOrderBy, SIGNAL( toggled( bool ) ), lineEditOrderBy, SLOT( setEnabled( bool ) ) );
connect( btnOrderBy, SIGNAL( clicked( bool ) ), this, SLOT( showOrderByDialog() ) );
connect( mEffectWidget, SIGNAL( showPanel( QgsRendererWidgetContainer* ) ), this, SLOT( showPanel( QgsRendererWidgetContainer* ) ) );

mEffectWidget->setDockMode( true );

syncToLayer();

Expand Down
4 changes: 4 additions & 0 deletions src/gui/symbology-ng/qgsrendererv2propertiesdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::Qgs
*/
void showPanel( QgsRendererWidgetContainer *container );

/**
* Closes the given panel in the stack of panels.
* @param container The container widget to close.
*/
void closePanel( QgsRendererWidgetContainer *container );

private slots:
Expand Down
7 changes: 3 additions & 4 deletions src/gui/symbology-ng/qgsrendererv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ class GUI_EXPORT QgsRendererV2Widget : public QWidget
*/
void widgetChanged();

/**
* @brief Emitted when a sub panel for the widget is opened.
* The renderer can open inline sub panels instead of dialogs.
* @param opened True of the a sub panel is opened.
/** Shows a panel widget inside the renderer widget.
* @param container widget panel to show
* @note added in QGIS 2.16
*/
void showPanel( QgsRendererWidgetContainer* widget );

Expand Down
13 changes: 13 additions & 0 deletions src/gui/symbology-ng/qgsrendererwidgetcontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,24 @@ class GUI_EXPORT QgsRendererWidgetContainer : public QWidget, private Ui::QgsRen
* Listen to this to clean up the callers state.
*/
void accepted( QgsRendererWidgetContainer* container );

/**
* Emiited when the internal widget changes state.
* @param conatiner The container holding the widget that changed state.
*/
void widgetChanged( QgsRendererWidgetContainer* conatiner );

public slots:

/**
* Accept the container. Causes accepted to be emiited.
*/
void accept();

/**
* Fire the widgetChanged event on the container. Connect your widgets dirty signal to
* this slot to fire the and listen to widgetChanged to handle the event.
*/
void emitWidgetChanged();

protected:
Expand Down

0 comments on commit 4556a0d

Please sign in to comment.