Crossfire Server, Branches 1.12  R18729
CREArtifactPanel.cpp
Go to the documentation of this file.
1 #include <QtGui>
2 
3 extern "C" {
4 #include "global.h"
5 #include "artifact.h"
6 }
7 
8 #include "CREArtifactPanel.h"
9 #include "CREUtils.h"
10 
12 {
13  myArtifact = NULL;
14 
15  QGridLayout* layout = new QGridLayout(this);
16 
17  QLabel* label = new QLabel(this);
18  label->setText("Name:");
19  layout->addWidget(label, 1, 1);
20  myName = new QLineEdit(this);
21  layout->addWidget(myName, 1, 2);
22 
23  label = new QLabel(this);
24  label->setText("Chance:");
25  layout->addWidget(label, 2, 1);
26  myChance = new QLineEdit(this);
27  layout->addWidget(myChance, 2, 2);
28 
29  label = new QLabel(this);
30  label->setText("Type:");
31  layout->addWidget(label, 3, 1);
32  myType = new QLineEdit(this);
33  layout->addWidget(myType, 3, 2);
34 
35  myArchetypes = new QTreeWidget(this);
36  layout->addWidget(myArchetypes, 4, 1, 1, 2);
37  myArchetypes->setHeaderLabel("Allowed/forbidden archetypes");
38  myArchetypes->setIconSize(QSize(32, 32));
39  myArchetypes->setRootIsDecorated(false);
40 }
41 
43 {
44  Q_ASSERT(artifact);
46 
47  myName->setText(artifact->item->name);
48  myChance->setText(QString::number(artifact->chance));
49  myType->setText(QString::number(artifact->item->type));
50 
51  const archt* arch;
52  const char* name;
53  QTreeWidgetItem* item;
54  bool check;
55 
56  myArchetypes->clear();
57 
58  for (const linked_char* allowed = artifact->allowed; allowed; allowed = allowed->next)
59  {
60  name = allowed->name;
61  if (name[0] == '!')
62  {
63  name = name + 1;
64  check = false;
65  }
66  else
67  check = true;
68 
69  arch = try_find_archetype(name);
70  if (!arch)
71  arch = find_archetype_by_object_name(name);
72 
73  if (arch)
74  {
75  item = CREUtils::archetypeNode(arch, NULL);
76  item->setCheckState(0, check ? Qt::Checked : Qt::Unchecked);
77  myArchetypes->addTopLevelItem(item);
78  }
79  }
80 }
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:11
QLineEdit * myName
QLineEdit * myType
Definition: object.h:321
QLineEdit * myChance
const artifact * myArtifact
struct linked_char * next
Definition: global.h:161
uint16 chance
Definition: artifact.h:39
struct artifactstruct artifact
const char * name
Definition: object.h:167
linked_char * allowed
Definition: artifact.h:42
archetype * find_archetype_by_object_name(const char *name)
Definition: arch.c:70
archetype * try_find_archetype(const char *name)
Definition: arch.c:671
void setArtifact(const artifact *artifact)
QTreeWidget * myArchetypes
object * item
Definition: artifact.h:38
uint8 type
Definition: object.h:189