Skip to content

Commit

Permalink
Multiple symbol selection for rule based renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Sep 5, 2011
1 parent ca6a225 commit c2cf5cb
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV
labels << tr( "Symbol" ) << tr( "Value" ) << tr( "Label" );
m->setHorizontalHeaderLabels( labels );
viewCategories->setModel( m );
viewCategories->setSelectionMode( QAbstractItemView::ExtendedSelection );

mCategorizedSymbol = QgsSymbolV2::defaultSymbol( mLayer->geometryType() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVecto
labels << tr( "Range" ) << tr( "Label" );
mg->setHorizontalHeaderLabels( labels );
viewGraduated->setModel( mg );
viewGraduated->setSelectionMode( QAbstractItemView::ExtendedSelection );

mGraduatedSymbol = QgsSymbolV2::defaultSymbol( mLayer->geometryType() );

Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgsrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void QgsRendererV2Widget::changeSymbolColor()
{
( *symbolIt )->setColor( color );
}
//populateCategories();
refreshSymbolView();
}
}

Expand Down
98 changes: 65 additions & 33 deletions src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye
btnDecreasePriority->setIcon( QIcon( QgsApplication::iconPath( "symbologyDown.png" ) ) );

connect( treeRules, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( editRule() ) );
connect( treeRules, SIGNAL( customContextMenuRequested( const QPoint& ) ), this, SLOT( contextMenuViewCategories( const QPoint& ) ) );

connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
Expand All @@ -87,8 +88,8 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye
chkUsingFirstRule->setChecked( mRenderer->usingFirstRule() );
chkEnableSymbolLevels->setChecked( mRenderer->usingSymbolLevels() );
// If symbol levels are used, forcefully check and gray-out the chkUsingFirstRule checkbox
if (mRenderer->usingSymbolLevels() ) { forceUsingFirstRule(); }
connect( chkUsingFirstRule, SIGNAL( clicked() ), this, SLOT( usingFirstRuleChanged() ));
if ( mRenderer->usingSymbolLevels() ) { forceUsingFirstRule(); }
connect( chkUsingFirstRule, SIGNAL( clicked() ), this, SLOT( usingFirstRuleChanged() ) );
connect( chkEnableSymbolLevels, SIGNAL( clicked() ), this, SLOT( symbolLevelsEnabledChanged() ) );
connect( this, SIGNAL( forceChkUsingFirstRule() ), this, SLOT( forceUsingFirstRule() ) );

Expand Down Expand Up @@ -191,23 +192,23 @@ void QgsRuleBasedRendererV2Widget::removeRule()
void QgsRuleBasedRendererV2Widget::increasePriority()
{
QTreeWidgetItem * item = treeRules->currentItem();
if ( ! item ) return; // No rule selected, exit
if ( ! item ) return; // No rule selected, exit
int rule_index = item->data( 0, Qt::UserRole + 1 ).toInt();
if ( rule_index < 0 )
{
return;// Group of rules selected, exit
}
else
{
if ( rule_index > 0 ) // do not increase priority of first rule
{
mRenderer->swapRules(rule_index, rule_index - 1);
if ( rule_index > 0 ) // do not increase priority of first rule
{
mRenderer->swapRules( rule_index, rule_index - 1 );
treeRules->populateRules();
// TODO: find out where the moved rule goes and reselect it (at least for non-grouped display)
// maybe based on the following functions :
// findItems(QString(rule_index - 1), Qt::MatchExactly, 4).first.index)
// setCurrentItem, setSelected, scrollToItem
}
// TODO: find out where the moved rule goes and reselect it (at least for non-grouped display)
// maybe based on the following functions :
// findItems(QString(rule_index - 1), Qt::MatchExactly, 4).first.index)
// setCurrentItem, setSelected, scrollToItem
}
}

}
Expand All @@ -216,19 +217,19 @@ void QgsRuleBasedRendererV2Widget::increasePriority()
void QgsRuleBasedRendererV2Widget::decreasePriority()
{
QTreeWidgetItem * item = treeRules->currentItem();
if ( ! item ) return; // No rule selected, exit
if ( ! item ) return; // No rule selected, exit
int rule_index = item->data( 0, Qt::UserRole + 1 ).toInt();
if ( rule_index < 0 )
{
return;// Group of rules selected, exit
}
else
{
if ( rule_index +1 < mRenderer->ruleCount() ) // do not increase priority of last rule
{
mRenderer->swapRules(rule_index, rule_index + 1);
treeRules->populateRules();
}
if ( rule_index + 1 < mRenderer->ruleCount() ) // do not increase priority of last rule
{
mRenderer->swapRules( rule_index, rule_index + 1 );
treeRules->populateRules();
}
}
}

Expand All @@ -237,11 +238,11 @@ void QgsRuleBasedRendererV2Widget::usingFirstRuleChanged()
{
if ( chkUsingFirstRule->checkState() == Qt::Checked )
{
mRenderer->setUsingFirstRule(true);
mRenderer->setUsingFirstRule( true );
}
else
{
mRenderer->setUsingFirstRule(false);
mRenderer->setUsingFirstRule( false );
}

}
Expand All @@ -251,30 +252,30 @@ void QgsRuleBasedRendererV2Widget::forceUsingFirstRule()
{
chkEnableSymbolLevels->setChecked( true );
chkUsingFirstRule->setChecked( true );
chkUsingFirstRule->setEnabled(false);
mRenderer->setUsingFirstRule(true);
chkUsingFirstRule->setEnabled( false );
mRenderer->setUsingFirstRule( true );
}


void QgsRuleBasedRendererV2Widget::forceNoSymbolLevels()
{
chkEnableSymbolLevels->setChecked( false );
chkUsingFirstRule->setEnabled( true );
mRenderer->setUsingSymbolLevels( false );
chkEnableSymbolLevels->setChecked( false );
chkUsingFirstRule->setEnabled( true );
mRenderer->setUsingSymbolLevels( false );
}


void QgsRuleBasedRendererV2Widget::symbolLevelsEnabledChanged()
{
if ( chkEnableSymbolLevels->checkState() == Qt::Checked )
{
mRenderer->setUsingSymbolLevels(true);
mRenderer->setUsingSymbolLevels( true );
emit forceChkUsingFirstRule();
}
else
{
mRenderer->setUsingSymbolLevels(false);
chkUsingFirstRule->setEnabled(true);
mRenderer->setUsingSymbolLevels( false );
chkUsingFirstRule->setEnabled( true );
}
}

Expand Down Expand Up @@ -405,6 +406,37 @@ QList<QgsRuleBasedRendererV2::Rule> QgsRuleBasedRendererV2Widget::refineRuleScal
return QgsRuleBasedRendererV2::refineRuleScales( initialRule, scales );
}

QList<QgsSymbolV2*> QgsRuleBasedRendererV2Widget::selectedSymbols()
{
QList<QgsSymbolV2*> symbolList;

if ( !mRenderer )
{
return symbolList;
}

QList<QTreeWidgetItem*> selectedItems = treeRules->selectedItems();
QList<QTreeWidgetItem*>::const_iterator it = selectedItems.constBegin();
for ( ; it != selectedItems.constEnd(); ++it )
{
int priority = ( *it )->data( 0, Qt::UserRole + 1 ).toInt();
if ( priority < mRenderer->ruleCount() )
{
symbolList.append( mRenderer->ruleAt( priority ).symbol() );
}
}

return symbolList;
}

void QgsRuleBasedRendererV2Widget::refreshSymbolView()
{
if ( treeRules )
{
treeRules->populateRules();
}
}


///////////

Expand Down Expand Up @@ -603,8 +635,8 @@ void QgsRendererRulesTreeWidget::populateRulesNoGrouping()
//item->setBackground( 3, Qt::lightGray );

// Priority (Id): add 1 to rule number and convert to string
item->setText( 4, QString("%1").arg( i+1, 4 ) );
item->setTextAlignment (4, Qt::AlignRight);
item->setText( 4, QString( "%1" ).arg( i + 1, 4 ) );
item->setTextAlignment( 4, Qt::AlignRight );
lst << item;
}

Expand Down Expand Up @@ -671,8 +703,8 @@ void QgsRendererRulesTreeWidget::populateRulesGroupByScale()
//item->setBackground( 3, Qt::lightGray );

// Priority (Id): add 1 to rule number and convert to string
item->setText( 4, QString("%1").arg( i+1, 4 ) );
item->setTextAlignment (4, Qt::AlignRight);
item->setText( 4, QString( "%1" ).arg( i + 1, 4 ) );
item->setTextAlignment( 4, Qt::AlignRight );

}
addTopLevelItems( scale_items.values() );
Expand Down Expand Up @@ -727,8 +759,8 @@ void QgsRendererRulesTreeWidget::populateRulesGroupByFilter()
}

// Priority (Id): add 1 to rule number and convert to string
item->setText( 4, QString("%1").arg( i+1, 4 ) );
item->setTextAlignment (4, Qt::AlignRight);
item->setText( 4, QString( "%1" ).arg( i + 1, 4 ) );
item->setTextAlignment( 4, Qt::AlignRight );
}

addTopLevelItems( filter_items.values() );
Expand Down
3 changes: 3 additions & 0 deletions src/gui/symbology-ng/qgsrulebasedrendererv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, priv
QList<QgsRuleBasedRendererV2::Rule> refineRuleRangesGui( QgsRuleBasedRendererV2::Rule& initialRule );
QList<QgsRuleBasedRendererV2::Rule> refineRuleScalesGui( QgsRuleBasedRendererV2::Rule& initialRule );

QList<QgsSymbolV2*> selectedSymbols();
void refreshSymbolView();

QgsRuleBasedRendererV2* mRenderer;

QMenu* mRefineMenu;
Expand Down
3 changes: 3 additions & 0 deletions src/ui/qgscategorizedsymbolrendererv2widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="iconSize">
<size>
<width>16</width>
Expand Down
3 changes: 3 additions & 0 deletions src/ui/qgsgraduatedsymbolrendererv2widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
Expand Down
6 changes: 6 additions & 0 deletions src/ui/qgsrulebasedrendererv2widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QgsRendererRulesTreeWidget" name="treeRules">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
Expand Down

0 comments on commit c2cf5cb

Please sign in to comment.