CuteLogger
Fast and simple logging solution for Qt based applications
motiontrackermodel.h
1/*
2 * Copyright (c) 2023 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef MOTIONTRACKERMODEL_H
19#define MOTIONTRACKERMODEL_H
20
21#include <MltProducer.h>
22#include <QAbstractListModel>
23#include <QList>
24#include <QMap>
25#include <QRectF>
26#include <QString>
27
28class QmlFilter;
29namespace Mlt {
30class Service;
31}
32
33class MotionTrackerModel : public QAbstractListModel
34{
35 Q_OBJECT
36 Q_PROPERTY(QString nameProperty READ trackerNameProperty CONSTANT)
37 Q_PROPERTY(QString operationProperty READ trackerOperationProperty CONSTANT)
38
39public:
40 struct TrackingItem
41 {
42 int frame;
43 QRectF rect;
44 };
45
46 explicit MotionTrackerModel(QObject *parent = nullptr);
47
48 void load(Mlt::Producer *producer = nullptr, bool reset = true);
49 QString add(const QString &name, const QString &data);
50 void updateData(const QString &key, const QString &data);
51 void remove(const QString &key);
52 Q_INVOKABLE void setName(QmlFilter *filter, const QString &name);
53 Q_INVOKABLE QString nextName() const;
54 QString keyForRow(int row) const;
55 QString keyForFilter(Mlt::Service *service);
56 Q_INVOKABLE void reset(QmlFilter *filter, const QString &property, int row);
57 QList<TrackingItem> trackingData(const QString &key) const;
58 Q_INVOKABLE QList<QRectF> trackingData(int row) const;
59 Q_INVOKABLE int keyframeIntervalFrames(int row) const;
60
61 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
62 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
63 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
64 Qt::ItemFlags flags(const QModelIndex &index) const override;
65 Q_INVOKABLE static void undo(QmlFilter *filter = nullptr,
66 const QString &propertyName = QString());
67 static QString trackerNameProperty()
68 {
69 return QString::fromLatin1("shotcut:motionTracker.name");
70 }
71 static QString trackerOperationProperty()
72 {
73 return QString::fromLatin1("shotcut:motionTracker.operation");
74 }
75
76public slots:
77 void removeFromService(Mlt::Service *service);
78
79private:
80 enum Roles { IdentifierRole = Qt::UserRole, TrackingDataRole = Qt::UserRole + 1 };
81
82 struct Item
83 {
84 QString name;
85 QString trackingData;
86 int intervalFrames;
87 };
88
89 QMap<QString, Item> m_data; // key is a UUID
90};
91
92#endif // MOTIONTRACKERMODEL_H