on dc81012 help sign in
unity8/plugins/Unity/Indicators/unitymenumodelcache.cpp
57 lines 1.4 kB history raw
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Nick Dedekind <nick.dedekind@canonical.com>
18 */
20#include "unitymenumodelcache.h"
21#include <unitymenumodel.h>
23UnityMenuModelCache::UnityMenuModelCache(QObject* parent)
24 : QObject(parent),
25 m_ref(0)
29UnityMenuModelCache::~UnityMenuModelCache()
31 qDeleteAll(m_menuModels);
34void UnityMenuModelCache::ref()
36 m_ref++;
39void UnityMenuModelCache::deref()
41 --m_ref;
42 if (m_ref == 0) {
43 qDeleteAll(m_menuModels);
44 m_menuModels.clear();
45 }
48UnityMenuModel* UnityMenuModelCache::model(const QString& path) const
50 return m_menuModels.value(path, NULL);
53void UnityMenuModelCache::registerModel(const QString& path, UnityMenuModel* menuModel)
55 menuModel->setParent(this);
56 m_menuModels[path] = menuModel;