Skip to content
Permalink
Browse files

Render widget now based on stack widget

  • Loading branch information
NathanW2 committed Jun 4, 2016
1 parent 7573b22 commit d409006ce0a4e705a42fe2365207ea98e111c55a
@@ -10,7 +10,7 @@ class QgsMapLayerStyleManagerWidget : QgsMapStylePanel
public:

/**
* @brief Style manager widget to mange the layers styles.
* @brief Style manager widget to manage the layers styles.
* @param layer The layer for the widget
* @param canvas The canvas object.
* @param parent The parent.
@@ -77,6 +77,8 @@ QgsMapStylingWidget::QgsMapStylingWidget( QgsMapCanvas* canvas, QList<QgsMapStyl
connect( mLayerCombo, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( setLayer( QgsMapLayer* ) ) );

mButtonBox->button( QDialogButtonBox::Apply )->setEnabled( false );

mStackedWidget->setCurrentIndex( 0 );
}

QgsMapStylingWidget::~QgsMapStylingWidget()
@@ -35,7 +35,7 @@ class GUI_EXPORT QgsMapLayerStyleManagerWidget : public QgsMapStylePanel
public:

/**
* @brief Style manager widget to mange the layers styles.
* @brief Style manager widget to manage the layers styles.
* @param layer The layer for the widget
* @param canvas The canvas object.
* @param parent The parent.
@@ -430,7 +430,8 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV
mOldClassificationAttribute = attrName;

// setup user interface
setupUi( this );
setupUi( mWidgetPage );
QMetaObject::connectSlotsByName( this );

mExpressionWidget->setLayer( mLayer );

@@ -573,9 +574,7 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorizedSymbol()
QgsRendererWidgetContainer* container = new QgsRendererWidgetContainer( dlg, "Select Symbol", nullptr );
connect( dlg, SIGNAL( symbolModified() ), this, SLOT( updateSymbolsFromWidget() ) );
connect( container, SIGNAL( accepted() ), this, SLOT( cleanUpSymbolSelector() ) );
int page = mStackedWidget->addWidget( container );
mStackedWidget->setCurrentIndex( page );
emit panelOpened( true );
this->showPanel( container );
}

void QgsCategorizedSymbolRendererV2Widget::updateCategorizedSymbolIcon()
@@ -620,9 +619,7 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorySymbol()
QgsRendererWidgetContainer* container = new QgsRendererWidgetContainer( dlg, "Select Symbol", nullptr );
connect( dlg, SIGNAL( symbolModified() ), this, SLOT( updateSymbolsFromWidget() ) );
connect( container, SIGNAL( accepted() ), this, SLOT( cleanUpSymbolSelector() ) );
int page = mStackedWidget->addWidget( container );
mStackedWidget->setCurrentIndex( page );
emit panelOpened( true );
this->showPanel( container );
}

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

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

void QgsCategorizedSymbolRendererV2Widget::updateSymbolsFromWidget()
{
QgsRendererWidgetContainer* container = qobject_cast<QgsRendererWidgetContainer*>( mStackedWidget->currentWidget() );
QgsRendererWidgetContainer* container = qobject_cast<QgsRendererWidgetContainer*>( this->currentWidget() );
QgsSymbolV2SelectorDialog* dlg = qobject_cast<QgsSymbolV2SelectorDialog*>( container->widget() );
delete mCategorizedSymbol;
mCategorizedSymbol = dlg->symbol()->clone();
@@ -1033,7 +1030,7 @@ void QgsCategorizedSymbolRendererV2Widget::updateSymbolsFromWidget()
QgsRendererCategoryV2 category = mRenderer->categories().value( idx );

QgsSymbolV2* newCatSymbol = mCategorizedSymbol->clone();
newCatSymbol->setColor( mRenderer->categories()[idx].symbol()->color() );
// newCatSymbol->setColor( mRenderer->categories()[idx].symbol()->color() );
mRenderer->updateCategorySymbol( idx, newCatSymbol );
}
emit widgetChanged();
@@ -433,7 +433,9 @@ QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVecto
}

// setup user interface
setupUi( this );
setupUi( mWidgetPage );
QMetaObject::connectSlotsByName( this );

mModel = new QgsGraduatedSymbolRendererV2Model( this );

mExpressionWidget->setFilters( QgsFieldProxyModel::Numeric | QgsFieldProxyModel::Date );
@@ -689,21 +691,21 @@ void QgsGraduatedSymbolRendererV2Widget::refreshRanges( bool reset )

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

void QgsGraduatedSymbolRendererV2Widget::updateSymbolsFromWidget()
{
QgsRendererWidgetContainer* container = qobject_cast<QgsRendererWidgetContainer*>( mStackedWidget->currentWidget() );
QgsRendererWidgetContainer* container = qobject_cast<QgsRendererWidgetContainer*>( this->currentWidget() );
QgsSymbolV2SelectorDialog* dlg = qobject_cast<QgsSymbolV2SelectorDialog*>( container->widget() );
delete mGraduatedSymbol;
mGraduatedSymbol = dlg->symbol()->clone();
@@ -729,10 +731,10 @@ void QgsGraduatedSymbolRendererV2Widget::updateSymbolsFromWidget()
}
}
else
{
updateGraduatedSymbolIcon();
mRenderer->updateSymbols( mGraduatedSymbol );
}
{
updateGraduatedSymbolIcon();
mRenderer->updateSymbols( mGraduatedSymbol );
}

refreshSymbolView();
emit widgetChanged();
@@ -839,8 +841,8 @@ 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 = mStackedWidget->addWidget( container );
mStackedWidget->setCurrentIndex( page );
int page = this->addWidget( container );
this->setCurrentIndex( page );
emit panelOpened( true );
}

@@ -920,9 +922,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() ) );
int page = mStackedWidget->addWidget( container );
mStackedWidget->setCurrentIndex( page );
emit panelOpened( true );
this->showPanel( container );
}

void QgsGraduatedSymbolRendererV2Widget::changeRange( int rangeIdx )
@@ -70,15 +70,16 @@ QgsHeatmapRendererWidget::QgsHeatmapRendererWidget( QgsVectorLayer* layer, QgsSt
{
//setup blank dialog
mRenderer = nullptr;
QGridLayout* layout = new QGridLayout( this );
QLabel* label = new QLabel( tr( "The heatmap renderer only applies to point and multipoint layers. \n"
"'%1' is not a point layer and cannot be rendered as a heatmap." )
.arg( layer->name() ), this );
layout->addWidget( label );
mWidgetPage->layout()->addWidget( label );
return;
}

setupUi( this );
setupUi( mWidgetPage );
QMetaObject::connectSlotsByName( this );

mRadiusUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::Pixel << QgsSymbolV2::MapUnit );
mWeightExpressionWidget->registerGetExpressionContextCallback( &_getExpressionContext, this );

@@ -46,10 +46,12 @@ QgsInvertedPolygonRendererWidget::QgsInvertedPolygonRendererWidget( QgsVectorLay
QLabel* label = new QLabel( tr( "The inverted polygon renderer only applies to polygon and multipolygon layers. \n"
"'%1' is not a polygon layer and then cannot be displayed" )
.arg( layer->name() ), this );
mWidgetPage->setLayout( layout );
layout->addWidget( label );
return;
}
setupUi( this );
setupUi( mWidgetPage );
QMetaObject::connectSlotsByName( this );

// try to recognize the previous renderer
// (null renderer means "no previous renderer")
@@ -125,14 +127,15 @@ void QgsInvertedPolygonRendererWidget::on_mRendererComboBox_currentIndexChanged(
if ( m )
{
mEmbeddedRendererWidget.reset( m->createRendererWidget( mLayer, mStyle, const_cast<QgsFeatureRendererV2*>( mRenderer->embeddedRenderer() )->clone() ) );
connect( mEmbeddedRendererWidget.data(), SIGNAL( widgetChanged() ), this, SIGNAL( widgetChanged() ) );
mEmbeddedRendererWidget->setMapCanvas( mMapCanvas );

if ( mLayout->count() > 2 )
if ( mWidgetPage->layout()->count() > 2 )
{
// remove the current renderer widget
mLayout->takeAt( 2 );
mWidgetPage->layout()->takeAt( 2 );
}
mLayout->addWidget( mEmbeddedRendererWidget.data() );
mWidgetPage->layout()->addWidget( mEmbeddedRendererWidget.data() );
}
}

@@ -37,7 +37,7 @@ QgsNullSymbolRendererWidget::QgsNullSymbolRendererWidget( QgsVectorLayer* layer,
mRenderer = new QgsNullSymbolRenderer();
}

QGridLayout* layout = new QGridLayout( this );
QGridLayout* layout = new QGridLayout( mWidgetPage );
QLabel* label = new QLabel( tr( "No symbols will be rendered for features in this layer." ) );
layout->addWidget( label );
}
@@ -48,7 +48,9 @@ QgsPointDisplacementRendererWidget::QgsPointDisplacementRendererWidget( QgsVecto
setupBlankUi( layer->name() );
return;
}
setupUi( this );
setupUi( mWidgetPage );
QMetaObject::connectSlotsByName( this );

mDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );

if ( renderer )
@@ -381,7 +383,9 @@ void QgsPointDisplacementRendererWidget::updateCenterIcon()

void QgsPointDisplacementRendererWidget::setupBlankUi( const QString& layerName )
{
QGridLayout* layout = new QGridLayout( this );
QLabel* label = new QLabel( tr( "The point displacement renderer only applies to (single) point layers. \n'%1' is not a point layer and cannot be displayed by the point displacement renderer" ).arg( layerName ), this );
layout->addWidget( label );
QVBoxLayout* layout = new QVBoxLayout;
layout->setContentsMargins( 0, 0, 0, 0 );
mWidgetPage->setLayout( layout );
mWidgetPage->layout()->addWidget( label );
}
@@ -270,7 +270,6 @@ void QgsRendererV2PropertiesDialog::rendererChanged()
connect( mActiveWidget, SIGNAL( layerVariablesChanged() ), this, SIGNAL( layerVariablesChanged() ) );
}
connect( mActiveWidget, SIGNAL( widgetChanged() ), this, SIGNAL( widgetChanged() ) );
connect( mActiveWidget, SIGNAL( panelOpened(bool)), this, SLOT( updateUIState(bool) ));
}
else
{
@@ -332,7 +331,7 @@ void QgsRendererV2PropertiesDialog::changeOrderBy( const QgsFeatureRequest::Orde
checkboxEnableOrderBy->setChecked( orderByEnabled );
}

void QgsRendererV2PropertiesDialog::updateUIState(bool hidden)
void QgsRendererV2PropertiesDialog::updateUIState( bool hidden )
{
groupBox->setHidden( hidden );
cboRenderers->setHidden( hidden );
@@ -25,11 +25,14 @@
#include <QMenu>

QgsRendererV2Widget::QgsRendererV2Widget( QgsVectorLayer* layer, QgsStyleV2* style )
: QWidget()
: QStackedWidget()
, mLayer( layer )
, mStyle( style )
, mMapCanvas( nullptr )
{
mWidgetPage = new QWidget();
this->addWidget( mWidgetPage );

contextMenu = new QMenu( tr( "Renderer Options" ), this );

mCopyAction = contextMenu->addAction( tr( "Copy" ), this, SLOT( copy() ) );
@@ -271,6 +274,13 @@ void QgsRendererV2Widget::applyChanges()
apply();
}

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


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

@@ -17,6 +17,7 @@

#include <QWidget>
#include <QMenu>
#include <QStackedWidget>
#include "qgssymbolv2.h"
#include "qgsdatadefined.h"

@@ -37,7 +38,7 @@ class QgsMapCanvas;
- on any change of renderer type, create some default (dummy?) version and change the stacked widget
- when clicked ok/apply, get the renderer from active widget and clone it for the layer
*/
class GUI_EXPORT QgsRendererV2Widget : public QWidget
class GUI_EXPORT QgsRendererV2Widget : public QStackedWidget
{
Q_OBJECT
public:
@@ -75,6 +76,8 @@ class GUI_EXPORT QgsRendererV2Widget : public QWidget
*/
void applyChanges();

void showPanel( QWidget *container );

signals:
/**
* Emitted when expression context variables on the associated
@@ -97,6 +100,7 @@ class GUI_EXPORT QgsRendererV2Widget : public QWidget
void panelOpened( bool opened );

protected:
QWidget* mWidgetPage;
QgsVectorLayer* mLayer;
QgsStyleV2* mStyle;
QMenu* contextMenu;
@@ -63,7 +63,8 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye
mRenderer = new QgsRuleBasedRendererV2( symbol );
}

setupUi( this );
setupUi( mWidgetPage );
QMetaObject::connectSlotsByName( this );

mModel = new QgsRuleBasedRendererV2Model( mRenderer );
#ifdef ENABLE_MODELTEST
@@ -54,10 +54,9 @@ QgsSingleSymbolRendererV2Widget::QgsSingleSymbolRendererV2Widget( QgsVectorLayer
mSelector = new QgsSymbolV2SelectorDialog( mSingleSymbol, mStyle, mLayer, nullptr, true );
connect( mSelector, SIGNAL( symbolModified() ), this, SLOT( changeSingleSymbol() ) );

QVBoxLayout* layout = new QVBoxLayout;
QVBoxLayout* layout = new QVBoxLayout( mWidgetPage );
layout->setContentsMargins( 0, 0, 0, 0 );
layout->addWidget( mSelector );
setLayout( layout );
mWidgetPage->layout()->addWidget( mSelector );

// advanced actions - data defined rendering
QMenu* advMenu = mSelector->advancedMenu();

0 comments on commit d409006

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