Commit 091c85fc authored by Jan Hambrecht's avatar Jan Hambrecht

* fix bug in the shape reorder command for the LowerShape mode,

where a shape at the second lowest position could not
be moved down further
* also add a test for the reorder command


svn path=/trunk/koffice/; revision=743366
parent f3b0151a
......@@ -93,10 +93,12 @@ KoShapeReorderCommand *KoShapeReorderCommand::createCommand(const QList<KoShape*
}
}
else if(move == LowerShape) {
if(--iter == sortedShapes.begin()) continue; // already at bottom
if(iter == sortedShapes.begin()) continue; // already at bottom
iter--; // go to the one below
int newIndex = (*iter)->zIndex()-1;
changedShapes.append(shape);
newIndexes.append(newIndex);
if(iter == sortedShapes.begin()) continue; // moved to the bottom
--iter; // skip the one we want to get below
while(iter != sortedShapes.begin() && newIndex >= (*iter)->zIndex()) {
changedShapes.append(*iter);
......
......@@ -86,3 +86,9 @@ kde4_add_unit_test(TestShapeGroupCommand TESTNAME libs-flake-TestShapeGroupComma
target_link_libraries(TestShapeGroupCommand ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### end ###############
set(TestShapeReorderCommand_test_SRCS TestShapeReorderCommand.cpp )
kde4_add_unit_test(TestShapeReorderCommand TESTNAME libs-flake-TestShapeReorderCommand ${TestShapeReorderCommand_test_SRCS})
target_link_libraries(TestShapeReorderCommand ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### end ###############
/* This file is part of the KDE project
* Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "TestShapeReorderCommand.h"
#include "MockShapes.h"
#include <KoShapeReorderCommand.h>
#include <KoShapeManager.h>
#include <kcomponentdata.h>
TestShapeReorderCommand::TestShapeReorderCommand()
{
KComponentData componentData( "TestShapeReorderCommand" ); // we need an instance for the canvas
}
TestShapeReorderCommand::~TestShapeReorderCommand()
{
}
void TestShapeReorderCommand::testBringToFront()
{
MockShape shape1, shape2, shape3;
shape1.setSize( QSizeF(100,100) );
shape1.setZIndex( 1 );
shape2.setSize( QSizeF(100,100) );
shape2.setZIndex( 2 );
shape3.setSize( QSizeF(100,100) );
shape3.setZIndex( 3 );
QList<KoShape*> shapes;
shapes.append( &shape1 );
shapes.append( &shape2 );
shapes.append( &shape3 );
MockCanvas canvas;
KoShapeManager manager(&canvas, shapes );
qSort( shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE( shapes.indexOf( &shape1 ), 0 );
QCOMPARE( shapes.indexOf( &shape2 ), 1 );
QCOMPARE( shapes.indexOf( &shape3 ), 2 );
QList<KoShape*> selectedShapes;
selectedShapes.append( &shape1 );
QUndoCommand * cmd = KoShapeReorderCommand::createCommand( selectedShapes, &manager, KoShapeReorderCommand::BringToFront );
cmd->redo();
qSort( shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE( shapes.indexOf( &shape2 ), 0 );
QCOMPARE( shapes.indexOf( &shape3 ), 1 );
QCOMPARE( shapes.indexOf( &shape1 ), 2 );
delete cmd;
}
void TestShapeReorderCommand::testSendToBack()
{
MockShape shape1, shape2, shape3;
shape1.setSize( QSizeF(100,100) );
shape1.setZIndex( 1 );
shape2.setSize( QSizeF(100,100) );
shape2.setZIndex( 2 );
shape3.setSize( QSizeF(100,100) );
shape3.setZIndex( 3 );
QList<KoShape*> shapes;
shapes.append( &shape1 );
shapes.append( &shape2 );
shapes.append( &shape3 );
MockCanvas canvas;
KoShapeManager manager(&canvas, shapes );
qSort( shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE( shapes.indexOf( &shape1 ), 0 );
QCOMPARE( shapes.indexOf( &shape2 ), 1 );
QCOMPARE( shapes.indexOf( &shape3 ), 2 );
QList<KoShape*> selectedShapes;
selectedShapes.append( &shape3 );
QUndoCommand * cmd = KoShapeReorderCommand::createCommand( selectedShapes, &manager, KoShapeReorderCommand::SendToBack );
cmd->redo();
qSort( shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE( shapes.indexOf( &shape3 ), 0 );
QCOMPARE( shapes.indexOf( &shape1 ), 1 );
QCOMPARE( shapes.indexOf( &shape2 ), 2 );
delete cmd;
}
void TestShapeReorderCommand::testMoveUp()
{
MockShape shape1, shape2, shape3;
shape1.setSize( QSizeF(100,100) );
shape1.setZIndex( 1 );
shape2.setSize( QSizeF(100,100) );
shape2.setZIndex( 2 );
shape3.setSize( QSizeF(100,100) );
shape3.setZIndex( 3 );
QList<KoShape*> shapes;
shapes.append( &shape1 );
shapes.append( &shape2 );
shapes.append( &shape3 );
MockCanvas canvas;
KoShapeManager manager(&canvas, shapes );
qSort( shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE( shapes.indexOf( &shape1 ), 0 );
QCOMPARE( shapes.indexOf( &shape2 ), 1 );
QCOMPARE( shapes.indexOf( &shape3 ), 2 );
QList<KoShape*> selectedShapes;
selectedShapes.append( &shape1 );
QUndoCommand * cmd = KoShapeReorderCommand::createCommand( selectedShapes, &manager, KoShapeReorderCommand::RaiseShape );
cmd->redo();
qSort( shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE( shapes.indexOf( &shape2 ), 0 );
QCOMPARE( shapes.indexOf( &shape1 ), 1 );
QCOMPARE( shapes.indexOf( &shape3 ), 2 );
delete cmd;
}
void TestShapeReorderCommand::testMoveDown()
{
MockShape shape1, shape2, shape3;
shape1.setSize( QSizeF(100,100) );
shape1.setZIndex( 1 );
shape2.setSize( QSizeF(100,100) );
shape2.setZIndex( 2 );
shape3.setSize( QSizeF(100,100) );
shape3.setZIndex( 3 );
QList<KoShape*> shapes;
shapes.append( &shape1 );
shapes.append( &shape2 );
shapes.append( &shape3 );
MockCanvas canvas;
KoShapeManager manager(&canvas, shapes );
qSort( shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE( shapes.indexOf( &shape1 ), 0 );
QCOMPARE( shapes.indexOf( &shape2 ), 1 );
QCOMPARE( shapes.indexOf( &shape3 ), 2 );
QList<KoShape*> selectedShapes;
selectedShapes.append( &shape2 );
QUndoCommand * cmd = KoShapeReorderCommand::createCommand( selectedShapes, &manager, KoShapeReorderCommand::LowerShape );
cmd->redo();
qSort( shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE( shapes.indexOf( &shape2 ), 0 );
QCOMPARE( shapes.indexOf( &shape1 ), 1 );
QCOMPARE( shapes.indexOf( &shape3 ), 2 );
delete cmd;
}
QTEST_MAIN(TestShapeReorderCommand)
#include "TestShapeReorderCommand.moc"
/* This file is part of the KDE project
* Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef TESTSHAPEREORDERCOMMAND_H
#define TESTSHAPEREORDERCOMMAND_H
#include <QtTest/QtTest>
class TestShapeReorderCommand : public QObject
{
Q_OBJECT
public:
TestShapeReorderCommand();
~TestShapeReorderCommand();
private slots:
void testBringToFront();
void testSendToBack();
void testMoveUp();
void testMoveDown();
};
#endif // TESTSHAPEREORDERCOMMAND_H
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