From 9234ff8237b201f259e0fe8563233d85bb03fcfe Mon Sep 17 00:00:00 2001 From: Jorge Cuadrado Date: Fri, 19 Oct 2007 13:07:26 -0500 Subject: [PATCH] - Used visual index for all model operation --- tests/command/rename/test_rename.cpp | 7 +++++-- yamf/common/inthash.cpp | 10 +++++++++- yamf/drawing/paintarea.cpp | 1 + yamf/model/command/removeframe.cpp | 2 +- yamf/model/command/removelayer.cpp | 3 +-- yamf/model/layer.cpp | 17 ++++++++--------- yamf/model/layer.h | 4 ++-- yamf/model/project.h | 2 +- yamf/model/scene.cpp | 17 ++++++++--------- yamf/model/scene.h | 4 ++-- 10 files changed, 38 insertions(+), 29 deletions(-) diff --git a/tests/command/rename/test_rename.cpp b/tests/command/rename/test_rename.cpp index a8f2251..abfea6b 100644 --- a/tests/command/rename/test_rename.cpp +++ b/tests/command/rename/test_rename.cpp @@ -9,7 +9,6 @@ #include #include #include -#include class TestRename: public QObject @@ -18,6 +17,10 @@ class TestRename: public QObject private slots: void execute(); void unexecute(); + + private: + YAMF::Model::Project *project; + }; void TestRename::execute() @@ -37,7 +40,7 @@ void TestRename::unexecute() scene.setSceneName("new name"); - project.commandManager()->history()->undo(); + //project.commandManager()->history()->undo(); QCOMPARE(scene.sceneName(), original ); } diff --git a/yamf/common/inthash.cpp b/yamf/common/inthash.cpp index f8e6edb..99ed4fd 100644 --- a/yamf/common/inthash.cpp +++ b/yamf/common/inthash.cpp @@ -121,7 +121,15 @@ void IntHash::moveVisual(int from, int to) template bool IntHash::containsVisual(int pos) { - return pos >= 0 && pos < visualIndices().count(); + QList visualValues; + int count = 0; + foreach(YAMFPrivate::VisualIndex vindex, d->visualIndices) + { + count += vindex.count(); + } + + + return pos >= 0 && pos < count; } template diff --git a/yamf/drawing/paintarea.cpp b/yamf/drawing/paintarea.cpp index 55a9ab5..45fb061 100644 --- a/yamf/drawing/paintarea.cpp +++ b/yamf/drawing/paintarea.cpp @@ -905,6 +905,7 @@ Photogram *PaintArea::photogram() const */ void PaintArea::setCurrentFrame(int sceneIndex, int layerIndex, int frameIndex) { +// dfDebug << "scene = " << sceneIndex << " layer = " << layerIndex << "frame = " << frameIndex; Model::Scene *scene = d->project->scene(sceneIndex); // if( scene ) diff --git a/yamf/model/command/removeframe.cpp b/yamf/model/command/removeframe.cpp index b5e2937..557d3ca 100644 --- a/yamf/model/command/removeframe.cpp +++ b/yamf/model/command/removeframe.cpp @@ -89,7 +89,6 @@ Model::Location RemoveFrame::location() const */ void RemoveFrame::execute() { - D_SHOW_VAR(d->frame->visualIndex()); d->frames->removeVisual(d->frame->visualIndex()); } @@ -100,6 +99,7 @@ void RemoveFrame::execute() void RemoveFrame::unexecute() { d->frames->insert(d->index, d->frame); + d->index = d->frame->visualIndex(); } /** diff --git a/yamf/model/command/removelayer.cpp b/yamf/model/command/removelayer.cpp index 73889a6..02a1e52 100644 --- a/yamf/model/command/removelayer.cpp +++ b/yamf/model/command/removelayer.cpp @@ -32,7 +32,6 @@ struct RemoveLayer::Private Common::IntHash *layers; Model::Layer *layer; - int position; int index; int scene; }; @@ -93,7 +92,7 @@ void RemoveLayer::execute() */ void RemoveLayer::unexecute() { - d->layers->insert(d->position, d->layer); + d->layers->insert(d->index, d->layer); d->index = d->layer->visualIndex(); } diff --git a/yamf/model/layer.cpp b/yamf/model/layer.cpp index 733818e..91a9be9 100644 --- a/yamf/model/layer.cpp +++ b/yamf/model/layer.cpp @@ -238,15 +238,14 @@ Model::Location Layer::location() const /** - * Remueve el marco que esta en la posición @p logicalIndex. + * Remueve el marco que esta en la posición @p visualIndex. */ -bool Layer::removeFrame(int position) +bool Layer::removeFrame(int visualIndex) { - Frame *toRemove = frame(position); - int visual = toRemove->visualIndex(); + Frame *toRemove = frame(visualIndex); if ( toRemove ) { - d->frames.removeVisual(visual); + d->frames.removeVisual(visualIndex); toRemove->setRepeat(toRemove->repeat()-1); if(toRemove->repeat() < 1) @@ -298,15 +297,15 @@ bool Layer::expandFrame(int visualIndex, int size) /** * Retorna el frame que esta en la posición @p logicalIndex. */ -Frame *Layer::frame(int logicalIndex) const +Frame *Layer::frame(int visualIndex) const { - if ( !d->frames.contains(logicalIndex) ) + if ( !d->frames.containsVisual(visualIndex) ) { - D_FUNCINFO << " FATAL ERROR: index out of bound " << logicalIndex; + D_FUNCINFO << " FATAL ERROR: index out of bound " << "layer " << this->visualIndex() << " frame " << visualIndex; return 0; } - return d->frames.value(logicalIndex); + return d->frames.visualValue(visualIndex); } diff --git a/yamf/model/layer.h b/yamf/model/layer.h index fe94a37..7d92f0a 100644 --- a/yamf/model/layer.h +++ b/yamf/model/layer.h @@ -84,11 +84,11 @@ class YAMF_EXPORT Layer : public QObject, public Common::AbstractSerializable Location location() const; public: - bool removeFrame(int logicalIndex); + bool removeFrame(int visualIndex); bool moveFrame(int from, int to); bool expandFrame(int visualIndex, int size); - Frame *frame(int logicalIndex) const; + Frame *frame(int visualIndex) const; Scene *scene() const; Project *project() const; diff --git a/yamf/model/project.h b/yamf/model/project.h index 68101e5..63876e3 100644 --- a/yamf/model/project.h +++ b/yamf/model/project.h @@ -85,7 +85,7 @@ class YAMF_EXPORT Project : public QObject, public Common::AbstractSerializable void insertScene(Scene *scene, int visualIndex); void addScene(Scene *scene); void removeScene(Scene *scene); - bool moveScene(int logicalIndex, int newPosition); + bool moveScene(int position, int newPosition); void clear(); void loadLibrary(const QString &filename); diff --git a/yamf/model/scene.cpp b/yamf/model/scene.cpp index b524ce1..00ba399 100644 --- a/yamf/model/scene.cpp +++ b/yamf/model/scene.cpp @@ -175,17 +175,16 @@ AudioLayer *Scene::createAudioLayer(int position, const QString &name) /** * @~spanish - * Remueve la capa que esta en la posición @p logicalIndex. + * Remueve la capa que esta en la posición @p visualIndex. * FIXME */ -bool Scene::removeLayer( int logicalIndex) +bool Scene::removeLayer( int visualIndex) { - Layer *layer = this->layer(logicalIndex); + Layer *layer = this->layer(visualIndex); if ( layer ) { - d->layers.removeAll(logicalIndex); + d->layers.removeAll(visualIndex); delete layer; - return true; } @@ -198,15 +197,15 @@ bool Scene::removeLayer( int logicalIndex) * @param position * @return */ -Layer *Scene::layer(int logicalIndex) const +Layer *Scene::layer(int visualIndex) const { - if ( !d->layers.contains(logicalIndex) ) + if ( !d->layers.containsVisual(visualIndex) ) { - D_FUNCINFO << " FATAL ERROR: index out of bound " << logicalIndex; + D_FUNCINFO << " FATAL ERROR: index out of bound " << visualIndex; return 0; } - return d->layers.value(logicalIndex); + return d->layers.visualValue(visualIndex); } /** diff --git a/yamf/model/scene.h b/yamf/model/scene.h index b8e9cba..5ca79fb 100644 --- a/yamf/model/scene.h +++ b/yamf/model/scene.h @@ -73,14 +73,14 @@ class YAMF_EXPORT Scene : public QObject, public Common::AbstractSerializable AudioLayers audioLayers() const; AudioLayer *createAudioLayer(int visualIndex = -1, const QString &name = QString()); - Layer *layer(int logicalIndex) const; + Layer *layer(int visualIndex) const; Model::Layer *createLayer(int visualIndex = -1, const QString &name = QString()); void insertLayer(int visualIndex, Model::Layer *layer); void addLayer(Model::Layer *layer); void removeLayer(Model::Layer *layer); - bool removeLayer(int logicalIndex); + bool removeLayer(int visualIndex); bool moveLayer(int from, int to); -- 2.11.4.GIT