Rule-based renderer: polish rule refining

This commit is contained in:
Martin Dobias 2012-01-25 12:46:59 +01:00
parent 8d59d04302
commit 785bc9ffaa
2 changed files with 19 additions and 5 deletions

View File

@ -79,11 +79,15 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye
// support for context menu (now handled generically) // support for context menu (now handled generically)
connect( viewRules, SIGNAL( customContextMenuRequested( const QPoint& ) ), this, SLOT( contextMenuViewCategories( const QPoint& ) ) ); connect( viewRules, SIGNAL( customContextMenuRequested( const QPoint& ) ), this, SLOT( contextMenuViewCategories( const QPoint& ) ) );
connect( viewRules->selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ), this, SLOT( currentRuleChanged( QModelIndex, QModelIndex ) ) );
connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) ); connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) ); connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) ); connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) );
connect( btnRenderingOrder, SIGNAL( clicked() ), this, SLOT( setRenderingOrder() ) ); connect( btnRenderingOrder, SIGNAL( clicked() ), this, SLOT( setRenderingOrder() ) );
currentRuleChanged();
} }
QgsRuleBasedRendererV2Widget::~QgsRuleBasedRendererV2Widget() QgsRuleBasedRendererV2Widget::~QgsRuleBasedRendererV2Widget()
@ -155,13 +159,21 @@ void QgsRuleBasedRendererV2Widget::editRule( const QModelIndex& index )
void QgsRuleBasedRendererV2Widget::removeRule() void QgsRuleBasedRendererV2Widget::removeRule()
{ {
QItemSelection sel = viewRules->selectionModel()->selection(); QItemSelection sel = viewRules->selectionModel()->selection();
QgsDebugMsg( QString("REMOVE RULES!!! ranges: %1").arg( sel.count()) ); QgsDebugMsg( QString( "REMOVE RULES!!! ranges: %1" ).arg( sel.count() ) );
foreach( QItemSelectionRange range, sel ) foreach( QItemSelectionRange range, sel )
{ {
QgsDebugMsg( QString( "RANGE: r %1 - %2").arg(range.top()).arg(range.bottom()) ); QgsDebugMsg( QString( "RANGE: r %1 - %2" ).arg( range.top() ).arg( range.bottom() ) );
if ( range.isValid() ) if ( range.isValid() )
mModel->removeRows( range.top(), range.bottom() - range.top() + 1, range.parent() ); mModel->removeRows( range.top(), range.bottom() - range.top() + 1, range.parent() );
} }
// make sure that the selection is gone
viewRules->selectionModel()->clear();
}
void QgsRuleBasedRendererV2Widget::currentRuleChanged( const QModelIndex& current, const QModelIndex& previous )
{
Q_UNUSED( previous );
btnRefineRule->setEnabled( current.isValid() );
} }
@ -189,8 +201,8 @@ void QgsRuleBasedRendererV2Widget::refineRule( int type )
// TODO: set initial rule's symbol to NULL (?) // TODO: set initial rule's symbol to NULL (?)
// update model // show the newly added rules
//mModel->updateRule( index.parent(), index.row() ); viewRules->expand( index );
} }
void QgsRuleBasedRendererV2Widget::refineRuleCategories() void QgsRuleBasedRendererV2Widget::refineRuleCategories()
@ -477,7 +489,7 @@ Qt::ItemFlags QgsRuleBasedRendererV2Model::flags( const QModelIndex &index ) con
return Qt::ItemIsDropEnabled; return Qt::ItemIsDropEnabled;
// allow drop only at first column // allow drop only at first column
Qt::ItemFlag drop = (index.column() == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags); Qt::ItemFlag drop = ( index.column() == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags );
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
Qt::ItemIsEditable | Qt::ItemIsEditable |

View File

@ -105,6 +105,8 @@ class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, priv
void setRenderingOrder(); void setRenderingOrder();
void currentRuleChanged( const QModelIndex& current = QModelIndex(), const QModelIndex& previous = QModelIndex() );
protected: protected:
void refineRule( int type ); void refineRule( int type );