Warning, file /graphics/krita/libs/ui/input/config/kis_input_profile_model.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * This file is part of the KDE project
0003  * SPDX-FileCopyrightText: 2013 Arjen Hiemstra <ahiemstra@heimr.nl>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #include "kis_input_profile_model.h"
0009 
0010 #include "input/kis_input_profile_manager.h"
0011 
0012 KisInputProfileModel::KisInputProfileModel(QObject *parent)
0013     : QStringListModel(parent)
0014 {
0015     setStringList(KisInputProfileManager::instance()->profileNames());
0016     connect(KisInputProfileManager::instance(), SIGNAL(profilesChanged()), SLOT(profileNamesChanged()));
0017 }
0018 
0019 KisInputProfileModel::~KisInputProfileModel()
0020 {
0021 
0022 }
0023 
0024 void KisInputProfileModel::profileNamesChanged()
0025 {
0026     setStringList(KisInputProfileManager::instance()->profileNames());
0027 }
0028 
0029 bool KisInputProfileModel::setData(const QModelIndex &index, const QVariant &value, int /*role*/)
0030 {
0031     QString oldName = profileName(index);
0032     return KisInputProfileManager::instance()->renameProfile(oldName, value.toString());
0033 }
0034 
0035 QString KisInputProfileModel::profileName(const QModelIndex &index)
0036 {
0037     return data(index, Qt::DisplayRole).toString();
0038 }
0039 
0040 QModelIndex KisInputProfileModel::find(const QString &name)
0041 {
0042     for (int i = 0; i < rowCount(); ++i) {
0043         QModelIndex ind = index(i, 0);
0044 
0045         if (profileName(ind) == name) {
0046             return ind;
0047         }
0048     }
0049 
0050     return QModelIndex();
0051 }
0052