Crossfire Server, Trunk  R21024
CREReportDialog.cpp
Go to the documentation of this file.
1 #include <QtWidgets>
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  myHeader->setWhatsThis(tr("Text to display at the top of the report."));
37 
38  layout->addWidget(new QLabel(tr("Footer:"), this), 4, 2, 1, 3);
39 
40  myFooter = new QTextEdit(this);
41  layout->addWidget(myFooter, 5, 2, 1, 3);
42  myFooter->setWhatsThis(tr("Text to display at the bottom of the report."));
43 
44  layout->addWidget(new QLabel(tr("Item sort:"), this), 6, 2, 1, 3);
45 
46  mySort = new QTextEdit(this);
47  layout->addWidget(mySort, 7, 2, 1, 3);
48  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."));
49 
50  layout->addWidget(new QLabel(tr("Item display:"), this), 8, 2, 1, 3);
51 
52  myDisplay = new QTextEdit(this);
53  layout->addWidget(myDisplay, 9, 2, 1, 3);
54  myDisplay->setWhatsThis(tr("Expression used to display one item. The current item is 'item', and the expression should be a string value."));
55 
56  QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close | QDialogButtonBox::Help, Qt::Horizontal, this);
57  connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
58  connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
59  connect(buttons, SIGNAL(helpRequested()), this, SLOT(onHelp()));
60 
61  layout->addWidget(buttons, 10, 2, 3, 1);
62 
63  setLayout(layout);
64  connect(myList, SIGNAL(currentRowChanged(int)), this, SLOT(currentRowChanged(int)));
65  refreshList();
66 }
67 
69 {
72  settings.saveReports(myReports);
73  QDialog::accept();
74 }
75 
77 {
78  if (QMessageBox::question(this, tr("Discard changes?"), tr("You are about to discard all changes!\nAre you sure?"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
79  return;
80 
81  QDialog::reject();
82 }
83 
85 {
86  QMessageBox::information(this, tr("Report help"), tr(
87 R"(
88 This dialog allows to define a report.<br />
89 <br />
90 A report consists of an optional header, a line for each item of the view optionally sorted, an optional footer.
91 <br />
92 <br />
93 '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.
94 <br />
95 <b>Example: </b><i>left.name.toLowerCase() &lt; right.name.toLowerCase()</i> will sort by ascending item's name (case unsensitive).
96 <br />
97 <br />
98 'Item display' is the expression used to display one item. The current item is 'item', and the expression should be a string value.
99 <br />
100 <b>Example: </b><i>item.name + " " + item.level</i> will display for each item its name and level.
101 )"));
102 }
103 
105 {
108  report->setName(tr("<new Report>"));
109  myReports.reports().append(report);
110  refreshList();
111  myList->setCurrentRow(myReports.reports().size() - 1);
112 }
113 
115 {
116  if (myReportIndex == -1)
117  return;
118 
120  if (QMessageBox::question(this, tr("Delete Report?"), tr("Really delete Report '%1'?").arg(report->name()), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
121  return;
122 
123  delete report;
124  myReports.reports().removeAt(myReportIndex);
125  myReportIndex = -1;
126  refreshList();
127 }
128 
130 {
131  myList->clear();
132 
133  foreach(const CREReportDefinition* report, myReports.reports())
134  {
135  myList->addItem(report->name());
136  }
137  myReportIndex = -1;
138 }
139 
141 {
142  if (myReportIndex != -1)
143  {
145  report->setName(myName->text());
146  report->setHeader(myHeader->toPlainText());
147  report->setItemDisplay(myDisplay->toPlainText());
148  report->setItemSort(mySort->toPlainText());
149  report->setFooter(myFooter->toPlainText());
150  myList->item(myReportIndex)->setText(report->name());
151  }
152 }
153 
155 {
157 
158  myReportIndex = -1;
159  if (currentRow >= 0 && currentRow < myReports.reports().size())
160  {
161  const CREReportDefinition* report = myReports.reports()[currentRow];
162  myName->setText(report->name());
163  myHeader->setText(report->header());
164  myFooter->setText(report->footer());
165  mySort->setText(report->itemSort());
166  myDisplay->setText(report->itemDisplay());
167  myReportIndex = currentRow;
168  }
169 }
virtual void accept()
void currentRowChanged(int currentRow)
void setItemSort(const QString &sort)
void setHeader(const QString &header)
QTextEdit * myFooter
QList< CREReportDefinition * > & reports()
const QString & itemDisplay() const
QTextEdit * mySort
QLineEdit * myName
void setName(const QString &name)
virtual void reject()
const QString & footer() const
QTextEdit * myHeader
const QString & itemSort() const
void saveReports(const CREReportDefinitionManager &reports)
Definition: CRESettings.cpp:65
CREReportDefinitionManager myReports
const QString & header() const
void setItemDisplay(const QString &display)
QTextEdit * myDisplay
const QString & name() const
struct Settings settings
Definition: init.c:40
void setFooter(const QString &footer)
QListWidget * myList
void loadReports(CREReportDefinitionManager &reports)
Definition: CRESettings.cpp:60
Definition: main.c:88