Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Immediately apply conditional formatting changes to table
  • Loading branch information
nyalldawson committed Aug 21, 2015
1 parent 9ce6b6b commit 9d984b1
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 10 deletions.
20 changes: 14 additions & 6 deletions python/gui/attributetable/qgsattributetablemodel.sip
Expand Up @@ -22,12 +22,6 @@ class QgsAttributeTableModel : QAbstractTableModel

virtual ~QgsAttributeTableModel();

/**
* Loads the layer into the model
* Preferably to be called, before basing any other models on this model
*/
virtual void loadLayer();

/**
* Returns the number of rows
* @param parent parent index
Expand Down Expand Up @@ -179,6 +173,20 @@ class QgsAttributeTableModel : QAbstractTableModel
*/
const QgsAttributeEditorContext& editorContext() const;

public slots:

/**
* Loads the layer into the model
* Preferably to be called, before using this model as source for any other proxy model
*/
virtual void loadLayer();

/** Handles updating the model when the conditional style for a field changes.
* @param fieldName name of field whose conditional style has changed
* @note added in QGIS 2.12
*/
void fieldConditionalStyleChanged( const QString& fieldName );

signals:
/**
* Model has been changed
Expand Down
Expand Up @@ -39,6 +39,7 @@ class QgsFieldConditionalFormatWidget : QWidget
signals:

/** Emitted when the conditional styling rules are updated.
* @param fieldName name of field whose rules have been modified.
*/
void rulesUpdates();
void rulesUpdated( const QString& fieldName );
};
2 changes: 2 additions & 0 deletions src/core/qgsconditionalstyle.h
Expand Up @@ -119,6 +119,8 @@ class CORE_EXPORT QgsConditionalStyle
*/
virtual bool writeXml( QDomNode & node, QDomDocument & doc );

private:

bool mValid;
QString mRule;
QScopedPointer<QgsSymbolV2> mSymbol;
Expand Down
11 changes: 11 additions & 0 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -385,6 +385,17 @@ void QgsAttributeTableModel::loadLayer()
endResetModel();
}

void QgsAttributeTableModel::fieldConditionalStyleChanged( const QString &fieldName )
{
int fieldIndex = mLayerCache->layer()->fieldNameIndex( fieldName );
if ( fieldIndex == -1 )
return;

//whole column has changed
int col = fieldCol( fieldIndex );
emit dataChanged( index( 0, col ), index( rowCount() - 1, col ) );
}

void QgsAttributeTableModel::swapRows( QgsFeatureId a, QgsFeatureId b )
{
if ( a == b )
Expand Down
6 changes: 6 additions & 0 deletions src/gui/attributetable/qgsattributetablemodel.h
Expand Up @@ -228,6 +228,12 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
*/
virtual void loadLayer();

/** Handles updating the model when the conditional style for a field changes.
* @param fieldName name of field whose conditional style has changed
* @note added in QGIS 2.12
*/
void fieldConditionalStyleChanged( const QString& fieldName );

signals:
/**
* Model has been changed
Expand Down
2 changes: 2 additions & 0 deletions src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -241,6 +241,8 @@ void QgsDualView::initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest&
connect( mMasterModel, SIGNAL( progress( int, bool & ) ), this, SLOT( progress( int, bool & ) ) );
connect( mMasterModel, SIGNAL( finished() ), this, SLOT( finished() ) );

connect( mConditionalFormatWidget, SIGNAL( rulesUpdated( QString ) ), mMasterModel, SLOT( fieldConditionalStyleChanged( QString ) ) );

mMasterModel->loadLayer();

mFilterModel = new QgsAttributeTableFilterModel( mapCanvas, mMasterModel, mMasterModel );
Expand Down
4 changes: 2 additions & 2 deletions src/gui/attributetable/qgsfieldconditionalformatwidget.cpp
Expand Up @@ -121,7 +121,7 @@ void QgsFieldConditionalFormatWidget::deleteRule()
mLayer->setFieldUIProperties( mFieldCombo->currentField(), props );
pages->setCurrentIndex( 0 );
reloadStyles();
emit rulesUpdates();
emit rulesUpdated( mFieldCombo->currentField() );
}

void QgsFieldConditionalFormatWidget::cancelRule()
Expand Down Expand Up @@ -195,7 +195,7 @@ void QgsFieldConditionalFormatWidget::saveRule()
mLayer->setFieldUIProperties( mFieldCombo->currentField(), props );
pages->setCurrentIndex( 0 );
reloadStyles();
emit rulesUpdates();
emit rulesUpdated( mFieldCombo->currentField() );
reset();
}

Expand Down
3 changes: 2 additions & 1 deletion src/gui/attributetable/qgsfieldconditionalformatwidget.h
Expand Up @@ -63,8 +63,9 @@ class GUI_EXPORT QgsFieldConditionalFormatWidget : public QWidget, private Ui::Q
signals:

/** Emitted when the conditional styling rules are updated.
* @param fieldName name of field whose rules have been modified.
*/
void rulesUpdates();
void rulesUpdated( const QString& fieldName );

public slots:

Expand Down

0 comments on commit 9d984b1

Please sign in to comment.