CuteLogger
Fast and simple logging solution for Qt based applications
attachedfiltersmodel.h
1 /*
2  * Copyright (c) 2013-2017 Meltytech, LLC
3  * Author: Dan Dennedy <dan@dennedy.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef ATTACHEDFILTERSMODEL_H
20 #define ATTACHEDFILTERSMODEL_H
21 
22 #include <QAbstractListModel>
23 #include <MltFilter.h>
24 #include <MltProducer.h>
25 #include <MltEvent.h>
26 
27 class QmlMetadata;
28 
29 class AttachedFiltersModel : public QAbstractListModel
30 {
31  Q_OBJECT
32  Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged)
33  Q_PROPERTY(QString producerTitle READ producerTitle NOTIFY trackTitleChanged)
34  Q_PROPERTY(bool isProducerSelected READ isProducerSelected NOTIFY isProducerSelectedChanged)
35 public:
36  enum ModelRoles {
37  TypeDisplayRole = Qt::UserRole + 1
38  };
39 
40  explicit AttachedFiltersModel(QObject *parent = 0);
41 
42  bool isReady();
43  Mlt::Filter* getFilter(int row) const;
44  QmlMetadata* getMetadata(int row) const;
45  void setProducer(Mlt::Producer* producer = 0);
46  QString producerTitle() const;
47  bool isProducerSelected() const;
48  Mlt::Producer* producer() const { return m_producer.data(); }
49 
50  // QAbstractListModel Implementation
51  int rowCount(const QModelIndex &parent = QModelIndex()) const;
52  Qt::ItemFlags flags(const QModelIndex &index) const;
53  QVariant data(const QModelIndex &index, int role) const;
54  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
55  QHash<int, QByteArray> roleNames() const;
56  Qt::DropActions supportedDropActions() const;
57  bool insertRows(int row, int count, const QModelIndex &parent);
58  bool removeRows(int row, int count, const QModelIndex &parent);
59  bool moveRows(const QModelIndex & sourceParent, int sourceRow, int count, const QModelIndex & destinationParent, int destinationRow);
60 
61 signals:
62  void changed();
63  void readyChanged();
64  void duplicateAddFailed(int index);
65  void trackTitleChanged();
66  void isProducerSelectedChanged();
67  void addedOrRemoved(Mlt::Producer*);
68 
69 public slots:
70  void add(QmlMetadata* meta);
71  void remove(int row);
72  bool move(int fromRow, int toRow);
73 
74 private:
75  static void producerChanged(mlt_properties owner, AttachedFiltersModel* model);
76  void reset(Mlt::Producer *producer = 0);
77 
78  int m_dropRow;
79  int m_removeRow;
80  QScopedPointer<Mlt::Producer> m_producer;
81  QScopedPointer<Mlt::Event> m_event;
82  typedef QList<QmlMetadata*> MetadataList;
83  MetadataList m_metaList;
84  typedef QList<int> IndexMap;
85  IndexMap m_mltIndexMap;
86 };
87 
88 #endif // ATTACHEDFILTERSMODEL_H