Skip to content
Permalink
Browse files

Immediately apply conditional formatting changes to table

  • Loading branch information
nyalldawson committed Aug 21, 2015
1 parent 9ce6b6b commit 9d984b163e41c97ab0cd5ae4620b8a2584ba77a5
@@ -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
@@ -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
@@ -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 );
};
@@ -119,6 +119,8 @@ class CORE_EXPORT QgsConditionalStyle
*/
virtual bool writeXml( QDomNode & node, QDomDocument & doc );

private:

bool mValid;
QString mRule;
QScopedPointer<QgsSymbolV2> mSymbol;
@@ -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 )
@@ -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
@@ -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 );
@@ -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()
@@ -195,7 +195,7 @@ void QgsFieldConditionalFormatWidget::saveRule()
mLayer->setFieldUIProperties( mFieldCombo->currentField(), props );
pages->setCurrentIndex( 0 );
reloadStyles();
emit rulesUpdates();
emit rulesUpdated( mFieldCombo->currentField() );
reset();
}

@@ -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:

0 comments on commit 9d984b1

Please sign in to comment.
You can’t perform that action at this time.