Skip to content

Commit

Permalink
Clean up showPanel API. Open dialog if not in dock mode
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Jun 15, 2016
1 parent 15efc31 commit a555f91
Show file tree
Hide file tree
Showing 19 changed files with 153 additions and 162 deletions.
7 changes: 0 additions & 7 deletions python/gui/effects/qgseffectstackpropertieswidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,6 @@ class QgsEffectStackCompactWidget : QgsPanelWidget
*/
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
21 changes: 21 additions & 0 deletions python/gui/qgspanelwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ class QgsPanelWidget : public QWidget
* @param dockMode True to enable dock mode.
*/
virtual void setDockMode( bool dockMode );

/**
* Return the dock mode state.
* @return True if in dock mode. If in dock mode the widget
* will emit the showPanel signal to handle panel opening
* If false it will open dialogs when openPanel is called.
*/
bool dockMode();

/**
* Open a panel or dialog depending on dock mode setting
* If dock mode is true this method will emit the showPanel signal
* for connected slots to handle the open event.
*
* If dock mode is false this method will open a dialog
* and block the user.
*
* @param panel The panel widget to open.
*/
void openPanel( QgsPanelWidget* panel );

signals:

/**
Expand Down
5 changes: 5 additions & 0 deletions python/gui/symbology-ng/qgsrendererv2propertiesdialog.sip
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class QgsRendererV2PropertiesDialog : QDialog
*/
void setMapCanvas( QgsMapCanvas* canvas );

/**
* Set the widget in dock mode which tells the widget to emit panel
* widgets and not open dialogs
* @param dockMode True to enable dock mode.
*/
void setDockMode( bool dockMode );

signals:
Expand Down
7 changes: 0 additions & 7 deletions python/gui/symbology-ng/qgsrendererv2widget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ class QgsRendererV2Widget : QgsPanelWidget
*/
void applyChanges();

/**
* Set the widget in dock mode which tells the widget to emit panel
* widgets and not open dialogs
* @param dockMode True to enable dock mode.
*/
virtual void setDockMode( bool dockMode);

signals:
/**
* Emitted when expression context variables on the associated
Expand Down
6 changes: 0 additions & 6 deletions python/gui/symbology-ng/qgssymbolv2selectordialog.sip
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ class QgsSymbolV2SelectorWidget : QgsPanelWidget
*/
QgsSymbolV2* symbol();

/**
* Set the widget in dock mode which will emit showPanel when a sub widget requests
* to show a widget.
* @param dockMode True to enable dock mode.
*/
void setDockMode( bool dockMode );
protected:
//! Reimplements dialog keyPress event so we can ignore it
void keyPressEvent( QKeyEvent * event );
Expand Down
31 changes: 6 additions & 25 deletions src/gui/effects/qgseffectstackpropertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ void QgsEffectStackPropertiesDialog::setPreviewPicture( const QPicture &picture

QgsEffectStackCompactWidget::QgsEffectStackCompactWidget( QWidget *parent , QgsPaintEffect *effect )
: QgsPanelWidget( parent )
, mDockMode( false )
, mEnabledCheckBox( nullptr )
, mButton( nullptr )
, mPreviewPicture( nullptr )
Expand Down Expand Up @@ -452,32 +451,14 @@ void QgsEffectStackCompactWidget::showDialog()
return;

QgsEffectStack* clone = static_cast<QgsEffectStack*>( mStack->clone() );
if ( mDockMode )
{
QgsEffectStackPropertiesWidget* widget = new QgsEffectStackPropertiesWidget( clone, nullptr );
if ( mPreviewPicture )
{
widget->setPreviewPicture( *mPreviewPicture );
}
connect( widget, SIGNAL( widgetChanged() ), this, SLOT( updateEffectLive() ) );
connect( widget, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( updateAcceptWidget( QgsPanelWidget* ) ) );
emit showPanel( widget );
}
else
QgsEffectStackPropertiesWidget* widget = new QgsEffectStackPropertiesWidget( clone, nullptr );
if ( mPreviewPicture )
{
QgsEffectStackPropertiesDialog dialog( clone, this );
if ( mPreviewPicture )
{
dialog.setPreviewPicture( *mPreviewPicture );
}
if ( dialog.exec() == QDialog::Accepted )
{
*mStack = *clone;
emit changed();
}

delete clone;
widget->setPreviewPicture( *mPreviewPicture );
}
connect( widget, SIGNAL( widgetChanged() ), this, SLOT( updateEffectLive() ) );
connect( widget, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( updateAcceptWidget( QgsPanelWidget* ) ) );
openPanel( widget );
}

void QgsEffectStackCompactWidget::enableToggled( bool checked )
Expand Down
9 changes: 0 additions & 9 deletions src/gui/effects/qgseffectstackpropertieswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,6 @@ class GUI_EXPORT QgsEffectStackCompactWidget: public QgsPanelWidget
*/
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
Expand All @@ -242,8 +235,6 @@ class GUI_EXPORT QgsEffectStackCompactWidget: public QgsPanelWidget
void updateEffectLive();

private:
bool mDockMode;

QgsEffectStack* mStack;
QCheckBox* mEnabledCheckBox;
QToolButton* mButton;
Expand Down
22 changes: 22 additions & 0 deletions src/gui/qgspanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/
#include <QDialogButtonBox>
#include <QPushButton>
#include <QDialog>

#include "qgspanelwidget.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -42,6 +43,27 @@ void QgsPanelWidget::setDockMode( bool dockMode )
mDockMode = dockMode;
}

void QgsPanelWidget::openPanel( QgsPanelWidget* panel )
{
if ( mDockMode )
{
emit showPanel( panel );
}
else
{
// Show the dialog version if no one is connected
QDialog* dlg = new QDialog();
dlg->setWindowTitle( panel->panelTitle() );
dlg->setLayout( new QVBoxLayout() );
dlg->layout()->addWidget( panel );
QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok );
connect( buttonBox, SIGNAL( accepted() ), dlg, SLOT( accept() ) );
dlg->layout()->addWidget( buttonBox );
dlg->exec();
emit panelAccepted( panel );
}
}

void QgsPanelWidget::acceptPanel()
{
emit panelAccepted( this );
Expand Down
20 changes: 20 additions & 0 deletions src/gui/qgspanelwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ class GUI_EXPORT QgsPanelWidget : public QWidget
*/
virtual void setDockMode( bool dockMode );

/**
* Return the dock mode state.
* @return True if in dock mode. If in dock mode the widget
* will emit the showPanel signal to handle panel opening
* If false it will open dialogs when openPanel is called.
*/
bool dockMode() { return mDockMode; }

/**
* Open a panel or dialog depending on dock mode setting
* If dock mode is true this method will emit the showPanel signal
* for connected slots to handle the open event.
*
* If dock mode is false this method will open a dialog
* and block the user.
*
* @param panel The panel widget to open.
*/
void openPanel( QgsPanelWidget* panel );

signals:

/**
Expand Down
12 changes: 6 additions & 6 deletions src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,12 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorizedSymbol()
{
QgsSymbolV2* newSymbol = mCategorizedSymbol->clone();
QgsSymbolV2SelectorWidget* dlg = new QgsSymbolV2SelectorWidget( newSymbol, mStyle, mLayer, nullptr );
dlg->setDockMode( true );
dlg->setDockMode( this->dockMode() );
dlg->setMapCanvas( mMapCanvas );

connect( dlg, SIGNAL( widgetChanged() ), this, SLOT( updateSymbolsFromWidget() ) );
connect( dlg, SIGNAL( accepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
emit showPanel( dlg );
connect( dlg, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
openPanel( dlg );
}

void QgsCategorizedSymbolRendererV2Widget::updateCategorizedSymbolIcon()
Expand Down Expand Up @@ -617,11 +617,11 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorySymbol()
}

QgsSymbolV2SelectorWidget* dlg = new QgsSymbolV2SelectorWidget( symbol, mStyle, mLayer, nullptr );
dlg->setDockMode( true );
dlg->setDockMode( this->dockMode() );
dlg->setMapCanvas( mMapCanvas );
connect( dlg, SIGNAL( widgetChanged() ), this, SLOT( updateSymbolsFromWidget() ) );
connect( dlg, SIGNAL( accepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
emit showPanel( dlg );
connect( dlg, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
openPanel( dlg );
}

static void _createCategories( QgsCategoryList& cats, QList<QVariant>& values, QgsSymbolV2* symbol )
Expand Down
6 changes: 3 additions & 3 deletions src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeGraduatedSymbol()

connect( dlg, SIGNAL( widgetChanged() ), this, SLOT( updateSymbolsFromWidget() ) );
connect( dlg, SIGNAL( accepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
emit showPanel( dlg );
openPanel( dlg );
}

void QgsGraduatedSymbolRendererV2Widget::updateGraduatedSymbolIcon()
Expand Down Expand Up @@ -906,12 +906,12 @@ void QgsGraduatedSymbolRendererV2Widget::changeRangeSymbol( int rangeIdx )
{
QgsSymbolV2* newSymbol = mRenderer->ranges()[rangeIdx].symbol()->clone();
QgsSymbolV2SelectorWidget* dlg = new QgsSymbolV2SelectorWidget( newSymbol, mStyle, mLayer, nullptr );
dlg->setDockMode( true );
dlg->setDockMode( this->dockMode() );
dlg->setMapCanvas( mMapCanvas );

connect( dlg, SIGNAL( widgetChanged() ), this, SLOT( updateSymbolsFromWidget() ) );
connect( dlg, SIGNAL( accepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
emit showPanel( dlg );
openPanel( dlg );
}

void QgsGraduatedSymbolRendererV2Widget::changeRange( int rangeIdx )
Expand Down
7 changes: 2 additions & 5 deletions src/gui/symbology-ng/qgslayerpropertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,8 @@ void QgsLayerPropertiesWidget::setMapCanvas( QgsMapCanvas *canvas )

void QgsLayerPropertiesWidget::setDockMode( bool dockMode )
{
mDockMode = dockMode;
if ( dockMode )
{
mEffectWidget->setDockMode( dockMode );
}
QgsPanelWidget::setDockMode( dockMode );
mEffectWidget->setDockMode( this->dockMode() );
}

void QgsLayerPropertiesWidget::setExpressionContext( QgsExpressionContext *context )
Expand Down
3 changes: 1 addition & 2 deletions src/gui/symbology-ng/qgslayerpropertieswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class GUI_EXPORT QgsLayerPropertiesWidget : public QgsPanelWidget, private Ui::L
* widgets and not open dialogs
* @param dockMode True to enable dock mode.
*/
void setDockMode( bool dockMode );
virtual void setDockMode( bool dockMode ) override;

public slots:
void layerTypeChanged();
Expand Down Expand Up @@ -92,7 +92,6 @@ class GUI_EXPORT QgsLayerPropertiesWidget : public QgsPanelWidget, private Ui::L
void reloadLayer();

private:
bool mDockMode;
QgsExpressionContext* mPresetExpressionContext;
QgsMapCanvas* mMapCanvas;

Expand Down
5 changes: 0 additions & 5 deletions src/gui/symbology-ng/qgsrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,6 @@ void QgsRendererV2Widget::applyChanges()
apply();
}

void QgsRendererV2Widget::setDockMode( bool dockMode )
{
mDockMode = dockMode;
}



////////////
Expand Down
9 changes: 0 additions & 9 deletions src/gui/symbology-ng/qgsrendererv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,6 @@ class GUI_EXPORT QgsRendererV2Widget : public QgsPanelWidget
*/
void applyChanges();

/**
* Set the widget in dock mode which tells the widget to emit panel
* widgets and not open dialogs
* @param dockMode True to enable dock mode.
*/
virtual void setDockMode( bool dockMode ) override;


signals:
/**
* Emitted when expression context variables on the associated
Expand All @@ -93,7 +85,6 @@ class GUI_EXPORT QgsRendererV2Widget : public QgsPanelWidget
void layerVariablesChanged();

protected:
bool mDockMode;
QgsVectorLayer* mLayer;
QgsStyleV2* mStyle;
QMenu* contextMenu;
Expand Down
1 change: 0 additions & 1 deletion src/gui/symbology-ng/qgssinglesymbolrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ void QgsSingleSymbolRendererV2Widget::setMapCanvas( QgsMapCanvas* canvas )
void QgsSingleSymbolRendererV2Widget::setDockMode( bool dockMode )
{
QgsRendererV2Widget::setDockMode( dockMode );
mDockMode = dockMode;
if ( mSelector )
mSelector->setDockMode( dockMode );
}
Expand Down
7 changes: 1 addition & 6 deletions src/gui/symbology-ng/qgssymbolv2selectordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,6 @@ void QgsSymbolV2SelectorWidget::setMapCanvas( QgsMapCanvas *canvas )
listWidget->setMapCanvas( canvas );
}

void QgsSymbolV2SelectorWidget::setDockMode( bool dockMode )
{
mDockMode = dockMode;
}

void QgsSymbolV2SelectorWidget::loadSymbol( QgsSymbolV2* symbol, SymbolLayerItem* parent )
{
SymbolLayerItem* symbolItem = new SymbolLayerItem( symbol );
Expand Down Expand Up @@ -419,7 +414,7 @@ void QgsSymbolV2SelectorWidget::layerChanged()
SymbolLayerItem *parent = static_cast<SymbolLayerItem*>( currentItem->parent() );
mDataDefineRestorer.reset( new DataDefinedRestorer( parent->symbol(), currentItem->layer() ) );
QgsLayerPropertiesWidget *layerProp = new QgsLayerPropertiesWidget( currentItem->layer(), parent->symbol(), mVectorLayer );
layerProp->setDockMode( mDockMode );
layerProp->setDockMode( this->dockMode() );
layerProp->setExpressionContext( mPresetExpressionContext.data() );
layerProp->setMapCanvas( mMapCanvas );
setWidget( layerProp );
Expand Down
8 changes: 0 additions & 8 deletions src/gui/symbology-ng/qgssymbolv2selectordialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ class GUI_EXPORT QgsSymbolV2SelectorWidget: public QgsPanelWidget, private Ui::Q
*/
QgsSymbolV2* symbol() { return mSymbol; }

/**
* Set the widget in dock mode which will emit showPanel when a sub widget requests
* to show a widget.
* @param dockMode True to enable dock mode.
*/
void setDockMode( bool dockMode );

protected:

/**
Expand Down Expand Up @@ -255,7 +248,6 @@ class GUI_EXPORT QgsSymbolV2SelectorWidget: public QgsPanelWidget, private Ui::Q
QWidget *mPresentWidget;

private:
bool mDockMode;
QScopedPointer<DataDefinedRestorer> mDataDefineRestorer;
QScopedPointer< QgsExpressionContext > mPresetExpressionContext;

Expand Down
Loading

0 comments on commit a555f91

Please sign in to comment.