Crossfire Server, Trunk
TreasureListComboBox.cpp
Go to the documentation of this file.
1 #include "TreasureListComboBox.h"
2 #include "CREPixmap.h"
3 #include "AssetsManager.h"
4 #include "assets.h"
5 
6 TreasureListComboBox::TreasureListComboBox(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()->treasures()->each([this, &names] (const treasurelist *list) {
14  addItem(list->total_chance == 0 ? CREPixmap::getTreasureIcon() : CREPixmap::getTreasureOneIcon(), list->name, QVariant::fromValue(static_cast<void *>(const_cast<treasurelist *>(list))));
15  names << list->name;
16  });
17 
18  setEditable(true);
19  setInsertPolicy(QComboBox::NoInsert);
20  setCompleter(new QCompleter(names, this));
21  completer()->setFilterMode(Qt::MatchContains);
22  completer()->setCaseSensitivity(Qt::CaseInsensitive);
23 }
24 
26  setCurrentIndex(findData(QVariant::fromValue(static_cast<void *>(const_cast<treasurelist *>(list)))));
27 }
28 
30  return static_cast<const treasurelist *>(currentData().value<void *>());
31 }
AssetsManager.h
TreasureListComboBox.h
CREPixmap::getTreasureIcon
static QIcon getTreasureIcon()
Definition: CREPixmap.cpp:92
guildoracle.list
list
Definition: guildoracle.py:87
TreasureListComboBox::setList
void setList(const treasurelist *list)
Definition: TreasureListComboBox.cpp:25
treasureliststruct::name
sstring name
Definition: treasure.h:83
getManager
AssetsManager * getManager()
Definition: assets.cpp:333
AssetsManager::treasures
Treasures * treasures()
Definition: AssetsManager.h:54
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:135
treasureliststruct::total_chance
int16_t total_chance
Definition: treasure.h:84
guildbuy.names
list names
Definition: guildbuy.py:18
CREPixmap::getTreasureOneIcon
static QIcon getTreasureOneIcon()
Definition: CREPixmap.cpp:98
assets.h
TreasureListComboBox::list
const treasurelist list
Definition: TreasureListComboBox.h:16
TreasureListComboBox::TreasureListComboBox
TreasureListComboBox(QWidget *parent, bool allowNone)
Definition: TreasureListComboBox.cpp:6
CREPixmap.h
treasureliststruct
Definition: treasure.h:82