Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Update Input Profile configuration schema to version 7

Dmitry Kazakov3c20f91774b3
diff --git a/krita/data/input/clipstudiopaintcompatible.profile b/krita/data/input/clipstudiopaintcompatible.profile
index c3db3381eb..42578666b6 100644
--- a/krita/data/input/clipstudiopaintcompatible.profile
+++ b/krita/data/input/clipstudiopaintcompatible.profile
@@ -15,7 +15,7 @@
[General]
name=Clip Studio Paint Compatible
-version=6
+version=7
[Pan Canvas]
0={0;2;[20];1;0;0}
@@ -76,3 +76,4 @@ version=6
[Zoom and Rotate Canvas]
0={0;4;[];0;0;7}
+1={0;5;[];0;0;1}
diff --git a/krita/data/input/kritadefault.profile b/krita/data/input/kritadefault.profile
index a4143fb72f..689624cc55 100644
--- a/krita/data/input/kritadefault.profile
+++ b/krita/data/input/kritadefault.profile
@@ -15,10 +15,10 @@
[General]
name=Krita Default
-version=6
+version=7
[Pan Canvas]
-0={0;5;[];0;0;2}
+0={0;4;[];0;0;6}
1={0;2;[20];1;0;0}
2={0;2;[];4;0;0}
3={1;1;[];0;0;0}
@@ -26,7 +26,6 @@ version=6
5={3;1;[];0;0;0}
6={4;1;[];0;0;0}
7={0;3;[];0;5;0}
-8={0;4;[];0;0;6}
[Rotate Canvas]
0={0;2;[1000020,20];1;0;0}
@@ -35,7 +34,6 @@ version=6
3={2;1;[34];0;0;0}
4={4;1;[35];0;0;0}
5={3;1;[36];0;0;0}
-6={0;5;[];0;0;3}
[Select Layer]
0={1;2;[1000020,52];1;0;0}
@@ -60,8 +58,7 @@ version=6
0={2;1;[2b];0;0;0}
1={4;1;[31];0;0;0}
10={5;1;[32];0;0;0}
-11={0;5;[];0;0;1}
-12={8;2;[1000021,1000023];4;0;0}
+11={8;2;[1000021,1000023];4;0;0}
2={3;1;[2d];0;0;0}
3={2;1;[3d];0;0;0}
4={3;3;[];0;2;0}
@@ -73,6 +70,7 @@ version=6
[Zoom and Rotate Canvas]
0={0;4;[];0;0;7}
+1={0;5;[];0;0;1}
[Touch Gestures]
0={0;4;[];0;0;2}
diff --git a/krita/data/input/painttoolsaicompatible.profile b/krita/data/input/painttoolsaicompatible.profile
index 9384dbfe31..9d1e4b11c0 100644
--- a/krita/data/input/painttoolsaicompatible.profile
+++ b/krita/data/input/painttoolsaicompatible.profile
@@ -15,7 +15,7 @@
[General]
name=Paint Tool Sai Compatible
-version=6
+version=7
[Pan Canvas]
0={4;1;[];0;0;0}
@@ -24,7 +24,6 @@ version=6
3={1;1;[];0;0;0}
4={0;2;[];4;0;0}
5={0;2;[20];1;0;0}
-6={0;5;[];0;0;2}
[Rotate Canvas]
0={3;1;[36];0;0;0}
@@ -56,9 +55,8 @@ version=6
0={2;3;[];0;1;0}
1={0;2;[1000021];4;0;0}
10={0;2;[1000021,20];1;0;0}
-11={0;5;[];0;0;1}
-12={6;1;[33];0;0;0}
-13={1;2;[1000021,1000023,20];1;0;0}
+11={6;1;[33];0;0;0}
+12={1;2;[1000021,1000023,20];1;0;0}
2={5;1;[32];0;0;0}
3={2;1;[2b];0;0;0}
4={4;1;[1000010];0;0;0}
@@ -70,6 +68,7 @@ version=6
[Zoom and Rotate Canvas]
0={0;4;[];0;0;7}
+1={0;5;[];0;0;1}
[Touch Gestures]
0={0;4;[];0;0;2}
diff --git a/krita/data/input/photoshopcompatible.profile b/krita/data/input/photoshopcompatible.profile
index b103cf3a5b..404ec78f4c 100644
--- a/krita/data/input/photoshopcompatible.profile
+++ b/krita/data/input/photoshopcompatible.profile
@@ -15,16 +15,15 @@
[General]
name=Photoshop Compatible
-version=6
+version=7
[Pan Canvas]
-0={0;5;[];0;0;2}
-1={0;2;[20];1;0;0}
-2={0;2;[];4;0;0}
-3={1;1;[];0;0;0}
-4={2;1;[];0;0;0}
-5={3;1;[];0;0;0}
-6={4;1;[];0;0;0}
+0={0;2;[20];1;0;0}
+1={0;2;[];4;0;0}
+2={1;1;[];0;0;0}
+3={2;1;[];0;0;0}
+4={3;1;[];0;0;0}
+5={4;1;[];0;0;0}
[Rotate Canvas]
0={0;2;[1000020,20];1;0;0}
@@ -62,11 +61,11 @@ version=6
5={4;1;[1000021,31];0;0;0}
6={2;1;[2b];0;0;0}
7={5;1;[1000021,30];0;0;0}
-8={0;5;[];0;0;1}
-9={0;2;[1000021,20];1;0;0}
+8={0;2;[1000021,20];1;0;0}
[Zoom and Rotate Canvas]
0={0;4;[];0;0;7}
+1={0;5;[];0;0;1}
[Touch Gestures]
0={0;4;[];0;0;2}
diff --git a/krita/data/input/tabletpro.profile b/krita/data/input/tabletpro.profile
index 25d1324543..c9678f1998 100644
--- a/krita/data/input/tabletpro.profile
+++ b/krita/data/input/tabletpro.profile
@@ -15,7 +15,7 @@
[General]
name=Tablet Pro (for use with the Tablet Pro application on Windows)
-version=5
+version=7
[Pan Canvas]
0={4;1;[];0;0;0}
@@ -69,5 +69,9 @@ version=5
8={3;1;[2d];0;0;0}
9={2;1;[3d];0;0;0}
+[Zoom and Rotate Canvas]
+0={0;4;[];0;0;7}
+1={0;5;[];0;0;1}
+
[Toggle Canvas Only]
0={0;4;[];0;0;6}
diff --git a/libs/ui/input/KisInputProfileMigrator.cpp b/libs/ui/input/KisInputProfileMigrator.cpp
index 40d9bc4d62..8505b31047 100644
--- a/libs/ui/input/KisInputProfileMigrator.cpp
+++ b/libs/ui/input/KisInputProfileMigrator.cpp
@@ -6,21 +6,26 @@
#include "KisInputProfileMigrator.h"
+#include <QDebug>
+
+#include <KisMpl.h>
+
#include <KConfig>
#include <KConfigGroup>
#include <KoResourcePaths.h>
-#include <QDebug>
+#include <kis_assert.h>
#include "kis_abstract_input_action.h"
#include "kis_input_profile_manager.h"
#include "kis_shortcut_configuration.h"
+#include "kis_zoom_and_rotate_action.h"
KisInputProfileMigrator::~KisInputProfileMigrator()
{
}
-KisInputProfileMigrator5To6::KisInputProfileMigrator5To6(KisInputProfileManager *manager)
+KisInputProfileMigratorFrom5::KisInputProfileMigratorFrom5(KisInputProfileManager *manager)
: m_manager(manager)
{
// FIXME(sh_zam): Should we declare this as "the default profile" somewhere?
@@ -37,13 +42,13 @@ KisInputProfileMigrator5To6::KisInputProfileMigrator5To6(KisInputProfileManager
}
}
-KisInputProfileMigrator5To6::~KisInputProfileMigrator5To6()
+KisInputProfileMigratorFrom5::~KisInputProfileMigratorFrom5()
{
}
-QList<KisShortcutConfiguration> KisInputProfileMigrator5To6::defaultTouchShortcuts()
+QList<KisShortcutConfiguration> KisInputProfileMigratorFrom5::defaultTouchShortcuts()
{
- QList<KisShortcutConfiguration> shortcuts = getShortcutsFromProfile(m_defaultProfile);
+ QList<KisShortcutConfiguration> shortcuts = getShortcutsFromProfile(m_defaultProfile, m_manager);
filterShortcuts(shortcuts, [](KisShortcutConfiguration shortcut) {
return shortcut.type() == KisShortcutConfiguration::TouchGestureType ||
shortcut.type() == KisShortcutConfiguration::NativeGestureType;
@@ -53,7 +58,7 @@ QList<KisShortcutConfiguration> KisInputProfileMigrator5To6::defaultTouchShortcu
}
template <typename Func>
-void KisInputProfileMigrator5To6::filterShortcuts(QList<KisShortcutConfiguration> &shortcuts, Func pred)
+void KisInputProfileMigratorFrom5::filterShortcuts(QList<KisShortcutConfiguration> &shortcuts, Func pred)
{
auto it = shortcuts.begin();
while (it != shortcuts.end()) {
@@ -66,13 +71,13 @@ void KisInputProfileMigrator5To6::filterShortcuts(QList<KisShortcutConfiguration
}
}
-QList<KisShortcutConfiguration> KisInputProfileMigrator5To6::getShortcutsFromProfile(QString profile) const
+QList<KisShortcutConfiguration> KisInputProfileMigrator::getShortcutsFromProfile(QString profile, KisInputProfileManager *manager)
{
QList<KisShortcutConfiguration> shortcuts;
KConfig config(profile, KConfig::SimpleConfig);
- const QList<KisAbstractInputAction *> actions = m_manager->actions();
+ const QList<KisAbstractInputAction *> actions = manager->actions();
for (const auto action : actions) {
if (!config.hasGroup(action->id())) {
continue;
@@ -91,23 +96,66 @@ QList<KisShortcutConfiguration> KisInputProfileMigrator5To6::getShortcutsFromPro
return shortcuts;
}
-QMap<ProfileEntry, QList<KisShortcutConfiguration>>
-KisInputProfileMigrator5To6::migrate(const QMap<QString, ProfileEntry> profiles)
+QList<KisShortcutConfiguration> KisInputProfileMigratorFrom5::migrate(const ProfileEntry &profile)
{
- QMap<ProfileEntry, QList<KisShortcutConfiguration>> parsedProfiles;
- for (const auto &profile : profiles) {
- QList<KisShortcutConfiguration> shortcuts = getShortcutsFromProfile(profile.fullpath);
+ QList<KisShortcutConfiguration> shortcuts = getShortcutsFromProfile(profile.fullpath, m_manager);
- // we ignore the touch shortcuts, because they're from an older version
- filterShortcuts(shortcuts, [](KisShortcutConfiguration shortcut) {
- return shortcut.type() != KisShortcutConfiguration::TouchGestureType && shortcut.type() != KisShortcutConfiguration::NativeGestureType;
- });
+ // we ignore the touch shortcuts, because they're from an older version
+ filterShortcuts(shortcuts, [](KisShortcutConfiguration shortcut) {
+ return shortcut.type() != KisShortcutConfiguration::TouchGestureType
+ && shortcut.type() != KisShortcutConfiguration::NativeGestureType;
+ });
- // now we add the default new shortcuts -- this should complete the migration.
- shortcuts.append(defaultTouchShortcuts());
+ // now we add the default new shortcuts -- this should complete the migration.
+ shortcuts.append(defaultTouchShortcuts());
- parsedProfiles[profile] = shortcuts;
- }
+ return shortcuts;
+}
+
+
+KisInputProfileMigratorFrom6::KisInputProfileMigratorFrom6(KisInputProfileManager *manager)
+ : m_manager(manager)
+{
+
+}
+
+KisInputProfileMigratorFrom6::~KisInputProfileMigratorFrom6()
+{
- return parsedProfiles;
}
+
+QList<KisShortcutConfiguration> KisInputProfileMigratorFrom6::migrate(const ProfileEntry &profile)
+{
+ /**
+ * Firstly, remove all native gesture shortcuts, since they change
+ * semantics in Version 7
+ */
+
+ auto shortcuts = getShortcutsFromProfile(profile.fullpath, m_manager);
+ for (auto it = shortcuts.begin(); it != shortcuts.end();) {
+ if (it->type() == KisShortcutConfiguration::NativeGestureType) {
+ it = shortcuts.erase(it);
+ } else {
+ ++it;
+ }
+ }
+
+ /**
+ * Now add the default connection between native gestures and
+ * "Zoom and Rotate Canvas" action
+ */
+
+ auto actions = m_manager->actions();
+
+ auto it = std::find_if(actions.begin(), actions.end(), kismpl::mem_equal_to(&KisAbstractInputAction::id, "Zoom and Rotate Canvas"));
+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(it != actions.end(), shortcuts);
+
+ KisShortcutConfiguration newNativeGestureShortcut;
+ newNativeGestureShortcut.setAction(*it);
+ newNativeGestureShortcut.setType(KisShortcutConfiguration::NativeGestureType);
+ newNativeGestureShortcut.setNativeGesture(KisShortcutConfiguration::PinchGesture);
+ newNativeGestureShortcut.setMode(KisZoomAndRotateAction::PanAndZoomAndRotateMode);
+ shortcuts.append(newNativeGestureShortcut);
+
+ return shortcuts;
+}
\ No newline at end of file
diff --git a/libs/ui/input/KisInputProfileMigrator.h b/libs/ui/input/KisInputProfileMigrator.h
index 13a3384c44..2df9fc48be 100644
--- a/libs/ui/input/KisInputProfileMigrator.h
+++ b/libs/ui/input/KisInputProfileMigrator.h
@@ -31,22 +31,23 @@ class KisInputProfileMigrator
public:
virtual ~KisInputProfileMigrator();
- virtual QMap<ProfileEntry, QList<KisShortcutConfiguration>>
- migrate(const QMap<QString, ProfileEntry> profiles) = 0;
+ virtual QList<KisShortcutConfiguration> migrate(const ProfileEntry &profile) = 0;
+
+protected:
+ static QList<KisShortcutConfiguration> getShortcutsFromProfile(QString profile, KisInputProfileManager *manager);
};
/**
- * Migrates Krita profile version 5 to 6
+ * Migrates Krita profile from version 5 to the current version
*/
-class KisInputProfileMigrator5To6 : public KisInputProfileMigrator
+class KisInputProfileMigratorFrom5 : public KisInputProfileMigrator
{
public:
- KisInputProfileMigrator5To6(KisInputProfileManager *manager);
- ~KisInputProfileMigrator5To6() override;
+ KisInputProfileMigratorFrom5(KisInputProfileManager *manager);
+ ~KisInputProfileMigratorFrom5() override;
- QMap<ProfileEntry, QList<KisShortcutConfiguration>>
- migrate(const QMap<QString, ProfileEntry> profiles) override;
+ QList<KisShortcutConfiguration> migrate(const ProfileEntry &profile) override;
private:
QList<KisShortcutConfiguration> defaultTouchShortcuts();
@@ -54,12 +55,26 @@ private:
template <typename Func>
void filterShortcuts(QList<KisShortcutConfiguration> &shortcuts, Func func);
- QList<KisShortcutConfiguration> getShortcutsFromProfile(QString profile) const;
-
private:
KisInputProfileManager *m_manager;
QStringList m_profilesList;
QString m_defaultProfile;
};
+/**
+ * Migrates Krita profile from version 6 to the current version
+ */
+class KisInputProfileMigratorFrom6 : public KisInputProfileMigrator
+{
+
+public:
+ KisInputProfileMigratorFrom6(KisInputProfileManager *manager);
+ ~KisInputProfileMigratorFrom6() override;
+
+ QList<KisShortcutConfiguration> migrate(const ProfileEntry &profile) override;
+
+private:
+ KisInputProfileManager *m_manager;
+};
+
#endif // __KISINPUTPROFILEMIGRATOR_H_
diff --git a/libs/ui/input/kis_input_profile_manager.cpp b/libs/ui/input/kis_input_profile_manager.cpp
index a7edcbe6d9..a4db3f3fcf 100644
--- a/libs/ui/input/kis_input_profile_manager.cpp
+++ b/libs/ui/input/kis_input_profile_manager.cpp
@@ -211,7 +211,7 @@ void KisInputProfileManager::loadProfiles()
// NOTE: Migrating profiles doesn't just mean porting them to new version. Migrating a profile
// may override the existing newer profile file.
- if (entry.version == PROFILE_VERSION - 1) {
+ if (entry.version < PROFILE_VERSION) {
// we only utilize the first entry, because it is the most local one and the one which has to be
// migrated.
profileEntriesToMigrate[entry.name] = entry;
@@ -259,39 +259,8 @@ void KisInputProfileManager::loadProfiles()
}
}
- {
- KisInputProfileMigrator5To6 migrator(this);
- QMap<ProfileEntry, QList<KisShortcutConfiguration>> parsedProfilesToMigrate =
- migrator.migrate(profileEntriesToMigrate);
-
- for (ProfileEntry profileEntry : parsedProfilesToMigrate.keys()) {
- const QString storagePath = KoResourcePaths::saveLocation("data", "input/", true);
-
- {
- // the profile we have here uses the previous config, the only thing we need to make sure is
- // it doesn't overwrite the existing profile to preserve backwards compatibility.
- const QString profilePath = profileEntry.fullpath;
- QString oldProfileName = QFileInfo(profilePath).fileName();
- oldProfileName.replace(".profile", QString::number(PROFILE_VERSION - 1) + ".profile");
-
- QString oldProfilePath = storagePath + oldProfileName;
- // copy the profile to a new file but add version number to the name
- QFile::copy(profilePath, oldProfilePath);
-
- KConfig config(oldProfilePath, KConfig::SimpleConfig);
- config.group("General").writeEntry("migrated", PROFILE_VERSION);
- }
-
- KisInputProfile *newProfile = addProfile(profileEntry.name);
- QList<KisShortcutConfiguration> shortcuts = parsedProfilesToMigrate.value(profileEntry);
- for (const auto &shortcut : shortcuts) {
- newProfile->addShortcut(new KisShortcutConfiguration(shortcut));
- }
-
- // save the new profile with migrated shortcuts. We overwrite the previous version of file (which
- // previously has been moved for backward compatibility).
- saveProfile(newProfile, storagePath);
- }
+ for (const auto &profileEntry : profileEntriesToMigrate) {
+ loadProfileWithMigration(profileEntry);
}
Q_FOREACH(const QString & profileName, profileEntries.keys()) {
@@ -304,28 +273,7 @@ void KisInputProfileManager::loadProfiles()
// because that's the most local one.
ProfileEntry entry = profileEntries[profileName].first();
- KConfig config(entry.fullpath, KConfig::SimpleConfig);
-
- KisInputProfile *newProfile = addProfile(entry.name);
- Q_FOREACH(KisAbstractInputAction * action, d->actions) {
- if (!config.hasGroup(action->id())) {
- continue;
- }
-
- KConfigGroup grp = config.group(action->id());
- //Read the settings for the action and create the appropriate shortcuts.
- Q_FOREACH(const QString & entry, grp.entryMap()) {
- KisShortcutConfiguration *shortcut = new KisShortcutConfiguration;
- shortcut->setAction(action);
-
- if (shortcut->unserialize(entry)) {
- newProfile->addShortcut(shortcut);
- }
- else {
- delete shortcut;
- }
- }
- }
+ loadProfileInternal(entry.fullpath);
}
QString currentProfile = cfg.currentInputProfile();
@@ -347,6 +295,92 @@ void KisInputProfileManager::loadProfiles()
}
}
+KisInputProfile* KisInputProfileManager::loadProfileInternal(const QString &fullPath)
+{
+ KConfig config(fullPath, KConfig::SimpleConfig);
+
+ QList<KisShortcutConfiguration*> loadedShortcuts;
+
+ // Only entries of exactly the right version can be considered
+ const int version = config.group("General").readEntry("version", 0);
+ const QString name = config.group("General").readEntry("name");
+
+ // the profile must be already converted by this point
+ KIS_SAFE_ASSERT_RECOVER_NOOP(version == PROFILE_VERSION);
+
+ Q_FOREACH (KisAbstractInputAction *action, d->actions) {
+ if (!config.hasGroup(action->id())) {
+ continue;
+ }
+
+ KConfigGroup grp = config.group(action->id());
+ // Read the settings for the action and create the appropriate shortcuts.
+ Q_FOREACH (const QString &entry, grp.entryMap()) {
+ KisShortcutConfiguration *shortcut = new KisShortcutConfiguration;
+ shortcut->setAction(action);
+
+ if (shortcut->unserialize(entry)) {
+ loadedShortcuts.append(shortcut);
+ } else {
+ delete shortcut;
+ }
+ }
+ }
+
+ KisInputProfile *newProfile = addProfile(name);
+ Q_FOREACH(KisShortcutConfiguration *shortcut, loadedShortcuts) {
+ newProfile->addShortcut(shortcut);
+ }
+ return newProfile;
+}
+
+KisInputProfile* KisInputProfileManager::loadProfileWithMigration(const ProfileEntry &profileEntry)
+{
+ QList<KisShortcutConfiguration> parsedShortcuts;
+
+ if (profileEntry.version == 5) {
+ KisInputProfileMigratorFrom5 migratorFromV5(this);
+ parsedShortcuts = migratorFromV5.migrate(profileEntry);
+ } else if (profileEntry.version == 6) {
+ KisInputProfileMigratorFrom6 migratorFromV6(this);
+ parsedShortcuts = migratorFromV6.migrate(profileEntry);
+ } else {
+ warnKrita << "Unable to migrate input profile: unknown version:" << profileEntry.version << "("
+ << profileEntry.fullpath << ")";
+ return nullptr;
+ }
+
+ dbgKrita << "Migrating a profile " << profileEntry.name << "(" << profileEntry.fullpath << ")" << "from version" << profileEntry.version;
+
+ const QString storagePath = KoResourcePaths::saveLocation("data", "input/", true);
+
+ {
+ // the profile we have here uses the previous config, the only thing we need to make sure is
+ // it doesn't overwrite the existing profile to preserve backwards compatibility.
+ const QString profilePath = profileEntry.fullpath;
+ QString oldProfileName = QFileInfo(profilePath).fileName();
+ oldProfileName.replace(".profile", QString::number(PROFILE_VERSION - 1) + ".profile");
+
+ QString oldProfilePath = storagePath + oldProfileName;
+ // copy the profile to a new file but add version number to the name
+ QFile::copy(profilePath, oldProfilePath);
+
+ KConfig config(oldProfilePath, KConfig::SimpleConfig);
+ config.group("General").writeEntry("migrated", PROFILE_VERSION);
+ }
+
+ KisInputProfile *newProfile = addProfile(profileEntry.name);
+ for (const auto &shortcut : parsedShortcuts) {
+ newProfile->addShortcut(new KisShortcutConfiguration(shortcut));
+ }
+
+ // save the new profile with migrated shortcuts. We overwrite the previous version of file (which
+ // previously has been moved for backward compatibility).
+ saveProfile(newProfile, storagePath);
+
+ return newProfile;
+}
+
void KisInputProfileManager::saveProfiles()
{
QString storagePath = KoResourcePaths::saveLocation("data", "input/", true);
diff --git a/libs/ui/input/kis_input_profile_manager.h b/libs/ui/input/kis_input_profile_manager.h
index 4c0b10f387..fd56d8fa46 100644
--- a/libs/ui/input/kis_input_profile_manager.h
+++ b/libs/ui/input/kis_input_profile_manager.h
@@ -12,11 +12,12 @@
#include "kritaui_export.h"
-#define PROFILE_VERSION 6
+#define PROFILE_VERSION 7
class KisAbstractInputAction;
class KisInputProfile;
class KisShortcutConfiguration;
+class ProfileEntry;
/**
* \brief A class to manage a list of profiles and actions.
@@ -141,6 +142,22 @@ Q_SIGNALS:
*/
void currentProfileChanged();
+private:
+ friend class KisInputProfileManagerTest;
+
+ /**
+ * Loads a single profile from a file without applying any migrations
+ */
+ KisInputProfile* loadProfileInternal(const QString &fullPath);
+
+ /**
+ * Loads a single profile from a file performing all the migrations
+ * necessary. The old profile will be saved into KoResourcePaths::saveLocation
+ * with a version suffix, and the new version will be written with the
+ * profile name.
+ */
+ KisInputProfile* loadProfileWithMigration(const ProfileEntry &profileEntry);
+
private:
class Private;
Private *const d;
diff --git a/libs/ui/tests/KisInputProfileManagerTest.cpp b/libs/ui/tests/KisInputProfileManagerTest.cpp
index 0a94bd924a..3a1d388c41 100644
--- a/libs/ui/tests/KisInputProfileManagerTest.cpp
+++ b/libs/ui/tests/KisInputProfileManagerTest.cpp
@@ -7,6 +7,7 @@
#include "KisInputProfileManagerTest.h"
#include <simpletest.h>
+#include <testutil.h>
#include <KisMpl.h>
@@ -19,6 +20,11 @@
#include <input/kis_abstract_input_action.h>
#include <input/kis_tool_invocation_action.h>
+// for native gestures migration testing
+#include <input/KisInputProfileMigrator.h>
+#include <input/kis_zoom_and_rotate_action.h>
+
+
void KisInputProfileManagerTest::testProfileCreation()
{
auto *profileManager = KisInputProfileManager::instance();
@@ -30,6 +36,57 @@ void KisInputProfileManagerTest::testProfileCreation()
QCOMPARE(profileManager->currentProfile(), profile);
}
+void KisInputProfileManagerTest::testLoadProfileV6()
+{
+ auto *profileManager = KisInputProfileManager::instance();
+
+ const QString profileFileName = TestUtil::fetchDataFileLazy("krita_default_input_profile_v6.profile");
+
+ ProfileEntry profileEntry;
+ profileEntry.fullpath = profileFileName;
+
+ {
+ KConfig config(profileFileName, KConfig::SimpleConfig);
+ profileEntry.version = config.group("General").readEntry("version", 0);
+ profileEntry.name = config.group("General").readEntry("name");
+ }
+
+ auto *profile = profileManager->loadProfileWithMigration(profileEntry);
+
+ QVERIFY(profile);
+ QCOMPARE(profile->name(), "Test V6 Profile");
+
+ QList< KisShortcutConfiguration* > shortcuts = profile->allShortcuts();
+
+ KisShortcutConfiguration *foundNativeGestureShortcut = nullptr;
+ int numInvalidNativeGestureShortcuts = 0;
+ int totalNativeGestureShortcuts = 0;
+
+ Q_FOREACH(KisShortcutConfiguration *shortcut, shortcuts) {
+ if (shortcut->type() == KisShortcutConfiguration::NativeGestureType) {
+ if (shortcut->nativeGesture() == KisShortcutConfiguration::PinchGesture) {
+ totalNativeGestureShortcuts++;
+ foundNativeGestureShortcut = shortcut;
+ }
+ if (shortcut->nativeGesture() > KisShortcutConfiguration::PinchGesture &&
+ shortcut->nativeGesture() < KisShortcutConfiguration::SmartZoomGesture) {
+ numInvalidNativeGestureShortcuts++;
+ }
+ }
+ }
+
+ if (foundNativeGestureShortcut) {
+ QCOMPARE(foundNativeGestureShortcut->action()->id(), "Zoom and Rotate Canvas");
+ QCOMPARE(foundNativeGestureShortcut->mode(), KisZoomAndRotateAction::PanAndZoomAndRotateMode);
+
+ }
+
+ QCOMPARE(totalNativeGestureShortcuts, 1);
+ QCOMPARE(numInvalidNativeGestureShortcuts, 0);
+
+ profileManager->removeProfile(profile->name());
+}
+
void KisInputProfileManagerTest::testShortcutConfigurationTouchGesture_data()
{
QTest::addColumn<KisShortcutConfiguration::TouchGestureAction>("touchGestureAction");
diff --git a/libs/ui/tests/KisInputProfileManagerTest.h b/libs/ui/tests/KisInputProfileManagerTest.h
index 069d175c6c..258ad8e397 100644
--- a/libs/ui/tests/KisInputProfileManagerTest.h
+++ b/libs/ui/tests/KisInputProfileManagerTest.h
@@ -14,6 +14,9 @@ class KisInputProfileManagerTest : public QObject
Q_OBJECT
private Q_SLOTS:
void testProfileCreation();
+
+ void testLoadProfileV6();
+
void testShortcutConfigurationTouchGesture_data();
void testShortcutConfigurationTouchGesture();
diff --git a/libs/ui/tests/data/krita_default_input_profile_v6.profile b/libs/ui/tests/data/krita_default_input_profile_v6.profile
new file mode 100644
index 0000000000..ac7db8b629
--- /dev/null
+++ b/libs/ui/tests/data/krita_default_input_profile_v6.profile
@@ -0,0 +1,81 @@
+[Alternate Invocation]
+0={1;2;[1000023,1000020];1;0;0}
+1={0;2;[1000021,1000020];1;0;0}
+2={5;2;[1000021];2;0;0}
+3={3;2;[1000021,1000023];2;0;0}
+4={2;2;[1000023,1000021];1;0;0}
+5={4;2;[1000021];1;0;0}
+6={4;4;[];0;0;b}
+
+[Change Primary Setting]
+0={0;2;[1000020];1;0;0}
+
+[Exposure or Gamma]
+0={0;2;[59];1;0;0}
+
+[General]
+name=Test V6 Profile
+version=6
+
+[Pan Canvas]
+0={0;5;[];0;0;2}
+1={0;2;[20];1;0;0}
+2={0;2;[];4;0;0}
+3={1;1;[];0;0;0}
+4={2;1;[];0;0;0}
+5={3;1;[];0;0;0}
+6={4;1;[];0;0;0}
+7={0;3;[];0;5;0}
+8={0;4;[];0;0;6}
+
+[Rotate Canvas]
+0={0;2;[1000020,20];1;0;0}
+1={1;2;[1000020,1000023,20];1;0;0}
+2={0;2;[1000020];4;0;0}
+3={2;1;[34];0;0;0}
+4={4;1;[35];0;0;0}
+5={3;1;[36];0;0;0}
+6={0;5;[];0;0;3}
+
+[Select Layer]
+0={1;2;[1000020,52];1;0;0}
+1={0;2;[52];1;0;0}
+
+[Show Popup Widget]
+0={0;2;[];2;0;0}
+1={0;4;[];0;0;1}
+
+[Switch Time]
+0={0;1;[1000014];0;0;0}
+1={1;1;[1000012];0;0;0}
+
+[Tool Invocation]
+0={3;2;[56];1;0;0}
+1={1;1;[1000005];0;0;0}
+2={0;2;[];1;0;0}
+3={1;1;[1000004];0;0;0}
+4={2;1;[1000000];0;0;0}
+
+[Zoom Canvas]
+0={2;1;[2b];0;0;0}
+1={4;1;[31];0;0;0}
+10={5;1;[32];0;0;0}
+11={0;5;[];0;0;1}
+12={8;2;[1000021,1000023];4;0;0}
+2={3;1;[2d];0;0;0}
+3={2;1;[3d];0;0;0}
+4={3;3;[];0;2;0}
+5={2;3;[];0;1;0}
+6={7;2;[1000021];4;0;0}
+7={7;2;[1000021,20];1;0;0}
+8={6;1;[33];0;0;0}
+9={8;2;[1000021,1000023,20];1;0;0}
+
+[Zoom and Rotate Canvas]
+0={0;4;[];0;0;7}
+
+[Touch Gestures]
+0={0;4;[];0;0;2}
+1={1;4;[];0;0;3}
+2={2;4;[];0;0;4}
+3={3;2;[];20;0;0}