Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 6910da3f authored by Dmitry Kazakov's avatar Dmitry Kazakov

Drop now deprecated stripping of the shape selection

parent 01c32383
......@@ -174,10 +174,8 @@ bool KoSelection::hitTest(const QPointF &position) const
return false;
}
const QList<KoShape*> KoSelection::selectedShapes(KoFlake::SelectionType strip) const
const QList<KoShape*> KoSelection::selectedShapes() const
{
Q_UNUSED(strip);
Q_D(const KoSelection);
return d->selectedShapes;
}
......@@ -196,10 +194,8 @@ bool KoSelection::isSelected(const KoShape *shape) const
return tmpShape;
}
KoShape *KoSelection::firstSelectedShape(KoFlake::SelectionType strip) const
KoShape *KoSelection::firstSelectedShape() const
{
Q_UNUSED(strip);
Q_D(const KoSelection);
return !d->selectedShapes.isEmpty() ? d->selectedShapes.first() : 0;
}
......@@ -219,6 +215,7 @@ KoShapeLayer* KoSelection::activeLayer() const
void KoSelection::notifyShapeChanged(KoShape::ChangeType type, KoShape *shape)
{
Q_UNUSED(shape);
Q_D(KoSelection);
if (type >= KoShape::PositionChanged && type <= KoShape::GenericMatrixChange) {
......
......@@ -104,14 +104,14 @@ public:
* @param strip if StrippedSelection, the returned list will not include any children
* of a container shape if the container-parent is itself also in the set.
*/
const QList<KoShape*> selectedShapes(KoFlake::SelectionType strip = KoFlake::FullSelection) const;
const QList<KoShape*> selectedShapes() const;
/**
* Return the first selected shape, or 0 if there is nothing selected.
* @param strip if StrippedSelection, the returned list will not include any children
* of a grouped shape if the group-parent is itself also in the set.
*/
KoShape *firstSelectedShape(KoFlake::SelectionType strip = KoFlake::FullSelection) const;
KoShape *firstSelectedShape() const;
/// return true if the shape is selected
bool isSelected(const KoShape *shape) const;
......
......@@ -2363,3 +2363,19 @@ void KoShape::removeShapeChangeListener(KoShape::ShapeChangeListener *listener)
d->listeners.removeAll(listener);
listener->unregisterShape(this);
}
QList<KoShape *> KoShape::linearizeSubtree(const QList<KoShape *> &shapes)
{
QList<KoShape *> result;
Q_FOREACH (KoShape *shape, shapes) {
result << shape;
KoShapeContainer *container = dynamic_cast<KoShapeContainer*>(shape);
if (container) {
result << linearizeSubtree(container->shapes());
}
}
return result;
}
......@@ -1111,6 +1111,9 @@ public:
void addShapeChangeListener(ShapeChangeListener *listener);
void removeShapeChangeListener(ShapeChangeListener *listener);
public:
static QList<KoShape*> linearizeSubtree(const QList<KoShape*> &shapes);
protected:
/// constructor
KoShape(KoShapePrivate *);
......
......@@ -36,46 +36,32 @@ void TestSelection::testSelectedShapes()
QCOMPARE(selection.selectedShapes().count(), 0);
selection.select(shape1);
QCOMPARE(selection.count(), 1);
QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 1);
QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 1);
QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 1);
QCOMPARE(selection.selectedShapes().count(), 1);
selection.select(shape1); // same one.
QCOMPARE(selection.count(), 1);
QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 1);
QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 1);
QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 1);
QCOMPARE(selection.selectedShapes().count(), 1);
selection.select(shape2);
selection.select(shape3);
QCOMPARE(selection.count(), 3);
QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 3);
QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 3);
QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 3);
QCOMPARE(selection.selectedShapes().count(), 3);
MockGroup *group1 = new MockGroup();
group1->addShape(shape1);
group1->addShape(shape2);
selection.select(group1);
QCOMPARE(selection.count(), 3); // don't return the grouping shape.
// Stripped returns no groups, so simply all 3 shapes
QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 3);
// stripped returns no groups; so simply all shapes.
QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 3);
// toplevel returns shape3 and group1
QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 2);
QCOMPARE(selection.selectedShapes().count(), 2);
MockGroup *group2 = new MockGroup();
group2->addShape(shape3);
group2->addShape(group1);
selection.select(group2);
QCOMPARE(selection.count(), 3); // thats 5 minus 2 grouping shapes.
// Stripped returns no groups, so simply all 3 shapes
QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 3);
// Stripped returns no groups, so simply all 3 shapes
QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 3);
// toplevel returns only group2
QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 1);
QCOMPARE(selection.selectedShapes().count(), 1);
group1->removeShape(shape1);
......@@ -85,12 +71,8 @@ void TestSelection::testSelectedShapes()
container->addShape(shape2);
selection.select(container);
QCOMPARE(selection.count(), 4); // thats 6 minus 2 grouping shapes.
// Stripped returns no groups, so simply all 3 shapes + container
QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 4);
// Stripped returns no groups, and no children of a container. So; container + shape3
QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 2);
// toplevel returns only group2 + container
QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 2);
QCOMPARE(selection.selectedShapes().count(), 2);
delete group2;
delete container;
......
......@@ -159,7 +159,7 @@ void KoShadowConfigWidget::applyChanges()
{
if (d->canvas) {
KoSelection *selection = d->canvas->shapeManager()->selection();
KoShape * shape = selection->firstSelectedShape(KoFlake::TopLevelSelection);
KoShape * shape = selection->firstSelectedShape();
if (! shape) {
return;
}
......@@ -169,7 +169,7 @@ void KoShadowConfigWidget::applyChanges()
newShadow->setColor(shadowColor());
newShadow->setOffset(shadowOffset());
newShadow->setBlur(shadowBlur());
d->canvas->addCommand(new KoShapeShadowCommand(selection->selectedShapes(KoFlake::TopLevelSelection), newShadow));
d->canvas->addCommand(new KoShapeShadowCommand(selection->selectedShapes(), newShadow));
}
}
......@@ -180,7 +180,7 @@ void KoShadowConfigWidget::selectionChanged()
}
KoSelection *selection = d->canvas->shapeManager()->selection();
KoShape * shape = selection->firstSelectedShape(KoFlake::TopLevelSelection);
KoShape * shape = selection->firstSelectedShape();
setEnabled(shape != 0);
......
......@@ -80,7 +80,7 @@ QPolygonF selectionPolygon(KoSelection *selection)
{
QPolygonF result;
QList<KoShape*> selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape*> selectedShapes = selection->selectedShapes();
if (!selectedShapes.size()) {
return result;
......@@ -382,7 +382,7 @@ void DefaultTool::updateCursor()
QString statusText;
if (koSelection()->count() > 0) { // has a selection
bool editable = editableShapesCount(koSelection()->selectedShapes(KoFlake::StrippedSelection));
bool editable = editableShapesCount(koSelection()->selectedShapes());
if (!m_mouseWasInsideHandles) {
m_angle = rotationOfHandle(m_lastHandle, true);
......@@ -623,7 +623,7 @@ bool DefaultTool::moveSelection(int direction, Qt::KeyboardModifiers modifiers)
QList<QPointF> prevPos;
QList<QPointF> newPos;
QList<KoShape *> shapes;
Q_FOREACH (KoShape *shape, koSelection()->selectedShapes(KoFlake::TopLevelSelection)) {
Q_FOREACH (KoShape *shape, koSelection()->selectedShapes()) {
if (shape->isGeometryProtected()) {
continue;
}
......@@ -690,7 +690,7 @@ void DefaultTool::repaintDecorations()
void DefaultTool::copy() const
{
QList<KoShape *> shapes = canvas()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> shapes = canvas()->shapeManager()->selection()->selectedShapes();
if (!shapes.empty()) {
KoShapeOdfSaveHelper saveHelper(shapes);
KoDrag drag;
......@@ -702,7 +702,7 @@ void DefaultTool::copy() const
void DefaultTool::deleteSelection()
{
QList<KoShape *> shapes;
foreach (KoShape *s, canvas()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection)) {
foreach (KoShape *s, canvas()->shapeManager()->selection()->selectedShapes()) {
if (s->isGeometryProtected()) {
continue;
}
......@@ -867,7 +867,7 @@ void DefaultTool::selectionGroup()
return;
}
QList<KoShape *> selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = selection->selectedShapes();
QList<KoShape *> groupedShapes;
// only group shapes with an unselected parent
......@@ -895,7 +895,7 @@ void DefaultTool::selectionUngroup()
return;
}
QList<KoShape *> selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = selection->selectedShapes();
QList<KoShape *> containerSet;
// only ungroup shape groups with an unselected parent
......@@ -930,7 +930,7 @@ void DefaultTool::selectionAlign(KoShapeAlignCommand::Align align)
return;
}
QList<KoShape *> selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = selection->selectedShapes();
if (selectedShapes.count() < 1) {
return;
}
......@@ -985,7 +985,7 @@ void DefaultTool::selectionReorder(KoShapeReorderCommand::MoveShapeType order)
return;
}
QList<KoShape *> selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = selection->selectedShapes();
if (selectedShapes.count() < 1) {
return;
}
......@@ -1040,7 +1040,7 @@ KoInteractionStrategy *DefaultTool::createStrategy(KoPointerEvent *event)
bool insideSelection = false;
KoFlake::SelectionHandle handle = handleAt(event->point, &insideSelection);
bool editableShape = editableShapesCount(selection->selectedShapes(KoFlake::TopLevelSelection));
bool editableShape = editableShapesCount(selection->selectedShapes());
// TODO: use modifiers instead
if (event->buttons() & Qt::MidButton) {
......@@ -1154,7 +1154,7 @@ void DefaultTool::updateActions()
QList<KoShape*> selectedShapes;
if (koSelection()) {
selectedShapes = koSelection()->selectedShapes(KoFlake::TopLevelSelection);
selectedShapes = koSelection()->selectedShapes();
}
......
......@@ -78,7 +78,7 @@ void DefaultToolTransformWidget::resourceChanged(int key, const QVariant &res)
void DefaultToolTransformWidget::rotationChanged()
{
QList<KoShape *> selectedShapes = m_tool->canvas()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = m_tool->canvas()->shapeManager()->selection()->selectedShapes();
QList<QTransform> oldTransforms;
Q_FOREACH (KoShape *shape, selectedShapes) {
......@@ -113,7 +113,7 @@ void DefaultToolTransformWidget::rotationChanged()
void DefaultToolTransformWidget::shearXChanged()
{
KoSelection *selection = m_tool->canvas()->shapeManager()->selection();
QList<KoShape *> selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = selection->selectedShapes();
QList<QTransform> oldTransforms;
Q_FOREACH (KoShape *shape, selectedShapes) {
......@@ -148,7 +148,7 @@ void DefaultToolTransformWidget::shearXChanged()
void DefaultToolTransformWidget::shearYChanged()
{
KoSelection *selection = m_tool->canvas()->shapeManager()->selection();
QList<KoShape *> selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = selection->selectedShapes();
QList<QTransform> oldTransforms;
Q_FOREACH (KoShape *shape, selectedShapes) {
......@@ -182,7 +182,7 @@ void DefaultToolTransformWidget::shearYChanged()
void DefaultToolTransformWidget::scaleXChanged()
{
QList<KoShape *> selectedShapes = m_tool->canvas()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = m_tool->canvas()->shapeManager()->selection()->selectedShapes();
QList<QTransform> oldTransforms;
Q_FOREACH (KoShape *shape, selectedShapes) {
......@@ -222,7 +222,7 @@ void DefaultToolTransformWidget::scaleXChanged()
void DefaultToolTransformWidget::scaleYChanged()
{
QList<KoShape *> selectedShapes = m_tool->canvas()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = m_tool->canvas()->shapeManager()->selection()->selectedShapes();
QList<QTransform> oldTransforms;
Q_FOREACH (KoShape *shape, selectedShapes) {
......@@ -256,7 +256,7 @@ void DefaultToolTransformWidget::scaleYChanged()
void DefaultToolTransformWidget::resetTransformations()
{
QList<KoShape *> selectedShapes = m_tool->canvas()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = m_tool->canvas()->shapeManager()->selection()->selectedShapes();
QList<QTransform> oldTransforms;
Q_FOREACH (KoShape *shape, selectedShapes) {
......
......@@ -107,7 +107,7 @@ void DefaultToolWidget::updatePosition()
positionXSpinBox->changeValue(selPosition.x());
positionYSpinBox->changeValue(selPosition.y());
QList<KoShape *> selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = selection->selectedShapes();
bool aspectLocked = false;
foreach (KoShape *shape, selectedShapes) {
aspectLocked = aspectLocked | shape->keepAspectRatio();
......@@ -130,7 +130,7 @@ void DefaultToolWidget::positionHasChanged()
return;
}
QList<KoShape *> selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = selection->selectedShapes();
QPointF moveBy = newPos - oldPos;
QList<QPointF> oldPositions;
QList<QPointF> newPositions;
......@@ -197,7 +197,7 @@ void DefaultToolWidget::sizeHasChanged()
resizeMatrix.scale(rect.width() ? newSize.width() / rect.width() : 1, rect.height() ? newSize.height() / rect.height() : 1);
resizeMatrix.translate(-scaleCenter.x(), -scaleCenter.y());
QList<KoShape *> selectedShapes = selection->selectedShapes(KoFlake::StrippedSelection);
QList<KoShape *> selectedShapes = selection->selectedShapes();
QList<QSizeF> oldSizes, newSizes;
QList<QTransform> oldState;
QList<QTransform> newState;
......@@ -271,7 +271,7 @@ void DefaultToolWidget::aspectButtonToggled(bool keepAspect)
return;
}
KoSelection *selection = m_tool->canvas()->shapeManager()->selection();
foreach (KoShape *shape, selection->selectedShapes(KoFlake::TopLevelSelection)) {
foreach (KoShape *shape, selection->selectedShapes()) {
shape->setKeepAspectRatio(keepAspect);
}
}
......@@ -79,7 +79,11 @@ void SelectionDecorator::paint(QPainter &painter, const KoViewConverter &convert
painter.setPen(pen);
bool editable = false;
foreach (KoShape *shape, m_selection->selectedShapes(KoFlake::StrippedSelection)) {
QList<KoShape*> selectedShapes = m_selection->selectedShapes();
if (selectedShapes.isEmpty()) return;
foreach (KoShape *shape, KoShape::linearizeSubtree(selectedShapes)) {
painter.setWorldTransform(shape->absoluteTransformation(&converter) * painterMatrix);
KoShape::applyConversion(painter, converter);
......@@ -91,9 +95,6 @@ void SelectionDecorator::paint(QPainter &painter, const KoViewConverter &convert
}
}
QList<KoShape*> selectedShapes = m_selection->selectedShapes(KoFlake::TopLevelSelection);
if (selectedShapes.isEmpty()) return;
handleArea = m_selection->outlineRect();
painter.setTransform(m_selection->absoluteTransformation(&converter) * painterMatrix);
KoShape::applyConversion(painter, converter);
......
......@@ -41,7 +41,7 @@ ShapeMoveStrategy::ShapeMoveStrategy(KoToolBase *tool, const QPointF &clicked)
, m_start(clicked)
, m_canvas(tool->canvas())
{
QList<KoShape *> selectedShapes = m_canvas->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = m_canvas->shapeManager()->selection()->selectedShapes();
QRectF boundingRect;
Q_FOREACH (KoShape *shape, selectedShapes) {
......@@ -55,7 +55,7 @@ ShapeMoveStrategy::ShapeMoveStrategy(KoToolBase *tool, const QPointF &clicked)
}
KoSelection *selection = m_canvas->shapeManager()->selection();
m_initialOffset = selection->absolutePosition(SelectionDecorator::hotPosition()) - m_start;
m_canvas->snapGuide()->setIgnoredShapes(selection->selectedShapes(KoFlake::FullSelection));
m_canvas->snapGuide()->setIgnoredShapes(KoShape::linearizeSubtree(selection->selectedShapes()));
tool->setStatusText(i18n("Press ALT to hold x- or y-position."));
}
......
......@@ -40,7 +40,7 @@ ShapeResizeStrategy::ShapeResizeStrategy(KoToolBase *tool, const QPointF &clicke
: KoInteractionStrategy(tool)
{
Q_ASSERT(tool->canvas()->shapeManager()->selection()->count() > 0);
QList<KoShape *> selectedShapes = tool->canvas()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = tool->canvas()->shapeManager()->selection()->selectedShapes();
Q_FOREACH (KoShape *shape, selectedShapes) {
if (!shape->isEditable()) {
continue;
......
......@@ -36,7 +36,7 @@ ShapeRotateStrategy::ShapeRotateStrategy(KoToolBase *tool, const QPointF &clicke
: KoInteractionStrategy(tool)
, m_start(clicked)
{
QList<KoShape *> selectedShapes = tool->canvas()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = tool->canvas()->shapeManager()->selection()->selectedShapes();
Q_FOREACH (KoShape *shape, selectedShapes) {
if (!shape->isEditable()) {
continue;
......
......@@ -42,7 +42,7 @@ ShapeShearStrategy::ShapeShearStrategy(KoToolBase *tool, const QPointF &clicked,
, m_start(clicked)
{
KoSelection *sel = tool->canvas()->shapeManager()->selection();
QList<KoShape *> selectedShapes = sel->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape *> selectedShapes = sel->selectedShapes();
Q_FOREACH (KoShape *shape, selectedShapes) {
if (!shape->isEditable()) {
continue;
......
......@@ -281,7 +281,7 @@ void KarbonFilterEffectsTool::activate(ToolActivation toolActivation, const QSet
return;
}
d->currentShape = canvas()->shapeManager()->selection()->firstSelectedShape(KoFlake::TopLevelSelection);
d->currentShape = canvas()->shapeManager()->selection()->firstSelectedShape();
d->fillConfigSelector(d->currentShape, this);
}
......@@ -404,7 +404,7 @@ void KarbonFilterEffectsTool::filterSelected(int index)
void KarbonFilterEffectsTool::selectionChanged()
{
d->currentShape = canvas()->shapeManager()->selection()->firstSelectedShape(KoFlake::TopLevelSelection);
d->currentShape = canvas()->shapeManager()->selection()->firstSelectedShape();
d->fillConfigSelector(d->currentShape, this);
}
......
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