File indexing completed on 2025-04-27 04:08:14
0001 /* 0002 * This file is part of the KDE project 0003 * SPDX-FileCopyrightText: 2014 Arjen Hiemstra <ahiemstra@heimr.nl> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "ColorDepthModel.h" 0009 #include <libs/pigment/KoColorSpaceRegistry.h> 0010 0011 class ColorDepthModel::Private 0012 { 0013 public: 0014 Private() { } 0015 0016 QString colorModelId; 0017 QList<KoID> colorDepths; 0018 }; 0019 0020 ColorDepthModel::ColorDepthModel(QObject* parent) 0021 : QAbstractListModel(parent), d(new Private) 0022 { 0023 } 0024 0025 ColorDepthModel::~ColorDepthModel() 0026 { 0027 delete d; 0028 } 0029 0030 QHash<int, QByteArray> ColorDepthModel::roleNames() const 0031 { 0032 QHash<int, QByteArray> roleNames; 0033 roleNames.insert(TextRole, "text"); 0034 return roleNames; 0035 } 0036 0037 int ColorDepthModel::rowCount(const QModelIndex& parent) const 0038 { 0039 Q_UNUSED(parent); 0040 return d->colorDepths.count(); 0041 } 0042 0043 QVariant ColorDepthModel::data(const QModelIndex& index, int role) const 0044 { 0045 if(!index.isValid() || index.row() < 0 || index.row() >= d->colorDepths.count()) 0046 return QVariant(); 0047 0048 if(role == TextRole) { 0049 return d->colorDepths.at(index.row()).name(); 0050 } 0051 0052 return QVariant(); 0053 } 0054 0055 QString ColorDepthModel::colorModelId() const 0056 { 0057 return d->colorModelId; 0058 } 0059 0060 void ColorDepthModel::setColorModelId(const QString& id) 0061 { 0062 if(id != d->colorModelId) { 0063 d->colorModelId = id; 0064 if(d->colorDepths.count() > 0) { 0065 beginRemoveRows(QModelIndex(), 0, d->colorDepths.count() - 1); 0066 endRemoveRows(); 0067 } 0068 d->colorDepths = KoColorSpaceRegistry::instance()->colorDepthList(d->colorModelId, KoColorSpaceRegistry::OnlyUserVisible); 0069 if(d->colorDepths.count() > 0) { 0070 beginInsertRows(QModelIndex(), 0, d->colorDepths.count() - 1); 0071 endInsertRows(); 0072 } 0073 emit colorModelIdChanged(); 0074 } 0075 } 0076 0077 QString ColorDepthModel::id(int index) 0078 { 0079 if(index < 0 || index >= d->colorDepths.count()) 0080 return QString(); 0081 0082 return d->colorDepths.at(index).id(); 0083 } 0084 0085 int ColorDepthModel::indexOf(const QString& id) 0086 { 0087 return d->colorDepths.indexOf(KoID(id)); 0088 }