print: Clamp margins entered by the user in the page setup dialog

The current functionality discards all margins if any values fall
outside the minimum or maximum limits. This can confuse and
frustrate users since the Windows native page setup dialog doesn't
enforce minimum values.

Introduce a new parameter outOfBoundsPolicy for the set margins
functions in the QPageLayout:
- OutOfBoundsPolicy::Reject The old behavior rejecting out of
  bounds values.
- OutOfBoundsPolicy::Clamp The new behavior for clamping the values.

The OutOfBoundsPolicy is applied only in StandardMode to maintain
backwards compatibility in FullPageMode, where all margins are
accepted.

Use the new Clamp policy in the printsupport where the clamping is
necessary.

Maintain binary compatibility by putting the declaration of the old
symbols without policy parameter behind QT_GUI_REMOVED_SINCE, and
implement them in removed_api.cpp to call the new versions.

Task-number: QTBUG-122410
Change-Id: I06aee292c1daff2863502f471b03798dafbcd81b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Jarkko Koivikko 2024-01-04 15:47:11 +02:00
parent b4c63b89df
commit 6c72080f26
8 changed files with 278 additions and 65 deletions

View File

@ -26,8 +26,34 @@ bool Qt::mightBeRichText(const QString& text)
return Qt::mightBeRichText(qToStringViewIgnoringNull(text));
}
#endif // QT_GUI_REMOVED_SINCE(6, 7)
#if QT_GUI_REMOVED_SINCE(6, 8)
#include "qpagelayout.h"
bool QPageLayout::setMargins(const QMarginsF &margins)
{
return setMargins(margins, OutOfBoundsPolicy::Reject);
}
bool QPageLayout::setLeftMargin(qreal leftMargin)
{
return setLeftMargin(leftMargin, OutOfBoundsPolicy::Reject);
}
bool QPageLayout::setRightMargin(qreal rightMargin)
{
return setRightMargin(rightMargin, OutOfBoundsPolicy::Reject);
}
bool QPageLayout::setTopMargin(qreal topMargin)
{
return setTopMargin(topMargin, OutOfBoundsPolicy::Reject);
}
// #include "qotherheader.h"
// // implement removed functions from qotherheader.h
// order sections alphabetically
#endif // QT_GUI_REMOVED_SINCE(6, 7)
#endif // QT_GUI_REMOVED_SINCE(6, 8)

View File

@ -79,7 +79,7 @@ public:
bool isValid() const;
void clampMargins(const QMarginsF &margins);
QMarginsF clampMargins(const QMarginsF &margins) const;
QMarginsF margins(QPageLayout::Unit units) const;
QMarginsF marginsPoints() const;
@ -151,9 +151,9 @@ bool QPageLayoutPrivate::isValid() const
return m_pageSize.isValid();
}
void QPageLayoutPrivate::clampMargins(const QMarginsF &margins)
QMarginsF QPageLayoutPrivate::clampMargins(const QMarginsF &margins) const
{
m_margins = QMarginsF(qBound(m_minMargins.left(), margins.left(), m_maxMargins.left()),
return QMarginsF(qBound(m_minMargins.left(), margins.left(), m_maxMargins.left()),
qBound(m_minMargins.top(), margins.top(), m_maxMargins.top()),
qBound(m_minMargins.right(), margins.right(), m_maxMargins.right()),
qBound(m_minMargins.bottom(), margins.bottom(), m_maxMargins.bottom()));
@ -182,7 +182,7 @@ void QPageLayoutPrivate::setDefaultMargins(const QMarginsF &minMargins)
qMax(m_fullSize.width() - m_minMargins.left(), qreal(0)),
qMax(m_fullSize.height() - m_minMargins.top(), qreal(0)));
if (m_mode == QPageLayout::StandardMode)
clampMargins(m_margins);
m_margins = clampMargins(m_margins);
}
QSizeF QPageLayoutPrivate::fullSizeUnits(QPageLayout::Unit units) const
@ -288,6 +288,27 @@ QRectF QPageLayoutPrivate::paintRect() const
\value StandardMode Paint Rect includes margins, margins must fall between the minimum and maximum.
\value FullPageMode Paint Rect excludes margins, margins can be any value and must be managed manually.
In StandardMode, when setting margins, use \l{QPageLayout::OutOfBoundsPolicy::}{Clamp} to
automatically clamp the margins to fall between the minimum and maximum
allowed values.
\sa OutOfBoundsPolicy
*/
/*!
\enum QPageLayout::OutOfBoundsPolicy
\since 6.8
Defines the policy for margins that are out of bounds
\value Reject The margins must fall within the minimum and maximum values,
otherwise they will be rejected.
\value Clamp The margins are clamped between the minimum and maximum
values to ensure they are valid.
\note The policy has no effect in \l{QPageLayout::Mode}{FullPageMode},
where all margins are accepted.
*/
/*!
@ -525,28 +546,38 @@ QPageLayout::Unit QPageLayout::units() const
}
/*!
Sets the page margins of the page layout to \a margins
Sets the page margins of the page layout to \a margins.
Returns true if the margins were successfully set.
The units used are those currently defined for the layout. To use different
units then call setUnits() first.
If in the default StandardMode then all the new margins must fall between the
minimum margins set and the maximum margins allowed by the page size,
otherwise the margins will not be set.
If in FullPageMode then any margin values will be accepted.
Since Qt 6.8, the optional \a outOfBoundsPolicy can be used to specify how
margins that are out of bounds are handled.
\sa margins(), units()
*/
bool QPageLayout::setMargins(const QMarginsF &margins)
bool QPageLayout::setMargins(const QMarginsF &margins, OutOfBoundsPolicy outOfBoundsPolicy)
{
if (d->m_mode == FullPageMode) {
if (margins != d->m_margins) {
d.detach();
d->m_margins = margins;
}
return true;
} else if (margins.left() >= d->m_minMargins.left()
}
if (outOfBoundsPolicy == OutOfBoundsPolicy::Clamp) {
const QMarginsF clampedMargins = d->clampMargins(margins);
if (clampedMargins != d->m_margins) {
d.detach();
d->m_margins = clampedMargins;
}
return true;
}
if (margins.left() >= d->m_minMargins.left()
&& margins.right() >= d->m_minMargins.right()
&& margins.top() >= d->m_minMargins.top()
&& margins.bottom() >= d->m_minMargins.bottom()
@ -554,10 +585,13 @@ bool QPageLayout::setMargins(const QMarginsF &margins)
&& margins.right() <= d->m_maxMargins.right()
&& margins.top() <= d->m_maxMargins.top()
&& margins.bottom() <= d->m_maxMargins.bottom()) {
if (margins != d->m_margins) {
d.detach();
d->m_margins = margins;
}
return true;
}
return false;
}
@ -568,23 +602,27 @@ bool QPageLayout::setMargins(const QMarginsF &margins)
The units used are those currently defined for the layout. To use different
units call setUnits() first.
If in the default StandardMode then the new margin must fall between the
minimum margin set and the maximum margin allowed by the page size,
otherwise the margin will not be set.
If in FullPageMode then any margin values will be accepted.
Since Qt 6.8, the optional \a outOfBoundsPolicy can be used to specify how
margins that are out of bounds are handled.
\sa setMargins(), margins()
*/
bool QPageLayout::setLeftMargin(qreal leftMargin)
bool QPageLayout::setLeftMargin(qreal leftMargin, OutOfBoundsPolicy outOfBoundsPolicy)
{
if (d->m_mode == StandardMode && outOfBoundsPolicy == OutOfBoundsPolicy::Clamp)
leftMargin = qBound(d->m_minMargins.left(), leftMargin, d->m_maxMargins.left());
if (qFuzzyCompare(leftMargin, d->m_margins.left()))
return true;
if (d->m_mode == FullPageMode
|| (leftMargin >= d->m_minMargins.left() && leftMargin <= d->m_maxMargins.left())) {
d.detach();
d->m_margins.setLeft(leftMargin);
return true;
}
return false;
}
@ -595,23 +633,27 @@ bool QPageLayout::setLeftMargin(qreal leftMargin)
The units used are those currently defined for the layout. To use different
units call setUnits() first.
If in the default StandardMode then the new margin must fall between the
minimum margin set and the maximum margin allowed by the page size,
otherwise the margin will not be set.
If in FullPageMode then any margin values will be accepted.
Since Qt 6.8, the optional \a outOfBoundsPolicy can be used to specify how
margins that are out of bounds are handled.
\sa setMargins(), margins()
*/
bool QPageLayout::setRightMargin(qreal rightMargin)
bool QPageLayout::setRightMargin(qreal rightMargin, OutOfBoundsPolicy outOfBoundsPolicy)
{
if (d->m_mode == StandardMode && outOfBoundsPolicy == OutOfBoundsPolicy::Clamp)
rightMargin = qBound(d->m_minMargins.right(), rightMargin, d->m_maxMargins.right());
if (qFuzzyCompare(rightMargin, d->m_margins.right()))
return true;
if (d->m_mode == FullPageMode
|| (rightMargin >= d->m_minMargins.right() && rightMargin <= d->m_maxMargins.right())) {
d.detach();
d->m_margins.setRight(rightMargin);
return true;
}
return false;
}
@ -622,23 +664,27 @@ bool QPageLayout::setRightMargin(qreal rightMargin)
The units used are those currently defined for the layout. To use different
units call setUnits() first.
If in the default StandardMode then the new margin must fall between the
minimum margin set and the maximum margin allowed by the page size,
otherwise the margin will not be set.
If in FullPageMode then any margin values will be accepted.
Since Qt 6.8, the optional \a outOfBoundsPolicy can be used to specify how
margins that are out of bounds are handled.
\sa setMargins(), margins()
*/
bool QPageLayout::setTopMargin(qreal topMargin)
bool QPageLayout::setTopMargin(qreal topMargin, OutOfBoundsPolicy outOfBoundsPolicy)
{
if (d->m_mode == StandardMode && outOfBoundsPolicy == OutOfBoundsPolicy::Clamp)
topMargin = qBound(d->m_minMargins.top(), topMargin, d->m_maxMargins.top());
if (qFuzzyCompare(topMargin, d->m_margins.top()))
return true;
if (d->m_mode == FullPageMode
|| (topMargin >= d->m_minMargins.top() && topMargin <= d->m_maxMargins.top())) {
d.detach();
d->m_margins.setTop(topMargin);
return true;
}
return false;
}
@ -649,23 +695,27 @@ bool QPageLayout::setTopMargin(qreal topMargin)
The units used are those currently defined for the layout. To use different
units call setUnits() first.
If in the default StandardMode then the new margin must fall between the
minimum margin set and the maximum margin allowed by the page size,
otherwise the margin will not be set.
If in FullPageMode then any margin values will be accepted.
Since Qt 6.8, the optional \a outOfBoundsPolicy can be used to specify how
margins that are out of bounds are handled.
\sa setMargins(), margins()
*/
bool QPageLayout::setBottomMargin(qreal bottomMargin)
bool QPageLayout::setBottomMargin(qreal bottomMargin, OutOfBoundsPolicy outOfBoundsPolicy)
{
if (d->m_mode == StandardMode && outOfBoundsPolicy == OutOfBoundsPolicy::Clamp)
bottomMargin = qBound(d->m_minMargins.bottom(), bottomMargin, d->m_maxMargins.bottom());
if (qFuzzyCompare(bottomMargin, d->m_margins.bottom()))
return true;
if (d->m_mode == FullPageMode
|| (bottomMargin >= d->m_minMargins.bottom() && bottomMargin <= d->m_maxMargins.bottom())) {
d.detach();
d->m_margins.setBottom(bottomMargin);
return true;
}
return false;
}

View File

@ -40,6 +40,11 @@ public:
FullPageMode // Paint Rect excludes margins
};
enum class OutOfBoundsPolicy {
Reject,
Clamp
};
QPageLayout();
QPageLayout(const QPageSize &pageSize, Orientation orientation,
const QMarginsF &margins, Unit units = Point,
@ -68,11 +73,19 @@ public:
void setUnits(Unit units);
Unit units() const;
#if QT_GUI_REMOVED_SINCE(6, 8)
bool setMargins(const QMarginsF &margins);
bool setLeftMargin(qreal leftMargin);
bool setRightMargin(qreal rightMargin);
bool setTopMargin(qreal topMargin);
bool setBottomMargin(qreal bottomMargin);
#endif
bool setMargins(const QMarginsF &margins, OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject);
bool setLeftMargin(qreal leftMargin, OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject);
bool setRightMargin(qreal rightMargin, OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject);
bool setTopMargin(qreal topMargin, OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject);
bool setBottomMargin(qreal bottomMargin, OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject);
QMarginsF margins() const;
QMarginsF margins(Unit units) const;

View File

@ -123,10 +123,10 @@ int QPageSetupDialog::exec()
pageSize = QPageSize(unitSize, layout.units() == QPageLayout::Inch
? QPageSize::Inch : QPageSize::Millimeter);
}
layout.setPageSize(pageSize);
layout.setPageSize(pageSize, layout.minimumMargins());
const QMarginsF margins(psd.rtMargin.left, psd.rtMargin.top, psd.rtMargin.right, psd.rtMargin.bottom);
layout.setMargins(margins / multiplier);
layout.setMargins(margins / multiplier, QPageLayout::OutOfBoundsPolicy::Clamp);
d->printer->setPageLayout(layout);
// copy from our temp DEVMODE struct

View File

@ -184,7 +184,8 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
Q_ASSERT(margins.size() == 4);
d->m_pageLayout.setUnits(QPageLayout::Point);
d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
margins.at(2).toReal(), margins.at(3).toReal()));
margins.at(2).toReal(), margins.at(3).toReal()),
QPageLayout::OutOfBoundsPolicy::Clamp);
break;
}
case PPK_QPageSize: {
@ -196,7 +197,7 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
case PPK_QPageMargins: {
QPair<QMarginsF, QPageLayout::Unit> pair = qvariant_cast<QPair<QMarginsF, QPageLayout::Unit> >(value);
d->m_pageLayout.setUnits(pair.second);
d->m_pageLayout.setMargins(pair.first);
d->m_pageLayout.setMargins(pair.first, QPageLayout::OutOfBoundsPolicy::Clamp);
break;
}
case PPK_QPageLayout: {

View File

@ -576,7 +576,8 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
QList<QVariant> margins(value.toList());
Q_ASSERT(margins.size() == 4);
d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
margins.at(2).toReal(), margins.at(3).toReal()));
margins.at(2).toReal(), margins.at(3).toReal()),
QPageLayout::OutOfBoundsPolicy::Clamp);
break;
}
case PPK_QPageSize:
@ -585,7 +586,7 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
case PPK_QPageMargins: {
QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >();
d->m_pageLayout.setUnits(pair.second);
d->m_pageLayout.setMargins(pair.first);
d->m_pageLayout.setMargins(pair.first, QPageLayout::OutOfBoundsPolicy::Clamp);
break;
}
case PPK_QPageLayout: {
@ -595,7 +596,7 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
setProperty(PPK_FullPage, pageLayout.mode() == QPageLayout::FullPageMode);
setProperty(PPK_Orientation, QVariant::fromValue(pageLayout.orientation()));
d->m_pageLayout.setUnits(pageLayout.units());
d->m_pageLayout.setMargins(pageLayout.margins());
d->m_pageLayout.setMargins(pageLayout.margins(), QPageLayout::OutOfBoundsPolicy::Clamp);
}
break;
}

View File

@ -1285,7 +1285,8 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
Q_ASSERT(margins.size() == 4);
d->m_pageLayout.setUnits(QPageLayout::Point);
d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
margins.at(2).toReal(), margins.at(3).toReal()));
margins.at(2).toReal(), margins.at(3).toReal()),
QPageLayout::OutOfBoundsPolicy::Clamp);
d->updateMetrics();
#ifdef QT_DEBUG_METRICS
qDebug() << "QWin32PrintEngine::setProperty(PPK_PageMargins," << margins << ')';
@ -1313,7 +1314,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
case PPK_QPageMargins: {
QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >();
d->m_pageLayout.setUnits(pair.second);
d->m_pageLayout.setMargins(pair.first);
d->m_pageLayout.setMargins(pair.first, QPageLayout::OutOfBoundsPolicy::Clamp);
d->updateMetrics();
#ifdef QT_DEBUG_METRICS
qDebug() << "QWin32PrintEngine::setProperty(PPK_QPageMargins," << pair.first << pair.second << ')';
@ -1329,7 +1330,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
setProperty(PPK_FullPage, pageLayout.mode() == QPageLayout::FullPageMode);
setProperty(PPK_Orientation, QVariant::fromValue(pageLayout.orientation()));
d->m_pageLayout.setUnits(pageLayout.units());
d->m_pageLayout.setMargins(pageLayout.margins());
d->m_pageLayout.setMargins(pageLayout.margins(), QPageLayout::OutOfBoundsPolicy::Clamp);
d->updateMetrics();
#ifdef QT_DEBUG_METRICS
qDebug() << "QWin32PrintEngine::setProperty(PPK_QPageLayout," << pageLayout << ')';

View File

@ -12,6 +12,7 @@ private slots:
void invalid();
void basics();
void setGetMargins();
void setGetClampedMargins();
void setUnits_data();
void setUnits();
};
@ -216,7 +217,7 @@ void tst_QPageLayout::basics()
void tst_QPageLayout::setGetMargins()
{
// A4, 20pt margins
// A4, 10pt margins
QMarginsF margins = QMarginsF(10, 10, 10, 10);
QMarginsF min = QMarginsF(10, 10, 10, 10);
QMarginsF max = QMarginsF(585, 832, 585, 832);
@ -229,7 +230,7 @@ void tst_QPageLayout::setGetMargins()
QCOMPARE(change.minimumMargins(), min);
QCOMPARE(change.maximumMargins(), max);
// Set magins within min/max ok
// Set margins within min/max ok
margins = QMarginsF(20, 20, 20, 20);
change.setMargins(margins);
QCOMPARE(change.margins(QPageLayout::Millimeter), QMarginsF(7.06, 7.06, 7.06, 7.06));
@ -289,7 +290,7 @@ void tst_QPageLayout::setGetMargins()
fullPage.setMargins(margins);
QCOMPARE(fullPage.margins(), margins);
// Set margins all above max is rejected
// Set margins all above max is accepted
margins = QMarginsF(1000, 1000, 1000, 1000);
fullPage.setMargins(margins);
QCOMPARE(fullPage.margins(), margins);
@ -312,6 +313,126 @@ void tst_QPageLayout::setGetMargins()
QCOMPARE(fullPage.maximumMargins(), max);
}
void tst_QPageLayout::setGetClampedMargins()
{
// A4, 10pt margins
QMarginsF margins = QMarginsF(10, 10, 10, 10);
QMarginsF min = QMarginsF(10, 10, 10, 10);
QMarginsF max = QMarginsF(585, 832, 585, 832);
QPageLayout change = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, margins, QPageLayout::Point, min);
QCOMPARE(change.isValid(), true);
// Clamp margins within min/max ok
margins = QMarginsF(20, 20, 20, 20);
change.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins(QPageLayout::Millimeter), QMarginsF(7.06, 7.06, 7.06, 7.06));
QCOMPARE(change.marginsPoints(), QMargins(20, 20, 20, 20));
QCOMPARE(change.marginsPixels(72), QMargins(20, 20, 20, 20));
QCOMPARE(change.margins(), margins);
// Clamp margins all below min
change.setMargins(QMarginsF(0, 0, 0, 0), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins(), change.minimumMargins());
// Clamp margins all above max
change.setMargins(QMarginsF(1000, 1000, 1000, 1000), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins(), change.maximumMargins());
// Only 1 wrong, clamp still works
change.setMargins(QMarginsF(50, 50, 50, 0), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins(), QMarginsF(50, 50, 50, change.minimumMargins().bottom()));
// A4, 20pt margins
margins = QMarginsF(20, 20, 20, 20);
min = QMarginsF(10, 10, 10, 10);
max = QMarginsF(585, 832, 585, 832);
QPageLayout fullPage = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, margins, QPageLayout::Point, min);
fullPage.setMode(QPageLayout::FullPageMode);
QCOMPARE(fullPage.isValid(), true);
QCOMPARE(fullPage.margins(), margins);
QCOMPARE(fullPage.minimumMargins(), min);
QCOMPARE(fullPage.maximumMargins(), max);
// Clamp margins within min/max ok
margins = QMarginsF(50, 50, 50, 50);
fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(fullPage.margins(), margins);
// Clamp margins all below min, no clamping
margins = QMarginsF(0, 0, 0, 0);
fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(fullPage.margins(), margins);
// Clamp margins all above max, no clamping
margins = QMarginsF(1000, 1000, 1000, 1000);
fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(fullPage.margins(), margins);
// Only 1 wrong, no clamping
margins = QMarginsF(50, 50, 50, 0);
fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(fullPage.margins(), margins);
// Set page size, sets min/max, clamps existing margins
margins = QMarginsF(20, 500, 20, 500);
fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(fullPage.margins(), margins);
min = QMarginsF(30, 30, 30, 30);
max = QMarginsF(267, 390, 267, 390);
fullPage.setPageSize(QPageSize(QPageSize::A6));
fullPage.setMinimumMargins(min);
QCOMPARE(fullPage.margins(), margins);
QCOMPARE(fullPage.minimumMargins(), min);
QCOMPARE(fullPage.maximumMargins(), max);
// Test set* API calls
min = QMarginsF(1, 2, 3, 4);
max = QMarginsF(595 - min.right(), 842 - min.bottom(), 595 - min.left(), 842 - min.top());
change = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, margins, QPageLayout::Point, min);
QCOMPARE(change.minimumMargins(), min);
QCOMPARE(change.maximumMargins(), max);
// Test setLeftMargin
change.setLeftMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().left(), min.left());
change.setLeftMargin(change.fullRectPoints().width(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().left(), max.left());
change.setLeftMargin(min.left(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().left(), min.left());
change.setLeftMargin(max.left(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().left(), max.left());
// Test setTopMargin
change.setTopMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().top(), min.top());
change.setTopMargin(change.fullRectPoints().height(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().top(), max.top());
change.setTopMargin(min.top(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().top(), min.top());
change.setTopMargin(max.top(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().top(), max.top());
// Test setRightMargin
change.setRightMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().right(), min.right());
change.setRightMargin(change.fullRectPoints().width(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().right(), max.right());
change.setRightMargin(min.right(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().right(), min.right());
change.setRightMargin(max.right(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().right(), max.right());
// Test setBottomMargin
change.setBottomMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().bottom(), min.bottom());
change.setBottomMargin(change.fullRectPoints().height(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().bottom(), max.bottom());
change.setBottomMargin(min.bottom(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().bottom(), min.bottom());
change.setBottomMargin(max.bottom(), QPageLayout::OutOfBoundsPolicy::Clamp);
QCOMPARE(change.margins().bottom(), max.bottom());
}
void tst_QPageLayout::setUnits_data()
{
QTest::addColumn<QPageLayout::Unit>("units");