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