|
21 | 21 | #include "controllers/filtercontroller.h"
|
22 | 22 | #include "mainwindow.h"
|
23 | 23 | #include "mltcontroller.h"
|
| 24 | +#include "qmltypes/qmlapplication.h" |
24 | 25 | #include "qmltypes/qmlmetadata.h"
|
25 | 26 |
|
26 | 27 | class FindProducerParser : public Mlt::Parser
|
@@ -291,6 +292,55 @@ bool DisableCommand::mergeWith(const QUndoCommand *other)
|
291 | 292 | */
|
292 | 293 | }
|
293 | 294 |
|
| 295 | +PasteCommand::PasteCommand(AttachedFiltersModel &model, |
| 296 | + const QString &filterProducerXml, |
| 297 | + QUndoCommand *parent) |
| 298 | + : QUndoCommand(parent) |
| 299 | + , m_model(model) |
| 300 | + , m_xml(filterProducerXml) |
| 301 | + , m_producerUuid(MLT.ensureHasUuid(*model.producer())) |
| 302 | +{ |
| 303 | + setText(QObject::tr("Paste filters")); |
| 304 | + m_beforeXml = MLT.XML(model.producer()); |
| 305 | +} |
| 306 | + |
| 307 | +void PasteCommand::redo() |
| 308 | +{ |
| 309 | + LOG_DEBUG() << text(); |
| 310 | + Mlt::Producer producer = findProducer(m_producerUuid); |
| 311 | + Q_ASSERT(producer.is_valid()); |
| 312 | + Mlt::Profile profile(kDefaultMltProfile); |
| 313 | + Mlt::Producer filtersProducer(profile, "xml-string", m_xml.toUtf8().constData()); |
| 314 | + if (filtersProducer.is_valid() && filtersProducer.filter_count() > 0) { |
| 315 | + MLT.pasteFilters(&producer, &filtersProducer); |
| 316 | + } |
| 317 | + emit QmlApplication::singleton().filtersPasted(&producer); |
| 318 | +} |
| 319 | + |
| 320 | +void PasteCommand::undo() |
| 321 | +{ |
| 322 | + LOG_DEBUG() << text(); |
| 323 | + Mlt::Producer producer = findProducer(m_producerUuid); |
| 324 | + Q_ASSERT(producer.is_valid()); |
| 325 | + // Remove all filters |
| 326 | + for (int i = 0; i < producer.filter_count(); i++) { |
| 327 | + Mlt::Filter *filter = producer.filter(i); |
| 328 | + if (filter && filter->is_valid() && !filter->get_int("_loader") |
| 329 | + && !filter->get_int(kShotcutHiddenProperty)) { |
| 330 | + producer.detach(*filter); |
| 331 | + i--; |
| 332 | + } |
| 333 | + delete filter; |
| 334 | + } |
| 335 | + // Restore the "before" filters |
| 336 | + Mlt::Profile profile(kDefaultMltProfile); |
| 337 | + Mlt::Producer filtersProducer(profile, "xml-string", m_beforeXml.toUtf8().constData()); |
| 338 | + if (filtersProducer.is_valid() && filtersProducer.filter_count() > 0) { |
| 339 | + MLT.pasteFilters(&producer, &filtersProducer); |
| 340 | + } |
| 341 | + emit QmlApplication::singleton().filtersPasted(&producer); |
| 342 | +} |
| 343 | + |
294 | 344 | UndoParameterCommand::UndoParameterCommand(const QString &name,
|
295 | 345 | FilterController *controller,
|
296 | 346 | int row,
|
|
0 commit comments