-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdlistmodel.h
64 lines (54 loc) · 1.78 KB
/
cmdlistmodel.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
#ifndef CMDLISTMODEL_H
#define CMDLISTMODEL_H
#include <QAbstractTableModel>
#include <QProcess>
struct Cmd
{
int id;
QString name;
QString exec;
int pos;
~Cmd();
};
QDebug operator<<(QDebug dbg, const Cmd &c);
enum CustomRoles
{
DataRole = Qt::UserRole,
FileRole,
StateRole,
};
class CmdListModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit CmdListModel(QObject *parent = nullptr);
private slots:
void procStateChanged(QProcess::ProcessState state);
private:
QList<Cmd> cmdList;
QMap<int, QProcess *> procMap;
void assignPositions();
void toggleProc(const QModelIndex &index);
void updateDB(const Cmd &cmd);
void insertDB(Cmd &cmd);
void deleteDB(const Cmd &cmd);
void reloadDB();
// QAbstractItemModel interface
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
bool insertRows(int row, int count, const QModelIndex &parent) override;
bool removeRows(int row, int count, const QModelIndex &parent) override;
// QAbstractItemModel interface
public:
Qt::DropActions supportedDropActions() const override;
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
const QModelIndex &parent) override;
QStringList mimeTypes() const override;
QMimeData *mimeData(const QModelIndexList &indexes) const override;
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
const QModelIndex &parent) const override;
};
#endif // CMDLISTMODEL_H