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 extern "C" {
15 #include "global.h"
16 #include "quest.h"
17 }
18 #include "CREPixmap.h"
19 #include "AssetsManager.h"
20 #include "assets.h"
21 
22 QuestComboBox::QuestComboBox(QWidget* parent, bool allowNone) : QComboBox(parent)
23 {
24  QStringList names;
25  if (allowNone)
26  {
27  names << "(none)";
28  addItem(QIcon(), "(none)", QVariant::fromValue<void*>(nullptr));
29  }
30 
31  getManager()->quests()->each([this, &names] (const quest_definition* quest) {
32  addItem(quest->face ? CREPixmap::getIcon(quest->face->number) : QIcon(), quest->quest_code, QVariant::fromValue(static_cast<void*>(const_cast<quest_definition *>(quest))));
33  names << quest->quest_code;
34  });
35 
36  setEditable(true);
37  setInsertPolicy(QComboBox::NoInsert);
38  setCompleter(new QCompleter(names, this));
39  completer()->setFilterMode(Qt::MatchContains);
40  completer()->setCaseSensitivity(Qt::CaseInsensitive);
41 }
42 
44 {
45 }
46 
48 {
49  setCurrentIndex(findData(QVariant::fromValue(static_cast<void*>(const_cast<quest_definition *>(quest)))));
50 }
51 
53 {
54  return static_cast<const quest_definition *>(currentData().value<void*>());
55 }
global.h
QuestComboBox::setQuest
void setQuest(const quest_definition *quest)
Definition: QuestComboBox.cpp:47
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:309
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:43
quest.h
QuestComboBox::QuestComboBox
QuestComboBox(QWidget *parent, bool allowNone)
Definition: QuestComboBox.cpp:22
quest_definition
Definition: quest.h:38
assets.h
names
const char *const names[]
Definition: AssetOriginAndCreationDialog.cpp:24
CREPixmap.h