Skip to content
Permalink
Browse files

[style dock] inline refine rules for rule based styles

  • Loading branch information
NathanW2 committed Jun 28, 2016
1 parent 3d6ea7b commit f6e67ae155d50634d21b5bacef7872f7c8e930f8
@@ -253,61 +253,26 @@ void QgsRuleBasedRendererV2Widget::refineRuleScales()

void QgsRuleBasedRendererV2Widget::refineRuleCategoriesGui( const QModelIndexList& indexList )
{
QDialog dlg;
dlg.setWindowTitle( tr( "Refine a rule to categories" ) );
QVBoxLayout* l = new QVBoxLayout();
QgsCategorizedSymbolRendererV2Widget* w = new QgsCategorizedSymbolRendererV2Widget( mLayer, mStyle, nullptr );
w->setPanelTitle( tr( "Add categories to rules" ) );
connect( w, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( refineRuleCategoriesAccepted( QgsPanelWidget* ) ) );
w->setDockMode( this->dockMode() );
w->setMapCanvas( mMapCanvas );
l->addWidget( w );
QDialogButtonBox* bb = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
l->addWidget( bb );
connect( bb, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
connect( bb, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );
dlg.setLayout( l );

if ( !dlg.exec() )
return;
openPanel( w );

// create new rules
QgsCategorizedSymbolRendererV2* r = static_cast<QgsCategorizedSymbolRendererV2*>( w->renderer() );
Q_FOREACH ( const QModelIndex& index, indexList )
{
QgsRuleBasedRendererV2::Rule* initialRule = mModel->ruleForIndex( index );
mModel->willAddRules( index, r->categories().count() );
QgsRuleBasedRendererV2::refineRuleCategories( initialRule, r );
}
mModel->finishedAddingRules();
}


void QgsRuleBasedRendererV2Widget::refineRuleRangesGui( const QModelIndexList& indexList )
{


QDialog dlg;
dlg.setWindowTitle( tr( "Refine a rule to ranges" ) );
QVBoxLayout* l = new QVBoxLayout();
QgsGraduatedSymbolRendererV2Widget* w = new QgsGraduatedSymbolRendererV2Widget( mLayer, mStyle, nullptr );
w->setPanelTitle( tr( "Add ranges to rules" ) );
connect( w, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( refineRuleRangesAccepted( QgsPanelWidget* ) ) );
w->setMapCanvas( mMapCanvas );
l->addWidget( w );
QDialogButtonBox* bb = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
l->addWidget( bb );
connect( bb, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
connect( bb, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );
dlg.setLayout( l );

if ( !dlg.exec() )
return;
w->setDockMode( this->dockMode() );
openPanel( w );

// create new rules
QgsGraduatedSymbolRendererV2* r = static_cast<QgsGraduatedSymbolRendererV2*>( w->renderer() );
Q_FOREACH ( const QModelIndex& index, indexList )
{
QgsRuleBasedRendererV2::Rule* initialRule = mModel->ruleForIndex( index );
mModel->willAddRules( index, r->ranges().count() );
QgsRuleBasedRendererV2::refineRuleRanges( initialRule, r );
}
mModel->finishedAddingRules();
}

void QgsRuleBasedRendererV2Widget::refineRuleScalesGui( const QModelIndexList& indexList )
@@ -487,6 +452,39 @@ void QgsRuleBasedRendererV2Widget::paste()
mModel->dropMimeData( mime, Qt::CopyAction, index.row(), index.column(), index.parent() );
}

void QgsRuleBasedRendererV2Widget::refineRuleCategoriesAccepted( QgsPanelWidget *panel )
{
QgsCategorizedSymbolRendererV2Widget* w = qobject_cast<QgsCategorizedSymbolRendererV2Widget*>( panel );

// create new rules
QgsCategorizedSymbolRendererV2* r = static_cast<QgsCategorizedSymbolRendererV2*>( w->renderer() );
QModelIndexList indexList = viewRules->selectionModel()->selectedRows();
Q_FOREACH ( const QModelIndex& index, indexList )
{
QgsRuleBasedRendererV2::Rule* initialRule = mModel->ruleForIndex( index );
mModel->willAddRules( index, r->categories().count() );
QgsRuleBasedRendererV2::refineRuleCategories( initialRule, r );
}
mModel->finishedAddingRules();
emit widgetChanged();
}

void QgsRuleBasedRendererV2Widget::refineRuleRangesAccepted( QgsPanelWidget *panel )
{
QgsGraduatedSymbolRendererV2Widget* w = qobject_cast<QgsGraduatedSymbolRendererV2Widget*>( panel );
// create new rules
QgsGraduatedSymbolRendererV2* r = static_cast<QgsGraduatedSymbolRendererV2*>( w->renderer() );
QModelIndexList indexList = viewRules->selectionModel()->selectedRows();
Q_FOREACH ( const QModelIndex& index, indexList )
{
QgsRuleBasedRendererV2::Rule* initialRule = mModel->ruleForIndex( index );
mModel->willAddRules( index, r->ranges().count() );
QgsRuleBasedRendererV2::refineRuleRanges( initialRule, r );
}
mModel->finishedAddingRules();
emit widgetChanged();
}

void QgsRuleBasedRendererV2Widget::ruleWidgetPanelAccepted( QgsPanelWidget *panel )
{
QgsRendererRulePropsWidget* widget = qobject_cast<QgsRendererRulePropsWidget*>( panel );
@@ -157,6 +157,8 @@ class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, priv
void paste() override;

private slots:
void refineRuleCategoriesAccepted( QgsPanelWidget* panel );
void refineRuleRangesAccepted( QgsPanelWidget* panel );
void ruleWidgetPanelAccepted( QgsPanelWidget* panel );
void liveUpdateRuleFromPanel();
};
@@ -11,6 +11,18 @@
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTreeView" name="viewRules">
<property name="contextMenuPolicy">
@@ -93,7 +105,7 @@
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionSum.svg</normaloff>:/images/themes/default/mActionSum.svg</iconset>
<normaloff>:/images/themes/default/mActionSum.svg</normaloff>:/images/themes/default/mActionSum.svg</iconset>
</property>
</widget>
</item>

0 comments on commit f6e67ae

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