File indexing completed on 2024-12-22 04:12:41

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.h"
0009 
0010 #include <QStringList>
0011 #include <QMultiHash>
0012 
0013 #include "kis_abstract_input_action.h"
0014 #include "kis_shortcut_configuration.h"
0015 
0016 class KisInputProfile::Private
0017 {
0018 public:
0019     Private() { }
0020     ~Private()
0021     {
0022         qDeleteAll(shortcuts);
0023     }
0024 
0025     QString name;
0026     QMultiHash<KisAbstractInputAction *, KisShortcutConfiguration *> shortcuts;
0027 };
0028 
0029 KisInputProfile::KisInputProfile(QObject *parent)
0030     : QObject(parent), d(new Private())
0031 {
0032 
0033 }
0034 
0035 KisInputProfile::~KisInputProfile()
0036 {
0037     delete d;
0038 }
0039 
0040 QString KisInputProfile::name() const
0041 {
0042     return d->name;
0043 }
0044 void KisInputProfile::setName(const QString &name)
0045 {
0046     if (d->name != name) {
0047         d->name = name;
0048         emit nameChanged();
0049     }
0050 }
0051 
0052 QList< KisShortcutConfiguration * > KisInputProfile::allShortcuts() const
0053 {
0054     return d->shortcuts.values();
0055 }
0056 
0057 QList< KisShortcutConfiguration * > KisInputProfile::shortcutsForAction(KisAbstractInputAction *action) const
0058 {
0059     if (d->shortcuts.contains(action)) {
0060         return d->shortcuts.values(action);
0061     }
0062 
0063     return QList<KisShortcutConfiguration *>();
0064 }
0065 
0066 void KisInputProfile::addShortcut(KisShortcutConfiguration *shortcut)
0067 {
0068     Q_ASSERT(shortcut);
0069     Q_ASSERT(shortcut->action());
0070     d->shortcuts.insert(shortcut->action(), shortcut);
0071 }
0072 
0073 void KisInputProfile::removeShortcut(KisShortcutConfiguration *shortcut)
0074 {
0075     Q_ASSERT(shortcut);
0076     Q_ASSERT(shortcut->action());
0077     d->shortcuts.remove(shortcut->action(), shortcut);
0078 }