QPageLayout: use QExplicitlySharedDataPointer
Many setters check for an actual change before making changes to data members, but because of QSharedDataPointer, the detach had already happened by the time the comparison returned false. Change-Id: I320806e74de4a64fa3a340831621c1f5120ebb0f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: John Layt <jlayt@kde.org>
This commit is contained in:
parent
7b3d9bbdf2
commit
0de0f494bd
@ -466,6 +466,7 @@ bool QPageLayout::isValid() const
|
|||||||
|
|
||||||
void QPageLayout::setMode(Mode mode)
|
void QPageLayout::setMode(Mode mode)
|
||||||
{
|
{
|
||||||
|
d.detach();
|
||||||
d->m_mode = mode;
|
d->m_mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,6 +495,7 @@ void QPageLayout::setPageSize(const QPageSize &pageSize, const QMarginsF &minMar
|
|||||||
{
|
{
|
||||||
if (!pageSize.isValid())
|
if (!pageSize.isValid())
|
||||||
return;
|
return;
|
||||||
|
d.detach();
|
||||||
d->m_pageSize = pageSize;
|
d->m_pageSize = pageSize;
|
||||||
d->m_fullSize = d->fullSizeUnits(d->m_units);
|
d->m_fullSize = d->fullSizeUnits(d->m_units);
|
||||||
d->setDefaultMargins(minMargins);
|
d->setDefaultMargins(minMargins);
|
||||||
@ -522,6 +524,7 @@ QPageSize QPageLayout::pageSize() const
|
|||||||
void QPageLayout::setOrientation(Orientation orientation)
|
void QPageLayout::setOrientation(Orientation orientation)
|
||||||
{
|
{
|
||||||
if (orientation != d->m_orientation) {
|
if (orientation != d->m_orientation) {
|
||||||
|
d.detach();
|
||||||
d->m_orientation = orientation;
|
d->m_orientation = orientation;
|
||||||
d->m_fullSize = d->fullSizeUnits(d->m_units);
|
d->m_fullSize = d->fullSizeUnits(d->m_units);
|
||||||
// Adust the max margins to reflect change in max page size
|
// Adust the max margins to reflect change in max page size
|
||||||
@ -549,6 +552,7 @@ QPageLayout::Orientation QPageLayout::orientation() const
|
|||||||
void QPageLayout::setUnits(Unit units)
|
void QPageLayout::setUnits(Unit units)
|
||||||
{
|
{
|
||||||
if (units != d->m_units) {
|
if (units != d->m_units) {
|
||||||
|
d.detach();
|
||||||
d->m_margins = qt_convertMargins(d->m_margins, d->m_units, units);
|
d->m_margins = qt_convertMargins(d->m_margins, d->m_units, units);
|
||||||
d->m_minMargins = qt_convertMargins(d->m_minMargins, d->m_units, units);
|
d->m_minMargins = qt_convertMargins(d->m_minMargins, d->m_units, units);
|
||||||
d->m_maxMargins = qt_convertMargins(d->m_maxMargins, d->m_units, units);
|
d->m_maxMargins = qt_convertMargins(d->m_maxMargins, d->m_units, units);
|
||||||
@ -585,6 +589,7 @@ QPageLayout::Unit QPageLayout::units() const
|
|||||||
bool QPageLayout::setMargins(const QMarginsF &margins)
|
bool QPageLayout::setMargins(const QMarginsF &margins)
|
||||||
{
|
{
|
||||||
if (d->m_mode == FullPageMode) {
|
if (d->m_mode == FullPageMode) {
|
||||||
|
d.detach();
|
||||||
d->m_margins = margins;
|
d->m_margins = margins;
|
||||||
return true;
|
return true;
|
||||||
} else if (margins.left() >= d->m_minMargins.left()
|
} else if (margins.left() >= d->m_minMargins.left()
|
||||||
@ -595,6 +600,7 @@ bool QPageLayout::setMargins(const QMarginsF &margins)
|
|||||||
&& margins.right() <= d->m_maxMargins.right()
|
&& margins.right() <= d->m_maxMargins.right()
|
||||||
&& margins.top() <= d->m_maxMargins.top()
|
&& margins.top() <= d->m_maxMargins.top()
|
||||||
&& margins.bottom() <= d->m_maxMargins.bottom()) {
|
&& margins.bottom() <= d->m_maxMargins.bottom()) {
|
||||||
|
d.detach();
|
||||||
d->m_margins = margins;
|
d->m_margins = margins;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -621,6 +627,7 @@ bool QPageLayout::setLeftMargin(qreal leftMargin)
|
|||||||
{
|
{
|
||||||
if (d->m_mode == FullPageMode
|
if (d->m_mode == FullPageMode
|
||||||
|| (leftMargin >= d->m_minMargins.left() && leftMargin <= d->m_maxMargins.left())) {
|
|| (leftMargin >= d->m_minMargins.left() && leftMargin <= d->m_maxMargins.left())) {
|
||||||
|
d.detach();
|
||||||
d->m_margins.setLeft(leftMargin);
|
d->m_margins.setLeft(leftMargin);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -647,6 +654,7 @@ bool QPageLayout::setRightMargin(qreal rightMargin)
|
|||||||
{
|
{
|
||||||
if (d->m_mode == FullPageMode
|
if (d->m_mode == FullPageMode
|
||||||
|| (rightMargin >= d->m_minMargins.right() && rightMargin <= d->m_maxMargins.right())) {
|
|| (rightMargin >= d->m_minMargins.right() && rightMargin <= d->m_maxMargins.right())) {
|
||||||
|
d.detach();
|
||||||
d->m_margins.setRight(rightMargin);
|
d->m_margins.setRight(rightMargin);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -673,6 +681,7 @@ bool QPageLayout::setTopMargin(qreal topMargin)
|
|||||||
{
|
{
|
||||||
if (d->m_mode == FullPageMode
|
if (d->m_mode == FullPageMode
|
||||||
|| (topMargin >= d->m_minMargins.top() && topMargin <= d->m_maxMargins.top())) {
|
|| (topMargin >= d->m_minMargins.top() && topMargin <= d->m_maxMargins.top())) {
|
||||||
|
d.detach();
|
||||||
d->m_margins.setTop(topMargin);
|
d->m_margins.setTop(topMargin);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -699,6 +708,7 @@ bool QPageLayout::setBottomMargin(qreal bottomMargin)
|
|||||||
{
|
{
|
||||||
if (d->m_mode == FullPageMode
|
if (d->m_mode == FullPageMode
|
||||||
|| (bottomMargin >= d->m_minMargins.bottom() && bottomMargin <= d->m_maxMargins.bottom())) {
|
|| (bottomMargin >= d->m_minMargins.bottom() && bottomMargin <= d->m_maxMargins.bottom())) {
|
||||||
|
d.detach();
|
||||||
d->m_margins.setBottom(bottomMargin);
|
d->m_margins.setBottom(bottomMargin);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -764,6 +774,7 @@ QMargins QPageLayout::marginsPixels(int resolution) const
|
|||||||
|
|
||||||
void QPageLayout::setMinimumMargins(const QMarginsF &minMargins)
|
void QPageLayout::setMinimumMargins(const QMarginsF &minMargins)
|
||||||
{
|
{
|
||||||
|
d.detach();
|
||||||
d->setDefaultMargins(minMargins);
|
d->setDefaultMargins(minMargins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend class QPageLayoutPrivate;
|
friend class QPageLayoutPrivate;
|
||||||
QSharedDataPointer<QPageLayoutPrivate> d;
|
QExplicitlySharedDataPointer<QPageLayoutPrivate> d;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_SHARED(QPageLayout)
|
Q_DECLARE_SHARED(QPageLayout)
|
||||||
|
Loading…
Reference in New Issue
Block a user