Use a static colors cache to preserve partition colors.

This commit is contained in:
Teo Mrnjavac 2015-04-28 17:08:41 +02:00
parent 2c9d6fff17
commit 6b40c8aaa1

View File

@ -27,6 +27,7 @@
// Qt
#include <QColor>
#include <QMap>
static const int NUM_PARTITION_COLORS = 5;
static const int NUM_NEW_PARTITION_COLORS = 4;
@ -49,6 +50,8 @@ static const QColor NEW_PARTITION_COLORS[ NUM_NEW_PARTITION_COLORS ] =
static QColor FREE_SPACE_COLOR = "#777777";
static QColor EXTENDED_COLOR = "#aaaaaa";
static QMap< QString, QColor > s_partitionColorsCache;
namespace ColorUtils
{
@ -75,6 +78,9 @@ colorForPartition( Partition* partition )
return FREE_SPACE_COLOR;
if ( partition->roles().has( PartitionRole::Extended ) )
return EXTENDED_COLOR;
if ( s_partitionColorsCache.contains( partition->partitionPath() ) )
return s_partitionColorsCache[ partition->partitionPath() ];
// No partition-specific color needed, pick one from our list, but skip
// free space: we don't want a partition to change colors if space before
// it is inserted or removed
@ -102,6 +108,9 @@ colorForPartition( Partition* partition )
if ( PMUtils::isPartitionNew( partition ) )
return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];
s_partitionColorsCache.insert( partition->partitionPath(),
PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ] );
return PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ];
}