Skip to content

Commit ec39f08

Browse files
committed
Add an isDirty method to QgsColorSchemeList
1 parent 78db2c1 commit ec39f08

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

python/gui/qgscolorschemelist.sip

+10
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class QgsColorSchemeModel: QAbstractItemModel
8787
*/
8888
void addColor( const QColor color, const QString label = QString() );
8989

90+
/**Returns whether the color scheme model has been modified
91+
* @returns true if colors have been modified
92+
*/
93+
bool isDirty() const;
94+
9095
};
9196

9297
/** \ingroup gui
@@ -138,6 +143,11 @@ class QgsColorSchemeList: QTreeView
138143
*/
139144
bool exportColorsToGpl( QFile &file );
140145

146+
/**Returns whether the color scheme list has been modified
147+
* @returns true if colors have been modified
148+
*/
149+
bool isDirty() const;
150+
141151
public slots:
142152

143153
/**Removes any selected colors from the list

src/app/qgsoptions.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,10 @@ void QgsOptions::saveOptions()
13151315
//
13161316
// Color palette
13171317
//
1318-
mTreeCustomColors->saveColorsToScheme();
1318+
if ( mTreeCustomColors->isDirty() )
1319+
{
1320+
mTreeCustomColors->saveColorsToScheme();
1321+
}
13191322

13201323
//
13211324
// Composer settings

src/app/qgsprojectproperties.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,10 @@ void QgsProjectProperties::apply()
918918
QgsProject::instance()->writeEntry( "DefaultStyles", "/ColorRamp", cboStyleColorRamp->currentText() );
919919
QgsProject::instance()->writeEntry( "DefaultStyles", "/AlphaInt", ( int )( 255 - ( mTransparencySlider->value() * 2.55 ) ) );
920920
QgsProject::instance()->writeEntry( "DefaultStyles", "/RandomColors", cbxStyleRandomColors->isChecked() );
921-
mTreeProjectColors->saveColorsToScheme();
921+
if ( mTreeProjectColors->isDirty() )
922+
{
923+
mTreeProjectColors->saveColorsToScheme();
924+
}
922925

923926
// store project macros
924927
QString pythonMacros = ptePythonMacros->text();

src/gui/qgscolorschemelist.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ bool QgsColorSchemeList::exportColorsToGpl( QFile &file )
162162
return QgsSymbolLayerV2Utils::saveColorsToGpl( file, QString(), mModel->colors() );
163163
}
164164

165+
bool QgsColorSchemeList::isDirty() const
166+
{
167+
if ( !mModel )
168+
{
169+
return false;
170+
}
171+
172+
return mModel->isDirty();
173+
}
174+
165175
//
166176
// QgsColorSchemeModel
167177
//
@@ -171,6 +181,7 @@ QgsColorSchemeModel::QgsColorSchemeModel( QgsColorScheme *scheme, const QString
171181
, mScheme( scheme )
172182
, mContext( context )
173183
, mBaseColor( baseColor )
184+
, mIsDirty( false )
174185
{
175186
if ( scheme )
176187
{
@@ -297,11 +308,13 @@ bool QgsColorSchemeModel::setData( const QModelIndex &index, const QVariant &val
297308
case ColorSwatch:
298309
mColors[ index.row()].first = value.value<QColor>();
299310
emit dataChanged( index, index );
311+
mIsDirty = true;
300312
return true;
301313

302314
case ColorLabel:
303315
mColors[ index.row()].second = value.toString();
304316
emit dataChanged( index, index );
317+
mIsDirty = true;
305318
return true;
306319

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

429443
return true;
430444
}
@@ -434,6 +448,7 @@ void QgsColorSchemeModel::setScheme( QgsColorScheme *scheme, const QString conte
434448
mScheme = scheme;
435449
mContext = context;
436450
mBaseColor = baseColor;
451+
mIsDirty = false;
437452
beginResetModel();
438453
mColors = scheme->fetchColors( mContext, mBaseColor );
439454
endResetModel();
@@ -462,6 +477,8 @@ bool QgsColorSchemeModel::removeRows( int row, int count, const QModelIndex &par
462477
mColors.removeAt( i );
463478
endRemoveRows();
464479
}
480+
481+
mIsDirty = true;
465482
return true;
466483
}
467484

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

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

502521

src/gui/qgscolorschemelist.h

+11
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ class GUI_EXPORT QgsColorSchemeModel: public QAbstractItemModel
117117
*/
118118
void addColor( const QColor color, const QString label = QString() );
119119

120+
/**Returns whether the color scheme model has been modified
121+
* @returns true if colors have been modified
122+
*/
123+
bool isDirty() const { return mIsDirty; }
124+
120125
private:
121126

122127
enum Columns
@@ -129,6 +134,7 @@ class GUI_EXPORT QgsColorSchemeModel: public QAbstractItemModel
129134
QgsColorScheme* mScheme;
130135
QString mContext;
131136
QColor mBaseColor;
137+
bool mIsDirty;
132138
};
133139

134140
/** \ingroup gui
@@ -178,6 +184,11 @@ class GUI_EXPORT QgsColorSchemeList: public QTreeView
178184
*/
179185
bool exportColorsToGpl( QFile &file );
180186

187+
/**Returns whether the color scheme list has been modified
188+
* @returns true if colors have been modified
189+
*/
190+
bool isDirty() const;
191+
181192
public slots:
182193

183194
/**Removes any selected colors from the list

0 commit comments

Comments
 (0)