Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add an isDirty method to QgsColorSchemeList
  • Loading branch information
nyalldawson committed Sep 15, 2014
1 parent 78db2c1 commit ec39f08
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
10 changes: 10 additions & 0 deletions python/gui/qgscolorschemelist.sip
Expand Up @@ -87,6 +87,11 @@ class QgsColorSchemeModel: QAbstractItemModel
*/
void addColor( const QColor color, const QString label = QString() );

/**Returns whether the color scheme model has been modified
* @returns true if colors have been modified
*/
bool isDirty() const;

};

/** \ingroup gui
Expand Down Expand Up @@ -138,6 +143,11 @@ class QgsColorSchemeList: QTreeView
*/
bool exportColorsToGpl( QFile &file );

/**Returns whether the color scheme list has been modified
* @returns true if colors have been modified
*/
bool isDirty() const;

public slots:

/**Removes any selected colors from the list
Expand Down
5 changes: 4 additions & 1 deletion src/app/qgsoptions.cpp
Expand Up @@ -1315,7 +1315,10 @@ void QgsOptions::saveOptions()
//
// Color palette
//
mTreeCustomColors->saveColorsToScheme();
if ( mTreeCustomColors->isDirty() )
{
mTreeCustomColors->saveColorsToScheme();
}

//
// Composer settings
Expand Down
5 changes: 4 additions & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -918,7 +918,10 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( "DefaultStyles", "/ColorRamp", cboStyleColorRamp->currentText() );
QgsProject::instance()->writeEntry( "DefaultStyles", "/AlphaInt", ( int )( 255 - ( mTransparencySlider->value() * 2.55 ) ) );
QgsProject::instance()->writeEntry( "DefaultStyles", "/RandomColors", cbxStyleRandomColors->isChecked() );
mTreeProjectColors->saveColorsToScheme();
if ( mTreeProjectColors->isDirty() )
{
mTreeProjectColors->saveColorsToScheme();
}

// store project macros
QString pythonMacros = ptePythonMacros->text();
Expand Down
19 changes: 19 additions & 0 deletions src/gui/qgscolorschemelist.cpp
Expand Up @@ -162,6 +162,16 @@ bool QgsColorSchemeList::exportColorsToGpl( QFile &file )
return QgsSymbolLayerV2Utils::saveColorsToGpl( file, QString(), mModel->colors() );
}

bool QgsColorSchemeList::isDirty() const
{
if ( !mModel )
{
return false;
}

return mModel->isDirty();
}

//
// QgsColorSchemeModel
//
Expand All @@ -171,6 +181,7 @@ QgsColorSchemeModel::QgsColorSchemeModel( QgsColorScheme *scheme, const QString
, mScheme( scheme )
, mContext( context )
, mBaseColor( baseColor )
, mIsDirty( false )
{
if ( scheme )
{
Expand Down Expand Up @@ -297,11 +308,13 @@ bool QgsColorSchemeModel::setData( const QModelIndex &index, const QVariant &val
case ColorSwatch:
mColors[ index.row()].first = value.value<QColor>();
emit dataChanged( index, index );
mIsDirty = true;
return true;

case ColorLabel:
mColors[ index.row()].second = value.toString();
emit dataChanged( index, index );
mIsDirty = true;
return true;

default:
Expand Down Expand Up @@ -425,6 +438,7 @@ bool QgsColorSchemeModel::dropMimeData( const QMimeData *data, Qt::DropAction ac
setData( labelIdx, !( *colorIt ).second.isEmpty() ? ( *colorIt ).second : QgsSymbolLayerV2Utils::colorToName(( *colorIt ).first ) );
beginRow++;
}
mIsDirty = true;

return true;
}
Expand All @@ -434,6 +448,7 @@ void QgsColorSchemeModel::setScheme( QgsColorScheme *scheme, const QString conte
mScheme = scheme;
mContext = context;
mBaseColor = baseColor;
mIsDirty = false;
beginResetModel();
mColors = scheme->fetchColors( mContext, mBaseColor );
endResetModel();
Expand Down Expand Up @@ -462,6 +477,8 @@ bool QgsColorSchemeModel::removeRows( int row, int count, const QModelIndex &par
mColors.removeAt( i );
endRemoveRows();
}

mIsDirty = true;
return true;
}

Expand All @@ -481,6 +498,7 @@ bool QgsColorSchemeModel::insertRows( int row, int count, const QModelIndex& par
mColors.insert( i, newColor );
}
endInsertRows();
mIsDirty = true;
return true;
}

Expand All @@ -497,6 +515,7 @@ void QgsColorSchemeModel::addColor( const QColor color, const QString label )
setData( colorIdx, QVariant( color ) );
QModelIndex labelIdx = index( row, 1, QModelIndex() );
setData( labelIdx, QVariant( label ) );
mIsDirty = true;
}


Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgscolorschemelist.h
Expand Up @@ -117,6 +117,11 @@ class GUI_EXPORT QgsColorSchemeModel: public QAbstractItemModel
*/
void addColor( const QColor color, const QString label = QString() );

/**Returns whether the color scheme model has been modified
* @returns true if colors have been modified
*/
bool isDirty() const { return mIsDirty; }

private:

enum Columns
Expand All @@ -129,6 +134,7 @@ class GUI_EXPORT QgsColorSchemeModel: public QAbstractItemModel
QgsColorScheme* mScheme;
QString mContext;
QColor mBaseColor;
bool mIsDirty;
};

/** \ingroup gui
Expand Down Expand Up @@ -178,6 +184,11 @@ class GUI_EXPORT QgsColorSchemeList: public QTreeView
*/
bool exportColorsToGpl( QFile &file );

/**Returns whether the color scheme list has been modified
* @returns true if colors have been modified
*/
bool isDirty() const;

public slots:

/**Removes any selected colors from the list
Expand Down

0 comments on commit ec39f08

Please sign in to comment.