Crossfire Server, Trunk
ArchetypeComboBox.cpp
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 #include "ArchetypeComboBox.h"
14 #include "CREPixmap.h"
15 #include "AssetsManager.h"
16 #include "assets.h"
17 
18 ArchetypeComboBox::ArchetypeComboBox(QWidget *parent, bool allowNone) : QComboBox(parent) {
19  QStringList names;
20  if (allowNone) {
21  names << "(none)";
22  addItem(QIcon(), "(none)", QVariant::fromValue<void*>(nullptr));
23  }
24 
25  getManager()->archetypes()->each([this, &names] (const archetype *arch) {
26  if (arch->head) {
27  return;
28  }
29  QString name = tr("%1 (%2)").arg(arch->clone.name, arch->name);
30  addItem(CREPixmap::getIcon(arch->clone.face), name, QVariant::fromValue(static_cast<void *>(const_cast<archetype *>(arch))));
31  names << name;
32  });
33 
34  setEditable(true);
35  setInsertPolicy(QComboBox::NoInsert);
36  setCompleter(new QCompleter(names, this));
37  completer()->setFilterMode(Qt::MatchContains);
38  completer()->setCaseSensitivity(Qt::CaseInsensitive);
39 }
40 
42  setCurrentIndex(findData(QVariant::fromValue(static_cast<void *>(const_cast<archetype *>(arch)))));
43 }
44 
45 const archetype *ArchetypeComboBox::arch() const {
46  return static_cast<const archetype *>(currentData().value<void *>());
47 }
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:65
ArchetypeComboBox::ArchetypeComboBox
ArchetypeComboBox(QWidget *parent, bool allowNone)
Definition: ArchetypeComboBox.cpp:18
archetype::head
archetype * head
Definition: object.h:485
ArchetypeComboBox::arch
const archetype arch
Definition: ArchetypeComboBox.h:26
getManager
AssetsManager * getManager()
Definition: assets.cpp:305
archetype::clone
object clone
Definition: object.h:487
object::face
const Face * face
Definition: object.h:341
archetype
Definition: object.h:483
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:158
AssetsManager::archetypes
Archetypes * archetypes()
Definition: AssetsManager.h:44
object::name
sstring name
Definition: object.h:319
ArchetypeComboBox.h
assets.h
archetype::name
sstring name
Definition: object.h:484
names
const char *const names[]
Definition: AssetOriginAndCreationDialog.cpp:26
CREPixmap.h
ArchetypeComboBox::setArch
void setArch(const archetype *arch)
Definition: ArchetypeComboBox.cpp:41
give.name
name
Definition: give.py:27