Crossfire Server, Trunk  R20513
CREReportDialog.cpp
Go to the documentation of this file.
1 #include <QtGui>
2 
3 #include "CREReportDialog.h"
4 #include "CRESettings.h"
5 #include "CREReportDefinition.h"
6 
8 {
10  settings.loadReports(myReports);
11 
12  setWindowTitle(tr("Report parameters"));
13 
14  QGridLayout* layout = new QGridLayout(this);
15 
16  myList = new QListWidget(this);
17  layout->addWidget(myList, 0, 0, 10, 2);
18 
19  QPushButton* add = new QPushButton(tr("Add"), this);
20  connect(add, SIGNAL(clicked()), this, SLOT(onAdd()));
21  layout->addWidget(add, 10, 0, 1, 1);
22 
23  QPushButton* del = new QPushButton(tr("Remove"), this);
24  connect(del, SIGNAL(clicked()), this, SLOT(onDelete()));
25  layout->addWidget(del, 10, 1, 1, 1);
26 
27  layout->addWidget(new QLabel(tr("Name:"), this), 0, 2, 1, 3);
28 
29  myName = new QLineEdit(this);
30  layout->addWidget(myName, 1, 2, 1, 3);
31 
32  layout->addWidget(new QLabel(tr("Header:"), this), 2, 2, 1, 3);
33 
34  myHeader = new QTextEdit(this);
35  layout->addWidget(myHeader, 3, 2, 1, 3);
36 
37  layout->addWidget(new QLabel(tr("Footer:"), this), 4, 2, 1, 3);
38 
39  myFooter = new QTextEdit(this);
40  layout->addWidget(myFooter, 5, 2, 1, 3);
41 
42  layout->addWidget(new QLabel(tr("Item sort:"), this), 6, 2, 1, 3);
43 
44  mySort = new QTextEdit(this);
45  layout->addWidget(mySort, 7, 2, 1, 3);
46 
47  layout->addWidget(new QLabel(tr("Item display:"), this), 8, 2, 1, 3);
48 
49  myDisplay = new QTextEdit(this);
50  layout->addWidget(myDisplay, 9, 2, 1, 3);
51 
52  QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close | QDialogButtonBox::Help, Qt::Horizontal, this);
53  connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
54  connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
55  connect(buttons, SIGNAL(helpRequested()), this, SLOT(onHelp()));
56 
57  layout->addWidget(buttons, 10, 2, 3, 1);
58 
59  setLayout(layout);
60  connect(myList, SIGNAL(currentRowChanged(int)), this, SLOT(currentRowChanged(int)));
61  refreshList();
62 }
63 
65 {
68  settings.saveReports(myReports);
69  QDialog::accept();
70 }
71 
73 {
74  if (QMessageBox::question(this, tr("Discard changes?"), tr("You are about to discard all changes!\nAre you sure?"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
75  return;
76 
77  QDialog::reject();
78 }
79 
81 {
82  QMessageBox::information(this, tr("Report help"), tr("Enter the script expression with which to Report items in the view. Current item is <b>item</b>, and it has the following properties:<br /><ul><li>for an archetype: name, clone</li><li>for a formulae: title, chance, difficulty, archs</li><li>for an artifact: item, chance, difficulty, allowed</li><li>for an object (for clone and item): type</li></ul><br />An item is shown if the expression evaluates to <i>true</i>.If a property is not defined for the current item, it will not be shown.<br /><br />Examples:<ul><li>items of type 5: <i>item.clone.type == 5</i></li><li>artifact allowed for all items of the type: <i>item.allowed.length == 0</i></il></ul>"));
83 }
84 
86 {
89  report->setName(tr("<new Report>"));
90  myReports.reports().append(report);
91  refreshList();
92  myList->setCurrentRow(myReports.reports().size() - 1);
93 }
94 
96 {
97  if (myReportIndex == -1)
98  return;
99 
101  if (QMessageBox::question(this, tr("Delete Report?"), tr("Really delete Report '%1'?").arg(report->name()), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
102  return;
103 
104  delete report;
105  myReports.reports().removeAt(myReportIndex);
106  myReportIndex = -1;
107  refreshList();
108 }
109 
111 {
112  myList->clear();
113 
114  foreach(const CREReportDefinition* report, myReports.reports())
115  {
116  myList->addItem(report->name());
117  }
118  myReportIndex = -1;
119 }
120 
122 {
123  if (myReportIndex != -1)
124  {
126  report->setName(myName->text());
127  report->setHeader(myHeader->toPlainText());
128  report->setItemDisplay(myDisplay->toPlainText());
129  report->setItemSort(mySort->toPlainText());
130  report->setFooter(myFooter->toPlainText());
131  myList->item(myReportIndex)->setText(report->name());
132  }
133 }
134 
136 {
138 
139  myReportIndex = -1;
140  if (currentRow >= 0 && currentRow < myReports.reports().size())
141  {
142  const CREReportDefinition* report = myReports.reports()[currentRow];
143  myName->setText(report->name());
144  myHeader->setText(report->header());
145  myFooter->setText(report->footer());
146  mySort->setText(report->itemSort());
147  myDisplay->setText(report->itemDisplay());
148  myReportIndex = currentRow;
149  }
150 }
virtual void accept()
void currentRowChanged(int currentRow)
void setItemSort(const QString &sort)
void setHeader(const QString &header)
QTextEdit * myFooter
QList< CREReportDefinition * > & reports()
QTextEdit * mySort
QLineEdit * myName
const QString & footer() const
void setName(const QString &name)
virtual void reject()
const QString & header() const
const QString & itemSort() const
QTextEdit * myHeader
void saveReports(const CREReportDefinitionManager &reports)
Definition: CRESettings.cpp:65
CREReportDefinitionManager myReports
void setItemDisplay(const QString &display)
QTextEdit * myDisplay
struct Settings settings
Server settings.
Definition: init.c:40
void setFooter(const QString &footer)
QListWidget * myList
const QString & itemDisplay() const
const QString & name() const
void loadReports(CREReportDefinitionManager &reports)
Definition: CRESettings.cpp:60
Definition: main.c:88