Crossfire Server, Trunk
AssetWrapperPanel.h
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 #ifndef ASSETWRAPPERPANEL_H
14 #define ASSETWRAPPERPANEL_H
15 
16 #include <QtWidgets>
17 
18 #include "AssetWrapper.h"
19 
21 class ArchetypeComboBox;
22 class AssetUseTree;
23 class AssetModel;
24 
26 class AssetWrapperPanel : public QWidget {
27  Q_OBJECT
28 public:
29  AssetWrapperPanel(QWidget *parent);
30  virtual ~AssetWrapperPanel();
31 
32  void addTab(const QString &title);
33 
34  virtual void setAsset(AssetWrapper *item);
35  virtual void commitData() {}
36 
37  QLabel *addLabel(const QString &label, const char *property);
38  QLineEdit *addLineEdit(const QString &label, const char *property, bool readOnly = true);
39  QTextEdit *addTextEdit(const QString &label, const char *property, bool readOnly = true);
40  QCheckBox *addCheckBox(const QString &label, const char *property, bool readOnly = true);
41  void addFaceChoice(const QString &label, const char *property, bool readOnly = true, bool allowNone = true);
42  void addQuestChoice(const QString &label, const char *property, bool readOnly = true, bool allowNone = true);
43  QSpinBox *addSpinBox(const QString &label, const char *property, int min = 0, int max = 100, bool readOnly = true);
44  TreasureListComboBox *addTreasureList(const QString &label, const char *property, bool readOnly = true, bool allowNone = true);
45  ArchetypeComboBox *addArchetype(const QString &label, const char *property, bool readOnly = false, bool allowNone = true);
46  AssetUseTree *addAssetUseTree(const QString &label, AssetModel *assets, const char *property);
47  void addBottomFiller();
48 
49 protected slots:
50  void dataChanged();
51  void itemChanged();
52 
53 protected:
54  QGridLayout *myLayout;
55  QTabWidget *myTab;
57  bool myInhibit;
58  QMetaObject::Connection myChanged;
59  QMetaObject::Connection myDelete;
60 
61  template<class T>
62  T *addWidget(const QString &label, T *widget, bool sideBySide, const char *property, const char *widgetProperty) {
63  int line = myLayout->rowCount();
64  if (!label.isEmpty()) {
65  myLayout->addWidget(new QLabel(label, this), line, 0, 1, sideBySide ? 1 : 2);
66  if (!sideBySide) {
67  line++;
68  }
69  }
70 
71  myLayout->addWidget(widget, line, sideBySide ? 1 : 0, 1, sideBySide ? 1 : 2);
72  if (property) {
73  myLinks.append({property, widget, widgetProperty});
74  }
75  return widget;
76  }
77 
78  struct PropertyLink {
79  const char *assetPropertyName;
80  QWidget *widget;
81  const char *widgetPropertyName;
82  };
83  QList<PropertyLink> myLinks;
84 };
85 
89 template<typename T>
91 public:
92  AssetTWrapperPanel(QWidget* parent) : AssetWrapperPanel(parent), myItem(nullptr) {};
93 
94  virtual void setAsset(AssetWrapper *asset) override {
96  auto aw = dynamic_cast<AssetTWrapper<T> *>(asset);
97  myItem = aw ? aw->wrappedItem() : nullptr;
98  updateItem();
99  }
101  virtual void updateItem() = 0;
102 
103 protected:
104  T *myItem;
105 };
106 
110 template<typename T>
112 public:
113  AssetSWrapperPanel(QWidget* parent) : AssetWrapperPanel(parent), myItem(nullptr) {};
114 
115  virtual void setAsset(AssetWrapper *asset) override {
117  myItem = dynamic_cast<T *>(asset);
118  updateItem();
119  }
121  virtual void updateItem() = 0;
122 
123 protected:
124  T *myItem;
125 };
126 
127 #endif /* ASSETWRAPPERPANEL_H */
AssetWrapperPanel
Definition: AssetWrapperPanel.h:26
AssetWrapper.h
AssetWrapperPanel::addTextEdit
QTextEdit * addTextEdit(const QString &label, const char *property, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:82
AssetWrapperPanel::addTab
void addTab(const QString &title)
Definition: AssetWrapperPanel.cpp:36
AssetWrapperPanel::addLineEdit
QLineEdit * addLineEdit(const QString &label, const char *property, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:72
AssetTWrapperPanel::setAsset
virtual void setAsset(AssetWrapper *asset) override
Definition: AssetWrapperPanel.h:94
AssetSWrapperPanel::myItem
T * myItem
Definition: AssetWrapperPanel.h:124
AssetWrapperPanel::addAssetUseTree
AssetUseTree * addAssetUseTree(const QString &label, AssetModel *assets, const char *property)
Definition: AssetWrapperPanel.cpp:144
AssetWrapperPanel::addQuestChoice
void addQuestChoice(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:107
AssetWrapperPanel::addSpinBox
QSpinBox * addSpinBox(const QString &label, const char *property, int min=0, int max=100, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:112
AssetWrapperPanel::commitData
virtual void commitData()
Definition: AssetWrapperPanel.h:35
AssetWrapperPanel::~AssetWrapperPanel
virtual ~AssetWrapperPanel()
Definition: AssetWrapperPanel.cpp:27
AssetWrapperPanel::myChanged
QMetaObject::Connection myChanged
Definition: AssetWrapperPanel.h:58
AssetWrapperPanel::addArchetype
ArchetypeComboBox * addArchetype(const QString &label, const char *property, bool readOnly=false, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:134
is_valid_types_gen.line
line
Definition: is_valid_types_gen.py:34
AssetWrapperPanel::myLayout
QGridLayout * myLayout
Definition: AssetWrapperPanel.h:54
titlestruct
Definition: readable.c:107
AssetWrapperPanel::dataChanged
void dataChanged()
Definition: AssetWrapperPanel.cpp:154
AssetTWrapperPanel
Definition: AssetWrapperPanel.h:90
AssetWrapperPanel::AssetWrapperPanel
AssetWrapperPanel(QWidget *parent)
Definition: AssetWrapperPanel.cpp:23
AssetWrapper
Definition: AssetWrapper.h:22
AssetWrapperPanel::myAsset
AssetWrapper * myAsset
Definition: AssetWrapperPanel.h:56
AssetWrapperPanel::addBottomFiller
void addBottomFiller()
Definition: AssetWrapperPanel.cpp:148
AssetTWrapperPanel::AssetTWrapperPanel
AssetTWrapperPanel(QWidget *parent)
Definition: AssetWrapperPanel.h:92
AssetModel
Definition: AssetModel.h:26
ArchetypeComboBox
Definition: ArchetypeComboBox.h:25
say.max
dictionary max
Definition: say.py:148
AssetWrapperPanel::addLabel
QLabel * addLabel(const QString &label, const char *property)
Definition: AssetWrapperPanel.cpp:68
AssetSWrapperPanel::setAsset
virtual void setAsset(AssetWrapper *asset) override
Definition: AssetWrapperPanel.h:115
AssetWrapperPanel::itemChanged
void itemChanged()
Definition: AssetWrapperPanel.cpp:59
AssetTWrapperPanel::updateItem
virtual void updateItem()=0
AssetWrapperPanel::myInhibit
bool myInhibit
Definition: AssetWrapperPanel.h:57
AssetSWrapperPanel
Definition: AssetWrapperPanel.h:111
AssetWrapperPanel::myDelete
QMetaObject::Connection myDelete
Definition: AssetWrapperPanel.h:59
AssetTWrapperPanel::myItem
T * myItem
Definition: AssetWrapperPanel.h:104
AssetSWrapperPanel::updateItem
virtual void updateItem()=0
AssetWrapperPanel::myLinks
QList< PropertyLink > myLinks
Definition: AssetWrapperPanel.h:83
AssetUseTree
Definition: AssetUseTree.h:22
item
Definition: item.py:1
TreasureListComboBox
Definition: TreasureListComboBox.h:25
AssetWrapperPanel::addWidget
T * addWidget(const QString &label, T *widget, bool sideBySide, const char *property, const char *widgetProperty)
Definition: AssetWrapperPanel.h:62
AssetWrapperPanel::addTreasureList
TreasureListComboBox * addTreasureList(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:124
AssetWrapperPanel::setAsset
virtual void setAsset(AssetWrapper *item)
Definition: AssetWrapperPanel.cpp:46
AssetWrapperPanel::myTab
QTabWidget * myTab
Definition: AssetWrapperPanel.h:55
AssetWrapperPanel::addCheckBox
QCheckBox * addCheckBox(const QString &label, const char *property, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:92
AssetSWrapperPanel::AssetSWrapperPanel
AssetSWrapperPanel(QWidget *parent)
Definition: AssetWrapperPanel.h:113
AssetWrapperPanel::addFaceChoice
void addFaceChoice(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:102
AssetTWrapper
Definition: AssetWrapper.h:87