00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GRAPH_H
00020 #define GRAPH_H
00021
00022 #include <QObject>
00023 #include <QList>
00024 #include <QString>
00025 #include <KComboBox>
00026
00027 #include <klocalizedstring.h>
00028 #include "rocslib_export.h"
00029
00030 #include "node.h"
00031 #include "edge.h"
00032
00033 class GraphDocument;
00034
00038 class ROCSLIB_EXPORT Graph : public QObject
00039 {
00040 Q_OBJECT
00041
00043 Q_PROPERTY( bool directed READ directed WRITE setDirected )
00044
00045
00046 Q_PROPERTY( QString name READ name WRITE setName )
00047
00049 Q_PROPERTY( QString nodeDefaultColor READ nodeDefaultColor WRITE setNodeDefaultColor )
00050
00052 Q_PROPERTY( QString edgeDefaultColor READ edgeDefaultColor WRITE setEdgeDefaultColor )
00053
00055 Q_PROPERTY( bool automate READ automate WRITE setAutomate )
00056
00057 public:
00061 Graph( GraphDocument* parent = 0 );
00062
00064 ~Graph();
00065
00068 void calcRelativeCenter();
00069
00073 QPointF relativeCenter() const;
00074
00078 GraphDocument* document() const;
00079
00080 void readOnly( bool r )
00081 {
00082 _readOnly = r;
00083 }
00084 bool readOnly() const
00085 {
00086 return _readOnly;
00087 }
00088 void setKCB( KComboBox* list );
00089
00090 public slots:
00093 void setName( const QString& s );
00094
00097 const QString& name() const;
00098
00102 void setDirected( bool directed = true );
00103
00107 bool directed() const;
00108
00112 NodeList nodes() const;
00113
00114
00118 EdgeList edges() const;
00119
00120
00124 Node* begin() const;
00125
00129 bool setBegin( Node* b );
00130
00135 Node* addNode( QString name );
00136
00144 Edge* addEdge( Node* from, Node* to, QGraphicsSvgItem* cFrom, QGraphicsSvgItem* cTo );
00145
00151
00152
00157 Node* node( const QString& name = i18n( "Untitled" ) );
00158
00162 void remove( Node* n );
00163
00167 void remove( Edge* e );
00168
00174 Node* addEnd( Node* n );
00175
00179 void removeEnd( Node* n );
00180
00184 void setNodeDefaultColor( const QString& color );
00185
00189 const QString& nodeDefaultColor() const;
00190
00194 void setEdgeDefaultColor( const QString& color );
00195
00199 const QString& edgeDefaultColor() const;
00200
00204 void setAutomate( bool b );
00205
00209 bool automate();
00210
00215 void addDynamicProperty( QString property, QVariant value = QVariant( 0 ) );
00219 void removeDynamicProperty( QString property );
00220
00225 void addNodesDynamicProperty( QString property, QVariant value = QVariant( 0 ) );
00226
00230 void addEdgesDynamicProperty( QString property, QVariant value = QVariant( 0 ) );
00231
00236 void removeNodesDynamicProperty( QString property );
00237
00241 void removeEdgesDynamicProperty( QString property );
00242
00247 void addNode( QString name, QPointF point );
00248
00254 void addNode( QString name, QPointF point, QString type );
00255
00260 void addNode( QString name, QString type );
00261
00265 void setNodesColor( QString c );
00266
00270 void setEdgesColor( QString c );
00271
00274 void setNodeNameVisibility( bool b );
00275 bool nodeNameVisibility();
00276
00277 void setEdgeNameVisibility( bool b );
00278 bool edgeNameVisibility();
00279
00280 void setNodeValueVisibility( bool b );
00281 bool nodeValueVisibility();
00282
00283 void setEdgeValueVisibility( bool b );
00284 bool edgeValueVisibility();
00285
00287 void remove();
00288
00289
00290 signals:
00291 void nodeCreated( Node* n );
00292 void edgeCreated( Edge* e );
00293 void complexityChanged( bool directed );
00294 void changed();
00295 void orientedChanged( bool b );
00296 void automateChanged( bool b );
00297 void iAmDisappoint();
00298 void forceUpdate();
00299
00300 private:
00301 bool _directed;
00302 NodeList _nodes;
00303 EdgeList _edges;
00304
00305 qreal _top;
00306 qreal _bottom;
00307 qreal _left;
00308 qreal _right;
00309
00310 QPointF _relativeCenter;
00311 QString _name;
00312 Node* _begin;
00313 NodeList _ends;
00314 QString _nodeDefaultColor;
00315 QString _edgeDefaultColor;
00316 bool _automate;
00317 GraphDocument* _document;
00318 bool _readOnly;
00319 KComboBox* _listbox;
00320
00321 bool _nodeNamesVisible;
00322 bool _edgeNamesVisible;
00323 bool _nodeValuesVisible;
00324 bool _edgeValuesVisible;
00325
00326 bool assignEdgeAction( Node* from, Edge* edge );
00327 bool connectionIsValid( bool direction, QGraphicsSvgItem* svg );
00328
00329 };
00330
00331 #endif