Commit 508a4b77 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Add method to easily reload a custom effect

parent 4d93def3
Pipeline #36684 passed with stage
in 22 minutes and 23 seconds
......@@ -54,6 +54,7 @@ public:
/* @brief Delete a custom effect */
void deleteCustomEffect(const QModelIndex &index);
virtual void reloadCustomEffectIx(const QModelIndex &index) = 0;
/* @brief Returns the description of the asset given its model index */
QString getDescription(bool isEffect, const QModelIndex &index) const;
......
......@@ -330,6 +330,14 @@ Rectangle {
assetlist.deleteCustomEffect(sel.currentIndex)
}
}
MenuItem {
id: reloadMenu
text: i18n("Reload custom effect")
visible: isEffectList && assetContextMenu.isCustom
onTriggered: {
assetlist.reloadCustomEffectIx(sel.currentIndex)
}
}
}
TableViewColumn { role: "identifier"; title: i18n("Name"); }
......
......@@ -113,6 +113,16 @@ std::shared_ptr<EffectTreeModel> EffectTreeModel::construct(const QString &categ
return self;
}
void EffectTreeModel::reloadEffectFromIndex(const QModelIndex &index)
{
if (!index.isValid()) {
return;
}
std::shared_ptr<TreeItem> item = getItemById((int)index.internalId());
const QString path = EffectsRepository::get()->getCustomPath(item->dataColumn(idCol).toString());
reloadEffect(path);
}
void EffectTreeModel::reloadEffect(const QString &path)
{
QPair<QString, QString> asset = EffectsRepository::get()->reloadCustom(path);
......
......@@ -38,6 +38,7 @@ protected:
public:
static std::shared_ptr<EffectTreeModel> construct(const QString &categoryFile, QObject *parent);
void reloadEffect(const QString &path);
void reloadEffectFromIndex(const QModelIndex &index);
void reloadAssetMenu(QMenu *effectsMenu, KActionCategory *effectActions) override;
void setFavorite(const QModelIndex &index, bool favorite, bool isEffect) override;
void deleteEffect(const QModelIndex &index) override;
......
......@@ -84,6 +84,13 @@ QString EffectListWidget::getMimeType(const QString &assetId) const
return QStringLiteral("kdenlive/effect");
}
void EffectListWidget::reloadCustomEffectIx(const QModelIndex &index)
{
static_cast<EffectTreeModel *>(m_model.get())->reloadEffectFromIndex(m_proxyModel->mapToSource(index));
m_proxyModel->sort(0, Qt::AscendingOrder);
}
void EffectListWidget::reloadCustomEffect(const QString &path)
{
static_cast<EffectTreeModel *>(m_model.get())->reloadEffect(path);
......
......@@ -47,6 +47,7 @@ public:
QString getMimeType(const QString &assetId) const override;
void updateFavorite(const QModelIndex &index);
void reloadEffectMenu(QMenu *effectsMenu, KActionCategory *effectActions);
void reloadCustomEffectIx(const QModelIndex &index) override;
public slots:
void reloadCustomEffect(const QString &path);
......@@ -72,6 +73,7 @@ public:
}
Q_INVOKABLE QString getName(const QModelIndex &index) const { return q->getName(index); }
Q_INVOKABLE bool isFavorite(const QModelIndex &index) const { return q->isFavorite(index); }
Q_INVOKABLE void reloadCustomEffectIx(const QModelIndex &index) const { q->reloadCustomEffectIx(index); }
Q_INVOKABLE void setFavorite(const QModelIndex &index, bool favorite) const
{
q->setFavorite(index, favorite, true);
......
......@@ -231,6 +231,16 @@ bool EffectsRepository::hasInternalEffect(const QString &effectId) const
return false;
}
QString EffectsRepository::getCustomPath(const QString &id)
{
QString customAssetDir = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("effects"), QStandardPaths::LocateDirectory);
QPair <QStringList, QStringList> results;
QDir current_dir(customAssetDir);
qDebug()<<"==== FETCHING CUSTOM PATH FOR ID: "<<id;
return current_dir.absoluteFilePath(QString("%1.xml").arg(id));
}
QPair<QString, QString> EffectsRepository::reloadCustom(const QString &path)
{
std::unordered_map<QString, Info> customAssets;
......
......@@ -45,6 +45,7 @@ public:
/* @brief returns true if an effect exists in MLT (bypasses the blacklist/metadata parsing) */
bool hasInternalEffect(const QString &effectId) const;
QPair<QString, QString> reloadCustom(const QString &path);
QString getCustomPath(const QString &id);
/* @brief Returns whether this belongs to main effects */
bool isPreferred(const QString &effectId) const;
......
......@@ -103,3 +103,7 @@ void TransitionListWidget::downloadNewLumas()
// TODO: refresh currently displayd trans ?
}
}
void TransitionListWidget::reloadCustomEffectIx(const QModelIndex &path)
{
}
......@@ -43,6 +43,7 @@ public:
QString getMimeType(const QString &assetId) const override;
void updateFavorite(const QModelIndex &index);
void downloadNewLumas();
void reloadCustomEffectIx(const QModelIndex &path) override;
private:
TransitionListWidgetProxy *m_proxy;
......@@ -65,6 +66,7 @@ public:
}
Q_INVOKABLE QString getName(const QModelIndex &index) const { return q->getName(index); }
Q_INVOKABLE bool isFavorite(const QModelIndex &index) const { return q->isFavorite(index); }
Q_INVOKABLE void reloadCustomEffectIx(const QModelIndex &index) const { q->reloadCustomEffectIx(index); }
Q_INVOKABLE void setFavorite(const QModelIndex &index, bool favorite) const
{
q->setFavorite(index, favorite, false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment