Crossfire Server, Trunk
CREReportDialog.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 <QtWidgets>
14 
15 #include "CREReportDialog.h"
16 #include "CRESettings.h"
17 #include "CREReportDefinition.h"
18 
20 {
22  settings.loadReports(myReports);
23 
24  setWindowTitle(tr("Report parameters"));
25 
26  QGridLayout* layout = new QGridLayout(this);
27 
28  myList = new QListWidget(this);
29  layout->addWidget(myList, 0, 0, 10, 2);
30 
31  QPushButton* add = new QPushButton(tr("Add"), this);
32  connect(add, SIGNAL(clicked()), this, SLOT(onAdd()));
33  layout->addWidget(add, 10, 0, 1, 1);
34 
35  QPushButton* del = new QPushButton(tr("Remove"), this);
36  connect(del, SIGNAL(clicked()), this, SLOT(onDelete()));
37  layout->addWidget(del, 10, 1, 1, 1);
38 
39  layout->addWidget(new QLabel(tr("Name:"), this), 0, 2, 1, 3);
40 
41  myName = new QLineEdit(this);
42  layout->addWidget(myName, 1, 2, 1, 3);
43 
44  layout->addWidget(new QLabel(tr("Header:"), this), 2, 2, 1, 3);
45 
46  myHeader = new QTextEdit(this);
47  layout->addWidget(myHeader, 3, 2, 1, 3);
48  myHeader->setWhatsThis(tr("Text to display at the top of the report."));
49 
50  layout->addWidget(new QLabel(tr("Footer:"), this), 4, 2, 1, 3);
51 
52  myFooter = new QTextEdit(this);
53  layout->addWidget(myFooter, 5, 2, 1, 3);
54  myFooter->setWhatsThis(tr("Text to display at the bottom of the report."));
55 
56  layout->addWidget(new QLabel(tr("Item sort:"), this), 6, 2, 1, 3);
57 
58  mySort = new QTextEdit(this);
59  layout->addWidget(mySort, 7, 2, 1, 3);
60  mySort->setWhatsThis(tr("Expression used to sort items. The items to be compared are 'left' and 'right', and the expression should be true if left < right, false else."));
61 
62  layout->addWidget(new QLabel(tr("Item display:"), this), 8, 2, 1, 3);
63 
64  myDisplay = new QTextEdit(this);
65  layout->addWidget(myDisplay, 9, 2, 1, 3);
66  myDisplay->setWhatsThis(tr("Expression used to display one item. The current item is 'item', and the expression should be a string value."));
67 
68  QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close | QDialogButtonBox::Help, Qt::Horizontal, this);
69  connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
70  connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
71  connect(buttons, SIGNAL(helpRequested()), this, SLOT(onHelp()));
72 
73  layout->addWidget(buttons, 10, 2, 3, 1);
74 
75  setLayout(layout);
76  connect(myList, SIGNAL(currentRowChanged(int)), this, SLOT(currentRowChanged(int)));
77  refreshList();
78 }
79 
81 {
84  settings.saveReports(myReports);
86 }
87 
89 {
90  if (QMessageBox::question(this, tr("Discard changes?"), tr("You are about to discard all changes!\nAre you sure?"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
91  return;
92 
93  QDialog::reject();
94 }
95 
97 {
98  QMessageBox::information(this, tr("Report help"), tr(
99 R"(
100 This dialog allows to define a report.<br />
101 <br />
102 A report consists of an optional header, a line for each item of the view optionally sorted, an optional footer.
103 <br />
104 <br />
105 'Item sort' contains an optional script expression used to sort items. The items to be compared are 'left' and 'right', and the expression should be true if left &lt; right, false else.
106 <br />
107 <b>Example: </b><i>left.name.toLowerCase() &lt; right.name.toLowerCase()</i> will sort by ascending item's name (case unsensitive).
108 <br />
109 <br />
110 'Item display' is the expression used to display one item. The current item is 'item', and the expression should be a string value.
111 <br />
112 <b>Example: </b><i>item.name + " " + item.level</i> will display for each item its name and level.
113 )"));
114 }
115 
117 {
120  report->setName(tr("<new Report>"));
121  myReports.reports().append(report);
122  refreshList();
123  myList->setCurrentRow(myReports.reports().size() - 1);
124 }
125 
127 {
128  if (myReportIndex == -1)
129  return;
130 
132  if (QMessageBox::question(this, tr("Delete Report?"), tr("Really delete Report '%1'?").arg(report->name()), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
133  return;
134 
135  delete report;
136  myReports.reports().removeAt(myReportIndex);
137  myReportIndex = -1;
139 }
140 
142 {
143  myList->clear();
144 
145  foreach(const CREReportDefinition* report, myReports.reports())
146  {
147  myList->addItem(report->name());
148  }
149  myReportIndex = -1;
150 }
151 
153 {
154  if (myReportIndex != -1)
155  {
157  report->setName(myName->text());
158  report->setHeader(myHeader->toPlainText());
159  report->setItemDisplay(myDisplay->toPlainText());
160  report->setItemSort(mySort->toPlainText());
161  report->setFooter(myFooter->toPlainText());
162  myList->item(myReportIndex)->setText(report->name());
163  }
164 }
165 
166 void CREReportDialog::currentRowChanged(int currentRow)
167 {
169 
170  myReportIndex = -1;
171  if (currentRow >= 0 && currentRow < myReports.reports().size())
172  {
173  const CREReportDefinition* report = myReports.reports()[currentRow];
174  myName->setText(report->name());
175  myHeader->setText(report->header());
176  myFooter->setText(report->footer());
177  mySort->setText(report->itemSort());
178  myDisplay->setText(report->itemDisplay());
179  myReportIndex = currentRow;
180  }
181 }
settings
struct Settings settings
Definition: init.cpp:139
layout
Definition: main.cpp:84
CREReportDefinition
Definition: CREReportDefinition.h:19
CRESettings.h
report.report
def report(pl)
Definition: report.py:6
CREReportDefinitionManager::reports
QList< CREReportDefinition * > & reports()
Definition: CREReportDefinitionManager.cpp:42
CREReportDialog::myReports
CREReportDefinitionManager myReports
Definition: CREReportDialog.h:38
CREReportDialog::CREReportDialog
CREReportDialog()
Definition: CREReportDialog.cpp:19
CREReportDialog::myReportIndex
int myReportIndex
Definition: CREReportDialog.h:39
CREReportDialog::myName
QLineEdit * myName
Definition: CREReportDialog.h:33
CREReportDialog::onHelp
void onHelp()
Definition: CREReportDialog.cpp:96
CREReportDialog::currentRowChanged
void currentRowChanged(int currentRow)
Definition: CREReportDialog.cpp:152
CREReportDialog::refreshList
void refreshList()
Definition: CREReportDialog.cpp:127
CREReportDialog::reject
virtual void reject()
Definition: CREReportDialog.cpp:88
CREReportDefinition.h
buttons
TIPS on SURVIVING Crossfire is populated with a wealth of different monsters These monsters can have varying immunities and attack types In some of them can be quite a bit smarter than others It will be important for new players to learn the abilities of different monsters and learn just how much it will take to kill them This section discusses how monsters can interact with players Most monsters in the game are out to mindlessly kill and destroy the players These monsters will help boost a player s after he kills them When fighting a large amount of monsters in a single attempt to find a narrower hallway so that you are not being attacked from all sides Charging into a room full of Beholders for instance would not be open the door and fight them one at a time For there are several maps designed for them Find these areas and clear them out All throughout these a player can find signs and books which they can read by stepping onto them and hitting A to apply the book sign These messages will help the player to learn the system One more always keep an eye on your food If your food drops to your character will soon so BE CAREFUL ! NPCs Non Player Character are special monsters which have intelligence Players may be able to interact with these monsters to help solve puzzles and find items of interest To speak with a monster you suspect to be a simply move to an adjacent square to them and push the double ie Enter your and press< Return > You can also use say if you feel like typing a little extra Other NPCs may not speak to but display intelligence with their movement Some monsters can be and may attack the nearest of your enemies Others can be in that they follow you around and help you in your quest to kill enemies and find treasure SPECIAL ITEMS There are many special items which can be found in of these the most important may be the signs all a player must do is apply the handle In the case of buttons
Definition: survival-guide.txt:57
CRESettings
Definition: CRESettings.h:21
CREReportDialog.h
CREReportDialog::onDelete
void onDelete()
Definition: CREReportDialog.cpp:112
CREReportDialog::saveCurrentReport
void saveCurrentReport()
Definition: CREReportDialog.cpp:138
CREReportDialog::mySort
QTextEdit * mySort
Definition: CREReportDialog.h:35
report
Definition: report.py:1
CREReportDialog::myDisplay
QTextEdit * myDisplay
Definition: CREReportDialog.h:36
CREReportDialog::myFooter
QTextEdit * myFooter
Definition: CREReportDialog.h:37
connect
Definition: connect.py:1
CREReportDialog::myHeader
QTextEdit * myHeader
Definition: CREReportDialog.h:34
CREReportDialog::onAdd
void onAdd()
Definition: CREReportDialog.cpp:102
CREReportDialog::myList
QListWidget * myList
Definition: CREReportDialog.h:32
altar_valkyrie.accept
def accept(description)
Definition: altar_valkyrie.py:22
CREReportDialog::accept
virtual void accept()
Definition: CREReportDialog.cpp:80