KD Reports API Documentation  2.0
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-2022 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDAB-KDReports OR LicenseRef-KDAB-KDReports-US
8 **
9 ** Licensees holding valid commercial KD Reports licenses may use this file in
10 ** accordance with the KD Reports Commercial License Agreement provided with
11 ** the Software.
12 **
13 ** Contact info@kdab.com if any conditions of this licensing are not clear to you.
14 **
15 ****************************************************************************/
16 
18 #include "KDReportsMainTable.h"
19 #include "KDReportsReport.h"
21 #include "ui_tablebreakingdialogbase.h"
22 #include <QDebug>
23 
24 class KDReports::TableBreakingSettingsDialogPrivate : public Ui::TableBreakingSettingsDialog
25 {
26 public:
27  TableBreakingSettingsDialogPrivate(KDReports::Report *report)
28  : m_report(report)
29  {
30  }
31  void slotBreakTablesToggled(bool breakTables)
32  {
33  if (!breakTables) {
34  // If we can't break tables, then we can only scale to 1 pages horizontally
35  numHorizontalPages->setValue(1);
36  }
37  numHorizontalPages->setEnabled(breakTables);
38  }
39 
40  KDReports::Report *m_report;
41 };
42 
44  : QDialog(parent)
45  , d(new TableBreakingSettingsDialogPrivate(report))
46 {
47  d->setupUi(this);
48 
49  connect(d->breakTables, &QAbstractButton::toggled, this, [this](bool b) { d->slotBreakTablesToggled(b); } );
50 
51  // LOAD SETTINGS
52  d->breakTables->setChecked(true); // trigger the toggled signal if the next line sets it back to false
53  d->breakTables->setChecked(d->m_report->isTableBreakingEnabled());
54  if (d->m_report->isTableBreakingEnabled() && d->m_report->fontScalingFactor() == 1.0) {
55  const int maxH = d->m_report->maximumNumberOfPagesForHorizontalScaling();
56  const int maxV = d->m_report->maximumNumberOfPagesForVerticalScaling();
57  d->fit->setChecked(true);
58  d->numHorizontalPages->setValue(maxH);
59  d->numVerticalPages->setValue(maxV);
60  } else {
61  d->scaleFonts->setChecked(true); // default value, 100% scaling i.e. noop
62  d->scalingFactor->setValue(qRound(d->m_report->fontScalingFactor() * 100));
63  }
64 
65  if (d->m_report->tableBreakingPageOrder() == KDReports::Report::DownThenRight)
66  d->downThenRight->setChecked(true);
67  else
68  d->rightThenDown->setChecked(true);
69 
70  KDReports::AutoTableElement *autoTable = d->m_report->mainTable()->autoTableElement();
71  // Auto table settings
72  if (autoTable) {
73  d->showHorizontalHeader->setChecked(autoTable->isHorizontalHeaderVisible());
74  d->showVerticalHeader->setChecked(autoTable->isVerticalHeaderVisible());
75  d->showGrid->setChecked(autoTable->border() > 0);
76  } else {
77  d->tableSettingsGroupBox->hide();
78  }
79 }
80 
82 {
83  delete d;
84 }
85 
86 void KDReports::TableBreakingSettingsDialog::accept()
87 {
88  // SAVE SETTINGS
89  const bool breakTables = d->breakTables->isChecked();
90  if (d->fit->isChecked()) {
91  d->m_report->setFontScalingFactor(1.0);
92  d->m_report->scaleTo(breakTables ? d->numHorizontalPages->value() : 1, d->numVerticalPages->value());
93  } else {
94  d->m_report->setFontScalingFactor(static_cast<qreal>(d->scalingFactor->value()) / 100.0);
95  }
96 
97  if (d->downThenRight->isChecked()) {
98  d->m_report->setTableBreakingPageOrder(KDReports::Report::DownThenRight);
99  } else {
100  d->m_report->setTableBreakingPageOrder(KDReports::Report::RightThenDown);
101  }
102 
103  KDReports::AutoTableElement *autoTable = d->m_report->mainTable()->autoTableElement();
104  // Auto table settings
105  if (autoTable) {
106  autoTable->setHorizontalHeaderVisible(d->showHorizontalHeader->isChecked());
107  autoTable->setVerticalHeaderVisible(d->showVerticalHeader->isChecked());
108  const bool currentGrid = autoTable->border() > 0;
109  if (currentGrid != d->showGrid->isChecked()) // don't change a border of 2 if the user didn't toggle the checkbox
110  autoTable->setBorder(d->showGrid->isChecked() ? 1 : 0);
111  d->m_report->regenerateAutoTables();
112  } else {
113  d->tableSettingsGroupBox->hide();
114  }
115 
116  QDialog::accept();
117 }
118 
119 void KDReports::TableBreakingSettingsDialog::reject()
120 {
121  QDialog::reject();
122 }
KDReports::AbstractTableElement::setBorder
void setBorder(qreal border)
Definition: KDReportsAbstractTableElement.cpp:76
KDReports::TableBreakingSettingsDialog::TableBreakingSettingsDialog
TableBreakingSettingsDialog(KDReports::Report *report, QWidget *parent=nullptr)
Definition: KDReportsTableBreakingSettingsDialog.cpp:43
KDReports::TableBreakingSettingsDialog::~TableBreakingSettingsDialog
~TableBreakingSettingsDialog() override
Definition: KDReportsTableBreakingSettingsDialog.cpp:81
KDReportsMainTable.h
KDReports::AutoTableElement::isHorizontalHeaderVisible
bool isHorizontalHeaderVisible() const
Definition: KDReportsAutoTableElement.cpp:379
KDReportsTextDocument_p.h
KDReports::AbstractTableElement::border
qreal border() const
Definition: KDReportsAbstractTableElement.cpp:81
KDReports::Report
Definition: KDReportsReport.h:80
KDReports::AutoTableElement
Definition: KDReportsAutoTableElement.h:40
KDReports::Report::RightThenDown
@ RightThenDown
Definition: KDReportsReport.h:612
KDReportsReport.h
KDReports::AutoTableElement::setVerticalHeaderVisible
void setVerticalHeaderVisible(bool visible)
Definition: KDReportsAutoTableElement.cpp:359
KDReports::Report::DownThenRight
@ DownThenRight
Definition: KDReportsReport.h:611
KDReportsTableBreakingSettingsDialog.h
KDReports::AutoTableElement::setHorizontalHeaderVisible
void setHorizontalHeaderVisible(bool visible)
Definition: KDReportsAutoTableElement.cpp:364
KDReports::AutoTableElement::isVerticalHeaderVisible
bool isVerticalHeaderVisible() const
Definition: KDReportsAutoTableElement.cpp:374

© 2007-2021 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 on Sat Jan 8 2022 02:38:32 for KD Reports API Documentation by doxygen 1.8.17