Commit a69019b8 authored by Jan Hambrecht's avatar Jan Hambrecht

Do not let the group shape have a border or a shadow as that

leads to bugs when adding or removing child shapes. It does
not paint them anyway. 
The bug happened inside the childCountChanged method where 
the position and size is being adjusted when a child shape was 
added or removed. It called boundingRect() which adjusted the 
current bounding rect with the border and shadow insets.
So each time this method was called the position and size of the group
changed.



svn path=/trunk/koffice/; revision=922994
parent ceee65ef
......@@ -26,6 +26,8 @@
#include "KoXmlWriter.h"
#include "KoXmlReader.h"
#include "KoShapeRegistry.h"
#include "KoShapeBorderModel.h"
#include "KoShapeShadow.h"
#include <QPainter>
......@@ -49,6 +51,7 @@ bool KoShapeGroup::hitTest(const QPointF &position) const
void KoShapeGroup::childCountChanged()
{
// TODO: why is this needed here ? the group/ungroup command should take care of this
QRectF br = boundingRect();
setAbsolutePosition(br.topLeft(), KoFlake::TopLeftCorner);
setSize(br.size());
......@@ -101,3 +104,32 @@ bool KoShapeGroup::loadOdf(const KoXmlElement & element, KoShapeLoadingContext &
return true;
}
void KoShapeGroup::shapeChanged(ChangeType type)
{
switch( type )
{
case KoShape::BorderChanged:
{
KoShapeBorderModel * stroke = border();
if( stroke ) {
if( stroke->removeUser() )
delete stroke;
setBorder(0);
}
break;
}
case KoShape::ShadowChanged:
{
KoShapeShadow * shade = shadow();
if( shade ) {
if( shade->removeUser() )
delete shade;
setShadow(0);
}
break;
}
default:
break;
}
}
......@@ -59,6 +59,8 @@ public:
private:
void childCountChanged();
virtual void shapeChanged(ChangeType type);
};
#endif
......@@ -34,7 +34,7 @@ KoShapeGroupCommand::KoShapeGroupCommand(KoShapeContainer *container, QList<KoSh
{
Q_ASSERT(m_clipped.count() == m_shapes.count());
foreach(KoShape* shape, m_shapes)
m_oldParents.append(shape->parent());
m_oldParents.append(shape->parent());
setText(i18n("Group shapes"));
}
......@@ -121,7 +121,6 @@ void KoShapeGroupCommand::undo()
m_container->setAbsolutePosition(bound.topLeft(), KoFlake::TopLeftCorner);
m_container->setSize(bound.size());
}
}
}
......
......@@ -21,14 +21,17 @@
#include "MockShapes.h"
#include <KoShapeGroup.h>
#include <KoShapeGroupCommand.h>
#include <KoLineBorder.h>
#include <KoShapeShadow.h>
#include <QtGui/QUndoCommand>
TestShapeGroupCommand::TestShapeGroupCommand()
: toplevelGroup(0), sublevelGroup(0)
, cmd1(0), cmd2(0)
: toplevelGroup(0), sublevelGroup(0), strokeGroup(0)
, cmd1(0), cmd2(0), strokeCmd(0)
, toplevelShape1(0), toplevelShape2(0)
, sublevelShape1(0), sublevelShape2(0)
, extraShape1(0), extraShape2(0)
, strokeShape1(0), strokeShape2(0)
{
}
......@@ -64,20 +67,50 @@ void TestShapeGroupCommand::init()
toplevelGroup = new KoShapeGroup();
sublevelGroup = new KoShapeGroup();
strokeShape1 = new MockShape();
strokeShape1->setSize( QSizeF(50,50) );
strokeShape1->setPosition( QPointF(0,0) );
strokeShape2 = new MockShape();
strokeShape2->setSize( QSizeF(50,50) );
strokeShape2->setPosition( QPointF(25,25) );
strokeGroup = new KoShapeGroup();
strokeGroup->setBorder( new KoLineBorder( 2.0f ) );
strokeGroup->setShadow( new KoShapeShadow() );
}
void TestShapeGroupCommand::cleanup()
{
delete toplevelGroup;
toplevelGroup = 0;
delete sublevelGroup;
sublevelGroup = 0;
delete strokeGroup;
strokeGroup = 0;
delete toplevelShape1;
toplevelShape1 = 0;
delete toplevelShape2;
toplevelShape2 = 0;
delete sublevelShape1;
sublevelShape1 = 0;
delete sublevelShape2;
sublevelShape2 = 0;
delete extraShape1;
extraShape1 = 0;
delete extraShape2;
extraShape2 = 0;
delete strokeShape1;
strokeShape1 = 0;
delete strokeShape2;
strokeShape2 = 0;
delete cmd1;
cmd1 = 0;
delete cmd2;
cmd2 = 0;
delete strokeCmd;
strokeCmd = 0;
}
void TestShapeGroupCommand::testToplevelGroup()
......@@ -203,6 +236,29 @@ void TestShapeGroupCommand::testAddToSublevelGroup()
QCOMPARE(sublevelGroup->size(), QSizeF(150, 50));
}
void TestShapeGroupCommand::testGroupStrokeShapes()
{
QRectF bound = strokeShape1->boundingRect().unite( strokeShape2->boundingRect() );
if (strokeGroup->border()) {
KoInsets insets;
strokeGroup->border()->borderInsets(strokeGroup, insets);
bound.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
}
if (strokeGroup->shadow()) {
KoInsets insets;
strokeGroup->shadow()->insets(strokeGroup, insets);
bound.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
}
QList<KoShape*> strokeShapes;
strokeShapes << strokeShape2 << strokeShape1;
strokeCmd = new KoShapeGroupCommand(strokeGroup, strokeShapes);
strokeCmd->redo();
QCOMPARE(strokeShape1->size(), QSizeF(50, 50));
QCOMPARE(strokeShape2->size(), QSizeF(50, 50));
QCOMPARE(bound, strokeGroup->boundingRect());
}
QTEST_MAIN(TestShapeGroupCommand)
#include "TestShapeGroupCommand.moc"
......@@ -39,12 +39,15 @@ private slots:
void testSublevelGroup();
void testAddToToplevelGroup();
void testAddToSublevelGroup();
void testGroupStrokeShapes();
private:
KoShapeGroup *toplevelGroup, *sublevelGroup;
QUndoCommand *cmd1, *cmd2;
KoShapeGroup *toplevelGroup, *sublevelGroup, *strokeGroup;
QUndoCommand *cmd1, *cmd2, *strokeCmd;
MockShape *toplevelShape1, *toplevelShape2;
MockShape *sublevelShape1, *sublevelShape2;
MockShape *extraShape1, *extraShape2;
MockShape *strokeShape1, *strokeShape2;
};
#endif // TESTSHAPEGROUPCOMMAND_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