itemdocumentdata.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005 by David Saxton                                    *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #ifndef ITEMDOCUMENTDATA_H
00012 #define ITEMDOCUMENTDATA_H
00013 
00014 #include "item.h"
00015 #include "microsettings.h"
00016 
00017 #include <qdom.h>
00018 
00019 class Connector;
00020 class ECSubcircuit;
00021 class KURL;
00022 class Node;
00023 class PinMapping;
00024 
00025 typedef QValueList<QGuardedPtr<Connector> > ConnectorList;
00026 typedef QValueList<QGuardedPtr<Item> > ItemList;
00027 typedef QValueList<QGuardedPtr<Node> > NodeList;
00028 typedef QMap< QString, PinMapping > PinMappingMap;
00029 
00030 typedef QValueList<QPoint> QPointList;
00031 typedef QMap<QString, bool> BoolMap;
00032 typedef QMap<QString, double> DoubleMap;
00033 typedef QMap<QString, int> IntMap;
00034 typedef QMap<QString, QColor> QColorMap;
00035 typedef QMap<QString, QString> QStringMap;
00036 typedef QMap<QString, QBitArray> QBitArrayMap;
00037 
00038 
00039 class ItemData
00040 {
00041         public:
00042                 ItemData();
00043                 
00044                 QString type;
00045                 double x;
00046                 double y;
00047                 int z;
00048                 QRect size;
00049                 bool setSize;
00050                 int orientation; // used for flowparts, should be set to -1 if not used.
00051                 double angleDegrees;
00052                 bool flipped;
00053                 BoolMap buttonMap;
00054                 IntMap sliderMap;
00055                 QString parentId;
00056                 BoolMap dataBool;
00057                 DoubleMap dataNumber;
00058                 QColorMap dataColor;
00059                 QStringMap dataString;
00060                 QBitArrayMap dataRaw;
00061 };
00062 typedef QMap< QString, ItemData > ItemDataMap;
00063 
00064 
00065 class ConnectorData
00066 {
00067         public:
00068                 ConnectorData();
00069                 
00070                 QPointList route;
00071                 bool manualRoute;
00072                 
00073                 bool startNodeIsChild;
00074                 bool endNodeIsChild;
00075                 
00076                 QString startNodeCId;
00077                 QString endNodeCId;
00078                 
00079                 QString startNodeParent;
00080                 QString endNodeParent;
00081                 
00082                 QString startNodeId;
00083                 QString endNodeId;
00084 };
00085 typedef QMap< QString, ConnectorData > ConnectorDataMap;
00086 
00087 
00088 class NodeData
00089 {
00090         public:
00091                 NodeData();
00092                 
00093                 double x;
00094                 double y;
00095 };
00096 typedef QMap< QString, NodeData > NodeDataMap;
00097 
00098 
00099 class PinData
00100 {
00101         public:
00102                 PinData();
00103                 
00104                 PinSettings::pin_type type;
00105                 PinSettings::pin_state state;
00106 };
00107 typedef QMap< QString, PinData > PinDataMap;
00108 
00109 
00110 class MicroData
00111 {
00112         public:
00113                 MicroData();
00114                 void reset();
00115                 
00116                 QString id;
00117                 PinDataMap pinMap;
00118                 QStringMap variableMap;
00119                 PinMappingMap pinMappings;
00120 };
00121 
00122 
00129 class ItemDocumentData
00130 {
00131         public:
00132                 ItemDocumentData( uint documentType );
00133                 ~ItemDocumentData();
00137                 void reset();
00143                 bool loadData( const KURL &url );
00148                 bool saveData( const KURL &url );
00152                 QString toXML();
00157                 bool fromXML( const QString &xml );
00161                 void saveDocumentState( ItemDocument *itemDocument );
00165                 void restoreDocument( ItemDocument *itemDocument );
00171                 void mergeWithDocument( ItemDocument *itemDocument, bool selectNew );
00176                 void generateUniqueIDs( ItemDocument *itemDocument );
00180                 void translateContents( int dx, int dy );
00185                 uint documentType() const { return m_documentType; }
00186                 
00187                 //BEGIN functions for adding data
00188                 void setMicroData( const MicroData &data );
00189                 void addItems( const ItemList &itemList );
00190                 void addConnectors( const ConnectorList &connectorList );
00191                 void addNodes( const NodeList &nodeList );
00192                 
00196                 void addItemData( ItemData itemData, QString id );
00200                 void addConnectorData( ConnectorData connectorData, QString id );
00204                 void addNodeData( NodeData nodeData, QString id );
00205                 //END functions for adding data
00206                 
00207                 //BEGIN functions for returning strings for saving to xml
00208                 QString documentTypeString() const;
00209                 QString revisionString() const;
00210                 //END functions for returning strings for saving to xml
00211                 
00212         protected:
00213                 //BEGIN functions for generating QDomElements
00214                 QDomElement microDataToElement( QDomDocument &doc );
00215                 QDomElement itemDataToElement( QDomDocument &doc, const ItemData &itemData );
00216                 QDomElement nodeDataToElement( QDomDocument &doc, const NodeData &nodeData );
00217                 QDomElement connectorDataToElement( QDomDocument &doc, const ConnectorData &connectorData );
00218                 //END functions for generating QDomElements
00219                 
00220                 //BEGIN functions for reading QDomElements to stored data
00221                 void elementToMicroData( QDomElement element );
00222                 void elementToItemData( QDomElement element );
00223                 void elementToNodeData( QDomElement element );
00224                 void elementToConnectorData( QDomElement element );
00225                 //END functions for reading QDomElements to stored data
00226                 
00227                 ItemDataMap m_itemDataMap;
00228                 ConnectorDataMap m_connectorDataMap;
00229                 NodeDataMap m_nodeDataMap;
00230                 MicroData m_microData;
00231                 uint m_documentType; // See Document::DocumentType
00232 };
00233 
00234 
00235 class SubcircuitData : public ItemDocumentData
00236 {
00237         public:
00238                 SubcircuitData();
00239                 void initECSubcircuit( ECSubcircuit * ecSubcircuit );
00240 };
00241 
00242 #endif

Generated on Tue May 8 17:05:30 2007 for KTechLab by  doxygen 1.5.1