Skip to content

Commit 9d984b1

Browse files
committed
Immediately apply conditional formatting changes to table
1 parent 9ce6b6b commit 9d984b1

8 files changed

+41
-10
lines changed

python/gui/attributetable/qgsattributetablemodel.sip

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ class QgsAttributeTableModel : QAbstractTableModel
2222

2323
virtual ~QgsAttributeTableModel();
2424

25-
/**
26-
* Loads the layer into the model
27-
* Preferably to be called, before basing any other models on this model
28-
*/
29-
virtual void loadLayer();
30-
3125
/**
3226
* Returns the number of rows
3327
* @param parent parent index
@@ -179,6 +173,20 @@ class QgsAttributeTableModel : QAbstractTableModel
179173
*/
180174
const QgsAttributeEditorContext& editorContext() const;
181175

176+
public slots:
177+
178+
/**
179+
* Loads the layer into the model
180+
* Preferably to be called, before using this model as source for any other proxy model
181+
*/
182+
virtual void loadLayer();
183+
184+
/** Handles updating the model when the conditional style for a field changes.
185+
* @param fieldName name of field whose conditional style has changed
186+
* @note added in QGIS 2.12
187+
*/
188+
void fieldConditionalStyleChanged( const QString& fieldName );
189+
182190
signals:
183191
/**
184192
* Model has been changed

python/gui/attributetable/qgsfieldconditionalformatwidget.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class QgsFieldConditionalFormatWidget : QWidget
3939
signals:
4040

4141
/** Emitted when the conditional styling rules are updated.
42+
* @param fieldName name of field whose rules have been modified.
4243
*/
43-
void rulesUpdates();
44+
void rulesUpdated( const QString& fieldName );
4445
};

src/core/qgsconditionalstyle.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class CORE_EXPORT QgsConditionalStyle
119119
*/
120120
virtual bool writeXml( QDomNode & node, QDomDocument & doc );
121121

122+
private:
123+
122124
bool mValid;
123125
QString mRule;
124126
QScopedPointer<QgsSymbolV2> mSymbol;

src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,17 @@ void QgsAttributeTableModel::loadLayer()
385385
endResetModel();
386386
}
387387

388+
void QgsAttributeTableModel::fieldConditionalStyleChanged( const QString &fieldName )
389+
{
390+
int fieldIndex = mLayerCache->layer()->fieldNameIndex( fieldName );
391+
if ( fieldIndex == -1 )
392+
return;
393+
394+
//whole column has changed
395+
int col = fieldCol( fieldIndex );
396+
emit dataChanged( index( 0, col ), index( rowCount() - 1, col ) );
397+
}
398+
388399
void QgsAttributeTableModel::swapRows( QgsFeatureId a, QgsFeatureId b )
389400
{
390401
if ( a == b )

src/gui/attributetable/qgsattributetablemodel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
228228
*/
229229
virtual void loadLayer();
230230

231+
/** Handles updating the model when the conditional style for a field changes.
232+
* @param fieldName name of field whose conditional style has changed
233+
* @note added in QGIS 2.12
234+
*/
235+
void fieldConditionalStyleChanged( const QString& fieldName );
236+
231237
signals:
232238
/**
233239
* Model has been changed

src/gui/attributetable/qgsdualview.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ void QgsDualView::initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest&
241241
connect( mMasterModel, SIGNAL( progress( int, bool & ) ), this, SLOT( progress( int, bool & ) ) );
242242
connect( mMasterModel, SIGNAL( finished() ), this, SLOT( finished() ) );
243243

244+
connect( mConditionalFormatWidget, SIGNAL( rulesUpdated( QString ) ), mMasterModel, SLOT( fieldConditionalStyleChanged( QString ) ) );
245+
244246
mMasterModel->loadLayer();
245247

246248
mFilterModel = new QgsAttributeTableFilterModel( mapCanvas, mMasterModel, mMasterModel );

src/gui/attributetable/qgsfieldconditionalformatwidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void QgsFieldConditionalFormatWidget::deleteRule()
121121
mLayer->setFieldUIProperties( mFieldCombo->currentField(), props );
122122
pages->setCurrentIndex( 0 );
123123
reloadStyles();
124-
emit rulesUpdates();
124+
emit rulesUpdated( mFieldCombo->currentField() );
125125
}
126126

127127
void QgsFieldConditionalFormatWidget::cancelRule()
@@ -195,7 +195,7 @@ void QgsFieldConditionalFormatWidget::saveRule()
195195
mLayer->setFieldUIProperties( mFieldCombo->currentField(), props );
196196
pages->setCurrentIndex( 0 );
197197
reloadStyles();
198-
emit rulesUpdates();
198+
emit rulesUpdated( mFieldCombo->currentField() );
199199
reset();
200200
}
201201

src/gui/attributetable/qgsfieldconditionalformatwidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ class GUI_EXPORT QgsFieldConditionalFormatWidget : public QWidget, private Ui::Q
6363
signals:
6464

6565
/** Emitted when the conditional styling rules are updated.
66+
* @param fieldName name of field whose rules have been modified.
6667
*/
67-
void rulesUpdates();
68+
void rulesUpdated( const QString& fieldName );
6869

6970
public slots:
7071

0 commit comments

Comments
 (0)