Delete all css::Styles when the skin::StyleSheet is destroyed

This commit is contained in:
David Capello 2014-05-02 23:30:17 -03:00
parent 456bdaa20a
commit 9af8440ba6
3 changed files with 25 additions and 11 deletions

View File

@ -586,10 +586,10 @@ void SkinTheme::onRegenerate()
const css::Style* base = NULL;
if (base_id)
base = m_stylesheet.sheet().getStyle(base_id);
base = m_stylesheet.getCssStyle(base_id);
css::Style* style = new css::Style(style_id, base);
m_stylesheet.sheet().addStyle(style);
m_stylesheet.addCssStyle(style);
TiXmlElement* xmlRule = xmlStyle->FirstChildElement();
while (xmlRule) {

View File

@ -60,15 +60,28 @@ StyleSheet::StyleSheet()
StyleSheet::~StyleSheet()
{
destroyAllStyles();
delete m_sheet;
}
void StyleSheet::destroyAllStyles()
{
// Destroy skin::Styles
for (StyleMap::iterator it = m_styles.begin(), end = m_styles.end();
it != end; ++it)
delete it->second;
// Destroy css::Styles
for (std::vector<css::Style*>::iterator it = m_cssStyles.begin(), end = m_cssStyles.end();
it != end; ++it)
delete *it;
delete m_sheet;
}
void StyleSheet::addCssStyle(css::Style* style)
{
m_sheet->addStyle(style);
m_cssStyles.push_back(style);
}
const css::Style* StyleSheet::getCssStyle(const std::string& id)
{
return m_sheet->getStyle(id);
}
Style* StyleSheet::getStyle(const std::string& id)

View File

@ -32,6 +32,7 @@ class TiXmlElement;
namespace css {
class Sheet;
class Style;
class Value;
}
@ -56,7 +57,8 @@ namespace app {
static css::Rule& paddingRightRule() { return m_paddingRightRule; }
static css::Rule& paddingBottomRule() { return m_paddingBottomRule; }
css::Sheet& sheet() { return *m_sheet; }
void addCssStyle(css::Style* style);
const css::Style* getCssStyle(const std::string& id);
Style* getStyle(const std::string& id);
@ -66,8 +68,6 @@ namespace app {
private:
typedef std::map<std::string, Style*> StyleMap;
void destroyAllStyles();
static css::Rule m_backgroundColorRule;
static css::Rule m_backgroundPartRule;
static css::Rule m_iconAlignRule;
@ -80,6 +80,7 @@ namespace app {
static css::Rule m_paddingBottomRule;
css::Sheet* m_sheet;
std::vector<css::Style*> m_cssStyles;
StyleMap m_styles;
};