File indexing completed on 2024-04-21 05:43:53

0001 /***************************************************************************
0002  *   Copyright (C) 2003-2005 by David Saxton                               *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef CANVASITEMGROUP_H
0012 #define CANVASITEMGROUP_H
0013 
0014 #include "itemgroup.h"
0015 
0016 class CNItem;
0017 class Item;
0018 class ICNDocument;
0019 class Component;
0020 class Connector;
0021 class FlowPart;
0022 class Node;
0023 class ECNode;
0024 // class FPNode;
0025 class ICNDocument;
0026 class KtlQCanvasItem;
0027 class KtlQCanvasItemList;
0028 
0029 typedef QList<QPointer<Item>> ItemList;
0030 typedef QList<QPointer<Node>> NodeList;
0031 typedef QList<QPointer<Connector>> ConnectorList;
0032 
0033 /**
0034 @author David Saxton
0035 */
0036 class CNItemGroup : public ItemGroup
0037 {
0038     Q_OBJECT
0039 public:
0040     CNItemGroup(ICNDocument *icnDocument);
0041     ~CNItemGroup() override;
0042 
0043     /**
0044      * Adds a CNItem to the group, if it is not already in it, or other items at
0045      * a lower levels are already in the group. If there are items are a high level,
0046      * those items are removed first. Returns false on failure to add.
0047      */
0048     bool addItem(Item *item);
0049     /**
0050      * Adds a Node to the group, if it is not already in it. Note: This node
0051      * will *NOT* be added if it is a child node, and the function will return false.
0052      * If the node is not already present, and is added, then this will return true.
0053      */
0054     bool addNode(Node *node);
0055     /**
0056      * Adds a Connector to the group, if it is not already in it (if it is, returns false)
0057      */
0058     bool addConnector(Connector *con);
0059     /**
0060      * If the item is a CNItem, Node or Connector, returns the status
0061      * for that particular add function, else returns false
0062      */
0063     bool addQCanvasItem(KtlQCanvasItem *qcanvasItem) override;
0064     /**
0065      * Sets the contained items to those in this list
0066      */
0067     void setItems(KtlQCanvasItemList list) override;
0068     /**
0069      * Removes the CNItem from the group
0070      */
0071     void removeItem(Item *item);
0072     /**
0073      * Removes the Node from the group
0074      */
0075     void removeNode(Node *node);
0076     /**
0077      * Removes the Connector from the group
0078      */
0079     void removeConnector(Connector *con);
0080     /**
0081      * If the item is a CNItem, Node or Connector, then attempts to remove it
0082      */
0083     void removeQCanvasItem(KtlQCanvasItem *qcanvasItem) override;
0084     /**
0085      * Returns true if the KtlQCanvasItem passed is contained in the group
0086      */
0087     bool contains(KtlQCanvasItem *qcanvasItem) const override;
0088     /**
0089      * Returns the number of Nodes in the CanvasGroup
0090      */
0091     uint nodeCount() const
0092     {
0093         return m_nodeCount;
0094     }
0095     /**
0096      * Returns the number of Connectors in the CanvasGroup
0097      */
0098     uint connectorCount() const
0099     {
0100         return m_connectorCount;
0101     }
0102     /**
0103      * Returns the total number of items in the group
0104      * (CNItems, Nodes, Connectors)
0105      */
0106     uint count() const override
0107     {
0108         return itemCount() + m_nodeCount + m_connectorCount;
0109     }
0110     /**
0111      * Sets the selected state of all items in the group
0112      */
0113     void setSelected(bool sel) override;
0114     /**
0115      * Sets the orientation (degrees component) of all items in the group
0116      */
0117     void setOrientationAngle(int angleDegrees);
0118     /**
0119      * Sets the orientation (flipped component) of all items in the group
0120      */
0121     void setOrientationFlipped(bool flipped);
0122     /**
0123      * Sets the orientation of all flowparts in the group
0124      */
0125     void setFlowPartOrientation(unsigned orientation);
0126     /**
0127      * Sets the orientation (degrees and flipped) of all components in the group
0128      */
0129     void setComponentOrientation(int angleDegrees, bool flipped);
0130     /**
0131      * Merges all items in the given group with this group
0132      */
0133     void mergeGroup(ItemGroup *group) override;
0134     /**
0135      * Removes all items from this group (doesn't delete them)
0136      */
0137     void removeAllItems() override;
0138     /**
0139      * Attempts to delete everything in the group.
0140      * Note: You *must* call ICNDocument::flushDeleteList() after calling this function,
0141      * as this function only tells the items to remove themselves
0142      */
0143     void deleteAllItems() override;
0144     /**
0145      * Returns a list of all the Nodes in the group.
0146      * @param excludeParented if false, then nodes that are fully contained
0147      * within item children will also be returned.
0148      */
0149     NodeList nodes(bool excludeParented = true) const;
0150     /**
0151      * Returns a list of all the Connectors in the group.
0152      * @param excludeParented if false, then connectors that are fully contained
0153      * within item children will also be returned.
0154      */
0155     ConnectorList connectors(bool excludeParented = true) const;
0156     /**
0157      * Returns a list of the ids of all the CNItems in the group.
0158      */
0159     QStringList itemIDs();
0160     /**
0161      * Returns true if at least some of the CNItems in this group can be
0162      * rotated. Returns false if no items present.
0163      */
0164     bool canRotate() const;
0165     /**
0166      * Returns true if at least some of the CNItems in this group can be
0167      * flipped. Returns false if no items present.
0168      */
0169     bool canFlip() const;
0170     /**
0171      * @return whether all the components or flowparts have the same
0172      * orientation. If there are a mixture of components and flowparts
0173      * (or other items), this will return false.
0174      */
0175     bool haveSameOrientation() const;
0176 
0177 public slots:
0178     /**
0179      * Sets the orientation of all selected items to 0 degrees.
0180      */
0181     void slotSetOrientation0()
0182     {
0183         setOrientationAngle(0);
0184     }
0185     /**
0186      * Sets the orientation of all selected items to 90 degrees.
0187      */
0188     void slotSetOrientation90()
0189     {
0190         setOrientationAngle(90);
0191     }
0192     /**
0193      * Sets the orientation of all selected items to 180 degrees.
0194      */
0195     void slotSetOrientation180()
0196     {
0197         setOrientationAngle(180);
0198     }
0199     /**
0200      * Sets the orientation of all selected items to 270 (actually -90) degrees.
0201      */
0202     void slotSetOrientation270()
0203     {
0204         setOrientationAngle(-90);
0205     }
0206     /**
0207      * Rotates all CNItems in the group clockwise
0208      */
0209     void slotRotateCW();
0210     /**
0211      * Rotates all CNItems in the group counter-clockwise
0212      */
0213     void slotRotateCCW();
0214     /**
0215      * Flips all CNItems in the group through a horizontal axis.
0216      */
0217     void flipVertically();
0218     /**
0219      * Flips all CNItems in the group through a veritcal axis.
0220      */
0221     void flipHorizontally();
0222 
0223 signals:
0224     void connectorAdded(Connector *con);
0225     void connectorRemoved(Connector *con);
0226     void nodeAdded(Node *node);
0227     void nodeRemoved(Node *node);
0228 
0229 protected:
0230     void updateInfo();
0231     void getActiveItem();
0232     void setActiveItem(Item *item);
0233 
0234 private:
0235     ICNDocument *p_icnDocument;
0236     ConnectorList m_connectorList;
0237     NodeList m_nodeList;
0238     uint m_connectorCount;
0239     uint m_nodeCount;
0240     int m_currentLevel; // We can only accept CNItems of one level
0241 };
0242 
0243 #endif