Skip to content

Commit 60dce16

Browse files
committed
Flag project as dirty when attribute table configuration changes
1 parent 662bf43 commit 60dce16

6 files changed

+41
-8
lines changed

src/core/qgsattributetableconfig.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ void QgsAttributeTableConfig::setColumnHidden( int column, bool hidden )
228228
mColumns[ column ].hidden = hidden;
229229
}
230230

231+
bool QgsAttributeTableConfig::operator!=( const QgsAttributeTableConfig& other ) const
232+
{
233+
return mSortExpression != other.mSortExpression || mColumns != other.mColumns || mActionWidgetStyle != other.mActionWidgetStyle;
234+
}
235+
231236
void QgsAttributeTableConfig::writeXml( QDomNode& node ) const
232237
{
233238
QDomDocument doc( node.ownerDocument() );
@@ -263,3 +268,8 @@ void QgsAttributeTableConfig::writeXml( QDomNode& node ) const
263268

264269
node.appendChild( configElement );
265270
}
271+
272+
bool QgsAttributeTableConfig::ColumnConfig::operator== ( const ColumnConfig& other ) const
273+
{
274+
return type == other.type && name == other.name && hidden == other.hidden;
275+
}

src/core/qgsattributetableconfig.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class CORE_EXPORT QgsAttributeTableConfig
5252
, width( -1 )
5353
{}
5454

55+
bool operator== ( const ColumnConfig& other ) const;
56+
5557
Type type; //!< The type of this column.
5658
QString name; //!< The name of the attribute if this column represents a field
5759
bool hidden; //!< Flag that controls if the column is hidden
@@ -165,6 +167,11 @@ class CORE_EXPORT QgsAttributeTableConfig
165167
*/
166168
void setColumnHidden( int column, bool hidden );
167169

170+
/**
171+
* Compare this configuration to other.
172+
*/
173+
bool operator!= ( const QgsAttributeTableConfig& other ) const;
174+
168175
private:
169176
QVector<ColumnConfig> mColumns;
170177
ActionWidgetStyle mActionWidgetStyle;

src/core/qgsmaplayer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
672672
*/
673673
void legendChanged();
674674

675+
/**
676+
* Emitted whenever the configuration is changed. The project listens to this signal
677+
* to be marked as dirty.
678+
*/
679+
void configChanged();
680+
675681
protected:
676682
/** Set the extent */
677683
virtual void setExtent( const QgsRectangle &rect );

src/core/qgsproject.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,8 @@ void QgsProject::onMapLayersAdded( const QList<QgsMapLayer*>& layers )
10501050
}
10511051
vlayer->dataProvider()->setProviderProperty( QgsVectorDataProvider::EvaluateDefaultValues, evaluateDefaultValues() );
10521052
}
1053+
1054+
connect( layer, SIGNAL( configChanged() ), this, SLOT( setDirty() ) );
10531055
}
10541056
}
10551057

src/core/qgsproject.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ class CORE_EXPORT QgsProject : public QObject
116116
*/
117117
Q_DECL_DEPRECATED inline void dirty( bool b ) { setDirty( b ); }
118118

119-
/**
120-
* Flag the project as dirty (modified). If this flag is set, the user will
121-
* be asked to save changes to the project before closing the current project.
122-
*
123-
* @note added in 2.4
124-
*/
125-
void setDirty( bool b );
126119
//@}
127120

128121

@@ -470,6 +463,17 @@ class CORE_EXPORT QgsProject : public QObject
470463
//! Emitted when the list of layer which are excluded from map identification changes
471464
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
472465

466+
public slots:
467+
468+
/**
469+
* Flag the project as dirty (modified). If this flag is set, the user will
470+
* be asked to save changes to the project before closing the current project.
471+
*
472+
* @note added in 2.4
473+
* @note promoted to public slot in 2.16
474+
*/
475+
void setDirty( bool b = true );
476+
473477
private slots:
474478
void onMapLayersAdded( const QList<QgsMapLayer*>& layers );
475479
void cleanTransactionGroups( bool force = false );

src/core/qgsvectorlayer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3752,7 +3752,11 @@ QgsAttributeTableConfig QgsVectorLayer::attributeTableConfig() const
37523752

37533753
void QgsVectorLayer::setAttributeTableConfig( const QgsAttributeTableConfig& attributeTableConfig )
37543754
{
3755-
mAttributeTableConfig = attributeTableConfig;
3755+
if ( mAttributeTableConfig != attributeTableConfig )
3756+
{
3757+
mAttributeTableConfig = attributeTableConfig;
3758+
emit configChanged();
3759+
}
37563760
}
37573761

37583762
void QgsVectorLayer::setDiagramLayerSettings( const QgsDiagramLayerSettings& s )

0 commit comments

Comments
 (0)