-
Notifications
You must be signed in to change notification settings - Fork 28
/
ClipEditorModel.h
118 lines (85 loc) · 3.89 KB
/
ClipEditorModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/************************************************************************
**
** Copyright (C) 2023 Kevin B. Hendricks, Stratford Ontario Canada
** Copyright (C) 2012 John Schember <[email protected]>
** Copyright (C) 2012 Dave Heiland
** Copyright (C) 2012 Grant Drake
**
** This file is part of PageEdit.
**
** PageEdit is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** PageEdit is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with PageEdit. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#pragma once
#ifndef CLIPEDITORMODEL_H
#define CLIPEDITORMODEL_H
#include <QStandardItemModel>
#include <QFileSystemWatcher>
#include <QDropEvent>
#include "SettingsStore.h"
class ClipEditorModel : public QStandardItemModel
{
Q_OBJECT
public:
ClipEditorModel(QObject *parent = 0);
~ClipEditorModel();
static ClipEditorModel *instance();
struct clipEntry {
bool is_group;
QString fullname;
QString name;
QString text;
};
bool IsDataModified();
bool ItemIsGroup(QStandardItem *item);
QString GetFullName(QStandardItem *item);
void LoadInitialData();
void LoadData(const QString &filename = QString(), QStandardItem *parent_item = NULL);
void AddFullNameEntry(ClipEditorModel::clipEntry *entry = NULL, QStandardItem *parent_item = NULL, int row = -1);
QStandardItem *AddEntryToModel(ClipEditorModel::clipEntry *entry, bool is_group = false, QStandardItem *parent_item = NULL, int row = -1);
QString SaveData(QList<ClipEditorModel::clipEntry *> entries = QList<ClipEditorModel::clipEntry *>(), const QString &filename = QString());
QList<ClipEditorModel::clipEntry *> GetEntries(QList<QStandardItem *> items);
ClipEditorModel::clipEntry *GetEntry(QStandardItem *item);
ClipEditorModel::clipEntry *GetEntry(const QModelIndex &index);
ClipEditorModel::clipEntry *GetEntryFromName(const QString &name, QStandardItem *parent_item = NULL);
ClipEditorModel::clipEntry *GetEntryFromNumber(int clip_number);
QStandardItem *GetItemFromName(QString name, QStandardItem *item = NULL);
QList<QStandardItem *> GetNonGroupItems(QList<QStandardItem *> items);
QList<QStandardItem *> GetNonGroupItems(QStandardItem *item);
QList<QStandardItem *> GetNonParentItems(QList<QStandardItem *> items);
QList<QStandardItem *> GetNonParentItems(QStandardItem *item);
void Rename(QStandardItem *item, const QString &name = "");
void UpdateFullName(QStandardItem *item);
QVariant data(const QModelIndex &index, int role) const;
signals:
void SettingsFileUpdated() const;
void ItemDropped(const QModelIndex &) const;
void ClipsUpdated();
private slots:
void RowsRemovedHandler(const QModelIndex &parent, int start, int end);
void ItemChangedHandler(QStandardItem *item);
void SettingsFileChanged(const QString &path) const;
private:
void SetDataModified(bool modified);
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
Qt::DropActions supportedDropActions() const;
QStandardItem *GetItemFromId(quintptr id, int row, QStandardItem *item = NULL) const;
QStandardItem *GetItemFromNumber(int clip_number);
void AddExampleEntries();
static ClipEditorModel *m_instance;
QString m_SettingsPath;
QFileSystemWatcher *m_FSWatcher;
bool m_IsDataModified;
};
#endif // CLIPEDITORMODEL_H