From 6b40c8aaa103bf2b1f47f8419122ad75c2039116 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 28 Apr 2015 17:08:41 +0200 Subject: [PATCH] Use a static colors cache to preserve partition colors. --- src/modules/partition/core/ColorUtils.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/modules/partition/core/ColorUtils.cpp b/src/modules/partition/core/ColorUtils.cpp index a862322ef..28f5661a3 100644 --- a/src/modules/partition/core/ColorUtils.cpp +++ b/src/modules/partition/core/ColorUtils.cpp @@ -27,6 +27,7 @@ // Qt #include +#include 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 ]; }