25 #include <boost/shared_ptr.hpp>
30 return DataStructure::create<ListStructure>(parent);
35 boost::shared_ptr<ListStructure> ds = boost::static_pointer_cast<
ListStructure>(create(parent));
51 QHash < Data*, DataPtr > dataTodata;
52 foreach (
int type, other->document()->dataTypeList()) {
53 foreach (
DataPtr n, other->dataList(type)) {
55 newdata->setColor(n->color());
56 newdata->setProperty(
"value", n->property(
"value").toString());
57 newdata->setX(n->x());
58 newdata->setY(n->y());
59 newdata->setWidth(n->width());
60 dataTodata.insert(n.get(), newdata);
61 foreach (
const QString &property, other->document()->dataType(type)->properties()) {
62 newdata->setProperty(property.toLatin1(), n->property(property.toLatin1()));
66 foreach (
int type, other->document()->pointerTypeList()) {
67 foreach (
PointerPtr e, other->pointers(type)) {
68 DataPtr from = dataTodata.value(e->from().get());
69 DataPtr to = dataTodata.value(e->to().get());
71 PointerPtr newPointer = createPointer(from, to, type);
72 newPointer->setColor(e->color());
73 newPointer->setProperty(
"value", e->property(
"value").toString());
74 foreach (
const QString &property, other->document()->pointerType(type)->properties()) {
75 newPointer->setProperty(property.toLatin1(), e->property(property.toLatin1()));
84 void Rocs::ListStructure::init()
86 connect(
this, SIGNAL(changed()),
this, SLOT(arrangeNodes()));
88 m_animationGroup =
new QParallelAnimationGroup(parent());
89 if (!dataList(0).isEmpty()) {
90 m_begin = boost::static_pointer_cast<
ListNode>(dataList(0).first());
97 m_animationGroup->stop();
105 foreach(
PointerPtr e, from->outPointerList()) {
115 boost::shared_ptr<ListNode> n = boost::static_pointer_cast<
ListNode>(
118 n->setProperty(
"name", name);
130 m_begin = boost::static_pointer_cast<
ListNode>(n)->next();
137 return m_begin->scriptValue();
152 emit scriptError(i18n(
"The method \"%1\" is deprecated, please use \"%2\" instead.",
160 emit scriptError(i18n(
"The method \"%1\" is deprecated, please use \"%2\" instead.",
161 QString(
"setBegin(node)"),
162 QString(
"setHead(node)")));
173 return createNode(0);
178 boost::shared_ptr<ListNode> n = boost::static_pointer_cast<
ListNode>(
182 return n->scriptValue();
185 void Rocs::ListStructure::arrangeNodes()
193 qreal y = size.top() + 100;;
194 if (m_animationGroup->state() != QAnimationGroup::Stopped) {
195 m_animationGroup->stop();
198 QScopedArrayPointer<bool>visited(
new bool[dataList(0).count()]);
199 for (
int i = 0; i < dataList(0).count(); ++i) {
203 QPropertyAnimation * anim;
204 boost::shared_ptr<ListNode> n = m_begin;
206 x = size.left() + 50;
208 if (visited[dataList(0).indexOf(n)]) {
211 visited[dataList(0).indexOf(n)] =
true;
212 if (x > size.right() - 140 + n->width() * 40) {
213 x = size.left() + 50 + n->width() * 40;
216 x += 70 + n->width() * 40;
218 anim =
new QPropertyAnimation(n.get(),
"x");;
219 anim->setDuration(500);
220 anim->setStartValue(n->x());
221 anim->setEndValue(x);
222 m_animationGroup->addAnimation(anim);
223 anim =
new QPropertyAnimation(n.get(),
"y");;
224 anim->setDuration(500);
225 anim->setStartValue(n->y());
226 anim->setEndValue(y);
227 m_animationGroup->addAnimation(anim);
228 }
while ((n = n->next()));
230 x = 50 + size.left();
233 foreach(
DataPtr n, dataList(0)) {
234 if (!visited[dataList(0).indexOf(n)]) {
235 anim =
new QPropertyAnimation(n.get(),
"x");;
236 anim->setDuration(500);
237 anim->setStartValue(n->x());
238 anim->setEndValue(x);
239 m_animationGroup->addAnimation(anim);
240 anim =
new QPropertyAnimation(n.get(),
"y");;
241 anim->setDuration(500);
242 anim->setStartValue(n->y());
243 anim->setEndValue(y);
244 m_animationGroup->addAnimation(anim);
246 if (x > size.right() - 60) {
247 x = 50 + size.left();
252 m_animationGroup->start();
PointerPtr createPointer(DataPtr from, DataPtr to, int pointerType)
Internal method to create new graph edge.
void importStructure(DataStructurePtr other)
overwrites the current DataStructure with all values (Data and Pointer) from the given datastructure ...
Q_INVOKABLE QScriptValue begin()
Use head();.
virtual void setEngine(QScriptEngine *_engine)
Set script engine.
boost::shared_ptr< DataStructure > DataStructurePtr
void createData(const std::string &str)
static DataPtr create(DataStructurePtr parent, int uniqueIdentifier, int dataType)
Q_INVOKABLE void setHead(Data *headNode)
Set head node of linked list.
boost::shared_ptr< Pointer > PointerPtr
DataPtr addData(DataPtr data)
Q_INVOKABLE QScriptValue head()
Q_INVOKABLE void setBegin(Data *node)
Use setHead(node);.
Q_INVOKABLE QScriptValue createNode()
Creates a new data element and return it.
virtual PointerPtr createPointer(DataPtr from, DataPtr to, int pointerType)
Creates new pointer from data element "from" to data element "to" of given type "pointerType".
virtual DataPtr getData() const
void remove()
if this datastructure shall be deleted, call ONLY this function
DataPtr createData(const QString &name, int dataType)
Internal method to create new graph node.
boost::shared_ptr< Data > DataPtr
static DataStructurePtr create(Document *parent)
ListStructure(Document *parent=0)