diff --git a/src/Plugins/DataStructure/LinkedList/ListNode.cpp b/src/Plugins/DataStructure/LinkedList/ListNode.cpp index 9ea9cf68..29ac5a9a 100644 --- a/src/Plugins/DataStructure/LinkedList/ListNode.cpp +++ b/src/Plugins/DataStructure/LinkedList/ListNode.cpp @@ -1,59 +1,59 @@ /* This file is part of Rocs. Copyright 2011 Tomaz Canabrava 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "ListNode.h" #include #include "KDebug" DataPtr ListNode::create(DataStructurePtr parent) { return Data::create(parent); } ListNode::ListNode(DataStructurePtr parent): Data(parent) { } ListNode::~ListNode() { } QScriptValue ListNode::front(){ if (boost::shared_ptr n = next()){ return n->scriptValue(); } return 0; } -void ListNode::pointTo(boost::shared_ptr to ) +void ListNode::pointTo(ListNode* to ) { - addPointer(to); + addPointer(to->getData()); } boost::shared_ptr ListNode::next() const{ if (out_pointers().count() == 1 ){ if(boost::shared_ptr n = boost::static_pointer_cast( out_pointers().at(0)->to())){ return n; } } return boost::shared_ptr(); } diff --git a/src/Plugins/DataStructure/LinkedList/ListNode.h b/src/Plugins/DataStructure/LinkedList/ListNode.h index 292e2f16..94cd4687 100644 --- a/src/Plugins/DataStructure/LinkedList/ListNode.h +++ b/src/Plugins/DataStructure/LinkedList/ListNode.h @@ -1,43 +1,43 @@ /* This file is part of Rocs. Copyright 2011 Tomaz Canabrava 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef LISTNODE_H #define LISTNODE_H #include #include class ListNode : public Data { Q_OBJECT public: static DataPtr create(DataStructurePtr parent); ListNode(DataStructurePtr parent); ~ListNode(); boost::shared_ptr next() const; public slots: QScriptValue front(); - void pointTo(boost::shared_ptr to); + void pointTo(ListNode* to); }; #endif // LISTNODE_H diff --git a/src/Plugins/DataStructure/LinkedList/ListStructure.cpp b/src/Plugins/DataStructure/LinkedList/ListStructure.cpp index a5af903e..db4d57a2 100644 --- a/src/Plugins/DataStructure/LinkedList/ListStructure.cpp +++ b/src/Plugins/DataStructure/LinkedList/ListStructure.cpp @@ -1,217 +1,217 @@ /* This file is part of Rocs. Copyright 2011 Wagner Reck 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "ListStructure.h" #include "KDebug" #include "ListNode.h" #include "Pointer.h" #include #include namespace boost { void throw_exception( std::exception const & ) {} } DataStructurePtr Rocs::ListStructure::create(Document *parent) { return DataStructure::create(parent); } DataStructurePtr Rocs::ListStructure::create(DataStructurePtr other, Document *parent) { boost::shared_ptr ds = boost::static_pointer_cast(DataStructure::create(parent)); ds->importStructure(other); return ds; } Rocs::ListStructure::ListStructure ( Document* parent ) : DataStructure ( parent ) , m_building(true) { m_building = false; init(); } void Rocs::ListStructure::importStructure(DataStructurePtr other) { m_building = true; QHash < Data*, DataPtr > dataTodata; foreach(DataPtr n, other->dataList()){ DataPtr newdata = addData(n->name()); newdata->setColor(n->color()); newdata->setValue(n->value()); newdata->setX(n->x()); newdata->setY(n->y()); newdata->setWidth(n->width()); dataTodata.insert(n.get(), newdata); } foreach(PointerPtr e, other->pointers()){ DataPtr from = dataTodata.value(e->from().get()); DataPtr to = dataTodata.value(e->to().get()); PointerPtr newPointer = addPointer(from, to); newPointer->setColor(e->color()); newPointer->setValue(e->value()); } m_building = false; init(); } void Rocs::ListStructure::init() { m_animationGroup = new QParallelAnimationGroup(this); if (!dataList().isEmpty()){ m_begin = boost::static_pointer_cast( dataList().first()); arrangeNodes(); }else{ m_begin = boost::shared_ptr(); } } Rocs::ListStructure::~ListStructure() { m_animationGroup->deleteLater();; } PointerPtr Rocs::ListStructure::addPointer ( DataPtr from, DataPtr to ) { foreach(PointerPtr e, from->out_pointers() + from->self_pointers()){ e->remove(); } PointerPtr e = DataStructure::addPointer ( from, to ); arrangeNodes(); return e; } DataPtr Rocs::ListStructure::addData ( QString name ) { boost::shared_ptr n = boost::static_pointer_cast( ListNode::create(getDataStructure()) ); n->setName(name); if (m_building) { return addData(n);; } if (m_begin){ boost::shared_ptr tmp = m_begin; while (tmp->next() != 0) tmp = tmp->next(); - tmp->pointTo(n); + tmp->pointTo(n.get()); }else{ m_begin = n; } addData(n); arrangeNodes(); return n; } void Rocs::ListStructure::remove(DataPtr n) { if (m_begin == n){ m_begin = boost::static_pointer_cast(n)->next(); } DataStructure::remove(n); arrangeNodes(); } QScriptValue Rocs::ListStructure::begin() { return m_begin->scriptValue(); } -void Rocs::ListStructure::setBegin(boost::shared_ptr< ListNode > node) +void Rocs::ListStructure::setBegin(Data* node) { - m_begin = node; + m_begin = boost::static_pointer_cast(node->getData()); arrangeNodes(); } void Rocs::ListStructure::remove(PointerPtr ptr){ DataStructure::remove(ptr); arrangeNodes(); } QScriptValue Rocs::ListStructure::createNode(const QString & name){ boost::shared_ptr n = boost::static_pointer_cast(DataStructure::addData(ListNode::create(getDataStructure()))); n->setName(name); n->setEngine( engine() ); arrangeNodes(); return n->scriptValue(); } void Rocs::ListStructure::arrangeNodes(){ if (m_building) return; QRectF size = document()->size(); qreal x; qreal y = size.top() + 100;; if (m_animationGroup->state() != QAnimationGroup::Stopped){ m_animationGroup->stop(); } QScopedArrayPointervisited (new bool[dataList().count()]); for (int i = 0; i < dataList().count(); ++i){ visited[i] = false; } QPropertyAnimation * anim; boost::shared_ptr n = m_begin; if (n){ x = size.left() + 50; do{ if (visited[dataList().indexOf(n)]){ break; } visited[dataList().indexOf(n)] = true; if (x > size.right() - 140 + n->width()*40){ x = size.left() + 50 + n->width() * 40; y += 85; }else{ x += 70 + n->width()*40; } anim = new QPropertyAnimation(n.get(), "x");; anim->setDuration(500); anim->setStartValue(n->x()); anim->setEndValue(x); m_animationGroup->addAnimation(anim); anim = new QPropertyAnimation(n.get(), "y");; anim->setDuration(500); anim->setStartValue(n->y()); anim->setEndValue(y); m_animationGroup->addAnimation(anim); }while ((n = n->next())); } x = 50 + size.left(); y += 100; foreach (DataPtr n, dataList()){ if (!visited[dataList().indexOf(n)]){ anim = new QPropertyAnimation(n.get(), "x");; anim->setDuration(500); anim->setStartValue(n->x()); anim->setEndValue(x); m_animationGroup->addAnimation(anim); anim = new QPropertyAnimation(n.get(), "y");; anim->setDuration(500); anim->setStartValue(n->y()); anim->setEndValue(y); m_animationGroup->addAnimation(anim); x += 60; if (x > size.right() - 60){ x = 50 + size.left(); y += 50; } } } m_animationGroup->start(); } diff --git a/src/Plugins/DataStructure/LinkedList/ListStructure.h b/src/Plugins/DataStructure/LinkedList/ListStructure.h index 53d9953c..5fadc70d 100644 --- a/src/Plugins/DataStructure/LinkedList/ListStructure.h +++ b/src/Plugins/DataStructure/LinkedList/ListStructure.h @@ -1,71 +1,71 @@ /* This file is part of Rocs. Copyright 2011 Wagner Reck Copyright 2011 Tomaz Canabrava 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef LISTSTRUCTURE_H #define LISTSTRUCTURE_H #include "DataStructure.h" #include class ListNode; namespace Rocs{ class ListStructure : public DataStructure { Q_OBJECT public: using DataStructure::remove; using DataStructure::addPointer; using DataStructure::addData; static DataStructurePtr create(Document *parent); static DataStructurePtr create(DataStructurePtr other, Document *parent); ListStructure ( Document* parent = 0 ); void importStructure(DataStructurePtr other); virtual ~ListStructure(); public slots: virtual DataPtr addData ( QString name ); virtual void remove(DataPtr n); virtual PointerPtr addPointer ( DataPtr from, DataPtr to ); void arrangeNodes(); virtual void remove(PointerPtr e); QScriptValue begin(); - void setBegin(boost::shared_ptr node); + void setBegin(Data* node); QScriptValue createNode(const QString &name); private: void init(); void createFront(); boost::shared_ptr m_begin; QParallelAnimationGroup* m_animationGroup; bool m_building; }; } #endif // LISTSTRUCTURE_H