File indexing completed on 2024-05-12 16:01:36
0001 /* 0002 * SPDX-FileCopyrightText: 2009 Cyrille Berger <cberger@cberger.net> 0003 * SPDX-FileCopyrightText: 2010 Lukáš Tvrdý <lukast.dev@gmail.com> 0004 * SPDX-FileCopyrightText: 2011 Silvio Heinrich <plassy@web.de> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "kis_paint_ops_model.h" 0010 0011 #include "kis_debug.h" 0012 #include <brushengine/kis_paintop_registry.h> 0013 #include <brushengine/kis_paintop_factory.h> 0014 #include <KoResourcePaths.h> 0015 #include <QIcon> 0016 0017 0018 0019 KisPaintOpListModel::KisPaintOpListModel(QObject *parent) 0020 : BasePaintOpCategorizedListModel(parent) 0021 { 0022 } 0023 0024 QVariant KisPaintOpListModel::data(const QModelIndex& idx, int role) const 0025 { 0026 if (!idx.isValid()) return QVariant(); 0027 0028 DataItem *item = categoriesMapper()->itemFromRow(idx.row()); 0029 Q_ASSERT(item); 0030 0031 if(role == Qt::DecorationRole) { 0032 if (!item->isCategory()) { 0033 return item->data()->icon; 0034 } 0035 } else if (role == SortRole) { 0036 return item->isCategory() ? item->name() : 0037 QString("%1%2%3") 0038 .arg(item->parentCategory()->name()) 0039 .arg(item->data()->priority, 4) 0040 .arg(item->name()); 0041 } 0042 0043 return BasePaintOpCategorizedListModel::data(idx, role); 0044 } 0045 0046 void KisPaintOpListModel::fill(const QList<KisPaintOpFactory*>& list) 0047 { 0048 Q_FOREACH (KisPaintOpFactory *factory, list) { 0049 0050 categoriesMapper()->addEntry(factory->category(), 0051 KisPaintOpInfo(factory->id(), 0052 factory->name(), 0053 factory->category(), 0054 factory->icon(), 0055 factory->priority())); 0056 } 0057 categoriesMapper()->expandAllCategories(); 0058 }