QIcons are implictly shared. There's no need to pass pointers to them around and leak memory everywhere.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=851452
This commit is contained in:
parent
6f4ccf03c9
commit
240e0b4309
@ -92,7 +92,7 @@ void AppletBrowserWidgetPrivate::initFilters()
|
||||
filterModel.clear();
|
||||
|
||||
filterModel.addFilter(i18n("All Widgets"),
|
||||
KCategorizedItemsViewModels::Filter(), new KIcon("plasma"));
|
||||
KCategorizedItemsViewModels::Filter(), KIcon("plasma"));
|
||||
|
||||
// Recommended emblems and filters
|
||||
QRegExp rx("recommended[.]([0-9A-Za-z]+)[.]caption");
|
||||
@ -109,22 +109,22 @@ void AppletBrowserWidgetPrivate::initFilters()
|
||||
QString icon = configGroup.readEntry("recommended." + id + ".icon");
|
||||
QString plugins = configGroup.readEntry("recommended." + id + ".plugins");
|
||||
|
||||
appletList->addEmblem(i18n("Recommended by %1", caption), new KIcon(icon),
|
||||
appletList->addEmblem(i18n("Recommended by %1", caption), KIcon(icon),
|
||||
KCategorizedItemsViewModels::Filter("recommended." + id, true));
|
||||
filterModel.addFilter(i18n("Recommended by %1", caption),
|
||||
KCategorizedItemsViewModels::Filter("recommended." + id, true), new KIcon(icon));
|
||||
KCategorizedItemsViewModels::Filter("recommended." + id, true), KIcon(icon));
|
||||
}
|
||||
|
||||
// Filters: Special
|
||||
filterModel.addFilter(i18n("My Favorite Widgets"),
|
||||
KCategorizedItemsViewModels::Filter("favorite", true),
|
||||
new KIcon("bookmarks"));
|
||||
KIcon("bookmarks"));
|
||||
filterModel.addFilter(i18n("Widgets I Have Used Before"),
|
||||
KCategorizedItemsViewModels::Filter("used", true),
|
||||
new KIcon("view-history"));
|
||||
KIcon("view-history"));
|
||||
filterModel.addFilter(i18n("Currently Running Widgets"),
|
||||
KCategorizedItemsViewModels::Filter("running", true),
|
||||
new KIcon("view-history"));
|
||||
KIcon("view-history"));
|
||||
|
||||
filterModel.addSeparator(i18n("Categories:"));
|
||||
|
||||
@ -155,7 +155,7 @@ void AppletBrowserWidgetPrivate::init()
|
||||
layout->addWidget(appletList);
|
||||
|
||||
// Other Emblems
|
||||
appletList->addEmblem(i18n("Widgets I Have Used Before"), new KIcon("view-history"),
|
||||
appletList->addEmblem(i18n("Widgets I Have Used Before"), KIcon("view-history"),
|
||||
KCategorizedItemsViewModels::Filter("used", true));
|
||||
|
||||
initFilters();
|
||||
|
@ -185,8 +185,8 @@ void KCategorizedItemsView::updateColumnsWidth(bool force)
|
||||
itemsView->setColumnWidth(2, m_delegate->columnWidth(2, m_viewWidth));
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::addEmblem(const QString & title, QIcon * icon, const Filter & filter) {
|
||||
m_emblems[title] = QPair<Filter, QIcon *>(filter, icon);
|
||||
void KCategorizedItemsView::addEmblem(const QString & title, const QIcon & icon, const Filter & filter) {
|
||||
m_emblems[title] = QPair<Filter, QIcon>(filter, icon);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::clearEmblems() {
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
void setFilterModel(QStandardItemModel * model); ///< Sets the filters model
|
||||
void setItemModel(QStandardItemModel * model); ///< Sets the item model, as mentioned items must implement AbstractItem class
|
||||
|
||||
void addEmblem(const QString & title, QIcon * icon, const Filter & filter);
|
||||
void addEmblem(const QString & title, const QIcon & icon, const Filter & filter);
|
||||
void clearEmblems();
|
||||
|
||||
QList < AbstractItem * > selectedItems() const;
|
||||
@ -92,7 +92,7 @@ private:
|
||||
|
||||
int m_viewWidth;
|
||||
|
||||
QMap < QString, QPair < Filter, QIcon * > > m_emblems;
|
||||
QMap < QString, QPair < Filter, QIcon > > m_emblems;
|
||||
AbstractItem * getItemByProxyIndex(const QModelIndex & index) const;
|
||||
|
||||
friend class KCategorizedItemsViewDelegate;
|
||||
|
@ -135,7 +135,7 @@ void KCategorizedItemsViewDelegate::paintColMain(QPainter *painter,
|
||||
|
||||
// Counting the number of emblems for this item
|
||||
int emblemCount = 0;
|
||||
QPair < Filter, QIcon * > emblem;
|
||||
QPair < Filter, QIcon > emblem;
|
||||
foreach (emblem, m_parent->m_emblems) {
|
||||
if (item->passesFiltering(emblem.first)) ++emblemCount;
|
||||
}
|
||||
@ -176,7 +176,7 @@ void KCategorizedItemsViewDelegate::paintColMain(QPainter *painter,
|
||||
int emblemLeft = leftToRight ? (left + width - EMBLEM_ICON_SIZE) : left; // - FAV_ICON_SIZE - 2 * UNIVERSAL_PADDING
|
||||
foreach (emblem, m_parent->m_emblems) {
|
||||
if (item->passesFiltering(emblem.first)) {
|
||||
emblem.second->paint(&p,
|
||||
emblem.second.paint(&p,
|
||||
emblemLeft, top + UNIVERSAL_PADDING,
|
||||
EMBLEM_ICON_SIZE, EMBLEM_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
if (leftToRight) {
|
||||
@ -214,10 +214,10 @@ void KCategorizedItemsViewDelegate::paintColFav(QPainter *painter,
|
||||
left + width - FAV_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING,
|
||||
FAV_ICON_SIZE, FAV_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
|
||||
const KIcon * icon = (item->isFavorite())? & m_removeIcon : & m_favoriteAddIcon;
|
||||
const KIcon & icon = (item->isFavorite())? m_removeIcon : m_favoriteAddIcon;
|
||||
|
||||
if ((option.state & QStyle::State_MouseOver) && (m_onFavoriteIconItem != item))
|
||||
icon->paint(painter,
|
||||
icon.paint(painter,
|
||||
left + width - EMBLEM_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING,
|
||||
EMBLEM_ICON_SIZE, EMBLEM_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
}
|
||||
|
@ -57,12 +57,12 @@ DefaultFilterModel::DefaultFilterModel(QObject * parent) :
|
||||
}
|
||||
|
||||
void DefaultFilterModel::addFilter(const QString & caption,
|
||||
const Filter & filter, const KIcon * icon)
|
||||
const Filter & filter, const KIcon & icon)
|
||||
{
|
||||
QList<QStandardItem *> newRow;
|
||||
QStandardItem * item = new QStandardItem(caption);
|
||||
item->setData(qVariantFromValue<Filter>(filter));
|
||||
if (icon) item->setIcon(*icon);
|
||||
if (!icon.isNull()) item->setIcon(icon);
|
||||
|
||||
newRow << item;
|
||||
appendRow(newRow);
|
||||
|
@ -92,7 +92,7 @@ public:
|
||||
* @param caption The localized string to be displayed as a name of the filter
|
||||
* @param filter The filter structure
|
||||
*/
|
||||
void addFilter(const QString & caption, const Filter & filter, const KIcon * icon = NULL);
|
||||
void addFilter(const QString & caption, const Filter & filter, const KIcon & icon = KIcon());
|
||||
|
||||
/**
|
||||
* Adds a separator to the model
|
||||
|
Loading…
x
Reference in New Issue
Block a user