[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/edu/Rocs/src
From:       Tomaz Martins dos Santos Canabrava <tomaz.canabrava () gmail ! com>
Date:       2009-05-17 17:55:51
Message-ID: 1242582951.539679.4617.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 969225 by tcanabrava:

changed some dinamic properties to Q_PROPERTIES since I was using them too much

 M  +9 -6      Core/graph.cpp  
 M  +6 -1      Core/graph.h  
 M  +3 -3      Core/graphDocument.cpp  
 M  +10 -5     Core/node.cpp  
 M  +15 -2     Core/node.h  
 M  +1 -1      GraphicsItem/graphicsitem_Node.cpp  
 M  +1 -1      GraphicsItem/graphicsitem_OrientedEdge.cpp  
 M  +3 -2      Interface/action_MoveNode.cpp  


--- trunk/playground/edu/Rocs/src/Core/graph.cpp #969224:969225
@@ -51,7 +51,7 @@
 
 Node* Graph::addNode(QString name) {
     Node  *n = new Node(this);
-    n->setProperty("name", name);
+    n->setName(name);
     _nodes.append( n );
     emit nodeCreated(n);
     
@@ -79,7 +79,7 @@
     QString tmpName;
 
     foreach( Node* n,  _nodes) {
-        tmpName = n->property("name").toString();
+        tmpName = n->name();
 
         if (tmpName == name_from) {
             from = n;
@@ -102,7 +102,7 @@
 Node* Graph::node(const QString& name) {
     QString tmpName;
     foreach( Node* n,  _nodes) {
-        tmpName = n->property("name").toString();
+        tmpName = n->name();
         if (tmpName == name) {
             return n;
         }
@@ -135,7 +135,6 @@
             QList<Edge*> listEdges = n1->edges(n2);
             if (n1 != n2) {
                 listEdges.removeFirst();
-                kDebug()  << "Chamou Update Pos";
             }
             foreach(Edge *e, listEdges) {
                 remove(e);
@@ -180,6 +179,10 @@
 QPointF Graph::relativeCenter() const {
     return _relativeCenter;
 }
+
+const QString& Graph::name() const{ return _name; }
+void Graph::setName(const QString& s){ _name = s; }
+
 #ifdef USING_QTSCRIPT
 
 QScriptValue Graph::scriptValue() const {
@@ -191,8 +194,8 @@
 
     _value = _engine->newQObject(this);
 
-    if ( property("name") != QVariant() ) {
-        _engine->globalObject().setProperty(property("name").toString(), _value);
+    if ( _name.isEmpty() ) {
+        _engine->globalObject().setProperty(_name, _value);
     }
 
     foreach(Node *n, _nodes) {
--- trunk/playground/edu/Rocs/src/Core/graph.h #969224:969225
@@ -26,6 +26,7 @@
 #include <QObject>
 #include <QList>
 #include <QVariant>
+#include <QString>
 
 #ifdef USING_QTSCRIPT
 #include <QtScript>
@@ -41,7 +42,8 @@
 class Graph : public QObject {
     Q_OBJECT
     Q_PROPERTY(bool directed READ directed WRITE setDirected);
-
+    Q_PROPERTY(QString name READ name WRITE setName);
+    
 public:
     Graph(QObject *parent);
     ~Graph();
@@ -53,6 +55,8 @@
 #endif
 
 public  slots:
+    void setName(const QString& s);
+    const QString& name() const;
     void setDirected(bool directed = true);
     bool directed() const;
     QList<Node*> nodes() const;
@@ -89,6 +93,7 @@
     QList<GraphGroup*> _graphGroups;
     qreal _top, _bottom, _left, _right;
     QPointF _relativeCenter;
+    QString _name;
 #ifdef USING_QTSCRIPT
     QScriptValue _value;
     QtScriptBackend *_engine;
--- trunk/playground/edu/Rocs/src/Core/graphDocument.cpp #969224:969225
@@ -91,7 +91,7 @@
 
 Graph* GraphDocument::addGraph(QString name) {
     Graph *g = new Graph(this);
-    g->setProperty("name",name);
+    g->setName(name);
     append(g);
     return g;
 }
@@ -207,7 +207,7 @@
             QString gName = str.section(" ",1,1);
             gName.remove(']');
             tmpGraph = new Graph(this);
-            tmpGraph->setProperty("name", gName.toAscii());
+            tmpGraph->setName(gName.toAscii());
             tmpObject = tmpGraph;
             append(tmpGraph);
 	    kDebug() << "Graph Created";
@@ -237,7 +237,7 @@
         }
         else if (str.contains(":")) {
             QString propertyName = str.section(":",0,0).trimmed();
-	     QString propertyValue = str.section(":",1,1).trimmed();
+            QString propertyValue = str.section(":",1,1).trimmed();
             tmpObject->setProperty( propertyName.toAscii() , propertyValue.toAscii() );
 	    kDebug() << "Property" << propertyName.toAscii() << "value" << propertyValue.toAscii();
         }
--- trunk/playground/edu/Rocs/src/Core/node.cpp #969224:969225
@@ -22,11 +22,11 @@
 #include "graph.h"
 #include <QDebug>
 
-Node::Node(QObject *parent) : QObject(parent)
-{
-    setProperty("color", "#FF0000");
-    setProperty("x", 0);
-    setProperty("y", 0);
+
+Node::Node(QObject *parent) : QObject(parent){
+    setColor("#FF0000");
+    setX(0);
+    setY(0);
 }
 
 Node::~Node() {
@@ -163,10 +163,15 @@
     p->remove(this);
 }
 
+//! Properties:
 void Node::setX(qreal x){ _x = x; }
 qreal Node::x() const{ return _x; }
 void Node::setY(qreal y){ _y  = y;}
 qreal Node::y() const { return _y; }
+void Node::setColor(const QString& s){ _color = s; }
+const QString& Node::color() const { return _color; }
+void Node::setName(const QString& s){ _name = s; }
+const QString& Node::name() const { return _name; }
 
 #ifdef USING_QTSCRIPT
 void Node::self_remove(){
--- trunk/playground/edu/Rocs/src/Core/node.h #969224:969225
@@ -27,6 +27,7 @@
 #include <QObject>
 #include <QList>
 #include <QVariant>
+#include <QString>
 
 #ifdef USING_QTSCRIPT
 #include <QtScript>
@@ -37,8 +38,11 @@
 
 class Node : public QObject {
     Q_OBJECT
-    Q_PROPERTY(qreal _x READ x WRITE setX);
-    Q_PROPERTY(qreal _y READ y WRITE setY);
+    Q_PROPERTY(qreal x READ x WRITE setX);
+    Q_PROPERTY(qreal y READ y WRITE setY);
+    Q_PROPERTY(QString name READ name WRITE setName);
+    Q_PROPERTY(QString color READ color WRITE setColor);
+    
 public:
     Node(QObject *parent);
     ~Node();
@@ -67,6 +71,10 @@
     void setY(qreal y);
     qreal x() const;
     qreal y() const;
+    void setColor(const QString& s);
+    const QString& color() const;
+    void setName(const QString& s);
+    const QString& name() const;
     
 #ifdef USING_QTSCRIPT
     QScriptValue adj_nodes(); 
@@ -85,8 +93,13 @@
     QList<Edge*> _out_edges;
     QList<Edge*> _self_edges;
     void empty(QList<Edge*> *list);
+    
+    //! fixed properties
     qreal _x;
     qreal _y;
+    QString _name;
+    QString _color;
+    
 #ifdef USING_QTSCRIPT
     QScriptValue _value;
     QtScriptBackend *_engine;
--- trunk/playground/edu/Rocs/src/GraphicsItem/graphicsitem_Node.cpp #969224:969225
@@ -70,7 +70,7 @@
     }
 
     painter->setPen(Qt::NoPen);
-    QColor color = _node->property("color").value<QColor>();
+    QColor color = QColor(_node->color());
     painter->setBrush( color.dark(240) );
 
     painter->drawEllipse(-7, -7, 20, 20);
--- trunk/playground/edu/Rocs/src/GraphicsItem/graphicsitem_OrientedEdge.cpp #969224:969225
@@ -52,7 +52,7 @@
     _loop = (_edge->from() == edge->to()) ? true : false;
     _index = _edge->relativeIndex();
 
-    setCacheMode(DeviceCoordinateCache);
+  //  setCacheMode(DeviceCoordinateCache);
     setZValue(-_index);
     setFlag(ItemIsSelectable);
     connectSignals();
--- trunk/playground/edu/Rocs/src/Interface/action_MoveNode.cpp #969224:969225
@@ -57,7 +57,6 @@
     if ( ! _movableNode ) {
         return;
     }
-   // if (_graph->directed()) _graph->calcRelativeCenter();
     _movableNode -> updatePos( pos );
 }
 
@@ -65,8 +64,10 @@
     if ( !_movableNode ) {
         return;
     }
-    _movableNode = 0;
+    
     _view->setRenderHint(QPainter::Antialiasing, true);
+     _movableNode -> updatePos( pos );
+     _movableNode = 0;
 }
 
 void MoveNodeAction::setView(QGraphicsView *v){
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic