KD Reports API Documentation  2.2
KDReportsTableBreakingSettingsDialog.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** This file is part of the KD Reports library.
4 **
5 ** SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: MIT
8 **
9 ****************************************************************************/
10 
12 #include "KDReportsMainTable.h"
13 #include "KDReportsReport.h"
15 #include "ui_tablebreakingdialogbase.h"
16 #include <QDebug>
17 
18 class KDReports::TableBreakingSettingsDialogPrivate : public Ui::TableBreakingSettingsDialog
19 {
20 public:
21  TableBreakingSettingsDialogPrivate(KDReports::Report *report)
22  : m_report(report)
23  {
24  }
25  void slotBreakTablesToggled(bool breakTables)
26  {
27  if (!breakTables) {
28  // If we can't break tables, then we can only scale to 1 pages horizontally
29  numHorizontalPages->setValue(1);
30  }
31  numHorizontalPages->setEnabled(breakTables);
32  }
33 
34  KDReports::Report *m_report;
35 };
36 
38  : QDialog(parent)
39  , d(new TableBreakingSettingsDialogPrivate(report))
40 {
41  d->setupUi(this);
42 
43  connect(d->breakTables, &QAbstractButton::toggled, this, [this](bool b) { d->slotBreakTablesToggled(b); });
44 
45  // LOAD SETTINGS
46  d->breakTables->setChecked(true); // trigger the toggled signal if the next line sets it back to false
47  d->breakTables->setChecked(d->m_report->isTableBreakingEnabled());
48  if (d->m_report->isTableBreakingEnabled() && d->m_report->fontScalingFactor() == 1.0) {
49  const int maxH = d->m_report->maximumNumberOfPagesForHorizontalScaling();
50  const int maxV = d->m_report->maximumNumberOfPagesForVerticalScaling();
51  d->fit->setChecked(true);
52  d->numHorizontalPages->setValue(maxH);
53  d->numVerticalPages->setValue(maxV);
54  } else {
55  d->scaleFonts->setChecked(true); // default value, 100% scaling i.e. noop
56  d->scalingFactor->setValue(qRound(d->m_report->fontScalingFactor() * 100));
57  }
58 
59  if (d->m_report->tableBreakingPageOrder() == KDReports::Report::DownThenRight)
60  d->downThenRight->setChecked(true);
61  else
62  d->rightThenDown->setChecked(true);
63 
64  KDReports::AutoTableElement *autoTable = d->m_report->mainTable()->autoTableElement();
65  // Auto table settings
66  if (autoTable) {
67  d->showHorizontalHeader->setChecked(autoTable->isHorizontalHeaderVisible());
68  d->showVerticalHeader->setChecked(autoTable->isVerticalHeaderVisible());
69  d->showGrid->setChecked(autoTable->border() > 0);
70  } else {
71  d->tableSettingsGroupBox->hide();
72  }
73 }
74 
76 {
77 }
78 
79 void KDReports::TableBreakingSettingsDialog::accept()
80 {
81  // SAVE SETTINGS
82  const bool breakTables = d->breakTables->isChecked();
83  if (d->fit->isChecked()) {
84  d->m_report->setFontScalingFactor(1.0);
85  d->m_report->scaleTo(breakTables ? d->numHorizontalPages->value() : 1, d->numVerticalPages->value());
86  } else {
87  d->m_report->setFontScalingFactor(static_cast<qreal>(d->scalingFactor->value()) / 100.0);
88  }
89 
90  if (d->downThenRight->isChecked()) {
91  d->m_report->setTableBreakingPageOrder(KDReports::Report::DownThenRight);
92  } else {
93  d->m_report->setTableBreakingPageOrder(KDReports::Report::RightThenDown);
94  }
95 
96  KDReports::AutoTableElement *autoTable = d->m_report->mainTable()->autoTableElement();
97  // Auto table settings
98  if (autoTable) {
99  autoTable->setHorizontalHeaderVisible(d->showHorizontalHeader->isChecked());
100  autoTable->setVerticalHeaderVisible(d->showVerticalHeader->isChecked());
101  const bool currentGrid = autoTable->border() > 0;
102  if (currentGrid != d->showGrid->isChecked()) // don't change a border of 2 if the user didn't toggle the checkbox
103  autoTable->setBorder(d->showGrid->isChecked() ? 1 : 0);
104  d->m_report->regenerateAutoTables();
105  } else {
106  d->tableSettingsGroupBox->hide();
107  }
108 
109  QDialog::accept();
110 }
111 
112 void KDReports::TableBreakingSettingsDialog::reject()
113 {
114  QDialog::reject();
115 }
TableBreakingSettingsDialog(KDReports::Report *report, QWidget *parent=nullptr)

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-reports/
Generated by doxygen 1.9.1