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

0001 /*
0002  * SPDX-FileCopyrightText: 2022 Sharaf Zaman <shzam@sdf.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef __KISINPUTPROFILEMIGRATOR_H_
0008 #define __KISINPUTPROFILEMIGRATOR_H_
0009 
0010 #include <QList>
0011 #include <QMap>
0012 
0013 class KisShortcutConfiguration;
0014 class KisInputProfileManager;
0015 class KisAbstractInputAction;
0016 
0017 struct ProfileEntry
0018 {
0019     QString name;
0020     QString fullpath;
0021     int version;
0022 
0023     int operator<(const ProfileEntry other) const
0024     {
0025         return this->name < other.name;
0026     }
0027 };
0028 
0029 class KisInputProfileMigrator
0030 {
0031 public:
0032     virtual ~KisInputProfileMigrator();
0033 
0034     virtual QMap<ProfileEntry, QList<KisShortcutConfiguration>>
0035     migrate(const QMap<QString, ProfileEntry> profiles) = 0;
0036 };
0037 
0038 /**
0039  * Migrates Krita profile version 5 to 6
0040  */
0041 class KisInputProfileMigrator5To6 : public KisInputProfileMigrator
0042 {
0043 
0044 public:
0045     KisInputProfileMigrator5To6(KisInputProfileManager *manager);
0046     ~KisInputProfileMigrator5To6() override;
0047 
0048     QMap<ProfileEntry, QList<KisShortcutConfiguration>>
0049     migrate(const QMap<QString, ProfileEntry> profiles) override;
0050 
0051 private:
0052     QList<KisShortcutConfiguration> defaultTouchShortcuts();
0053 
0054     template <typename Func>
0055     void filterShortcuts(QList<KisShortcutConfiguration> &shortcuts, Func func);
0056 
0057     QList<KisShortcutConfiguration> getShortcutsFromProfile(QString profile) const;
0058 
0059 private:
0060     KisInputProfileManager *m_manager;
0061     QStringList m_profilesList;
0062     QString m_defaultProfile;
0063 };
0064 
0065 #endif // __KISINPUTPROFILEMIGRATOR_H_