Crossfire Server, Trunk
AssetModel.h
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #ifndef ASSET_MODEL_H
14 #define ASSET_MODEL_H
15 
16 #include <QAbstractItemModel>
17 #include <QVector>
18 #include <QSortFilterProxyModel>
19 
20 #include <map>
21 #include <tuple>
22 #include <utility>
23 
24 #include "assets/AssetWrapper.h"
25 
29 class AssetModel : public QAbstractItemModel {
30  Q_OBJECT
31 public:
32  AssetModel(AssetWrapper *assets, QObject *parent);
33  virtual ~AssetModel();
34 
35  virtual int columnCount(const QModelIndex& parent) const override;
36  virtual QModelIndex index(int row, int column, const QModelIndex& parent) const override;
37  virtual QModelIndex parent(const QModelIndex& index) const override;
38  virtual int rowCount(const QModelIndex & parent) const override;
39  virtual QVariant data(const QModelIndex& index, int role) const override;
40  virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
41  virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
42  // virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
43  // virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
44  virtual QMimeData *mimeData(const QModelIndexList &indexes) const override;
45  virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
46  virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
47 
48 protected slots:
50 
51 private:
53 };
54 
58 class UseFilterAssetModel : public QSortFilterProxyModel {
59 public:
60  UseFilterAssetModel(QObject *parent);
61 
62  void setFilter(AssetWrapper *asset);
63  virtual QVariant data(const QModelIndex& index, int role) const override;
64 
65 protected:
66  virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
67 
69  mutable std::map<AssetWrapper *, bool> myCachedFilter;
70  mutable std::map<AssetWrapper *, std::string> myCachedHints;
71 };
72 
73 class QScriptEngine;
74 
78 class ScriptFilterAssetModel : public QSortFilterProxyModel {
79 public:
80  ScriptFilterAssetModel(AssetModel *model, QScriptEngine *engine, QObject *parent);
81 
82  void setFilter(const QString &filter);
83  const QString& filter() const { return myFilter; }
84 
85 protected:
86  virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
87  bool acceptItem(AssetWrapper *item) const;
88 
89  QScriptEngine *myEngine;
90  QString myFilter;
91  mutable std::map<AssetWrapper *, bool> myCachedFilter;
92 };
93 
94 #endif /* ASSET_MODEL_H */
AssetWrapper.h
filter
Definition: filter.py:1
ScriptFilterAssetModel::filterAcceptsRow
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Definition: AssetModel.cpp:262
AssetModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: AssetModel.cpp:94
ScriptFilterAssetModel::setFilter
void setFilter(const QString &filter)
Definition: AssetModel.cpp:256
UseFilterAssetModel::myAsset
AssetWrapper * myAsset
Definition: AssetModel.h:68
UseFilterAssetModel::filterAcceptsRow
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Definition: AssetModel.cpp:204
AssetModel::myAssets
AssetWrapper * myAssets
Definition: AssetModel.h:52
UseFilterAssetModel::myCachedHints
std::map< AssetWrapper *, std::string > myCachedHints
Definition: AssetModel.h:70
AssetModel::canDropMimeData
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
Definition: AssetModel.cpp:121
UseFilterAssetModel::setFilter
void setFilter(AssetWrapper *asset)
Definition: AssetModel.cpp:197
ScriptFilterAssetModel::acceptItem
bool acceptItem(AssetWrapper *item) const
Definition: AssetModel.cpp:288
AssetModel::data
virtual QVariant data(const QModelIndex &index, int role) const override
Definition: AssetModel.cpp:70
AssetWrapper
Definition: AssetWrapper.h:25
ScriptFilterAssetModel::ScriptFilterAssetModel
ScriptFilterAssetModel(AssetModel *model, QScriptEngine *engine, QObject *parent)
Definition: AssetModel.cpp:251
UseFilterAssetModel
Definition: AssetModel.h:58
ScriptFilterAssetModel
Definition: AssetModel.h:78
convert.action
action
Definition: convert.py:25
UseFilterAssetModel::data
virtual QVariant data(const QModelIndex &index, int role) const override
Definition: AssetModel.cpp:238
AssetWrapper::ChangeType
ChangeType
Definition: AssetWrapper.h:32
AssetModel
Definition: AssetModel.h:29
AssetModel::columnCount
virtual int columnCount(const QModelIndex &parent) const override
Definition: AssetModel.cpp:26
UseFilterAssetModel::UseFilterAssetModel
UseFilterAssetModel(QObject *parent)
Definition: AssetModel.cpp:194
AssetModel::dropMimeData
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Definition: AssetModel.cpp:134
AssetModel::parent
virtual QModelIndex parent(const QModelIndex &index) const override
Definition: AssetModel.cpp:47
ScriptFilterAssetModel::filter
const QString & filter() const
Definition: AssetModel.h:83
item
Definition: item.py:1
ScriptFilterAssetModel::myFilter
QString myFilter
Definition: AssetModel.h:90
npc_dialog.index
int index
Definition: npc_dialog.py:102
AssetModel::~AssetModel
virtual ~AssetModel()
Definition: AssetModel.cpp:23
ScriptFilterAssetModel::myEngine
QScriptEngine * myEngine
Definition: AssetModel.h:89
AssetModel::rowCount
virtual int rowCount(const QModelIndex &parent) const override
Definition: AssetModel.cpp:63
ScriptFilterAssetModel::myCachedFilter
std::map< AssetWrapper *, bool > myCachedFilter
Definition: AssetModel.h:91
AssetModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const override
Definition: AssetModel.cpp:30
UseFilterAssetModel::myCachedFilter
std::map< AssetWrapper *, bool > myCachedFilter
Definition: AssetModel.h:69
AssetModel::assetModified
void assetModified(AssetWrapper *asset, AssetWrapper::ChangeType type, int extra)
Definition: AssetModel.cpp:148
AssetModel::AssetModel
AssetModel(AssetWrapper *assets, QObject *parent)
Definition: AssetModel.cpp:18
AssetModel::mimeData
virtual QMimeData * mimeData(const QModelIndexList &indexes) const override
Definition: AssetModel.cpp:105
AssetModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: AssetModel.cpp:82
is_valid_types_gen.type
list type
Definition: is_valid_types_gen.py:25