@@ -79,11 +79,15 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye
7979 // support for context menu (now handled generically)
8080 connect ( viewRules, SIGNAL ( customContextMenuRequested ( const QPoint& ) ), this , SLOT ( contextMenuViewCategories ( const QPoint& ) ) );
8181
82+ connect ( viewRules->selectionModel (), SIGNAL ( currentChanged ( QModelIndex, QModelIndex ) ), this , SLOT ( currentRuleChanged ( QModelIndex, QModelIndex ) ) );
83+
8284 connect ( btnAddRule, SIGNAL ( clicked () ), this , SLOT ( addRule () ) );
8385 connect ( btnEditRule, SIGNAL ( clicked () ), this , SLOT ( editRule () ) );
8486 connect ( btnRemoveRule, SIGNAL ( clicked () ), this , SLOT ( removeRule () ) );
8587
8688 connect ( btnRenderingOrder, SIGNAL ( clicked () ), this , SLOT ( setRenderingOrder () ) );
89+
90+ currentRuleChanged ();
8791}
8892
8993QgsRuleBasedRendererV2Widget::~QgsRuleBasedRendererV2Widget ()
@@ -155,13 +159,21 @@ void QgsRuleBasedRendererV2Widget::editRule( const QModelIndex& index )
155159void QgsRuleBasedRendererV2Widget::removeRule ()
156160{
157161 QItemSelection sel = viewRules->selectionModel ()->selection ();
158- QgsDebugMsg ( QString (" REMOVE RULES!!! ranges: %1" ).arg ( sel.count ()) );
162+ QgsDebugMsg ( QString ( " REMOVE RULES!!! ranges: %1" ).arg ( sel.count () ) );
159163 foreach ( QItemSelectionRange range, sel )
160164 {
161- QgsDebugMsg ( QString ( " RANGE: r %1 - %2" ).arg (range.top ()).arg (range.bottom ()) );
165+ QgsDebugMsg ( QString ( " RANGE: r %1 - %2" ).arg ( range.top () ).arg ( range.bottom () ) );
162166 if ( range.isValid () )
163167 mModel ->removeRows ( range.top (), range.bottom () - range.top () + 1 , range.parent () );
164168 }
169+ // make sure that the selection is gone
170+ viewRules->selectionModel ()->clear ();
171+ }
172+
173+ void QgsRuleBasedRendererV2Widget::currentRuleChanged ( const QModelIndex& current, const QModelIndex& previous )
174+ {
175+ Q_UNUSED ( previous );
176+ btnRefineRule->setEnabled ( current.isValid () );
165177}
166178
167179
@@ -189,8 +201,8 @@ void QgsRuleBasedRendererV2Widget::refineRule( int type )
189201
190202 // TODO: set initial rule's symbol to NULL (?)
191203
192- // update model
193- // mModel->updateRule ( index.parent(), index.row() );
204+ // show the newly added rules
205+ viewRules-> expand ( index );
194206}
195207
196208void QgsRuleBasedRendererV2Widget::refineRuleCategories ()
@@ -477,7 +489,7 @@ Qt::ItemFlags QgsRuleBasedRendererV2Model::flags( const QModelIndex &index ) con
477489 return Qt::ItemIsDropEnabled;
478490
479491 // allow drop only at first column
480- Qt::ItemFlag drop = (index.column () == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags);
492+ Qt::ItemFlag drop = ( index.column () == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags );
481493
482494 return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
483495 Qt::ItemIsEditable |
0 commit comments