Skip to content
Permalink
Browse files

[styledock] Handle stacked panels at a higher level

  • Loading branch information
NathanW2 committed Jun 6, 2016
1 parent f8dccf8 commit 91cd68ea8033768cf204437c33561b66f25bc630
@@ -572,9 +572,10 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorizedSymbol()
dlg->setMapCanvas( mMapCanvas );

QgsRendererWidgetContainer* container = new QgsRendererWidgetContainer( dlg, "Select Symbol", nullptr );
connect( dlg, SIGNAL( symbolModified() ), this, SLOT( updateSymbolsFromWidget() ) );
connect( container, SIGNAL( accepted() ), this, SLOT( cleanUpSymbolSelector() ) );
this->showPanel( container );
connect( dlg, SIGNAL( symbolModified() ), container, SLOT( emitWidgetChanged() ) );
connect( container, SIGNAL( widgetChanged( QgsRendererWidgetContainer* ) ), this, SLOT( updateSymbolsFromWidget( QgsRendererWidgetContainer* ) ) );
connect( container, SIGNAL( accepted( QgsRendererWidgetContainer* ) ), this, SLOT( cleanUpSymbolSelector( QgsRendererWidgetContainer* ) ) );
emit panelOpened( container );
}

void QgsCategorizedSymbolRendererV2Widget::updateCategorizedSymbolIcon()
@@ -616,10 +617,11 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorySymbol()
QgsSymbolV2SelectorDialog* dlg = new QgsSymbolV2SelectorDialog( symbol, mStyle, mLayer, nullptr, true );
dlg->setMapCanvas( mMapCanvas );

QgsRendererWidgetContainer* container = new QgsRendererWidgetContainer( dlg, "Select Symbol", nullptr );
connect( dlg, SIGNAL( symbolModified() ), this, SLOT( updateSymbolsFromWidget() ) );
connect( container, SIGNAL( accepted() ), this, SLOT( cleanUpSymbolSelector() ) );
this->showPanel( container );
QgsRendererWidgetContainer* container = new QgsRendererWidgetContainer( dlg, "Select Symbol", nullptr );
connect( dlg, SIGNAL( symbolModified() ), container, SLOT( emitWidgetChanged() ) );
connect( container, SIGNAL( widgetChanged( QgsRendererWidgetContainer* ) ), this, SLOT( updateSymbolsFromWidget( QgsRendererWidgetContainer* ) ) );
connect( container, SIGNAL( accepted( QgsRendererWidgetContainer* ) ), this, SLOT( cleanUpSymbolSelector( QgsRendererWidgetContainer* ) ) );
emit panelOpened( container );
}

static void _createCategories( QgsCategoryList& cats, QList<QVariant>& values, QgsSymbolV2* symbol )
@@ -992,23 +994,18 @@ void QgsCategorizedSymbolRendererV2Widget::matchToSymbolsFromXml()
}
}

void QgsCategorizedSymbolRendererV2Widget::cleanUpSymbolSelector()
void QgsCategorizedSymbolRendererV2Widget::cleanUpSymbolSelector( QgsRendererWidgetContainer *container )
{
QgsRendererWidgetContainer* container = qobject_cast<QgsRendererWidgetContainer*>( this->currentWidget() );
if ( container )
{
this->removeWidget( container );
QgsSymbolV2SelectorDialog* dlg = qobject_cast<QgsSymbolV2SelectorDialog*>( container->widget() );
delete dlg->symbol();
container->deleteLater();
this->setCurrentIndex( 0 );
emit panelOpened( false );
}
}

void QgsCategorizedSymbolRendererV2Widget::updateSymbolsFromWidget()
void QgsCategorizedSymbolRendererV2Widget::updateSymbolsFromWidget( QgsRendererWidgetContainer* container )
{
QgsRendererWidgetContainer* container = qobject_cast<QgsRendererWidgetContainer*>( this->currentWidget() );
QgsDebugMsg( "UPDATE SYMBOL!!!" );
QgsSymbolV2SelectorDialog* dlg = qobject_cast<QgsSymbolV2SelectorDialog*>( container->widget() );
delete mCategorizedSymbol;
mCategorizedSymbol = dlg->symbol()->clone();
@@ -131,8 +131,8 @@ class GUI_EXPORT QgsCategorizedSymbolRendererV2Widget : public QgsRendererV2Widg

private slots:

void cleanUpSymbolSelector();
void updateSymbolsFromWidget();
void cleanUpSymbolSelector( QgsRendererWidgetContainer* container );
void updateSymbolsFromWidget( QgsRendererWidgetContainer *container );

protected:

@@ -699,7 +699,6 @@ void QgsGraduatedSymbolRendererV2Widget::cleanUpSymbolSelector()
delete dlg->symbol();
container->deleteLater();
this->setCurrentIndex( 0 );
emit panelOpened( false );
}
}

@@ -841,9 +840,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeGraduatedSymbol()
QgsRendererWidgetContainer* container = new QgsRendererWidgetContainer( dlg, "Select Symbol", nullptr );
connect( dlg, SIGNAL( symbolModified() ), this, SLOT( updateSymbolsFromWidget() ) );
connect( container, SIGNAL( accepted() ), this, SLOT( cleanUpSymbolSelector() ) );
int page = this->addWidget( container );
this->setCurrentIndex( page );
emit panelOpened( true );
emit panelOpened( container );
}

void QgsGraduatedSymbolRendererV2Widget::updateGraduatedSymbolIcon()
@@ -922,7 +919,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeRangeSymbol( int rangeIdx )
QgsRendererWidgetContainer* container = new QgsRendererWidgetContainer( dlg, "Select Symbol", nullptr );
connect( dlg, SIGNAL( symbolModified() ), this, SLOT( updateSymbolsFromWidget() ) );
connect( container, SIGNAL( accepted() ), this, SLOT( cleanUpSymbolSelector() ) );
this->showPanel( container );
emit panelOpened( container );
}

void QgsGraduatedSymbolRendererV2Widget::changeRange( int rangeIdx )
@@ -27,6 +27,7 @@
#include "qgsheatmaprendererwidget.h"
#include "qgs25drendererwidget.h"
#include "qgsnullsymbolrendererwidget.h"
#include "qgsrendererwidgetcontainer.h"

#include "qgsorderbydialog.h"
#include "qgsapplication.h"
@@ -244,6 +245,7 @@ void QgsRendererV2PropertiesDialog::rendererChanged()
connect( mActiveWidget, SIGNAL( layerVariablesChanged() ), this, SIGNAL( layerVariablesChanged() ) );
}
connect( mActiveWidget, SIGNAL( widgetChanged() ), this, SIGNAL( widgetChanged() ) );
connect( mActiveWidget, SIGNAL( panelOpened( QgsRendererWidgetContainer* ) ), this, SLOT( showPanel( QgsRendererWidgetContainer* ) ) );
}
else
{
@@ -286,6 +288,21 @@ void QgsRendererV2PropertiesDialog::onOK()
accept();
}

void QgsRendererV2PropertiesDialog::showPanel( QgsRendererWidgetContainer *container )
{
connect( container, SIGNAL( accepted( QgsRendererWidgetContainer* ) ), this, SLOT( closePanel( QgsRendererWidgetContainer* ) ) );

int page = this->mainStack->addWidget( container );
this->mainStack->setCurrentIndex( page );
}

void QgsRendererV2PropertiesDialog::closePanel( QgsRendererWidgetContainer *container )
{
this->mainStack->removeWidget( container );
this->mainStack->setCurrentIndex( this->mainStack->currentIndex() - 1 );
container->deleteLater();
}

void QgsRendererV2PropertiesDialog::syncToLayer()
{
// Blend mode
@@ -31,6 +31,7 @@ class QgsSymbolV2;
class QgsPaintEffect;
class QgsRendererV2Widget;
class QgsMapCanvas;
class QgsRendererWidgetContainer;


class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::QgsRendererV2PropsDialogBase
@@ -72,6 +73,14 @@ class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::Qgs
//! 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 );

void closePanel( QgsRendererWidgetContainer *container );

private slots:
void showOrderByDialog();

@@ -274,12 +274,6 @@ void QgsRendererV2Widget::applyChanges()
apply();
}

void QgsRendererV2Widget::showPanel( QWidget* container )
{
int page = this->addWidget( container );
this->setCurrentIndex( page );
emit panelOpened( true );
}


////////////
@@ -26,6 +26,7 @@ class QgsStyleV2;
class QgsFeatureRendererV2;
class QgsSymbolV2SelectorDialog;
class QgsMapCanvas;
class QgsRendererWidgetContainer;


/**
@@ -76,11 +77,6 @@ class GUI_EXPORT QgsRendererV2Widget : public QStackedWidget
*/
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:
/**
@@ -101,7 +97,7 @@ class GUI_EXPORT QgsRendererV2Widget : public QStackedWidget
* The renderer can open inline sub panels instead of dialogs.
* @param opened True of the a sub panel is opened.
*/
void panelOpened( bool opened );
void panelOpened( QgsRendererWidgetContainer* widget );

protected:
QWidget* mWidgetPage;
@@ -19,25 +19,36 @@

QgsRendererWidgetContainer::QgsRendererWidgetContainer( QWidget *widget, const QString& title, QWidget *parent )
: QWidget( parent )
, mWidget( widget )
{
setupUi( this );
mWidgetLayout->addWidget( widget );
mWidgetLayout->setContentsMargins( 0, 0, 0, 0 );
mTitleText->setText( title );
QPushButton* button = mButtonBox->button( QDialogButtonBox::Close );
button->setDefault( true );
connect( button, SIGNAL( pressed() ), this, SIGNAL( accepted() ) );
connect( button, SIGNAL( pressed() ), this, SLOT( accept() ) );
}

QWidget *QgsRendererWidgetContainer::widget()
{
return mWidgetLayout->itemAt( 0 )->widget() ;
return mWidget;
}

void QgsRendererWidgetContainer::accept()
{
emit accepted( this );
}

void QgsRendererWidgetContainer::emitWidgetChanged()
{
emit widgetChanged( this );
}

void QgsRendererWidgetContainer::keyPressEvent( QKeyEvent *event )
{
if ( event->key() == Qt::Key_Escape )
{
emit accepted();
accept();
}
}
@@ -48,17 +48,24 @@ class GUI_EXPORT QgsRendererWidgetContainer : public QWidget, private Ui::QgsRen
* @brief Emitted when the container is accpeted and closed.
* Listen to this to clean up the callers state.
*/
void accepted();
void accepted( QgsRendererWidgetContainer* container );
void widgetChanged( QgsRendererWidgetContainer* conatiner );

public slots:

void accept();
void emitWidgetChanged();

protected:
/**
* @brief Overriden key press event to handle the esc event on the widget.
* @param event The key event
*/
void keyPressEvent( QKeyEvent* event );

private:
QWidget* mWidget;

};

#endif // QGSRENDERERWIDGETCONTAINER_H

0 comments on commit 91cd68e

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