Crossfire Server, Trunk
AssetsCollectionWrapper.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 ASSETS_COLLECTION_WRAPPER_H
14 #define ASSETS_COLLECTION_WRAPPER_H
15 
16 #include "AssetWrapper.h"
17 #include "../ResourcesManager.h"
18 #include "AssetsCollection.h"
19 
20 template<typename T>
22 public:
23  AssetsCollectionWrapper(AssetWrapper *parent, const QString &name, AssetsCollection<T> *collection, ResourcesManager *resources, const QString &tip)
24  : AssetWrapper(parent), myName(name) {
25  collection->each([&] (T *asset) {
26  myAssets.append(resources->wrap(asset, this));
27  });
28  qSort(myAssets.begin(), myAssets.end(), compareByDisplayName);
29  setProperty(tipProperty, tip);
30  }
31 
32  virtual QString displayName() const { return myName; }
33  virtual int childrenCount() const override { return myAssets.size(); }
34  virtual AssetWrapper *child(int index) override { return myAssets[index]; }
35  virtual int childIndex(AssetWrapper *child) override { return myAssets.indexOf(child); }
36 
37  virtual bool canDrop(const QMimeData *, int) const override { return true; }
38 
39 protected:
40  QString myName;
41  QVector<AssetWrapper *> myAssets;
42 };
43 
44 #endif /* ASSETS_COLLECTION_WRAPPER_H */
AssetWrapper.h
ResourcesManager
Definition: ResourcesManager.h:80
ResourcesManager::wrap
ArchetypeWrapper * wrap(archetype *arch, AssetWrapper *parent)
Definition: ResourcesManager.h:132
AssetsCollectionWrapper::AssetsCollectionWrapper
AssetsCollectionWrapper(AssetWrapper *parent, const QString &name, AssetsCollection< T > *collection, ResourcesManager *resources, const QString &tip)
Definition: AssetsCollectionWrapper.h:23
AssetWrapper::tipProperty
static const char * tipProperty
Definition: AssetWrapper.h:34
AssetsCollectionWrapper::myName
QString myName
Definition: AssetsCollectionWrapper.h:40
AssetsCollectionWrapper::canDrop
virtual bool canDrop(const QMimeData *, int) const override
Definition: AssetsCollectionWrapper.h:37
AssetsCollection
Definition: AssetsCollection.h:55
AssetsCollectionWrapper::child
virtual AssetWrapper * child(int index) override
Definition: AssetsCollectionWrapper.h:34
AssetWrapper
Definition: AssetWrapper.h:25
AssetsCollection.h
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:158
AssetsCollectionWrapper::displayName
virtual QString displayName() const
Definition: AssetsCollectionWrapper.h:32
AssetsCollectionWrapper::childIndex
virtual int childIndex(AssetWrapper *child) override
Definition: AssetsCollectionWrapper.h:35
npc_dialog.index
int index
Definition: npc_dialog.py:102
AssetsCollectionWrapper::childrenCount
virtual int childrenCount() const override
Definition: AssetsCollectionWrapper.h:33
AssetsCollectionWrapper::myAssets
QVector< AssetWrapper * > myAssets
Definition: AssetsCollectionWrapper.h:41
AssetsCollectionWrapper
Definition: AssetsCollectionWrapper.h:21
AssetWrapper::compareByDisplayName
static bool compareByDisplayName(const AssetWrapper *left, const AssetWrapper *right)
Definition: AssetWrapper.h:66
give.name
name
Definition: give.py:27