Skip to content
Snippets Groups Projects
Commit 09ca278c authored by Adam Leung's avatar Adam Leung Committed by Hugo Beauzée-Luyssen
Browse files

qt: Added distinct profile id parameter to controlbar profiles

parent 016945b8
No related branches found
No related tags found
1 merge request!527qt: added in new firstrun wizard
...@@ -162,6 +162,16 @@ void ControlbarProfile::setName(const QString &name) ...@@ -162,6 +162,16 @@ void ControlbarProfile::setName(const QString &name)
emit nameChanged(m_name); emit nameChanged(m_name);
} }
void ControlbarProfile::setId( const int id )
{
if(id == m_id)
return;
m_id = id;
emit idChanged(m_id);
}
bool ControlbarProfile::dirty() const bool ControlbarProfile::dirty() const
{ {
return (m_dirty > 0); return (m_dirty > 0);
...@@ -172,6 +182,11 @@ QString ControlbarProfile::name() const ...@@ -172,6 +182,11 @@ QString ControlbarProfile::name() const
return m_name; return m_name;
} }
int ControlbarProfile::id() const
{
return m_id;
}
void ControlbarProfile::injectDefaults(bool resetDirty) void ControlbarProfile::injectDefaults(bool resetDirty)
{ {
injectModel(m_defaults); injectModel(m_defaults);
......
...@@ -31,6 +31,7 @@ class ControlbarProfile : public QObject ...@@ -31,6 +31,7 @@ class ControlbarProfile : public QObject
Q_PROPERTY(bool dirty READ dirty RESET resetDirty NOTIFY dirtyChanged FINAL) Q_PROPERTY(bool dirty READ dirty RESET resetDirty NOTIFY dirtyChanged FINAL)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
Q_PROPERTY(int profileId READ id WRITE setId NOTIFY idChanged FINAL)
friend class ControlbarProfileModel; friend class ControlbarProfileModel;
...@@ -50,9 +51,16 @@ public: ...@@ -50,9 +51,16 @@ public:
bool dirty() const; bool dirty() const;
QString name() const; QString name() const;
// The id is a unique number supplied to each profile
// which differentiates it independently from its index
// in the profiles array. Provides a more stable way to
// identify a profile than using its name.
int id() const;
public slots: public slots:
void resetDirty(); void resetDirty();
void setName(const QString& name); void setName(const QString& name);
void setId( const int id );
private: private:
// m_dirty indicates the count of PlayerControlbarModel // m_dirty indicates the count of PlayerControlbarModel
...@@ -60,6 +68,7 @@ private: ...@@ -60,6 +68,7 @@ private:
// set true. // set true.
int m_dirty = 0; int m_dirty = 0;
int m_id = -1;
QString m_name {"N/A"}; QString m_name {"N/A"};
bool m_pauseControlListGeneration = false; bool m_pauseControlListGeneration = false;
...@@ -84,6 +93,7 @@ private slots: ...@@ -84,6 +93,7 @@ private slots:
signals: signals:
void dirtyChanged(bool dirty); void dirtyChanged(bool dirty);
void nameChanged(QString name); void nameChanged(QString name);
void idChanged(int id);
void controlListChanged(const QVector<int>& linearControlList); void controlListChanged(const QVector<int>& linearControlList);
}; };
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#define SETTINGS_ARRAYNAME_PROFILES "Profiles" #define SETTINGS_ARRAYNAME_PROFILES "Profiles"
#define SETTINGS_KEY_NAME "Name" #define SETTINGS_KEY_NAME "Name"
#define SETTINGS_KEY_MODEL "Model" #define SETTINGS_KEY_MODEL "Model"
#define SETTINGS_KEY_ID "Id"
#define SETTINGS_CONTROL_SEPARATOR "," #define SETTINGS_CONTROL_SEPARATOR ","
#define SETTINGS_CONFIGURATION_SEPARATOR "|" #define SETTINGS_CONFIGURATION_SEPARATOR "|"
...@@ -37,6 +38,7 @@ decltype (ControlbarProfileModel::m_defaults) ...@@ -37,6 +38,7 @@ decltype (ControlbarProfileModel::m_defaults)
ControlbarProfileModel::m_defaults = ControlbarProfileModel::m_defaults =
{ {
{ {
MINIMALIST_STYLE,
N_("Minimalist Style"), N_("Minimalist Style"),
{ {
{ {
...@@ -89,6 +91,7 @@ decltype (ControlbarProfileModel::m_defaults) ...@@ -89,6 +91,7 @@ decltype (ControlbarProfileModel::m_defaults)
} }
}, },
{ {
ONE_LINER_STYLE,
N_("One-liner Style"), N_("One-liner Style"),
{ {
{ {
...@@ -145,6 +148,7 @@ decltype (ControlbarProfileModel::m_defaults) ...@@ -145,6 +148,7 @@ decltype (ControlbarProfileModel::m_defaults)
} }
}, },
{ {
SIMPLEST_STYLE,
N_("Simplest Style"), N_("Simplest Style"),
{ {
{ {
...@@ -186,6 +190,7 @@ decltype (ControlbarProfileModel::m_defaults) ...@@ -186,6 +190,7 @@ decltype (ControlbarProfileModel::m_defaults)
} }
}, },
{ {
CLASSIC_STYLE,
N_("Classic Style"), N_("Classic Style"),
{ {
{ {
...@@ -281,12 +286,13 @@ void ControlbarProfileModel::insertDefaults() ...@@ -281,12 +286,13 @@ void ControlbarProfileModel::insertDefaults()
{ {
// First, add a blank new profile: // First, add a blank new profile:
// ControlbarProfile will inject the default configurations during its construction. // ControlbarProfile will inject the default configurations during its construction.
newProfile(tr("Default Profile")); m_maxId = 0;
newProfile(tr("Default Profile"), DEFAULT_STYLE);
// Add default profiles: // Add default profiles:
for (const auto& i : m_defaults) for (const auto& i : m_defaults)
{ {
const auto ptrNewProfile = newProfile(qfut(i.name)); const auto ptrNewProfile = newProfile(qfut(i.name), i.id);
if (!ptrNewProfile) if (!ptrNewProfile)
continue; continue;
...@@ -481,6 +487,18 @@ ControlbarProfile* ControlbarProfileModel::currentModel() const ...@@ -481,6 +487,18 @@ ControlbarProfile* ControlbarProfileModel::currentModel() const
return getProfile(selectedProfile()); return getProfile(selectedProfile());
} }
/* Set the selected profile to the profile with the matching id */
bool ControlbarProfileModel::setSelectedProfileFromId(int id)
{
for(int i = 0; i < rowCount(); i++)
{
if(id == m_profiles.at(i)->id())
return setSelectedProfile(i);
}
return false;
}
void ControlbarProfileModel::save(bool clearDirty) const void ControlbarProfileModel::save(bool clearDirty) const
{ {
assert(m_intf); assert(m_intf);
...@@ -541,6 +559,7 @@ void ControlbarProfileModel::save(bool clearDirty) const ...@@ -541,6 +559,7 @@ void ControlbarProfileModel::save(bool clearDirty) const
settings->setValue(SETTINGS_KEY_NAME, m_profiles.at(i)->name()); settings->setValue(SETTINGS_KEY_NAME, m_profiles.at(i)->name());
settings->setValue(SETTINGS_KEY_MODEL, val); settings->setValue(SETTINGS_KEY_MODEL, val);
settings->setValue(SETTINGS_KEY_ID, m_profiles.at(i)->id());
} }
settings->endArray(); settings->endArray();
...@@ -587,6 +606,7 @@ bool ControlbarProfileModel::reload() ...@@ -587,6 +606,7 @@ bool ControlbarProfileModel::reload()
const auto ptrNewProfile = new ControlbarProfile(this); const auto ptrNewProfile = new ControlbarProfile(this);
ptrNewProfile->setName(settings->value(SETTINGS_KEY_NAME).toString()); ptrNewProfile->setName(settings->value(SETTINGS_KEY_NAME).toString());
ptrNewProfile->setId(settings->value(SETTINGS_KEY_ID).toInt());
for (auto j : val) for (auto j : val)
{ {
...@@ -642,6 +662,7 @@ bool ControlbarProfileModel::reload() ...@@ -642,6 +662,7 @@ bool ControlbarProfileModel::reload()
bool ok = false; bool ok = false;
int index = settings->value(SETTINGS_KEY_SELECTEDPROFILE).toInt(&ok); int index = settings->value(SETTINGS_KEY_SELECTEDPROFILE).toInt(&ok);
m_maxId = m_profiles.isEmpty() ? 0 : m_profiles.back()->id() + 1;
if (ok) if (ok)
setSelectedProfile(index); setSelectedProfile(index);
...@@ -692,7 +713,7 @@ ControlbarProfile *ControlbarProfileModel::getProfile(int index) const ...@@ -692,7 +713,7 @@ ControlbarProfile *ControlbarProfileModel::getProfile(int index) const
return m_profiles.at(index); return m_profiles.at(index);
} }
ControlbarProfile *ControlbarProfileModel::newProfile(const QString &name) ControlbarProfile *ControlbarProfileModel::newProfile(const QString &name, const int id)
{ {
if (name.isEmpty()) if (name.isEmpty())
return nullptr; return nullptr;
...@@ -700,6 +721,8 @@ ControlbarProfile *ControlbarProfileModel::newProfile(const QString &name) ...@@ -700,6 +721,8 @@ ControlbarProfile *ControlbarProfileModel::newProfile(const QString &name)
const auto ptrProfile = newProfile(); const auto ptrProfile = newProfile();
ptrProfile->setName(generateUniqueName(name)); ptrProfile->setName(generateUniqueName(name));
ptrProfile->setId(id);
m_maxId++;
return ptrProfile; return ptrProfile;
} }
...@@ -719,7 +742,8 @@ ControlbarProfile *ControlbarProfileModel::newProfile() ...@@ -719,7 +742,8 @@ ControlbarProfile *ControlbarProfileModel::newProfile()
ControlbarProfile *ControlbarProfileModel::cloneProfile(const ControlbarProfile *profile) ControlbarProfile *ControlbarProfileModel::cloneProfile(const ControlbarProfile *profile)
{ {
const auto ptrNewProfile = newProfile(profile->name()); // Any new profiles will just have the next incremental id
const auto ptrNewProfile = newProfile(profile->name(), m_maxId);
if (!ptrNewProfile) if (!ptrNewProfile)
return nullptr; return nullptr;
...@@ -763,7 +787,6 @@ void ControlbarProfileModel::deleteSelectedProfile() ...@@ -763,7 +787,6 @@ void ControlbarProfileModel::deleteSelectedProfile()
return; return;
const auto _selectedProfile = m_selectedProfile; const auto _selectedProfile = m_selectedProfile;
beginRemoveRows(QModelIndex(), _selectedProfile, _selectedProfile); beginRemoveRows(QModelIndex(), _selectedProfile, _selectedProfile);
m_selectedProfile = -1; m_selectedProfile = -1;
......
...@@ -42,6 +42,7 @@ public: ...@@ -42,6 +42,7 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
enum {DEFAULT_STYLE, MINIMALIST_STYLE, ONE_LINER_STYLE, SIMPLEST_STYLE, CLASSIC_STYLE};
// Editable: // Editable:
Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value,
...@@ -62,13 +63,14 @@ public: ...@@ -62,13 +63,14 @@ public:
int selectedProfile() const; int selectedProfile() const;
ControlbarProfile* currentModel() const; ControlbarProfile* currentModel() const;
bool setSelectedProfileFromId(int id);
ControlbarProfile* cloneProfile(const ControlbarProfile* profile); ControlbarProfile* cloneProfile(const ControlbarProfile* profile);
Q_INVOKABLE void cloneSelectedProfile(const QString& newProfileName); Q_INVOKABLE void cloneSelectedProfile(const QString& newProfileName);
Q_INVOKABLE ControlbarProfile* getProfile(int index) const; Q_INVOKABLE ControlbarProfile* getProfile(int index) const;
Q_INVOKABLE ControlbarProfile* newProfile(const QString& name); Q_INVOKABLE ControlbarProfile* newProfile(const QString& name, const int id);
ControlbarProfile* newProfile(); ControlbarProfile* newProfile();
Q_INVOKABLE void deleteSelectedProfile(); Q_INVOKABLE void deleteSelectedProfile();
...@@ -89,8 +91,10 @@ private: ...@@ -89,8 +91,10 @@ private:
QVector<ControlbarProfile *> m_profiles; QVector<ControlbarProfile *> m_profiles;
int m_selectedProfile = -1; int m_selectedProfile = -1;
int m_maxId = 0;
struct Profile { struct Profile {
const int id;
const char* name; const char* name;
QVector<ControlbarProfile::Configuration> modelData; QVector<ControlbarProfile::Configuration> modelData;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment