95
QScriptValue Rocs::GraphStructure::nodes()
97
QScriptValue array = engine()->newArray();
98
foreach(int type, document()->dataTypeList()) {
99
foreach(DataPtr n, dataList(type)) {
100
array.property("push").call(array, QScriptValueList() << n->scriptValue());
106
QScriptValue Rocs::GraphStructure::nodes(int type)
108
QScriptValue array = engine()->newArray();
109
foreach(DataPtr n, dataList(type)) {
110
array.property("push").call(array, QScriptValueList() << n->scriptValue());
115
QScriptValue Rocs::GraphStructure::edges()
117
QScriptValue array = engine()->newArray();
118
foreach(int type, document()->pointerTypeList()) {
119
foreach(PointerPtr n, pointers(type)) {
120
array.property("push").call(array, QScriptValueList() << n->scriptValue());
126
QScriptValue Rocs::GraphStructure::edges(int type)
128
QScriptValue array = engine()->newArray();
129
foreach(PointerPtr n, pointers(type)) {
130
array.property("push").call(array, QScriptValueList() << n->scriptValue());
135
QScriptValue Rocs::GraphStructure::createNode()
137
return createNode(0);
140
QScriptValue Rocs::GraphStructure::createNode(int type)
142
DataPtr n = createData("", type);
143
n->setEngine(engine());
144
return n->scriptValue();
147
QScriptValue Rocs::GraphStructure::createEdge(Data* fromRaw, Data* toRaw)
149
return createEdge(fromRaw, toRaw, 0);
152
QScriptValue Rocs::GraphStructure::createEdge(Data* fromRaw, Data* toRaw, int type)
154
if (fromRaw == 0 || toRaw == 0) {
155
kError() << "No edge added: data does not exist";
156
emit scriptError(i18n("Cannot create edge: nodes are not defined."));
157
return QScriptValue();
159
if (!document()->pointerTypeList().contains(type)) {
160
emit scriptError(i18n("Cannot create edge: pointer type %1 not defined", type));
161
return QScriptValue();
164
DataPtr from = fromRaw->getData();
165
DataPtr to = toRaw->getData();
167
PointerPtr edge = createPointer(from, to, type);
169
edge->setEngine(engine());
170
return edge->scriptValue();
172
kError() << "Could not add pointer to data structure";
174
return QScriptValue();
89
177
QScriptValue Rocs::GraphStructure::overlay_edges(int overlay)
91
//FIXME deprecate this method
92
QScriptValue array = engine()->newArray();
93
foreach(PointerPtr n, pointers(overlay)) {
94
array.property("push").call(array, QScriptValueList() << n->scriptValue());
179
emit scriptError(i18n("The global method \"%1\" is deprecated, please use \"%2\" instead.",
180
QString("overlay_edges(int type)"),
181
QString("edges(int type)")));
182
return edges(overlay);
99
185
QScriptValue Rocs::GraphStructure::list_nodes()
101
QScriptValue array = engine()->newArray();
102
foreach(int type, document()->dataTypeList()) {
103
foreach(DataPtr n, dataList(type)) {
104
array.property("push").call(array, QScriptValueList() << n->scriptValue());
187
emit scriptError(i18n("The global method \"%1\" is deprecated, please use \"%2\" instead.",
188
QString("list_nodes()"),
189
QString("nodes()")));
110
193
QScriptValue Rocs::GraphStructure::list_nodes(int type)
112
QScriptValue array = engine()->newArray();
113
foreach(DataPtr n, dataList(type)) {
114
array.property("push").call(array, QScriptValueList() << n->scriptValue());
195
emit scriptError(i18n("The global method \"%1\" is deprecated, please use \"%2\" instead.",
196
QString("list_nodes(int type)"),
197
QString("nodes(int type)")));
119
201
QScriptValue Rocs::GraphStructure::list_edges()
121
QScriptValue array = engine()->newArray();
122
foreach(int type, document()->pointerTypeList()) {
123
foreach(PointerPtr n, pointers(type)) {
124
array.property("push").call(array, QScriptValueList() << n->scriptValue());
203
emit scriptError(i18n("The global method \"%1\" is deprecated, please use \"%2\" instead.",
204
QString("list_edges()"),
205
QString("edges()")));
130
209
QScriptValue Rocs::GraphStructure::list_edges(int type)
132
QScriptValue array = engine()->newArray();
133
foreach(PointerPtr n, pointers(type)) {
134
array.property("push").call(array, QScriptValueList() << n->scriptValue());
211
emit scriptError(i18n("The global method \"%1\" is deprecated, please use \"%2\" instead.",
212
QString("list_edges(int type)"),
213
QString("edges(int type)")));
139
217
QScriptValue Rocs::GraphStructure::add_node(const QString& name)
141
DataPtr n = addData(name);
219
emit scriptError(i18n("The global method \"%1\" is deprecated, please use \"%2\" instead.",
220
QString("add_node(string name)"),
221
QString("createNode()")));
222
DataPtr n = createData(name, 0);
142
223
n->setEngine(engine());
143
224
return n->scriptValue();
146
227
QScriptValue Rocs::GraphStructure::add_edge(Data* fromRaw, Data* toRaw)
229
emit scriptError(i18n("The global method \"%1\" is deprecated, please use \"%2\" instead.",
230
QString("add_edge(from, to)"),
231
QString("createEdge(node from, node to)")));
148
232
return add_overlay_edge(fromRaw, toRaw, 0);
151
235
QScriptValue Rocs::GraphStructure::add_overlay_edge(Data* fromRaw, Data* toRaw, int overlay)
153
if (fromRaw == 0 || toRaw == 0) {
154
kError() << "No edge added: data does not exist";
155
return QScriptValue();
157
if (!document()->pointerTypeList().contains(overlay)) {
158
kError() << "No edge added: pointer type does not exist";
159
return QScriptValue();
162
DataPtr from = fromRaw->getData();
163
DataPtr to = toRaw->getData();
165
PointerPtr edge = addPointer(from, to, overlay);
167
edge->setEngine(engine());
168
return edge->scriptValue();
170
kError() << "Could not at this pointer to the data structure";
172
return QScriptValue();
237
emit scriptError(i18n("The global method \"%1\" is deprecated, please use \"%2\" instead.",
238
QString("add_overlay_edge(from, to, overlay)"),
239
QString("createEdge(node from, node to, int type)")));
240
return createEdge(fromRaw, toRaw, overlay);
175
243
QScriptValue Rocs::GraphStructure::dijkstra_shortest_path(Data* fromRaw, Data* toRaw)