File indexing completed on 2025-01-26 04:05:02
0001 /* 0002 * SPDX-FileCopyrightText: 2006-2010 Thomas Zander <zander@kde.org> 0003 * SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 #include "TestSelection.h" 0006 #include <MockShapes.h> 0007 0008 #include <KoSelection.h> 0009 #include <FlakeDebug.h> 0010 0011 #include <simpletest.h> 0012 0013 void TestSelection::testSelectedShapes() 0014 { 0015 KoSelection selection; 0016 MockShape *shape1 = new MockShape(); 0017 MockShape *shape2 = new MockShape(); 0018 MockShape *shape3 = new MockShape(); 0019 0020 QCOMPARE(selection.count(), 0); 0021 QCOMPARE(selection.selectedShapes().count(), 0); 0022 selection.select(shape1); 0023 QCOMPARE(selection.count(), 1); 0024 QCOMPARE(selection.selectedShapes().count(), 1); 0025 0026 selection.select(shape1); // same one. 0027 QCOMPARE(selection.count(), 1); 0028 QCOMPARE(selection.selectedShapes().count(), 1); 0029 0030 selection.select(shape2); 0031 selection.select(shape3); 0032 QCOMPARE(selection.count(), 3); 0033 QCOMPARE(selection.selectedShapes().count(), 3); 0034 0035 selection.deselectAll(); 0036 0037 MockGroup *group1 = new MockGroup(); 0038 group1->addShape(shape1); 0039 group1->addShape(shape2); 0040 selection.select(group1); 0041 QCOMPARE(selection.count(), 1); 0042 QCOMPARE(selection.selectedShapes().count(), 1); 0043 0044 MockGroup *group2 = new MockGroup(); 0045 group2->addShape(shape3); 0046 group2->addShape(group1); 0047 selection.select(group2); 0048 QCOMPARE(selection.count(), 2); 0049 QCOMPARE(selection.selectedShapes().count(), 2); 0050 0051 group1->removeShape(shape1); 0052 group1->removeShape(shape2); 0053 MockContainer *container = new MockContainer(); 0054 container->addShape(shape1); 0055 container->addShape(shape2); 0056 selection.select(container); 0057 QCOMPARE(selection.count(), 3); 0058 QCOMPARE(selection.selectedShapes().count(), 3); 0059 0060 delete group2; 0061 delete container; 0062 } 0063 0064 void TestSelection::testSize() 0065 { 0066 KoSelection selection; 0067 0068 MockShape shape1; 0069 shape1.setSize( QSizeF( 100, 100 ) ); 0070 shape1.setPosition( QPointF( 0, 0 ) ); 0071 0072 selection.select( &shape1 ); 0073 QCOMPARE(selection.size(), QSizeF( 100, 100 )); 0074 0075 MockShape shape2; 0076 shape2.setSize( QSizeF( 100, 100 ) ); 0077 shape2.setPosition( QPointF( 100, 100 ) ); 0078 0079 selection.select( &shape2 ); 0080 QCOMPARE(selection.size(), QSizeF( 200, 200 )); 0081 0082 MockShape shape3; 0083 shape3.setSize( QSizeF( 100, 100 ) ); 0084 shape3.setPosition( QPointF( 200, 200 ) ); 0085 0086 selection.select( &shape3 ); 0087 QCOMPARE(selection.size(), QSizeF( 300, 300 )); 0088 0089 selection.deselect( &shape3 ); 0090 QCOMPARE(selection.size(), QSizeF( 200, 200 )); 0091 0092 selection.deselect( &shape2 ); 0093 QCOMPARE(selection.size(), QSizeF( 100, 100 )); 0094 } 0095 0096 QTEST_GUILESS_MAIN(TestSelection)