Skip to content
Permalink
Browse files

Add an isDirty method to QgsColorSchemeList

  • Loading branch information
nyalldawson committed Sep 15, 2014
1 parent 78db2c1 commit ec39f081b79b60840a81e11532372af699cfbfb9
@@ -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
@@ -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
@@ -1315,7 +1315,10 @@ void QgsOptions::saveOptions()
//
// Color palette
//
mTreeCustomColors->saveColorsToScheme();
if ( mTreeCustomColors->isDirty() )
{
mTreeCustomColors->saveColorsToScheme();
}

//
// Composer settings
@@ -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();
@@ -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
//
@@ -171,6 +181,7 @@ QgsColorSchemeModel::QgsColorSchemeModel( QgsColorScheme *scheme, const QString
, mScheme( scheme )
, mContext( context )
, mBaseColor( baseColor )
, mIsDirty( false )
{
if ( scheme )
{
@@ -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:
@@ -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;
}
@@ -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();
@@ -462,6 +477,8 @@ bool QgsColorSchemeModel::removeRows( int row, int count, const QModelIndex &par
mColors.removeAt( i );
endRemoveRows();
}

mIsDirty = true;
return true;
}

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

@@ -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;
}


@@ -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
@@ -129,6 +134,7 @@ class GUI_EXPORT QgsColorSchemeModel: public QAbstractItemModel
QgsColorScheme* mScheme;
QString mContext;
QColor mBaseColor;
bool mIsDirty;
};

/** \ingroup gui
@@ -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

0 comments on commit ec39f08

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