Crossfire Server, Trunk
TreasureListComboBox.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 "TreasureListComboBox.h"
14 #include "CREPixmap.h"
15 #include "AssetsManager.h"
16 #include "assets.h"
17 
18 TreasureListComboBox::TreasureListComboBox(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()->treasures()->each([this, &names] (const treasurelist *list) {
26  addItem(list->total_chance == 0 ? CREPixmap::getTreasureIcon() : CREPixmap::getTreasureOneIcon(), list->name, QVariant::fromValue(static_cast<void *>(const_cast<treasurelist *>(list))));
27  names << list->name;
28  });
29 
30  setEditable(true);
31  setInsertPolicy(QComboBox::NoInsert);
32  setCompleter(new QCompleter(names, this));
33  completer()->setFilterMode(Qt::MatchContains);
34  completer()->setCaseSensitivity(Qt::CaseInsensitive);
35 }
36 
38  setCurrentIndex(findData(QVariant::fromValue(static_cast<void *>(const_cast<treasurelist *>(list)))));
39 }
40 
42  return static_cast<const treasurelist *>(currentData().value<void *>());
43 }
AssetsManager.h
TreasureListComboBox.h
treasurelist::total_chance
int16_t total_chance
Definition: treasure.h:87
CREPixmap::getTreasureIcon
static QIcon getTreasureIcon()
Definition: CREPixmap.cpp:102
guildoracle.list
list
Definition: guildoracle.py:87
TreasureListComboBox::setList
void setList(const treasurelist *list)
Definition: TreasureListComboBox.cpp:37
getManager
AssetsManager * getManager()
Definition: assets.cpp:305
AssetsManager::treasures
Treasures * treasures()
Definition: AssetsManager.h:54
treasurelist
Definition: treasure.h:85
treasurelist::name
sstring name
Definition: treasure.h:86
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:158
CREPixmap::getTreasureOneIcon
static QIcon getTreasureOneIcon()
Definition: CREPixmap.cpp:108
assets.h
names
const char *const names[]
Definition: AssetOriginAndCreationDialog.cpp:26
TreasureListComboBox::list
const treasurelist list
Definition: TreasureListComboBox.h:26
TreasureListComboBox::TreasureListComboBox
TreasureListComboBox(QWidget *parent, bool allowNone)
Definition: TreasureListComboBox.cpp:18
CREPixmap.h