cnitemgroup.h

/*************************************************************************** * Copyright (C) 2003-2005 by David Saxton * * david@bluehaze.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/#ifndef CANVASITEMGROUP_H#define CANVASITEMGROUP_H#include "itemgroup.h"class CNItem;
class Item;
class ICNDocument;
class Component;
class Connector;
class FlowPart;
class Node;
class ECNode;
class FPNode;
class ICNDocument;
class QCanvasItem;
class QCanvasItemList;
typedef QValueList<QGuardedPtr<Item> > ItemList;
typedef QValueList<QGuardedPtr<Node> > NodeList;
typedef QValueList<QGuardedPtr<Connector> > ConnectorList;
/**@author David Saxton*/00037class CNItemGroup : publicItemGroup
{
Q_OBJECT
public:
CNItemGroup( ICNDocument *icnDocument, constchar *name = 0 );
~CNItemGroup();
/** * Adds a CNItem to the group, if it is not already in it, or other items at * a lower levels are already in the group. If there are items are a high level, * those items are removed first. Returns false on failure to add. */booladdItem( Item *item ); /** * Adds a Node to the group, if it is not already in it. Note: This node * will *NOT* be added if it is a child node, and the function will return false. * If the node is not already present, and is added, then this will return true. */booladdNode( Node *node ); /** * Adds a Connector to the group, if it is not already in it (if it is, returns false) */booladdConnector( Connector *con ); /** * If the item is a a CNItem, Node or Connector, returns the status * for that particular add function, else returns false */virtualbooladdQCanvasItem( QCanvasItem *qcanvasItem ); /** * Sets the contained items to those in this list */virtualvoidsetItems( QCanvasItemList list ); /** * Removes the CNItem from the group */voidremoveItem( Item *item ); /** * Removes the Node from the group */voidremoveNode( Node *node ); /** * Removes the Connector from the group */voidremoveConnector( Connector *con ); /** * If the item is a a CNItem, Node or Connector, then attempts to remove it */virtualvoidremoveQCanvasItem( QCanvasItem *qcanvasItem ); /** * Returns true if the QCanvasItem passed is contained in the group */virtualboolcontains( QCanvasItem *qcanvasItem ) const; /** * Returns the number of Nodes in the CanvasGroup */00092 uint nodeCount() const { return m_nodeCount; } /** * Returns the number of Connectors in the CanvasGroup */00096 uint connectorCount() const { return m_connectorCount; } /** * Returns the total number of items in the group * (CNItems, Nodes, Connectors) */00101 uint count() const { return itemCount()+m_nodeCount+m_connectorCount; } /** * Sets the selected state of all items in the group */virtualvoidsetSelected( bool sel ); /** * Sets the orientation (degrees component) of all items in the group */voidsetOrientationAngle( int angleDegrees ); /** * Sets the orientation (flipped component) of all items in the group */voidsetOrientationFlipped( bool flipped ); /** * Sets the orientation of all flowparts in the group */voidsetFlowPartOrientation( unsigned orientation ); /** * Sets the orientation (degrees and flipped) of all components in the group */voidsetComponentOrientation( int angleDegrees, bool flipped ); /** * Merges all items in the given group with this group */virtualvoidmergeGroup( ItemGroup *group ); /** * Removes all items from this group (doesn't delete them) * @param unselect whether to unselect the items or not. This will be done after removal from group */virtualvoidremoveAllItems(); /** * Attempts to delete everything in the group. * Note: You *must* call ICNDocument::flushDeleteList() after calling this function, * as this function only tells the items to remove themselves */virtualvoiddeleteAllItems(); /** * Returns a list of all the Nodes in the group. * @param excludeParented if false, then nodes that are fully contained * within item children will also be returned. */
NodeList nodes( bool excludeParented = true ) const; /** * Returns a list of all the Connectors in the group. * @param excludeParented if false, then connectors that are fully contained * within item children will also be returned. */
ConnectorList connectors( bool excludeParented = true ) const; /** * Returns a list of the ids of all the CNItems in the group. */
QStringList itemIDs(); /** * Returns true if at least some of the CNItems in this group can be * rotated. Returns false if no items present. */boolcanRotate() const; /** * Returns true if at least some of the CNItems in this group can be * flipped. Returns false if no items present. */boolcanFlip() const; /** * @return whether all the components or flowparts have the same * orientation. If there are a mixture of components and flowparts * (or other items), this will return false. */boolhaveSameOrientation() const;
public slots: /** * Sets the orientation of all selected items to 0 degrees. */00175voidslotSetOrientation0() { setOrientationAngle(0); } /** * Sets the orientation of all selected items to 90 degrees. */00179voidslotSetOrientation90() { setOrientationAngle(90); } /** * Sets the orientation of all selected items to 180 degrees. */00183voidslotSetOrientation180() { setOrientationAngle(180); } /** * Sets the orientation of all selected items to 270 (actually -90) degrees. */00187voidslotSetOrientation270() { setOrientationAngle(-90); } /** * Rotates all CNItems in the group clockwise */voidslotRotateCW(); /** * Rotates all CNItems in the group counter-clockwise */voidslotRotateCCW(); /** * Flips all CNItems in the group through a horizontal axis. */voidflipVertically(); /** * Flips all CNItems in the group through a veritcal axis. */voidflipHorizontally();
signals:
void connectorAdded( Connector *con );
void connectorRemoved( Connector *con );
void nodeAdded( Node *node );
void nodeRemoved( Node *node );
protected:
void updateInfo();
void getActiveItem();
void setActiveItem( Item *item );
private:
ICNDocument *p_icnDocument;
ConnectorList m_connectorList;
NodeList m_nodeList;
uint m_connectorCount;
uint m_nodeCount;
int m_currentLevel; // We can only accept CNItems of one level
};
#endif