Finished expand frame implementation
[dashstudio.git] / src / dash / commandparser.cpp
blob9ae4d3a69472931ed47d8ddb014df65eb2efe62d
1 /***************************************************************************
2 * Copyright (C) 2007 by David Cuadrado *
3 * krawek@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include "commandparser.h"
24 #include <yamf/model/command/base.h>
25 #include "datasource.h"
27 #include <dcore/debug.h>
29 namespace Dash {
31 struct CommandParser::Private
33 Private() : currentSource(0) {}
35 DataSource *currentSource;
38 CommandParser::CommandParser() : DCore::XmlParserBase(), d(new Private)
42 CommandParser::~CommandParser()
44 delete d;
47 bool CommandParser::startTag(const QString &tag, const QXmlAttributes &atts)
49 if( atts.count() > 0 )
51 DataSource::Values values;
53 for(int i = 0; i < atts.count(); i++)
55 QString qname = atts.qName(i);
56 values[qname] = atts.value(qname);
59 d->currentSource->setValues(tag, values);
62 if( tag == "addobject" || tag == "removeobject" )
64 d->currentSource->setType(DataSource::Object);
66 else if( tag == "insertscene" || tag == "removescene" || tag == "movescene" || tag == "renamescene" )
68 d->currentSource->setType(DataSource::Scene);
70 else if( tag == "insertlayer" || tag == "removelayer" || tag == "locklayer" || tag == "changelayervisibility"|| tag == "movelayer" || tag == "renamelayer")
72 d->currentSource->setType(DataSource::Layer);
74 else if( tag == "insertframe" || tag == "removeframe" || tag == "lockframe" || tag == "changeframevisibility" || tag == "moveframe" || tag == "renameframe" || tag == "expandframe" )
76 d->currentSource->setType(DataSource::Frame);
78 else if( tag == "addlibraryobject" || tag == "removelibraryobject" )
80 d->currentSource->setType(DataSource::Library);
83 #if 0
84 else if( tag == "" )
87 else if( tag == "" )
90 else if( tag == "" )
93 else if( tag == "" )
96 else if( tag == "" )
99 else if( tag == "" )
102 else if( tag == "" )
105 else if( tag == "" )
108 else if( tag == "" )
111 else if( tag == "" )
114 #endif
116 return true;
119 bool CommandParser::endTag(const QString &tag)
121 return true;
124 void CommandParser::text(const QString &text)
128 DataSource *CommandParser::build(const YAMF::Command::Base *command)
130 QString xml = command->toXml();
132 d->currentSource = new DataSource;
133 d->currentSource->setData("command", qVariantFromValue(command) );
134 d->currentSource->setData("xml", xml);
136 if( ! DCore::XmlParserBase::parse(xml) )
138 dError() << "Failed to parse";
139 return 0;
142 d->currentSource->setData("root", root());
144 DataSource *source = d->currentSource;
145 d->currentSource = 0;
147 return source;