Skip to content

Commit

Permalink
Flag project as dirty when attribute table configuration changes
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 3, 2016
1 parent 662bf43 commit 60dce16
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/core/qgsattributetableconfig.cpp
Expand Up @@ -228,6 +228,11 @@ void QgsAttributeTableConfig::setColumnHidden( int column, bool hidden )
mColumns[ column ].hidden = hidden;
}

bool QgsAttributeTableConfig::operator!=( const QgsAttributeTableConfig& other ) const
{
return mSortExpression != other.mSortExpression || mColumns != other.mColumns || mActionWidgetStyle != other.mActionWidgetStyle;
}

void QgsAttributeTableConfig::writeXml( QDomNode& node ) const
{
QDomDocument doc( node.ownerDocument() );
Expand Down Expand Up @@ -263,3 +268,8 @@ void QgsAttributeTableConfig::writeXml( QDomNode& node ) const

node.appendChild( configElement );
}

bool QgsAttributeTableConfig::ColumnConfig::operator== ( const ColumnConfig& other ) const
{
return type == other.type && name == other.name && hidden == other.hidden;
}
7 changes: 7 additions & 0 deletions src/core/qgsattributetableconfig.h
Expand Up @@ -52,6 +52,8 @@ class CORE_EXPORT QgsAttributeTableConfig
, width( -1 )
{}

bool operator== ( const ColumnConfig& other ) const;

Type type; //!< The type of this column.
QString name; //!< The name of the attribute if this column represents a field
bool hidden; //!< Flag that controls if the column is hidden
Expand Down Expand Up @@ -165,6 +167,11 @@ class CORE_EXPORT QgsAttributeTableConfig
*/
void setColumnHidden( int column, bool hidden );

/**
* Compare this configuration to other.
*/
bool operator!= ( const QgsAttributeTableConfig& other ) const;

private:
QVector<ColumnConfig> mColumns;
ActionWidgetStyle mActionWidgetStyle;
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsmaplayer.h
Expand Up @@ -672,6 +672,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
void legendChanged();

/**
* Emitted whenever the configuration is changed. The project listens to this signal
* to be marked as dirty.
*/
void configChanged();

protected:
/** Set the extent */
virtual void setExtent( const QgsRectangle &rect );
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsproject.cpp
Expand Up @@ -1050,6 +1050,8 @@ void QgsProject::onMapLayersAdded( const QList<QgsMapLayer*>& layers )
}
vlayer->dataProvider()->setProviderProperty( QgsVectorDataProvider::EvaluateDefaultValues, evaluateDefaultValues() );
}

connect( layer, SIGNAL( configChanged() ), this, SLOT( setDirty() ) );
}
}

Expand Down
18 changes: 11 additions & 7 deletions src/core/qgsproject.h
Expand Up @@ -116,13 +116,6 @@ class CORE_EXPORT QgsProject : public QObject
*/
Q_DECL_DEPRECATED inline void dirty( bool b ) { setDirty( b ); }

/**
* Flag the project as dirty (modified). If this flag is set, the user will
* be asked to save changes to the project before closing the current project.
*
* @note added in 2.4
*/
void setDirty( bool b );
//@}


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

public slots:

/**
* Flag the project as dirty (modified). If this flag is set, the user will
* be asked to save changes to the project before closing the current project.
*
* @note added in 2.4
* @note promoted to public slot in 2.16
*/
void setDirty( bool b = true );

private slots:
void onMapLayersAdded( const QList<QgsMapLayer*>& layers );
void cleanTransactionGroups( bool force = false );
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -3752,7 +3752,11 @@ QgsAttributeTableConfig QgsVectorLayer::attributeTableConfig() const

void QgsVectorLayer::setAttributeTableConfig( const QgsAttributeTableConfig& attributeTableConfig )
{
mAttributeTableConfig = attributeTableConfig;
if ( mAttributeTableConfig != attributeTableConfig )
{
mAttributeTableConfig = attributeTableConfig;
emit configChanged();
}
}

void QgsVectorLayer::setDiagramLayerSettings( const QgsDiagramLayerSettings& s )
Expand Down

0 comments on commit 60dce16

Please sign in to comment.