Commit 8dc80756 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Move max and min values of z-index into KoShape itself

It fixes linking on some strict compilers.

The patch also fixes the return value of zIndex methods. Now it
is more difficult to misuse it by setting overflowing values.
parent 17320b27
......@@ -197,7 +197,7 @@ void Viewport::handleDragEnterEvent(QDragEnterEvent *event)
if (!allShapes.isEmpty()) {
std::sort(allShapes.begin(), allShapes.end(), KoShape::compareShapeZIndex);
pasteZIndex = qMin(KoShapePrivate::MaxZIndex, allShapes.last()->zIndex() + 1);
pasteZIndex = qMin(int(KoShape::maxZIndex), allShapes.last()->zIndex() + 1);
}
}
......
......@@ -21,6 +21,8 @@
Boston, MA 02110-1301, USA.
*/
#include <limits>
#include "KoShape.h"
#include "KoShape_p.h"
#include "KoShapeContainer.h"
......@@ -302,6 +304,10 @@ QString KoShapePrivate::getStyleProperty(const char *property, KoShapeLoadingCon
// ======== KoShape
const qint16 KoShape::maxZIndex = std::numeric_limits<qint16>::max();
const qint16 KoShape::minZIndex = std::numeric_limits<qint16>::min();
KoShape::KoShape()
: d_ptr(new KoShapePrivate(this))
{
......@@ -691,7 +697,7 @@ bool KoShape::inheritsTransformFromAny(const QList<KoShape *> ancestorsInQuestio
return result;
}
int KoShape::zIndex() const
qint16 KoShape::zIndex() const
{
Q_D(const KoShape);
return d->zIndex;
......@@ -1124,7 +1130,7 @@ bool KoShape::inheritBackground() const
return d->inheritBackground;
}
void KoShape::setZIndex(int zIndex)
void KoShape::setZIndex(qint16 zIndex)
{
Q_D(KoShape);
if (d->zIndex == zIndex)
......
......@@ -581,7 +581,7 @@ public:
* @return the z-index of this shape.
* @see setZIndex()
*/
int zIndex() const;
qint16 zIndex() const;
/**
* Set the z-coordinate of this shape.
......@@ -594,7 +594,17 @@ public:
* and probably depends on the order in which they are added to the shape manager.
* @param zIndex the new z-index;
*/
void setZIndex(int zIndex);
void setZIndex(qint16 zIndex);
/**
* Maximum value of z-index
*/
static const qint16 maxZIndex;
/**
* Minimum value of z-index
*/
static const qint16 minZIndex;
/**
* Retrieve the run through property of this shape.
......
......@@ -60,9 +60,10 @@ public:
if (showDialog && !shape->shapeId().isEmpty()) {
KoShapeFactoryBase *factory = KoShapeRegistry::instance()->value(shape->shapeId());
Q_ASSERT(factory);
int z = 0;
Q_FOREACH (KoShape *sh, canvas->shapeManager()->shapes())
qint16 z = 0;
Q_FOREACH (KoShape *sh, canvas->shapeManager()->shapes()) {
z = qMax(z, sh->zIndex());
}
shape->setZIndex(z + 1);
// show config dialog.
......
......@@ -94,7 +94,6 @@ public:
qreal transparency; ///< the shapes transparency
QString hyperLink; //hyperlink for this shape
static const int MaxZIndex = 32767;
int zIndex : 16; // keep maxZIndex in sync!
int runThrough : 16;
int visible : 1;
......
......@@ -150,7 +150,7 @@ KoShapeReorderCommand *KoShapeReorderCommand::createCommand(const QList<KoShape*
for (; newIt!= newOrder.end(); ++newIt) {
QList<KoShape*> order(newIt.value());
order.removeAll(0);
int index = -KoShapePrivate::MaxZIndex - 1; // set minimum zIndex
int index = -KoShape::maxZIndex - 1; // set minimum zIndex
int pos = 0;
for (; pos < order.size(); ++pos) {
if (order[pos]->zIndex() > index) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment