Crossfire Server, Trunk
QuestComboBox.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 "QuestComboBox.h"
14 #include "global.h"
15 #include "quest.h"
16 #include "CREPixmap.h"
17 #include "AssetsManager.h"
18 #include "assets.h"
19 
20 QuestComboBox::QuestComboBox(QWidget* parent, bool allowNone) : QComboBox(parent)
21 {
22  QStringList names;
23  if (allowNone)
24  {
25  names << "(none)";
26  addItem(QIcon(), "(none)", QVariant::fromValue<void*>(nullptr));
27  }
28 
29  getManager()->quests()->each([this, &names] (const quest_definition* quest) {
30  addItem(quest->face ? CREPixmap::getIcon(quest->face->number) : QIcon(), quest->quest_code, QVariant::fromValue(static_cast<void*>(const_cast<quest_definition *>(quest))));
31  names << quest->quest_code;
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 {
43 }
44 
46 {
47  setCurrentIndex(findData(QVariant::fromValue(static_cast<void*>(const_cast<quest_definition *>(quest)))));
48 }
49 
51 {
52  return static_cast<const quest_definition *>(currentData().value<void*>());
53 }
global.h
QuestComboBox::setQuest
void setQuest(const quest_definition *quest)
Definition: QuestComboBox.cpp:45
AssetsManager.h
QuestComboBox::quest
const quest_definition quest
Definition: QuestComboBox.h:26
QuestComboBox.h
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:65
getManager
AssetsManager * getManager()
Definition: assets.cpp:305
quest
Definition: quest.py:1
AssetsManager::quests
Quests * quests()
Definition: AssetsManager.h:71
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:158
QuestComboBox::~QuestComboBox
virtual ~QuestComboBox()
Definition: QuestComboBox.cpp:41
quest.h
QuestComboBox::QuestComboBox
QuestComboBox(QWidget *parent, bool allowNone)
Definition: QuestComboBox.cpp:20
quest_definition
Definition: quest.h:37
assets.h
names
const char *const names[]
Definition: AssetOriginAndCreationDialog.cpp:26
CREPixmap.h