aboutsummaryrefslogtreecommitdiff
path: root/libs/installer_bsplugins/src/BSPluginList/PluginListModel.h
blob: d0de9c6ef6c65a27e667dd7c749e01d4694ed748 (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef BSPLUGINLIST_PLUGINLISTMODEL_H
#define BSPLUGINLIST_PLUGINLISTMODEL_H

#include "TESData/PluginList.h"

#include <QAbstractItemModel>

#include <functional>

namespace BSPluginList
{

class PluginListModel final : public QAbstractItemModel
{
  Q_OBJECT

public:
  friend class PluginGroupProxyModel;

  enum ItemDataRole
  {
    GroupingRole = Qt::UserRole,
    IndexRole,
    InfoRole,
    ConflictsIconRole,
    FlagsIconRole,
    OriginRole,
    OverridingRole,
    OverriddenRole,
    OverwritingAuxRole,
    OverwrittenAuxRole,
    ScrollMarkRole,
  };

  enum EColumn
  {
    COL_NAME,
    COL_CONFLICTS,
    COL_FLAGS,
    COL_PRIORITY,
    COL_MODINDEX,
    COL_FORMVERSION,
    COL_HEADERVERSION,
    COL_AUTHOR,
    COL_DESCRIPTION,

    COL_COUNT
  };

  explicit PluginListModel(TESData::PluginList* plugins);

  QModelIndex index(int row, int column,
                    const QModelIndex& parent = QModelIndex()) const override;
  QModelIndex parent(const QModelIndex& index) const override;

  Qt::ItemFlags flags(const QModelIndex& index) const override;
  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
  QVariant headerData(int section, Qt::Orientation orientation,
                      int role) const override;
  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
  int columnCount(const QModelIndex& parent = QModelIndex()) const override;

  bool setData(const QModelIndex& index, const QVariant& value,
               int role = Qt::EditRole) override;

  Qt::DropActions supportedDropActions() const override;
  bool canDropMimeData(const QMimeData* data, Qt::DropAction action, int row,
                       int column, const QModelIndex& parent) const override;
  bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column,
                    const QModelIndex& parent) override;

  [[nodiscard]] QStringList
  groups(std::function<bool(const TESData::FileInfo*)> pred = {}) const;
  [[nodiscard]] QStringList masterGroups() const;
  [[nodiscard]] QStringList regularGroups() const;

public slots:
  void refresh();

  void invalidate();
  void invalidateConflicts();

  void movePlugin(const QString& name, int oldPriority, int newPriority);

  void
  changePluginStates(const std::map<QString, MOBase::IPluginList::PluginStates>& infos);

  // enable/disable all plugins
  //
  void setEnabledAll(bool enabled);

  // enable/disable plugins at the given indices.
  //
  void setEnabled(const QModelIndexList& indices, bool enabled);

  // send plugins to the given priority
  //
  void sendToPriority(const QModelIndexList& indices, int priority,
                      bool disjoint = false);

  // shift the priority of mods at the given indices by the given offset
  //
  void shiftPluginsPriority(const QModelIndexList& indices, int offset);

  // toggle the active state of mods at the given indices
  //
  void toggleState(const QModelIndexList& indices);

  // assign plugins to a group
  //
  void setGroup(const QModelIndexList& indices, const QString& group);

  // send plugins to the bottom of a group
  //
  void sendToGroup(const QModelIndexList& indices, const QString& group, bool isESM);

signals:
  void pluginStatesChanged(const QModelIndexList& indices) const;
  void pluginOrderChanged() const;

private:
  [[nodiscard]] QVariant displayData(const QModelIndex& index) const;
  [[nodiscard]] QVariant checkstateData(const QModelIndex& index) const;
  [[nodiscard]] QVariant foregroundData(const QModelIndex& index) const;
  [[nodiscard]] QVariant backgroundData(const QModelIndex& index) const;
  [[nodiscard]] QVariant fontData(const QModelIndex& index) const;
  [[nodiscard]] QVariant alignmentData(const QModelIndex& index) const;
  [[nodiscard]] QVariant tooltipData(const QModelIndex& index) const;
  [[nodiscard]] QVariant conflictData(const QModelIndex& index) const;
  [[nodiscard]] QVariant iconData(const QModelIndex& index) const;

  TESData::PluginList* m_Plugins;
};

}  // namespace BSPluginList

#endif  // BSPLUGINLIST_PLUGINLISTMODEL_H