1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #pragma once
27
28 #include "baseitem.h"
29
30 #include <QGraphicsScene>
31
QT_FORWARD_DECLARE_CLASS(QGraphicsItem)32 QT_FORWARD_DECLARE_CLASS(QGraphicsItem)
33
34 namespace ScxmlEditor {
35
36 namespace PluginInterface {
37
38 class GraphicsScene;
39 class ConnectableItem;
40 class InitialStateItem;
41 class BaseItem;
42 class ScxmlTag;
43
44 /**
45 * Namespace SceneUtils includes some usable function to manipulate the data of the items.
46 */
47 namespace SceneUtils {
48
49 ScxmlTag *addChild(ScxmlTag *tag, const QVariantMap &data, GraphicsScene *scene);
50 ScxmlTag *addSibling(ScxmlTag *tag, const QVariantMap &data, GraphicsScene *scene);
51 ScxmlTag *addNewTag(ScxmlTag *parent, TagType type, GraphicsScene *scene);
52 ConnectableItem *createItem(ItemType type, const QPointF &pos = QPointF());
53 ConnectableItem *createItemByTagType(TagType type, const QPointF &pos = QPointF());
54 ScxmlTag *createTag(ItemType type, ScxmlDocument *document);
55 bool canDrop(int parentType, int childType);
56 QVector<ScxmlTag*> findCopyTags(const QVector<BaseItem*> &items, QPointF &minPos);
57 QVector<ScxmlTag*> findRemovedTags(const QVector<BaseItem*> &items);
58 void layout(const QList<QGraphicsItem*> &items);
59 bool isSomeSelected(QGraphicsItem *item);
60 void moveTop(BaseItem *item, GraphicsScene *scene);
61
62 bool isChild(const QGraphicsItem *parent, const QGraphicsItem *child);
63
64 template <class T>
65 bool hasSiblingStates(T *item)
66 {
67 if (item) {
68 QList<QGraphicsItem*> children;
69 QGraphicsItem *parentItem = item->parentItem();
70 if (parentItem) {
71 children = parentItem->childItems();
72 } else if (item->scene()) {
73 foreach (QGraphicsItem *it, item->scene()->items()) {
74 if (!it->parentItem())
75 children << it;
76 }
77 }
78
79 foreach (QGraphicsItem *it, children) {
80 if (it != item && it->type() == item->type()) {
81 return true;
82 }
83 }
84 }
85
86 return false;
87 }
88
89 } // namespace SceneUtils
90 } // namespace PluginInterface
91 } // namespace ScxmlEditor
92