File indexing completed on 2024-12-22 04:17:22
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2011 Joshua Netterfield * 0004 * joshua.netterfield@gmail.com * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #include "scriptinterface.h" 0014 0015 #include "namedobject.h" 0016 #include "object.h" 0017 0018 #include <QStringList> 0019 0020 namespace Kst { 0021 0022 QString ScriptInterface::doNamedObjectCommand(QString command, NamedObject *n) { 0023 static int iTest=0; 0024 0025 if (command.startsWith("setName(")) { 0026 command.remove("setName(").chop(1); 0027 n->setDescriptiveName(command); 0028 return QString("Done"); 0029 } else if (command.startsWith("name(")) { 0030 return n->Name(); 0031 } else if (command.startsWith("descriptionTip(")) { 0032 return n->descriptionTip(); 0033 } else if (command.startsWith("testCommand(")) { 0034 qDebug() << "Named object test command" << iTest++; 0035 return QString("Done"); 0036 } 0037 0038 return QString(); 0039 } 0040 0041 QString ScriptInterface::doObjectCommand(QString command, ObjectPtr ob) { 0042 0043 QString v=doNamedObjectCommand(command, ob); 0044 if (!v.isEmpty()) { 0045 return v; 0046 } 0047 0048 if (command.startsWith("type(")) { 0049 return ob->typeString(); 0050 } 0051 0052 return QString(); 0053 } 0054 0055 // convenience functions... for parsing commands. 0056 QStringList ScriptInterface::getArgs(const QString &command) { 0057 int i0 = command.indexOf('(')+1; 0058 int i1 = command.lastIndexOf(')'); 0059 int n = i1-i0; 0060 0061 QString x = command.mid(i0,n); 0062 return x.split(','); 0063 } 0064 0065 QString ScriptInterface::getArg(const QString &command) { 0066 int i0 = command.indexOf('(')+1; 0067 int i1 = command.lastIndexOf(')'); 0068 int n = i1-i0; 0069 0070 QString x = command.mid(i0,n); 0071 return x; 0072 0073 } 0074 0075 }