Commit 3c98024b authored by Nicolas Carion's avatar Nicolas Carion
Browse files

Keyframe model is now owned by assetparametermodel, not keyframewidget

parent b2c4af4c
......@@ -51,12 +51,14 @@ KeyframeView::KeyframeView(std::shared_ptr<KeyframeModelList> model, QWidget *pa
m_lineHeight = m_size / 2;
setMinimumHeight(m_size);
setMaximumHeight(m_size);
connect(m_model.get(), &KeyframeModelList::modelChanged, [&](){
emit atKeyframe(m_model->hasKeyframe(m_position));
update();
});
connect(m_model.get(), &KeyframeModelList::modelChanged, this, &KeyframeView::slotModelChanged);
}
void KeyframeView::slotModelChanged()
{
emit atKeyframe(m_model->hasKeyframe(m_position));
update();
}
void KeyframeView::slotSetPosition(int pos)
{
if (pos != m_position) {
......
......@@ -52,6 +52,7 @@ public slots:
void slotAddRemove();
void slotGoToNext();
void slotGoToPrev();
void slotModelChanged();
protected:
void paintEvent(QPaintEvent *event) override;
......
......@@ -20,6 +20,7 @@
***************************************************************************/
#include "assetparametermodel.hpp"
#include "assets/keyframes/model/keyframemodellist.hpp"
#include "core.h"
#include "kdenlivesettings.h"
#include "klocalizedstring.h"
......@@ -96,10 +97,22 @@ AssetParameterModel::AssetParameterModel(Mlt::Properties *asset, const QDomEleme
currentRow.name = title.isEmpty() ? name : title;
m_params[name] = currentRow;
m_rows.push_back(name);
}
qDebug() << "END parsing of "<<assetId<<". Number of found parameters"<<m_rows.size();
}
void AssetParameterModel::prepareKeyframes()
{
if (m_keyframes)
return;
for (const auto& name: m_rows) {
if (m_params[name].type == ParamType::KeyframeParam) {
addKeyframeParam(index(m_rows.size() -1, 0));
}
}
}
void AssetParameterModel::setParameter(const QString &name, const QString &value)
{
Q_ASSERT(m_asset->is_valid());
......@@ -355,3 +368,18 @@ ObjectId AssetParameterModel::getOwnerId() const
{
return m_ownerId;
}
void AssetParameterModel::addKeyframeParam(const QModelIndex index)
{
if (m_keyframes) {
m_keyframes->addParameter(index);
} else {
m_keyframes.reset(new KeyframeModelList(shared_from_this(), index, pCore->undoStack()));
}
}
std::shared_ptr<KeyframeModelList> AssetParameterModel::getKeyframeModel()
{
return m_keyframes;
}
......@@ -32,6 +32,7 @@
#include <memory>
#include <mlt++/MltProperties.h>
class KeyframeModelList;
/* @brief This class is the model for a list of parameters.
The behaviour of a transition or an effect is typically controlled by several parameters. This class exposes this parameters as a list that can be rendered
using the relevant widgets.
......@@ -117,6 +118,14 @@ public:
/* @brief Returns the id of the actual object associated with this asset */
ObjectId getOwnerId() const;
/* @brief Returns the keyframe model associated with this asset
Return empty ptr if there is no keyframable parameter in the asset or if prepareKeyframes was not called
*/
std::shared_ptr<KeyframeModelList> getKeyframeModel();
/* @brief Must be called before using the keyframes of this model */
void prepareKeyframes();
protected:
/* @brief Helper function to retrieve the type of a parameter given the string corresponding to it*/
static ParamType paramTypeFromStr(const QString &type);
......@@ -129,6 +138,12 @@ protected:
If keywords are found, mathematical operations are supported for double type params. For example "%width -1" is a valid value.
*/
static QVariant parseAttribute(const QString &attribute, const QDomElement &element, QVariant defaultValue = QVariant());
/* @brief Helper function to register one more parameter that is keyframable.
@param index is the index corresponding to this parameter
*/
void addKeyframeParam(const QModelIndex index);
struct ParamRow
{
ParamType type;
......@@ -145,6 +160,8 @@ protected:
QVector<QString> m_rows; // We store the params name in order of parsing. The order is important (cf some effects like sox)
std::unique_ptr<Mlt::Properties> m_asset;
std::shared_ptr<KeyframeModelList> m_keyframes;
};
#endif
......@@ -48,6 +48,7 @@ void AssetParameterView::setModel(const std::shared_ptr<AssetParameterModel> &mo
unsetModel();
QMutexLocker lock(&m_lock);
m_model = model;
m_model->prepareKeyframes();
connect(m_model.get(), &AssetParameterModel::dataChanged, this, &AssetParameterView::refresh);
AnimationWidget *animWidget = nullptr;
for (int i = 0; i < model->rowCount(); ++i) {
......
......@@ -35,7 +35,7 @@
KeyframeWidget::KeyframeWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent)
: AbstractParamWidget(model, index, parent)
{
m_keyframes = std::shared_ptr<KeyframeModelList>(new KeyframeModelList(model, index, pCore->undoStack()));
m_keyframes = model->getKeyframeModel();
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
......
......@@ -189,7 +189,8 @@ CollapsibleEffectView::CollapsibleEffectView(std::shared_ptr<EffectItemModel> ef
CollapsibleEffectView::~CollapsibleEffectView()
{
// delete m_paramWidget;
qDebug() << "deleting collapsibleeffectview";
delete m_view;
delete m_menu;
}
......
......@@ -37,6 +37,7 @@ TEST_CASE("Keyframe model", "[KeyframeModel]")
REQUIRE(effectstack->checkConsistency());
REQUIRE(effectstack->rowCount() == 1);
auto effect = std::dynamic_pointer_cast<EffectItemModel>(effectstack->getEffectStackRow(0));
effect->prepareKeyframes();
qDebug() << effect->getAssetId() << effect->getAllParameters();
REQUIRE(effect->rowCount() == 1);
......
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