Crossfire Server, Trunk
ArchetypeComboBox.cpp
Go to the documentation of this file.
1 #include "ArchetypeComboBox.h"
2 #include "CREPixmap.h"
3 #include "AssetsManager.h"
4 #include "assets.h"
5 
6 ArchetypeComboBox::ArchetypeComboBox(QWidget *parent, bool allowNone) : QComboBox(parent) {
7  QStringList names;
8  if (allowNone) {
9  names << "(none)";
10  addItem(QIcon(), "(none)", QVariant::fromValue<void*>(nullptr));
11  }
12 
13  getManager()->archetypes()->each([this, &names] (const archetype *arch) {
14  if (arch->head) {
15  return;
16  }
17  QString name = tr("%1 (%2)").arg(arch->clone.name, arch->name);
18  addItem(CREPixmap::getIcon(arch->clone.face), name, QVariant::fromValue(static_cast<void *>(const_cast<archetype *>(arch))));
19  names << name;
20  });
21 
22  setEditable(true);
23  setInsertPolicy(QComboBox::NoInsert);
24  setCompleter(new QCompleter(names, this));
25  completer()->setFilterMode(Qt::MatchContains);
26  completer()->setCaseSensitivity(Qt::CaseInsensitive);
27 }
28 
30  setCurrentIndex(findData(QVariant::fromValue(static_cast<void *>(const_cast<archetype *>(arch)))));
31 }
32 
33 const archetype *ArchetypeComboBox::arch() const {
34  return static_cast<const archetype *>(currentData().value<void *>());
35 }
obj::face
const Face * face
Definition: object.h:336
archt::head
struct archt * head
Definition: object.h:472
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
AssetsManager.h
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:55
ArchetypeComboBox::ArchetypeComboBox
ArchetypeComboBox(QWidget *parent, bool allowNone)
Definition: ArchetypeComboBox.cpp:6
ArchetypeComboBox::arch
const archetype arch
Definition: ArchetypeComboBox.h:16
getManager
AssetsManager * getManager()
Definition: assets.cpp:333
archt
Definition: object.h:470
obj::name
sstring name
Definition: object.h:314
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:135
AssetsManager::archetypes
Archetypes * archetypes()
Definition: AssetsManager.h:44
archt::clone
object clone
Definition: object.h:474
guildbuy.names
list names
Definition: guildbuy.py:18
ArchetypeComboBox.h
assets.h
archt::name
sstring name
Definition: object.h:471
CREPixmap.h
ArchetypeComboBox::setArch
void setArch(const archetype *arch)
Definition: ArchetypeComboBox.cpp:29
give.name
name
Definition: give.py:27