From 7cd827898ba8bf837dfc4e329b045f8708d41a6f Mon Sep 17 00:00:00 2001 From: Jorge Cuadrado Date: Fri, 12 Oct 2007 18:08:59 -0500 Subject: [PATCH] Finished expand frame implementation --- tests/command/command.pro | 1 + tests/command/expandframe/expandframe.pro | 14 +++++ tests/command/expandframe/test_expandframe.cpp | 74 ++++++++++++++++++++++++++ yamf/common/inthash.h | 19 ++++++- yamf/model/command/expandframe.cpp | 26 +++++++-- yamf/model/command/expandframe.h | 2 +- yamf/model/command/insertframe.cpp | 2 +- yamf/model/layer.h | 1 - 8 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 tests/command/expandframe/expandframe.pro create mode 100644 tests/command/expandframe/test_expandframe.cpp diff --git a/tests/command/command.pro b/tests/command/command.pro index b57c1d0..3a74489 100644 --- a/tests/command/command.pro +++ b/tests/command/command.pro @@ -7,6 +7,7 @@ SUBDIRS += rename \ addlayer \ addframe \ addobject \ + expandframe \ convertitem \ ungroupitem \ groupitem \ diff --git a/tests/command/expandframe/expandframe.pro b/tests/command/expandframe/expandframe.pro new file mode 100644 index 0000000..daa07be --- /dev/null +++ b/tests/command/expandframe/expandframe.pro @@ -0,0 +1,14 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Thu Jun 14 12:58:57 2007 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . + +# Input +SOURCES += test_expandframe.cpp + +include(../../tests_config.pri) + diff --git a/tests/command/expandframe/test_expandframe.cpp b/tests/command/expandframe/test_expandframe.cpp new file mode 100644 index 0000000..b4c9218 --- /dev/null +++ b/tests/command/expandframe/test_expandframe.cpp @@ -0,0 +1,74 @@ + +#include + +#include +#include + +#include +#include +#include +#include +#include + + +class TestExpandFrame: public QObject +{ + Q_OBJECT + private slots: + void initTestCase(); + void cleanupTestCase(); + + void execute(); + void unexecute(); + void toXml(); + + private: + YAMF::Model::Project *project; + YAMF::Command::ExpandFrame *cmd; + YAMF::Common::IntHash frames; +}; + +void TestExpandFrame::initTestCase() +{ + project = new YAMF::Model::Project; + + YAMF::Model::Scene *scene = project->createScene(); + YAMF::Model::Layer *layer = scene->createLayer(); + YAMF::Model::Frame *frame = layer->createFrame(); + frames = layer->frames(); + + cmd = new YAMF::Command::ExpandFrame(frame, &frames, 10); +} + +void TestExpandFrame::cleanupTestCase() +{ + delete cmd; + delete project; +} + +void TestExpandFrame::execute() +{ + cmd->redo(); + QCOMPARE(frames.visualIndices().count(), 11); + QCOMPARE(frames.count(), 1 ); +} + +void TestExpandFrame::unexecute() +{ + cmd->undo(); + QCOMPARE(frames.visualIndices().count(), 1); + QCOMPARE(frames.count(), 1 ); +} + +void TestExpandFrame::toXml() +{ + QString result = cmd->toXml().simplified(); + QString expected = QString(" ").simplified(); + + QCOMPARE(result, expected); +} + + +QTEST_MAIN(TestExpandFrame) +#include "test_expandframe.moc" + diff --git a/yamf/common/inthash.h b/yamf/common/inthash.h index 8b88736..8e1fc58 100644 --- a/yamf/common/inthash.h +++ b/yamf/common/inthash.h @@ -76,6 +76,7 @@ class YAMF_EXPORT IntHash void remove(T value); void expandValue(int index); + void reduceValue(int index); T value(int index) const; T operator[](int index) const; @@ -256,6 +257,22 @@ void IntHash::expandValue(int index) d->visualIndices.insert(index+1, value); } +template +void IntHash::reduceValue(int index) +{ + if(0 <= index && index < d->visualIndices.count()) + { + if( d->visualIndices[index] == d->visualIndices[index+1]) + { + d->visualIndices.removeAt( index+1 ); + } + else + { + dfDebug << "can't reduce value"; + } + } +} + template T IntHash::value(int index) const @@ -278,8 +295,6 @@ QList IntHash::visualValues() const { visualValues << d->logicalIndices.value(pos); } - - return visualValues; } diff --git a/yamf/model/command/expandframe.cpp b/yamf/model/command/expandframe.cpp index 57d980d..6db8d0e 100644 --- a/yamf/model/command/expandframe.cpp +++ b/yamf/model/command/expandframe.cpp @@ -51,7 +51,24 @@ ExpandFrame::~ExpandFrame() QString ExpandFrame::toXml() const { - return ""; + QDomDocument doc; + + QDomElement root = doc.createElement("expandframe"); + + QDomElement information = doc.createElement("information"); + information.setAttribute("size", d->size); + information.setAttribute("name", d->frame->frameName()); + root.appendChild(information); + + QDomElement location = doc.createElement("location"); + location.setAttribute("index", d->frame->visualIndex()); + location.setAttribute("scene", d->frame->scene()->visualIndex()); + location.setAttribute("layer", d->frame->layer()->visualIndex()); + root.appendChild(location); + + doc.appendChild(root); + + return doc.toString(); } void ExpandFrame::execute() @@ -59,14 +76,17 @@ void ExpandFrame::execute() for(int i = 0; i < d->size; i++) { d->frames->expandValue(d->frame->visualIndex()); -// d->frames.insert(visualIndex+i+1, toExpand); } d->frame->setRepeat(d->frame->repeat()+d->size); } void ExpandFrame::unexecute() { - //TODO: implementar y probar el undo + for(int i = 0; i < d->size; i++) + { + d->frames->reduceValue(d->frame->visualIndex()); + } + d->frame->setRepeat(d->frame->repeat()-d->size); } } diff --git a/yamf/model/command/expandframe.h b/yamf/model/command/expandframe.h index 936a30e..0205534 100644 --- a/yamf/model/command/expandframe.h +++ b/yamf/model/command/expandframe.h @@ -40,7 +40,7 @@ class YAMF_EXPORT ExpandFrame : public YAMF::Command::Base { public: ExpandFrame( YAMF::Model::Frame *frame, YAMF::Common::IntHash *frames, int size ); - ~ExpandFrame(); + virtual ~ExpandFrame(); virtual QString toXml() const; virtual void execute(); virtual void unexecute(); diff --git a/yamf/model/command/insertframe.cpp b/yamf/model/command/insertframe.cpp index bc86897..7d52000 100644 --- a/yamf/model/command/insertframe.cpp +++ b/yamf/model/command/insertframe.cpp @@ -99,7 +99,7 @@ QString InsertFrame::toXml() const doc.appendChild(root); root.appendChild(d->frame->toXml(doc)); - + return doc.toString(); } diff --git a/yamf/model/layer.h b/yamf/model/layer.h index 15b13a6..74a1de1 100644 --- a/yamf/model/layer.h +++ b/yamf/model/layer.h @@ -85,7 +85,6 @@ class YAMF_EXPORT Layer : public QObject, public Common::AbstractSerializable bool moveFrame(int from, int to); bool expandFrame(int visualIndex, int size); - Frame *frame(int logicalIndex) const; Scene *scene() const; Project *project() const; -- 2.11.4.GIT