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 <QString>
24#include <QMap>
25#include <QList>
26#include <QRectF>
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 int frame;
42 QRectF rect;
43 };
44
45 explicit MotionTrackerModel(QObject *parent = nullptr);
46
47 void load(Mlt::Producer *producer = nullptr, bool reset = true);
48 QString add(const QString &name, const QString &data);
49 void updateData(const QString &key, const QString &data);
50 void remove(const QString &key);
51 Q_INVOKABLE void setName(QmlFilter *filter, const QString &name);
52 Q_INVOKABLE QString nextName() const;
53 QString keyForRow(int row) const;
54 QString keyForFilter(Mlt::Service *service);
55 Q_INVOKABLE void reset(QmlFilter *filter, const QString &property, int row);
56 QList<TrackingItem> trackingData(const QString &key) const;
57 Q_INVOKABLE QList<QRectF> trackingData(int row) const;
58 Q_INVOKABLE int keyframeIntervalFrames(int row) const;
59
60 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
61 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
62 bool setData(const QModelIndex &index, const QVariant &value,
63 int role = Qt::EditRole) override;
64 Qt::ItemFlags flags(const QModelIndex &index) const override;
65 Q_INVOKABLE static void undo(QmlFilter *filter = nullptr, const QString &propertyName = QString());
66 static QString trackerNameProperty()
67 {
68 return QString::fromLatin1("shotcut:motionTracker.name");
69 }
70 static QString trackerOperationProperty()
71 {
72 return QString::fromLatin1("shotcut:motionTracker.operation");
73 }
74
75public slots:
76 void removeFromService(Mlt::Service *service);
77
78private:
79 enum Roles {
80 IdentifierRole = Qt::UserRole,
81 TrackingDataRole = Qt::UserRole + 1
82 };
83
84 struct Item {
85 QString name;
86 QString trackingData;
87 int intervalFrames;
88 };
89
90 QMap<QString, Item> m_data; // key is a UUID
91};
92
93#endif // MOTIONTRACKERMODEL_H