Crossfire Server, Trunk
AssetFieldCompleter.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 "AssetFieldCompleter.h"
14 #include <QStandardItemModel>
16 #include "regions/RegionWrapper.h"
17 #include "CREMapInformation.h"
21 #include "faces/FaceWrapper.h"
22 #include "quests/QuestWrapper.h"
23 
25 struct AssetData {
26  const char *name;
27  const QMetaObject *meta;
28  std::vector<AssetData> subfields;
29 };
30 
32 const std::vector<AssetData> assetData = {
33  { "region", &RegionWrapper::staticMetaObject, { } },
34  { "map", &CREMapInformation::staticMetaObject, { } },
35  { "archetype", &ArchetypeWrapper::staticMetaObject, { { "clone", &ObjectWrapper::staticMetaObject, { } } } },
36  { "artifact", &ArtifactWrapper::staticMetaObject, { } },
37  { "treasurelist", &TreasureListWrapper::staticMetaObject, { } },
38  { "face", &FaceWrapper::staticMetaObject, { } },
39  { "quest", &QuestWrapper::staticMetaObject, { } },
40 };
41 
47 static void addAssetData(QStandardItem *root, const AssetData &data) {
48  std::map<QString, QStandardItem *> fields;
49  for (int index = 0; index < data.meta->propertyCount(); ++index) {
50  auto property = data.meta->property(index);
51  if (fields.cend() == fields.find(property.name())) {
52  fields[property.name()] = new QStandardItem(property.name());
53  root->appendRow(fields[property.name()]);
54  }
55  for (const auto &sub : data.subfields) {
56  addAssetData(fields[property.name()], sub);
57  }
58  }
59 }
60 
61 AssetFieldCompleter::AssetFieldCompleter(QWidget *parent) : QCompleter(parent) {
62  QStandardItemModel *model = new QStandardItemModel();
63  auto root = model->invisibleRootItem();
64  auto item = new QStandardItem("item");
65  for (const auto &data : assetData) {
67  }
68  root->appendRow(item);
69 
70  setModel(model);
71 }
72 
73 QStringList AssetFieldCompleter::splitPath(const QString &path) const {
74  return path.split('.');
75 }
76 
77 QString AssetFieldCompleter::pathFromIndex(const QModelIndex &index) const {
78  QStringList dataList;
79  for (QModelIndex i = index; i.isValid(); i = i.parent()) {
80  dataList.prepend(model()->data(i, completionRole()).toString());
81  }
82 
83  return dataList.join('.');
84 }
AssetData::subfields
std::vector< AssetData > subfields
Definition: AssetFieldCompleter.cpp:28
CREMapInformation.h
AssetFieldCompleter::AssetFieldCompleter
AssetFieldCompleter(QWidget *parent)
Definition: AssetFieldCompleter.cpp:61
AssetData
Definition: AssetFieldCompleter.cpp:25
addAssetData
static void addAssetData(QStandardItem *root, const AssetData &data)
Definition: AssetFieldCompleter.cpp:47
root
static char root[500]
Definition: mapper.cpp:304
ObjectWrapper.h
assetData
const std::vector< AssetData > assetData
Definition: AssetFieldCompleter.cpp:32
QuestWrapper.h
AssetData::meta
const QMetaObject * meta
Definition: AssetFieldCompleter.cpp:27
python_init.path
path
Definition: python_init.py:8
navar-midane_time.data
data
Definition: navar-midane_time.py:11
ArchetypeWrapper.h
FaceWrapper.h
AssetFieldCompleter.h
RegionWrapper.h
item
Definition: item.py:1
AssetData::name
const char * name
Definition: AssetFieldCompleter.cpp:26
TreasureListWrapper.h
npc_dialog.index
int index
Definition: npc_dialog.py:102
AssetFieldCompleter::splitPath
virtual QStringList splitPath(const QString &path) const override
Definition: AssetFieldCompleter.cpp:73
ArtifactWrapper.h
AssetFieldCompleter::pathFromIndex
virtual QString pathFromIndex(const QModelIndex &index) const override
Definition: AssetFieldCompleter.cpp:77