-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QML: Add EffectManager proxy and visibleEffectModel
This allows accessing the visible effect list from QML.
- Loading branch information
Showing
6 changed files
with
201 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "skin/qml/qmleffectsmanagerproxy.h" | ||
|
||
#include <memory> | ||
|
||
#include "skin/qml/qmlvisibleeffectsmodel.h" | ||
|
||
namespace mixxx { | ||
namespace skin { | ||
namespace qml { | ||
|
||
QmlEffectsManagerProxy::QmlEffectsManagerProxy( | ||
std::shared_ptr<EffectsManager> pEffectsManager, QObject* parent) | ||
: QObject(parent), | ||
m_pEffectsManager(pEffectsManager), | ||
m_pVisibleEffectsModel( | ||
new QmlVisibleEffectsModel(pEffectsManager, this)) { | ||
} | ||
|
||
} // namespace qml | ||
} // namespace skin | ||
} // namespace mixxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
#include <QObject> | ||
|
||
#include "effects/effectsmanager.h" | ||
|
||
QT_FORWARD_DECLARE_CLASS(QAbstractListModel); | ||
|
||
namespace mixxx { | ||
namespace skin { | ||
namespace qml { | ||
|
||
class QmlVisibleEffectsModel; | ||
|
||
class QmlEffectsManagerProxy : public QObject { | ||
Q_OBJECT | ||
Q_PROPERTY(mixxx::skin::qml::QmlVisibleEffectsModel* visibleEffectsModel | ||
MEMBER m_pVisibleEffectsModel CONSTANT); | ||
|
||
public: | ||
explicit QmlEffectsManagerProxy( | ||
std::shared_ptr<EffectsManager> pEffectsManager, | ||
QObject* parent = nullptr); | ||
|
||
private: | ||
const std::shared_ptr<EffectsManager> m_pEffectsManager; | ||
QmlVisibleEffectsModel* m_pVisibleEffectsModel; | ||
}; | ||
|
||
} // namespace qml | ||
} // namespace skin | ||
} // namespace mixxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include "skin/qml/qmlvisibleeffectsmodel.h" | ||
|
||
#include <QModelIndex> | ||
|
||
#include "effects/effectmanifest.h" | ||
#include "effects/effectsmanager.h" | ||
|
||
namespace mixxx { | ||
namespace skin { | ||
namespace qml { | ||
namespace { | ||
const QHash<int, QByteArray> kRoleNames = { | ||
{Qt::DisplayRole, "display"}, | ||
{Qt::ToolTipRole, "tooltip"}, | ||
{QmlVisibleEffectsModel::EffectIdRole, "effectId"}, | ||
}; | ||
} | ||
|
||
QmlVisibleEffectsModel::QmlVisibleEffectsModel( | ||
std::shared_ptr<EffectsManager> pEffectsManager, | ||
QObject* parent) | ||
: QAbstractListModel(parent), m_pEffectsManager(pEffectsManager) { | ||
m_visibleEffectManifests = m_pEffectsManager->getVisibleEffectManifests(); | ||
connect(m_pEffectsManager.get(), | ||
&EffectsManager::visibleEffectsUpdated, | ||
this, | ||
&QmlVisibleEffectsModel::slotVisibleEffectsUpdated); | ||
} | ||
|
||
void QmlVisibleEffectsModel::slotVisibleEffectsUpdated() { | ||
const QList<EffectManifestPointer> visibleEffectManifests = | ||
m_pEffectsManager->getVisibleEffectManifests(); | ||
const auto firstMismatch = std::mismatch(visibleEffectManifests.begin(), | ||
visibleEffectManifests.end(), | ||
m_visibleEffectManifests.begin(), | ||
[](const auto a, const auto b) { return a->id() == b->id(); }); | ||
Q_UNUSED(firstMismatch); | ||
qWarning() << "first mismatched elements"; | ||
} | ||
|
||
QVariant QmlVisibleEffectsModel::data(const QModelIndex& index, int role) const { | ||
if (index.row() == 0) { | ||
switch (role) { | ||
case Qt::DisplayRole: | ||
return EffectsManager::kNoEffectString; | ||
case Qt::ToolTipRole: | ||
return tr("No effect loaded."); | ||
default: | ||
return QVariant(); | ||
} | ||
} | ||
|
||
if (index.row() > m_visibleEffectManifests.size()) { | ||
return QVariant(); | ||
} | ||
|
||
const EffectManifestPointer pManifest = m_visibleEffectManifests.at(index.row() - 1); | ||
switch (role) { | ||
case Qt::DisplayRole: | ||
return pManifest->displayName(); | ||
case Qt::ToolTipRole: | ||
return pManifest->description(); | ||
case QmlVisibleEffectsModel::EffectIdRole: | ||
return pManifest->id(); | ||
default: | ||
return QVariant(); | ||
} | ||
} | ||
|
||
int QmlVisibleEffectsModel::rowCount(const QModelIndex& parent) const { | ||
if (parent.isValid()) { | ||
return 0; | ||
} | ||
|
||
// Add +1 because we also include "no effect" in the model | ||
return m_visibleEffectManifests.size() + 1; | ||
} | ||
|
||
QHash<int, QByteArray> QmlVisibleEffectsModel::roleNames() const { | ||
return kRoleNames; | ||
} | ||
|
||
} // namespace qml | ||
} // namespace skin | ||
} // namespace mixxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
#include <QAbstractListModel> | ||
#include <memory> | ||
|
||
#include "effects/effectsmanager.h" | ||
|
||
namespace mixxx { | ||
namespace skin { | ||
namespace qml { | ||
|
||
class QmlVisibleEffectsModel : public QAbstractListModel { | ||
Q_OBJECT | ||
public: | ||
enum Roles { | ||
EffectIdRole = Qt::UserRole + 1, | ||
}; | ||
Q_ENUM(Roles) | ||
|
||
explicit QmlVisibleEffectsModel( | ||
std::shared_ptr<EffectsManager> pEffectsManager, | ||
QObject* parent = nullptr); | ||
|
||
QVariant data(const QModelIndex& index, int role) const override; | ||
int rowCount(const QModelIndex& parent) const override; | ||
QHash<int, QByteArray> roleNames() const override; | ||
|
||
private slots: | ||
void slotVisibleEffectsUpdated(); | ||
|
||
private: | ||
const std::shared_ptr<EffectsManager> m_pEffectsManager; | ||
QList<EffectManifestPointer> m_visibleEffectManifests; | ||
}; | ||
|
||
} // namespace qml | ||
} // namespace skin | ||
} // namespace mixxx |