Skip to content

Commit

Permalink
Fix filters not being initialized when added.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Nov 12, 2014
1 parent 88bb9f1 commit 0928a71
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
11 changes: 7 additions & 4 deletions src/controllers/filtercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ void FilterController::attachFilter(int metadataIndex)
QmlMetadata* meta = m_metadataModel.get(metadataIndex);
QmlFilter* filter = NULL;
if (meta) {
filter = new QmlFilter(m_attachedModel, *meta, -1);
m_currentFilterIndex = m_attachedModel.rowCount() - 1;
m_currentFilterIndex = m_attachedModel.add(meta);
Mlt::Filter* mltFilter = m_attachedModel.filterForRow(m_currentFilterIndex);
filter = new QmlFilter(mltFilter, meta);
filter->setIsNew(true);
} else {
m_currentFilterIndex = -1;
}
Expand All @@ -136,7 +138,9 @@ void FilterController::setCurrentFilter(int attachedIndex)
if (mltFilter && mltFilter->is_valid()) {
meta = metadataForService(mltFilter);
if (meta) {
filter = new QmlFilter(m_attachedModel, *meta, attachedIndex);
filter = new QmlFilter(mltFilter, meta);
} else {
delete mltFilter;
}
}

Expand All @@ -148,7 +152,6 @@ void FilterController::setCurrentFilter(int attachedIndex)

emit currentFilterChanged(filter, meta);
m_currentFilter.reset(filter);
delete mltFilter;
}

void FilterController::handleAttachedModelChange()
Expand Down
3 changes: 3 additions & 0 deletions src/docks/filtersdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ FiltersDock::FiltersDock(MetadataModel* metadataModel, AttachedFiltersModel* att

void FiltersDock::setCurrentFilter(QmlFilter* filter, QmlMetadata* meta)
{
m_qview.rootContext()->setContextProperty("metadata", NULL);
QMetaObject::invokeMethod(m_qview.rootObject(), "updateFilterConfig");
m_qview.rootContext()->setContextProperty("filter", filter);
m_qview.rootContext()->setContextProperty("metadata", meta);
QMetaObject::invokeMethod(m_qview.rootObject(), "updateFilterConfig");
}

void FiltersDock::setFadeInDuration(int duration)
Expand Down
7 changes: 4 additions & 3 deletions src/models/attachedfiltersmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,17 @@ bool AttachedFiltersModel::moveRows(const QModelIndex & sourceParent, int source
return false;
}

Mlt::Filter *AttachedFiltersModel::add(const QmlMetadata* meta)
int AttachedFiltersModel::add(const QmlMetadata* meta)
{
int insertIndex = -1;
Mlt::Filter* filter = new Mlt::Filter(MLT.profile(), meta->mlt_service().toUtf8().constData());
if (filter->is_valid()) {
if (!meta->objectName().isEmpty())
filter->set("shotcut:filter", meta->objectName().toUtf8().constData());

// Put the filter after the last filter that is greater than or equal
// in sort order.
int insertIndex = 0;
insertIndex = 0;
for (int i = m_rows - 1; i >= 0; i--) {
if (!sortIsLess(m_metaList[i], meta)) {
insertIndex = i + 1;
Expand All @@ -271,7 +272,7 @@ Mlt::Filter *AttachedFiltersModel::add(const QmlMetadata* meta)
emit changed();
}
else qWarning() << "Failed to load filter" << meta->mlt_service();
return filter;
return insertIndex;
}

void AttachedFiltersModel::remove(int row)
Expand Down
2 changes: 1 addition & 1 deletion src/models/attachedfiltersmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AttachedFiltersModel : public QAbstractListModel
void readyChanged();

public slots:
Mlt::Filter* add(const QmlMetadata* meta);
int add(const QmlMetadata* meta);
void remove(int row);
bool move(int fromRow, int toRow);
void reset(Mlt::Producer *producer = 0);
Expand Down
8 changes: 4 additions & 4 deletions src/qml/views/filter/filterview.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Rectangle {
signal attachFilterRequested(int metadataIndex)
signal removeFilterRequested(int attachedIndex)
signal currentFilterRequested(int attachedIndex)

function updateFilterConfig() {
filterConfig.source = metadata ? metadata.qmlFilePath : ""
}

color: activePalette.window
width: 400
Expand Down Expand Up @@ -63,9 +67,7 @@ Rectangle {
Layout.fillWidth: true
Layout.fillHeight: true
onSelectedIndexChanged: {
filterConfig.source = ""
root.currentFilterRequested(selectedIndex)
filterConfig.source = metadata ? metadata.qmlFilePath : ""
}
}

Expand All @@ -86,10 +88,8 @@ Rectangle {
opacity: enabled ? 1.0 : 0.5
tooltip: qsTr('Remove Selected Filter')
onClicked: {
filterConfig.source = ""
attachedfiltersmodel.remove(attachedFilters.selectedIndex)
root.currentFilterRequested(attachedFilters.selectedIndex)
filterConfig.source = metadata ? metadata.qmlFilePath : ""
}
}
Item {
Expand Down
25 changes: 10 additions & 15 deletions src/qmltypes/qmlfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "qmlfilter.h"
#include "mltcontroller.h"
#include "mainwindow.h"
#include "controllers/filtercontroller.h"
#include "jobqueue.h"
#include <QStandardPaths>
#include <QDir>
Expand All @@ -34,19 +36,13 @@ static const char* kHeightProperty = "meta.media.height";
static const char* kAspectNumProperty = "meta.media.sample_aspect_num";
static const char* kAspectDenProperty = "meta.media.sample_aspect_den";

QmlFilter::QmlFilter(AttachedFiltersModel& model, const QmlMetadata &metadata, int row, QObject *parent)
QmlFilter::QmlFilter(Mlt::Filter* mltFilter, const QmlMetadata* metadata, QObject* parent)
: QObject(parent)
, m_model(model)
, m_metadata(metadata)
, m_path(m_metadata.path().absolutePath().append('/'))
, m_isNew(row < 0)
, m_filter(mltFilter)
, m_path(m_metadata->path().absolutePath().append('/'))
, m_isNew(false)
{
if (m_isNew) {
m_filter = m_model.add(&m_metadata);
}
else {
m_filter = model.filterForRow(row);
}
}

QmlFilter::~QmlFilter()
Expand Down Expand Up @@ -235,7 +231,7 @@ void QmlFilter::analyze(bool isAudio)

MeltJob* job = new MeltJob(target, tmpName);
if (job) {
AnalyzeDelegate* delegate = new AnalyzeDelegate(m_model, m_filter);
AnalyzeDelegate* delegate = new AnalyzeDelegate(m_filter);
connect(job, &MeltJob::finished, delegate, &AnalyzeDelegate::onAnalyzeFinished);
connect(job, &MeltJob::finished, this, &QmlFilter::analyzeFinished);
QFileInfo info(QString::fromUtf8(service.get("resource")));
Expand Down Expand Up @@ -317,12 +313,11 @@ void QmlFilter::preset(const QString &name)

QString QmlFilter::objectNameOrService()
{
return m_metadata.objectName().isEmpty()? m_metadata.mlt_service() : m_metadata.objectName();
return m_metadata->objectName().isEmpty()? m_metadata->mlt_service() : m_metadata->objectName();
}

AnalyzeDelegate::AnalyzeDelegate(AttachedFiltersModel &model, Mlt::Filter* filter)
AnalyzeDelegate::AnalyzeDelegate(Mlt::Filter* filter)
: QObject(0)
, m_model(model)
, m_filter(*filter)
{}

Expand Down Expand Up @@ -357,7 +352,7 @@ void AnalyzeDelegate::onAnalyzeFinished(MeltJob *job, bool isSuccess)
QDomNode propertyNode = properties.at(j);
if (propertyNode.attributes().namedItem("name").toAttr().value() == "results") {
m_filter.set("results", propertyNode.toElement().text().toLatin1().constData());
emit m_model.changed();
emit MAIN.filterController()->attachedModel()->changed();
}
}
break;
Expand Down
10 changes: 4 additions & 6 deletions src/qmltypes/qmlfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <QVariant>
#include <QRectF>
#include <MltFilter.h>
#include "models/attachedfiltersmodel.h"
#include "qmlmetadata.h"

class MeltJob;
Expand All @@ -40,10 +39,11 @@ class QmlFilter : public QObject
Q_PROPERTY(double producerAspect READ producerAspect)

public:
explicit QmlFilter(AttachedFiltersModel& model, const QmlMetadata& metadata, int row, QObject *parent = 0);
explicit QmlFilter(Mlt::Filter* mltFilter, const QmlMetadata* metadata, QObject *parent = 0);
~QmlFilter();

bool isNew() const { return m_isNew; }
void setIsNew(bool isNew) { m_isNew = isNew; };

Q_INVOKABLE QString get(QString name);
Q_INVOKABLE double getDouble(QString name);
Expand Down Expand Up @@ -74,8 +74,7 @@ public slots:
void changed(); /// Use to let UI and VUI QML signal updates to each other.

private:
AttachedFiltersModel& m_model;
const QmlMetadata& m_metadata;
const QmlMetadata* m_metadata;
Mlt::Filter* m_filter;
QString m_path;
bool m_isNew;
Expand All @@ -88,13 +87,12 @@ class AnalyzeDelegate : public QObject
{
Q_OBJECT
public:
explicit AnalyzeDelegate(AttachedFiltersModel& model, Mlt::Filter *filter);
explicit AnalyzeDelegate(Mlt::Filter *filter);

public slots:
void onAnalyzeFinished(MeltJob *job, bool isSuccess);

private:
AttachedFiltersModel& m_model;
Mlt::Filter m_filter;
};

Expand Down

0 comments on commit 0928a71

Please sign in to comment.