20#include "KReportSectionEditor.h"
22#include "KReportDesigner.h"
23#include "KReportSection.h"
24#include "KReportDesignerSectionDetail.h"
25#include "KReportDetailGroupSectionDialog.h"
26#include "KReportDesignerSectionDetailGroup.h"
29#include <QDialogButtonBox>
40static inline bool isEditorHelperField(
const QString &key)
55 m_reportDesigner = designer;
68 connect(buttonBox, SIGNAL(rejected()),
this, SLOT(accept()));
73 m_ui.lGroupSectionsButtons->addWidget(m_btnAdd);
75 m_ui.lGroupSectionsButtons->addWidget(m_btnEdit);
77 m_ui.lGroupSectionsButtons->addWidget(m_btnRemove);
79 m_ui.lGroupSectionsButtons->addWidget(m_btnMoveUp);
81 m_ui.lGroupSectionsButtons->addWidget(m_btnMoveDown);
82 m_ui.lGroupSectionsButtons->addStretch();
90 connect(m_ui.cbReportHeader, SIGNAL(toggled(
bool)),
this, SLOT(cbReportHeader_toggled(
bool)));
91 connect(m_ui.cbReportFooter, SIGNAL(toggled(
bool)),
this, SLOT(cbReportFooter_toggled(
bool)));
92 connect(m_ui.cbHeadFirst, SIGNAL(toggled(
bool)),
this, SLOT(cbHeadFirst_toggled(
bool)));
93 connect(m_ui.cbHeadLast, SIGNAL(toggled(
bool)),
this, SLOT(cbHeadLast_toggled(
bool)));
94 connect(m_ui.cbHeadEven, SIGNAL(toggled(
bool)),
this, SLOT(cbHeadEven_toggled(
bool)));
95 connect(m_ui.cbHeadOdd, SIGNAL(toggled(
bool)),
this, SLOT(cbHeadOdd_toggled(
bool)));
96 connect(m_ui.cbFootFirst, SIGNAL(toggled(
bool)),
this, SLOT(cbFootFirst_toggled(
bool)));
97 connect(m_ui.cbFootLast, SIGNAL(toggled(
bool)),
this, SLOT(cbFootLast_toggled(
bool)));
98 connect(m_ui.cbFootEven, SIGNAL(toggled(
bool)),
this, SLOT(cbFootEven_toggled(
bool)));
99 connect(m_ui.cbFootOdd, SIGNAL(toggled(
bool)),
this, SLOT(cbFootOdd_toggled(
bool)));
100 connect(m_ui.cbHeadAny, SIGNAL(toggled(
bool)),
this, SLOT(cbHeadAny_toggled(
bool)));
101 connect(m_ui.cbFootAny, SIGNAL(toggled(
bool)),
this, SLOT(cbFootAny_toggled(
bool)));
104 connect(m_ui.lbGroups, SIGNAL(currentRowChanged(
int)),
105 this, SLOT(updateButtonsForRow(
int)));
107 connect(m_btnAdd, SIGNAL(clicked(
bool)),
this, SLOT(btnAdd_clicked()));
108 connect(m_btnEdit, SIGNAL(clicked(
bool)),
this, SLOT(btnEdit_clicked()));
109 connect(m_btnRemove, SIGNAL(clicked(
bool)),
this, SLOT(btnRemove_clicked()));
110 connect(m_btnMoveUp, SIGNAL(clicked(
bool)),
this, SLOT(btnMoveUp_clicked()));
111 connect(m_btnMoveDown, SIGNAL(clicked(
bool)),
this, SLOT(brnMoveDown_clicked()));
115 m_ui.cbReportHeader->setChecked(m_reportDesigner->section(KReportSectionData::Type::ReportHeader));
116 m_ui.cbReportFooter->setChecked(m_reportDesigner->section(KReportSectionData::Type::ReportFooter));
118 m_ui.cbHeadFirst->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageHeaderFirst));
119 m_ui.cbHeadOdd->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageHeaderOdd));
120 m_ui.cbHeadEven->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageHeaderEven));
121 m_ui.cbHeadLast->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageHeaderLast));
122 m_ui.cbHeadAny->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageHeaderAny));
124 m_ui.cbFootFirst->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageFooterFirst));
125 m_ui.cbFootOdd->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageFooterOdd));
126 m_ui.cbFootEven->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageFooterEven));
127 m_ui.cbFootLast->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageFooterLast));
128 m_ui.cbFootAny->setChecked(m_reportDesigner->section(KReportSectionData::Type::PageFooterAny));
131 if (m_reportSectionDetail) {
132 const QStringList columnNames = m_reportDesigner->fieldNames();
133 const QStringList keys = m_reportDesigner->fieldKeys();
134 for (
int i = 0; i < m_reportSectionDetail->groupSectionCount(); ++i) {
135 const QString key = m_reportSectionDetail->groupSection(i)->column();
136 const int idx = keys.
indexOf(key);
140 m_ui.lbGroups->addItem(item);
143 if (m_ui.lbGroups->count() == 0) {
145 m_ui.lbGroups->setCurrentItem(m_ui.lbGroups->item(0));
147 updateButtonsForItem(m_ui.lbGroups->currentItem());
149 updateButtonsForRow(m_ui.lbGroups->currentRow());
155KReportSectionEditor::~KReportSectionEditor()
160void KReportSectionEditor::cbReportHeader_toggled(
bool yes)
162 if (m_reportDesigner) {
164 m_reportDesigner->
insertSection(KReportSectionData::Type::ReportHeader);
166 m_reportDesigner->
removeSection(KReportSectionData::Type::ReportHeader);
172void KReportSectionEditor::cbReportFooter_toggled(
bool yes)
174 if (m_reportDesigner) {
176 m_reportDesigner->
insertSection(KReportSectionData::Type::ReportFooter);
178 m_reportDesigner->
removeSection(KReportSectionData::Type::ReportFooter);
184void KReportSectionEditor::cbHeadFirst_toggled(
bool yes)
186 if (m_reportDesigner) {
188 m_reportDesigner->
insertSection(KReportSectionData::Type::PageHeaderFirst);
190 m_reportDesigner->
removeSection(KReportSectionData::Type::PageHeaderFirst);
196void KReportSectionEditor::cbHeadLast_toggled(
bool yes)
198 if (m_reportDesigner) {
200 m_reportDesigner->
insertSection(KReportSectionData::Type::PageHeaderLast);
202 m_reportDesigner->
removeSection(KReportSectionData::Type::PageHeaderLast);
208void KReportSectionEditor::cbHeadEven_toggled(
bool yes)
210 if (m_reportDesigner) {
212 m_reportDesigner->
insertSection(KReportSectionData::Type::PageHeaderEven);
214 m_reportDesigner->
removeSection(KReportSectionData::Type::PageHeaderEven);
220void KReportSectionEditor::cbHeadOdd_toggled(
bool yes)
222 if (m_reportDesigner) {
224 m_reportDesigner->
insertSection(KReportSectionData::Type::PageHeaderOdd);
226 m_reportDesigner->
removeSection(KReportSectionData::Type::PageHeaderOdd);
232void KReportSectionEditor::cbFootFirst_toggled(
bool yes)
234 if (m_reportDesigner) {
236 m_reportDesigner->
insertSection(KReportSectionData::Type::PageFooterFirst);
238 m_reportDesigner->
removeSection(KReportSectionData::Type::PageFooterFirst);
244void KReportSectionEditor::cbFootLast_toggled(
bool yes)
246 if (m_reportDesigner) {
248 m_reportDesigner->
insertSection(KReportSectionData::Type::PageFooterLast);
250 m_reportDesigner->
removeSection(KReportSectionData::Type::PageFooterLast);
256void KReportSectionEditor::cbFootEven_toggled(
bool yes)
258 if (m_reportDesigner) {
260 m_reportDesigner->
insertSection(KReportSectionData::Type::PageFooterEven);
262 m_reportDesigner->
removeSection(KReportSectionData::Type::PageFooterEven);
268void KReportSectionEditor::cbFootOdd_toggled(
bool yes)
270 if (m_reportDesigner) {
272 m_reportDesigner->
insertSection(KReportSectionData::Type::PageFooterOdd);
274 m_reportDesigner->
removeSection(KReportSectionData::Type::PageFooterOdd);
282 KReportDetailGroupSectionDialog * dgsd =
new KReportDetailGroupSectionDialog(
this);
288 const QSet<QString> usedColumns = groupingColumns() << rsdg->column();
291 int indexOfCurrentColumn = -1;
292 for (
int i = 0; i < keys.
count(); ++i) {
295 if (isEditorHelperField(key)) {
301 if (key != rsdg->column()) {
305 indexOfCurrentColumn = dgsd->cbColumn->count();
307 dgsd->cbColumn->insertItem( i, columnNames.
value(i), key);
309 dgsd->cbColumn->setCurrentIndex(indexOfCurrentColumn);
313 dgsd->cbSort->setCurrentIndex(dgsd->cbSort->findData(rsdg->sort()));
315 dgsd->breakAfterFooter->setChecked(rsdg->pageBreak() == KReportDesignerSectionDetailGroup::PageBreak::AfterGroupFooter);
316 dgsd->cbHead->setChecked(rsdg->groupHeaderVisible());
317 dgsd->cbFoot->setChecked(rsdg->groupFooterVisible());
323 dgsd->cbColumn->itemData(dgsd->cbColumn->currentIndex()).toString();
324 const QString oldColumn = rsdg->column();
325 if (newColumn != oldColumn) {
326 rsdg->setColumn(newColumn);
329 rsdg->setGroupHeaderVisible(dgsd->cbHead->isChecked());
330 rsdg->setGroupFooterVisible(dgsd->cbFoot->isChecked());
332 const KReportDesignerSectionDetailGroup::PageBreak pageBreak
333 = dgsd->breakAfterFooter->isChecked()
334 ? KReportDesignerSectionDetailGroup::PageBreak::AfterGroupFooter
335 : KReportDesignerSectionDetailGroup::PageBreak::None;
336 rsdg->setPageBreak(pageBreak);
339 static_cast<Qt::SortOrder>(dgsd->cbSort->itemData(dgsd->cbSort->currentIndex()).toInt());
340 rsdg->setSort(sortOrder);
348QString KReportSectionEditor::columnName(
const QString &column)
const
352 return columnNames.
at(keys.
indexOf(column));
358 for (
int i = 0; i < m_ui.lbGroups->count(); ++i) {
359 result.insert(m_ui.lbGroups->item(i)->data(KeyRole).toString());
364void KReportSectionEditor::cbHeadAny_toggled(
bool yes)
366 if (m_reportDesigner) {
368 m_reportDesigner->
insertSection(KReportSectionData::Type::PageHeaderAny);
370 m_reportDesigner->
removeSection(KReportSectionData::Type::PageHeaderAny);
375void KReportSectionEditor::cbFootAny_toggled(
bool yes)
377 if (m_reportDesigner) {
379 m_reportDesigner->
insertSection(KReportSectionData::Type::PageFooterAny);
381 m_reportDesigner->
removeSection(KReportSectionData::Type::PageFooterAny);
386void KReportSectionEditor::btnEdit_clicked()
388 if (m_reportSectionDetail) {
389 const int idx = m_ui.lbGroups->currentRow();
394 if (editDetailGroup(rsdg)) {
396 m_ui.lbGroups->item(idx)->setText(columnName(rsdg->column()));
401void KReportSectionEditor::btnAdd_clicked()
403 if (m_reportSectionDetail) {
409 foreach(
const QString &key, keys) {
411 if (isEditorHelperField(key)) {
427 if (editDetailGroup(rsdg)) {
429 m_reportSectionDetail->insertGroupSection(m_reportSectionDetail->groupSectionCount(), rsdg);
431 const QString column = rsdg->column();
433 item->
setData(KeyRole, column);
434 m_ui.lbGroups->addItem(item);
435 m_ui.lbGroups->setCurrentRow(m_ui.lbGroups->count() - 1);
444void KReportSectionEditor::btnRemove_clicked()
446 if (m_reportSectionDetail) {
447 const int index = m_ui.lbGroups->currentRow();
451 m_reportSectionDetail->removeGroupSection(index,
true);
456 updateButtonsForRow(m_ui.lbGroups->currentRow());
462void KReportSectionEditor::btnMoveUp_clicked()
464 if (m_reportSectionDetail) {
465 int idx = m_ui.lbGroups->currentRow();
466 if (idx <= 0)
return;
467 QString s = m_ui.lbGroups->currentItem()->text();
468 m_ui.lbGroups->takeItem(idx);
469 m_ui.lbGroups->insertItem(idx - 1, s);
472 bool showgh = rsdg->groupHeaderVisible();
473 bool showgf = rsdg->groupFooterVisible();
474 m_reportSectionDetail->removeGroupSection(idx);
475 m_reportSectionDetail->insertGroupSection(idx - 1, rsdg);
476 rsdg->setGroupHeaderVisible(showgh);
477 rsdg->setGroupFooterVisible(showgf);
482void KReportSectionEditor::brnMoveDown_clicked()
484 if (m_reportSectionDetail) {
485 int idx = m_ui.lbGroups->currentRow();
486 if (idx == (
int)(m_ui.lbGroups->count() - 1))
return;
487 QString s = m_ui.lbGroups->currentItem()->text();
488 m_ui.lbGroups->takeItem(idx);
489 m_ui.lbGroups->insertItem (idx + 1, s);
492 bool showgh = rsdg->groupHeaderVisible();
493 bool showgf = rsdg->groupFooterVisible();
494 m_reportSectionDetail->removeGroupSection(idx);
495 m_reportSectionDetail->insertGroupSection(idx + 1, rsdg);
496 rsdg->setGroupHeaderVisible(showgh);
497 rsdg->setGroupFooterVisible(showgf);
501void KReportSectionEditor::updateButtonsForItem(
QListWidgetItem* currentItem)
503 const bool isItemSelected = currentItem;
509void KReportSectionEditor::updateButtonsForRow(
int row)
511 const bool enableMoveUpButton = (row > 0);
512 const bool enableMoveDownButton = (0 <= row) && (row+1 < m_ui.lbGroups->count());
515 m_btnMoveDown->
setEnabled(enableMoveDownButton);
518void KReportSectionEditor::updateAddButton()
521 bool foundUnusedColumn =
false;
524 foreach(
const QString &key, keys) {
526 if (isEditorHelperField(key)) {
530 foundUnusedColumn =
true;
A section group allows a header and footer to be used for a particular report field.
The ReportDesigner is the main widget for designing a report.
KReportDesignerSectionDetail * detailSection() const
Return a pointer to the detail section.
void insertSection(KReportSectionData::Type type)
Create a new section and insert it into the report.
QStringList fieldKeys() const
void removeSection(KReportSectionData::Type type)
Deletes the section specified.
QStringList fieldNames() const
QIcon fromTheme(const QString &name)
const_reference at(qsizetype i) const const
qsizetype count() const const
T value(qsizetype i) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
bool contains(const QSet< T > &other) const const
bool isEmpty() const const
qsizetype indexOf(const QRegularExpression &re, qsizetype from) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)