Crossfire Server, Trunk
CREPrePostList.cpp
Go to the documentation of this file.
1 #include <QtWidgets>
2 #include "CREPrePostList.h"
4 
5 CREPrePostList::CREPrePostList(QWidget* parent, Mode mode, const MessageManager* manager) : myMode(mode)
6 {
7  setModal(true);
8  switch (mode) {
9  case PreConditions:
10  setWindowTitle(tr("Message pre-conditions"));
11  break;
12  case PostConditions:
13  setWindowTitle(tr("Message post-conditions"));
14  break;
15  case SetWhen:
16  setWindowTitle(tr("Step set when conditions are met"));
17  break;
18  }
19 
20  myList = new QListWidget(parent);
21  myList->setItemDelegate(new CREPrePostSingleConditionDelegate(myList, mode, manager));
22 
23  QPushButton* addCondition = new QPushButton(tr("add"), this);
24  connect(addCondition, SIGNAL(clicked(bool)), this, SLOT(onAddCondition(bool)));
25 
26  QPushButton* delCondition = new QPushButton(tr("delete"), this);
27  connect(delCondition, SIGNAL(clicked(bool)), this, SLOT(onDeleteCondition(bool)));
28 
29  QPushButton* reset = new QPushButton(tr("reset changes"), this);
30  connect(reset, SIGNAL(clicked(bool)), this, SLOT(onReset(bool)));
31 
32  QHBoxLayout* buttons = new QHBoxLayout();
33  buttons->addWidget(addCondition);
34  buttons->addWidget(delCondition);
35  buttons->addWidget(reset);
36 
37  QVBoxLayout* l = new QVBoxLayout(this);
38  l->addWidget(myList);
39  l->addLayout(buttons);
40  setLayout(l);
41 }
42 
44 {
45 }
46 
47 QList<QStringList> CREPrePostList::data() const
48 {
49  QList<QStringList> value;
50  for (int i = 0; i < myList->count(); i++)
51  {
52  QListWidgetItem* wi = myList->item(i);
53  QStringList data = wi->data(Qt::UserRole).value<QStringList>();
54  if (myMode == SetWhen)
55  data.pop_front();
56  value.append(data);
57  }
58  return value;
59 }
60 
61 void CREPrePostList::addItem(const QStringList &item)
62 {
63  QStringList display(item);
64  if (myMode == SetWhen)
65  display.pop_front();
66  QListWidgetItem* wi = new QListWidgetItem(display.join(" "));
67  wi->setData(Qt::UserRole, QVariant::fromValue(item));
68  wi->setFlags(wi->flags() | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
69  myList->addItem(wi);
70 }
71 
72 void CREPrePostList::setData(const QList<QStringList>& data)
73 {
74  myList->clear();
75  for (QStringList item : data)
76  {
77  if (myMode == SetWhen && !item.empty() && item[0] != "quest")
78  item.push_front("quest");
79  addItem(item);
80  }
81  myOriginal = data;
82 }
83 
85 {
86  QStringList item;
87  item << "quest";
88  addItem(item);
89  myList->setCurrentRow(myList->count() - 1);
90  myList->edit(myList->currentIndex());
91 }
92 
94 {
95  if (myList->currentRow() == -1)
96  return;
97 
98  delete myList->takeItem(myList->currentRow());
99 }
100 
102 {
103  if (QMessageBox::question(this, "Confirm reset", "Reset the conditions to their initial values, losing all changes?") != QMessageBox::StandardButton::Yes)
104  return;
106 }
CREPrePostList::onDeleteCondition
void onDeleteCondition(bool)
Definition: CREPrePostList.cpp:93
banquet.l
l
Definition: banquet.py:164
CREPrePostList.h
CREPrePostList::onReset
void onReset(bool)
Definition: CREPrePostList.cpp:101
CREPrePostList::PostConditions
@ PostConditions
Definition: CREPrePostList.h:18
CREPrePostList::myMode
Mode myMode
Definition: CREPrePostList.h:35
CREPrePostList::myList
QListWidget * myList
Definition: CREPrePostList.h:33
navar-midane_time.data
data
Definition: navar-midane_time.py:11
CREPrePostList::addItem
void addItem(const QStringList &item)
Definition: CREPrePostList.cpp:61
CREPrePostList::Mode
Mode
Definition: CREPrePostList.h:18
CREPrePostList::onAddCondition
void onAddCondition(bool)
Definition: CREPrePostList.cpp:84
CREPrePostList::setData
void setData(const QList< QStringList > &data)
Definition: CREPrePostList.cpp:72
MessageManager
Definition: MessageManager.h:12
CREPrePostList::myOriginal
QList< QStringList > myOriginal
Definition: CREPrePostList.h:34
CREPrePostList::SetWhen
@ SetWhen
Definition: CREPrePostList.h:18
CREPrePostList::CREPrePostList
CREPrePostList(QWidget *parent, Mode mode, const MessageManager *manager)
Definition: CREPrePostList.cpp:5
CREPrePostList::~CREPrePostList
virtual ~CREPrePostList()
Definition: CREPrePostList.cpp:43
item
Definition: item.py:1
autojail.value
value
Definition: autojail.py:6
CREPrePostConditionDelegate.h
say.item
dictionary item
Definition: say.py:149
connect
Definition: connect.py:1
CREPrePostList::PreConditions
@ PreConditions
Definition: CREPrePostList.h:18
manager
static AssetsManager * manager
Definition: assets.cpp:63
CREPrePostList::data
QList< QStringList > data() const
Definition: CREPrePostList.cpp:47
CREPrePostSingleConditionDelegate
Definition: CREPrePostConditionDelegate.h:11