# HG changeset patch # User Chris Cannam # Date 1399652150 -3600 # Node ID 734ee80286c33f445b0584e077344a7e3862e1a2 # Parent 336ccf8fc3f8dfbb8a3878cfb88266810f7726ae# Parent 8b614632568c353c01d2a7e5c48ee9bb98a4ecea Merge from default branch diff -r 336ccf8fc3f8 -r 734ee80286c3 layer/SingleColourLayer.cpp --- a/layer/SingleColourLayer.cpp Wed May 07 16:51:04 2014 +0100 +++ b/layer/SingleColourLayer.cpp Fri May 09 17:15:50 2014 +0100 @@ -32,9 +32,17 @@ m_colourExplicitlySet(false), m_defaultColourSet(false) { + // Reference current colour because setDefaulColourFor + // will unreference it before (possibly) changing it. + refColor(); setDefaultColourFor(0); } +SingleColourLayer::~SingleColourLayer() +{ + unrefColor(); +} + QPixmap SingleColourLayer::getLayerPresentationPixmap(QSize size) const { @@ -152,10 +160,6 @@ int hint = -1; bool impose = false; if (v) { - if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && - m_colourRefCount[m_colour] > 0) { - m_colourRefCount[m_colour]--; - } // We don't want to call this if !v because that probably // means we're being called from the constructor, and this is // a virtual function @@ -174,6 +178,8 @@ return; } + unrefColor(); + int bestCount = 0, bestColour = -1; for (int i = 0; i < cdb->getColourCount(); ++i) { @@ -203,15 +209,11 @@ cerr << endl; #endif } - + if (bestColour < 0) m_colour = 0; else m_colour = bestColour; - if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { - m_colourRefCount[m_colour] = 1; - } else { - m_colourRefCount[m_colour]++; - } + refColor(); } void @@ -221,18 +223,9 @@ if (m_colour == colour) return; - if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && - m_colourRefCount[m_colour] > 0) { - m_colourRefCount[m_colour]--; - } - + refColor(); m_colour = colour; - - if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { - m_colourRefCount[m_colour] = 1; - } else { - m_colourRefCount[m_colour]++; - } + unrefColor(); flagBaseColourChanged(); emit layerParametersChanged(); @@ -307,6 +300,9 @@ int colour = ColourDatabase::getInstance()->putStringValues (colourName, colourSpec, darkbg); + if (colour == -1) + return; + m_colourExplicitlySet = true; if (m_colour != colour) { @@ -315,20 +311,27 @@ SVDEBUG << "SingleColourLayer::setProperties: changing colour from " << m_colour << " to " << colour << endl; #endif - if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && - m_colourRefCount[m_colour] > 0) { - m_colourRefCount[m_colour]--; - } - + unrefColor(); m_colour = colour; - - if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { - m_colourRefCount[m_colour] = 1; - } else { - m_colourRefCount[m_colour]++; - } + refColor(); flagBaseColourChanged(); } } +void SingleColourLayer::refColor() +{ + if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { + m_colourRefCount[m_colour] = 1; + } else { + m_colourRefCount[m_colour]++; + } +} + +void SingleColourLayer::unrefColor() +{ + if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && + m_colourRefCount[m_colour] > 0) { + m_colourRefCount[m_colour]--; + } +} diff -r 336ccf8fc3f8 -r 734ee80286c3 layer/SingleColourLayer.h --- a/layer/SingleColourLayer.h Wed May 07 16:51:04 2014 +0100 +++ b/layer/SingleColourLayer.h Fri May 09 17:15:50 2014 +0100 @@ -75,6 +75,7 @@ protected: SingleColourLayer(); + virtual ~SingleColourLayer(); virtual QColor getBaseQColor() const; virtual QColor getBackgroundQColor(View *v) const; @@ -91,6 +92,10 @@ int m_colour; bool m_colourExplicitlySet; bool m_defaultColourSet; + +private: + void refColor(); + void unrefColor(); }; #endif