[Ktutorial-commits] SF.net SVN: ktutorial:[108] trunk/ktutorial
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-02-26 18:55:58
|
Revision: 108 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=108&view=rev Author: danxuliu Date: 2010-02-26 18:55:44 +0000 (Fri, 26 Feb 2010) Log Message: ----------- Added convenience methods addOption(Option*, QString) and addWaitFor(WaitFor*, QString) to Step that request a change to another step identified by its id. It avoids the burden of creating a slot just to change to another step, as shown in the tutorials adapted to use them. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/Step.cpp trunk/ktutorial/ktutorial-library/src/Step.h trunk/ktutorial/ktutorial-library/src/Tutorial.cpp trunk/ktutorial/ktutorial-library/src/Tutorial.h trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h trunk/ktutorial/ktutorial-library/test/StepTest.cpp trunk/ktutorial/ktutorial-library/test/TutorialTest.cpp trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp trunk/ktutorial/ktutorial-test-app/TutorialClearText.cpp trunk/ktutorial/ktutorial-test-app/TutorialClearText.h trunk/ktutorial/ktutorial-test-app/TutorialClearText.js trunk/ktutorial/ktutorial-test-app/TutorialClearText.py trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h trunk/ktutorial/ktutorial-test-app/TutorialMoveText.py Modified: trunk/ktutorial/ktutorial-library/src/Step.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/Step.cpp 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-library/src/Step.cpp 2010-02-26 18:55:44 UTC (rev 108) @@ -41,56 +41,54 @@ } void Step::addOption(Option* option, QObject* receiver, const QString& slot) { - if (mOptions.contains(option)) { - kWarning() << "Option " << option->name() << " already added in step " << mId; + if (!addOption(option)) { return; } - QListIterator<Option*> it(mOptions); - while (it.hasNext()) { - if (it.next()->name() == option->name()) { - kWarning() << "Option named " << option->name() << " already added in step " << mId; - return; - } - } + bool deleteAddedObjectsInTearDownValue = mDeleteAddedObjectsInTearDown; + mDeleteAddedObjectsInTearDown = false; - option->setParent(this); + WaitForSignal* waitFor = new WaitForSignal(option, SIGNAL(selected())); + addWaitFor(waitFor, receiver, slot); - mOptions.append(option); + mOptionsWaitsFor.append(waitFor); + mDeleteAddedObjectsInTearDown = deleteAddedObjectsInTearDownValue; +} +void Step::addOption(Option* option, const QString& nextStepId) { + if (!addOption(option)) { + return; + } + bool deleteAddedObjectsInTearDownValue = mDeleteAddedObjectsInTearDown; mDeleteAddedObjectsInTearDown = false; WaitForSignal* waitFor = new WaitForSignal(option, SIGNAL(selected())); - addWaitFor(waitFor, receiver, slot); + addWaitFor(waitFor, nextStepId); mOptionsWaitsFor.append(waitFor); mDeleteAddedObjectsInTearDown = deleteAddedObjectsInTearDownValue; - - - if (mDeleteAddedObjectsInTearDown) { - mOptionsToBeDeletedInTearDown.append(option); - } } void Step::addWaitFor(WaitFor* waitFor, QObject* receiver, const QString& slot) { - if (mWaitsFor.contains(waitFor)) { - kWarning() << "Same WaitFor already added in step " << mId; + if (!addWaitFor(waitFor)) { return; } - waitFor->setActive(false); + connectWaitFor(waitFor, receiver, slot); +} - waitFor->setParent(this); +void Step::addWaitFor(WaitFor* waitFor, const QString& nextStepId) { + if (!addWaitFor(waitFor)) { + return; + } - mWaitsFor.append(waitFor); - connectWaitFor(waitFor, receiver, slot); + mNextStepForWaitFor.insert(waitFor, nextStepId); - if (mDeleteAddedObjectsInTearDown) { - mWaitsForToBeDeletedInTearDown.append(waitFor); - } + connect(waitFor, SIGNAL(waitEnded(WaitFor*)), + this, SLOT(requestNextStepForWaitFor(WaitFor*))); } void Step::removeOption(Option* option) { @@ -123,6 +121,12 @@ mWaitsFor.removeAt(mWaitsFor.indexOf(waitFor)); disconnectWaitFor(waitFor); + + if (mNextStepForWaitFor.contains(waitFor)) { + mNextStepForWaitFor.remove(waitFor); + disconnect(waitFor, SIGNAL(waitEnded(WaitFor*)), + this, SLOT(requestNextStepForWaitFor(WaitFor*))); + } } //protected: @@ -165,3 +169,55 @@ } mWaitsForToBeDeletedInTearDown.clear(); } + +bool Step::addOption(Option* option) { + if (mOptions.contains(option)) { + kWarning() << "Option " << option->name() << " already added in step " << mId; + return false; + } + + QListIterator<Option*> it(mOptions); + while (it.hasNext()) { + if (it.next()->name() == option->name()) { + kWarning() << "Option named " << option->name() << " already added in step " << mId; + return false; + } + } + + option->setParent(this); + + mOptions.append(option); + + if (mDeleteAddedObjectsInTearDown) { + mOptionsToBeDeletedInTearDown.append(option); + } + + return true; +} + +bool Step::addWaitFor(WaitFor* waitFor) { + if (mWaitsFor.contains(waitFor)) { + kWarning() << "Same WaitFor already added in step " << mId; + return false; + } + + waitFor->setActive(false); + + waitFor->setParent(this); + + mWaitsFor.append(waitFor); + + if (mDeleteAddedObjectsInTearDown) { + mWaitsForToBeDeletedInTearDown.append(waitFor); + } + + return true; +} + +//private slots: + +void Step::requestNextStepForWaitFor(WaitFor* waitFor) { + emit nextStepRequested(mNextStepForWaitFor.value(waitFor)); +} + +#include "Step.moc" Modified: trunk/ktutorial/ktutorial-library/src/Step.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/Step.h 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-library/src/Step.h 2010-02-26 18:55:44 UTC (rev 108) @@ -19,6 +19,7 @@ #ifndef STEP_H #define STEP_H +#include <QHash> #include <QList> #include <QObject> #include <QString> @@ -97,6 +98,14 @@ * } * \endcode * + * Sometimes, when a condition to wait for is met or an option is selected you + * may only want to change to another step, without further checks or actions. + * In these cases, you can create a slot that just changes to the next step and + * connect to it when adding the Option or WaitFor. But you can also use a + * shortcut: there are special versions of addOption and addWaitFor methods that + * receive the id of the next step to change to, which saves you the need to + * create a slot just for that. + * * When you need to perform something special when a Step is activated, you must * define a subclass of Step and redefine the setup() method in it. If something * must be performed when a Step is deactivated, you must redefine tearDown() @@ -218,6 +227,26 @@ const QString& slot); /** + * Adds an Option to this Step. + * When the Option is selected by the user, the tutorial this Step is part + * of will activate the step identified by nextStepId. + * + * This method only provides a shortcut to avoid creating an slot that + * just calls tutorial.nextStep(nextStepId). + * + * In evey other aspect, it behaves like + * addOption(Option*, QObject*, const QString&). See its documentation for + * further details. + * + * This method can be invoked from a script. + * + * @param option The Option to add. + * @param nextStep The id of the step to change to. + * @see addOption(Option*, QObject*, const QString&) + */ + Q_INVOKABLE void addOption(Option* option, const QString& nextStepId); + + /** * Adds a condition to wait for to this Step. * When the condition is met and this Step is active, the slot of the * receiver object is called. @@ -243,6 +272,26 @@ const QString& slot); /** + * Adds a condition to wait for to this Step. + * When the condition is met and this Step is active, the tutorial this Step + * is part of will activate the step identified by nextStepId. + * + * This method only provides a shortcut to avoid creating an slot that + * just calls tutorial.nextStep(nextStepId). + * + * In evey other aspect, it behaves like + * addWaitFor(WaitFor*, QObject*, const QString&). See its documentation for + * further details. + * + * This method can be invoked from a script. + * + * @param waitFor The condition to wait for. + * @param nextStep The id of the step to change to. + * @see addOption(Option*, QObject*, const QString&) + */ + Q_INVOKABLE void addWaitFor(WaitFor* waitFor, const QString& nextStepId); + + /** * Removes an Option from this Step. * The Option is reparented to null, so you must delete it explicitly. * @@ -258,8 +307,10 @@ * Removes a condition to wait for from this Step. * The slot of the receiver object associated when adding the WaitFor will * not be notified anymore when the condition is met (note that all the - * slots connected with waitEnded(WaitFor*) will be disconnected). The - * WaitFor will be also deactivated. + * slots connected with waitEnded(WaitFor*) will be disconnected). If the + * WaitFor was associated with a step id, the tutorial won't change to it + * anymore when the condition is met. In any case, the WaitFor will be also + * deactivated. * * The WaitFor is reparented to null, so you must delete it explicitly. * @@ -271,6 +322,17 @@ */ Q_INVOKABLE void removeWaitFor(WaitFor* waitFor); +Q_SIGNALS: + + /** + * Request a change to the next step. + * Don't connect nor emit this signal yourself. It is connected + * automatically by KTutorial. + * + * @param nextStepId The id of the Step to request a change to. + */ + void nextStepRequested(const QString& nextStepId); + protected: /** @@ -365,6 +427,12 @@ QList<WaitFor*> mWaitsForToBeDeletedInTearDown; /** + * Associates a condition to wait for with the id of the step to execute + * when the condition is met. + */ + QHash<WaitFor*, QString> mNextStepForWaitFor; + + /** * Wraps setup method to ensure that some code is executed before and after * inherited setup method. * It follows a Template Design Pattern. @@ -378,6 +446,35 @@ */ void tearDownWrapper(); + /** + * Adds a new Option. + * The Option is refused to be added if it is already added, or there is + * another Option with the same name. + * + * @param option The Option to add. + * @return True if the Option was added, false otherwise. + */ + bool addOption(Option* option); + + /** + * Adds a new WaitFor. + * The WaitFor is refused to be added if it is already added. + * + * @param waitFor The WaitFor to add. + * @return True if the WaitFor was added, false otherwise. + */ + bool addWaitFor(WaitFor* waitFor); + +private Q_SLOTS: + + /** + * Emits nextStepRequested(const QString&) with the id of the step + * associated to the given WaitFor. + * + * @param waitFor The WaitFor to request its associated step. + */ + void requestNextStepForWaitFor(WaitFor* waitFor); + }; #endif Modified: trunk/ktutorial/ktutorial-library/src/Tutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/Tutorial.cpp 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-library/src/Tutorial.cpp 2010-02-26 18:55:44 UTC (rev 108) @@ -38,6 +38,9 @@ step->setParent(this); mSteps.insert(step->id(), step); + + connect(step, SIGNAL(nextStepRequested(QString)), + this, SLOT(nextStep(QString))); } void Tutorial::start() { Modified: trunk/ktutorial/ktutorial-library/src/Tutorial.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/Tutorial.h 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-library/src/Tutorial.h 2010-02-26 18:55:44 UTC (rev 108) @@ -46,7 +46,9 @@ * first one to be activated. * * To activate a Step, any of Tutorial::nextStep must be called. You are advised - * to use the QString version for convenience. + * to use the QString version for convenience. Steps can activate another step + * when a condition is met or an option selected using an overloaded version of + * addOption and addWaitFor methods provided for convenience. * * The Tutorial finishes when the user closes it. It can happen in an * intermediate Step or when there are no more Steps. When making a Tutorial, @@ -117,6 +119,17 @@ void start(); /** + * Activates the next step in the Tutorial. + * Call this method when the Tutorial has to pass to another Step. Consider + * using nextStep(const QString&) instead for convenience. + * + * @param step The Step to change to. + */ + void nextStep(Step* step); + +public slots: + + /** * Activates the next Step in the Tutorial. * The identifier must be of one of the Steps added to this Tutorial. * @@ -127,20 +140,9 @@ * @param id The identifier of the next Step to set. * @see nextStep(Step*) */ - Q_INVOKABLE void nextStep(const QString& id); + void nextStep(const QString& id); /** - * Activates the next step in the Tutorial. - * Call this method when the Tutorial has to pass to another Step. Consider - * using nextStep(const QString&) instead for convenience. - * - * @param step The Step to change to. - */ - void nextStep(Step* step); - -public slots: - - /** * Finishes this Tutorial. * The current step is deactivated, this tutorial is cleaned, and finished * signal is emitted. Modified: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-26 18:55:44 UTC (rev 108) @@ -81,9 +81,8 @@ Q_OBJECT public: - CloseTextEditStep(UsingKTutorial* usingKTutorial): - Step("closeTextEdit"), - mUsingKTutorial(usingKTutorial) { + CloseTextEditStep(): + Step("closeTextEdit") { } virtual void setup() { @@ -91,22 +90,17 @@ "usingKTutorialTextEdit"); addWaitFor(new WaitForEvent(textEdit, QEvent::Close), - mUsingKTutorial, SLOT(closeTextEditDone())); + "moveWidgetPress"); } -private: - - UsingKTutorial* mUsingKTutorial; - }; class MoveWidgetPressStep: public Step { Q_OBJECT public: - MoveWidgetPressStep(UsingKTutorial* usingKTutorial): - Step("moveWidgetPress"), - mUsingKTutorial(usingKTutorial) { + MoveWidgetPressStep(): + Step("moveWidgetPress") { } virtual void setup() { @@ -114,22 +108,17 @@ findObject<view::StepWidget*>("ktutorial_StepWidget"); addWaitFor(new WaitForLeftMouseButtonPressed(mStepWidget), - mUsingKTutorial, SLOT(moveWidgetPressDone())); + "moveWidgetRelease"); } -private: - - UsingKTutorial* mUsingKTutorial; - }; class MoveWidgetReleaseStep: public Step { Q_OBJECT public: - MoveWidgetReleaseStep(UsingKTutorial* usingKTutorial): - Step("moveWidgetRelease"), - mUsingKTutorial(usingKTutorial) { + MoveWidgetReleaseStep(): + Step("moveWidgetRelease") { } virtual void setup() { @@ -137,13 +126,9 @@ findObject<view::StepWidget*>("ktutorial_StepWidget"); addWaitFor(new WaitForEvent(mStepWidget, QEvent::MouseButtonRelease), - mUsingKTutorial, SLOT(moveWidgetReleaseDone())); + "end"); } -private: - - UsingKTutorial* mUsingKTutorial; - }; //public: @@ -163,7 +148,7 @@ "works, or how to accomplish some task.</para>")); startStep->addOption(new Option(i18nc("@action", "Continue")), - this, SLOT(startDone())); + "singleOption"); addStep(startStep); @@ -177,7 +162,7 @@ "step.</para>")); singleOptionStep->addOption(new Option(i18nc("@action", "Continue")), - this, SLOT(singleOptionDone())); + "severalOptions"); addStep(singleOptionStep); @@ -189,9 +174,9 @@ "part of the tutorial, etcetera. Which option do you prefer?</para>")); severalOptionsStep->addOption(new Option(i18nc("@action", "Option 1")), - this, SLOT(severalOptionsOption1Selected())); + "option1Selected"); severalOptionsStep->addOption(new Option(i18nc("@action", "Option 2")), - this, SLOT(severalOptionsOption2Selected())); + "option2Selected"); addStep(severalOptionsStep); @@ -205,7 +190,7 @@ "written.</para>", i18nc("@action", "Option 1"))); option1SelectedStep->addOption(new Option(i18nc("@action", "Continue")), - this, SLOT(optionSelectedDone())); + "clearText"); addStep(option1SelectedStep); @@ -219,7 +204,7 @@ "written.</para>", i18nc("@action", "Option 2"))); option2SelectedStep->addOption(new Option(i18nc("@action", "Continue")), - this, SLOT(optionSelectedDone())); + "clearText"); addStep(option2SelectedStep); @@ -238,7 +223,7 @@ addStep(clearTextStep); //Step closeTextEdit - Step* closeTextEditStep = new CloseTextEditStep(this); + Step* closeTextEditStep = new CloseTextEditStep(); closeTextEditStep->setText(i18nc("@info", "<para>Do you see? You are in a new step, but you didn't tell the tutorial to " "continue to the next step, and neither you had to select between several " @@ -254,7 +239,7 @@ addStep(closeTextEditStep); //Step moveWidgetPress - Step* moveWidgetPressStep = new MoveWidgetPressStep(this); + Step* moveWidgetPressStep = new MoveWidgetPressStep(); moveWidgetPressStep->setText(i18nc("@info", "<para>You may have noticed that the tutorial window has no border. Does that " "mean that it can't be moved? Not at all. It can be dragged using the mouse " @@ -270,7 +255,7 @@ addStep(moveWidgetPressStep); //Step moveWidgetRelease - Step* moveWidgetReleaseStep = new MoveWidgetReleaseStep(this); + Step* moveWidgetReleaseStep = new MoveWidgetReleaseStep(); moveWidgetReleaseStep->setText(i18nc("@info", "<para>Now, and without releasing the button, move the mouse and the window " "will be moved. Once you release the button, the window will be kept in the " @@ -299,26 +284,6 @@ //public slots: -void UsingKTutorial::startDone() { - nextStep("singleOption"); -} - -void UsingKTutorial::singleOptionDone() { - nextStep("severalOptions"); -} - -void UsingKTutorial::severalOptionsOption1Selected() { - nextStep("option1Selected"); -} - -void UsingKTutorial::severalOptionsOption2Selected() { - nextStep("option2Selected"); -} - -void UsingKTutorial::optionSelectedDone() { - nextStep("clearText"); -} - void UsingKTutorial::clearTextTextModified() { QTextEdit* textEdit = KTutorial::self()-> findObject<QTextEdit*>("usingKTutorialTextEdit"); @@ -328,18 +293,6 @@ } } -void UsingKTutorial::closeTextEditDone() { - nextStep("moveWidgetPress"); -} - -void UsingKTutorial::moveWidgetPressDone() { - nextStep("moveWidgetRelease"); -} - -void UsingKTutorial::moveWidgetReleaseDone() { - nextStep("end"); -} - //protected: void UsingKTutorial::tearDown() { Modified: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h 2010-02-26 18:55:44 UTC (rev 108) @@ -29,24 +29,8 @@ public Q_SLOTS: - void startDone(); - - void singleOptionDone(); - - void severalOptionsOption1Selected(); - - void severalOptionsOption2Selected(); - - void optionSelectedDone(); - void clearTextTextModified(); - void closeTextEditDone(); - - void moveWidgetPressDone(); - - void moveWidgetReleaseDone(); - protected: void tearDown(); Modified: trunk/ktutorial/ktutorial-library/test/StepTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/StepTest.cpp 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-library/test/StepTest.cpp 2010-02-26 18:55:44 UTC (rev 108) @@ -48,11 +48,15 @@ void thirdDummySignal(); + void fourthDummySignal(); + private: int mDummySlotCallCount; int mAnotherDummySlotCallCount; + void assertStepId(const QSignalSpy& spy, int index, const QString& stepId); + private slots: void init() { @@ -69,6 +73,7 @@ void testAddOption(); void testAddOptionWithoutSlotMacro(); + void testAddOptionAssociatedToStepId(); void testAddOptionSeveralOptions(); void testAddOptionDuringSetup(); void testAddOptionNormalAndDuringSetup(); @@ -77,15 +82,18 @@ void testAddWaitFor(); void testAddWaitForWithoutSlotMacro(); + void testAddWaitForAssociatedToStepId(); void testAddWaitForSeveralWaitFors(); void testAddWaitForDuringSetup(); void testAddWaitForNormalAndDuringSetup(); void testAddWaitForTwice(); void testRemoveOption(); + void testRemoveOptionAssociatedToStepId(); void testRemoveOptionSeveralOptions(); void testRemoveWaitFor(); + void testRemoveWaitForAssociatedToStepId(); void testRemoveWaitForSeveralWaitFors(); }; @@ -236,6 +244,30 @@ QCOMPARE(mDummySlotCallCount, 1); } +void StepTest::testAddOptionAssociatedToStepId() { + Step step("doSomethingConstructive"); + + Option* option1 = new Option("Bathe your iguana"); + + step.addOption(option1, "batheYourIguanaStep"); + connect(this, SIGNAL(dummySignal()), option1, SIGNAL(selected())); + + QSignalSpy nextStepRequestedSpy(&step, SIGNAL(nextStepRequested(QString))); + + QCOMPARE(option1->parent(), &step); + QCOMPARE(step.options().count(), 1); + QVERIFY(step.options().contains(option1)); + QCOMPARE(nextStepRequestedSpy.count(), 0); + + emit dummySignal(); + QCOMPARE(nextStepRequestedSpy.count(), 0); + + step.setActive(true); + emit dummySignal(); + QCOMPARE(nextStepRequestedSpy.count(), 1); + assertStepId(nextStepRequestedSpy, 0, "batheYourIguanaStep"); +} + void StepTest::testAddOptionSeveralOptions() { Step step("doSomethingConstructive"); @@ -251,25 +283,45 @@ step.addOption(option3, this, SLOT(dummySlot())); connect(this, SIGNAL(dummySignal()), option3, SIGNAL(selected())); + Option* option4 = new Option("Lull the penguin"); + step.addOption(option4, "lullThePenguinStep"); + connect(this, SIGNAL(anotherDummySignal()), option4, SIGNAL(selected())); + + Option* option5 = new Option("Pamper the Tasmanian devil"); + step.addOption(option5, "pamperTheTasmanianDevilStep"); + connect(this, SIGNAL(dummySignal()), option5, SIGNAL(selected())); + + QSignalSpy nextStepRequestedSpy(&step, SIGNAL(nextStepRequested(QString))); + QCOMPARE(option1->parent(), &step); QCOMPARE(option2->parent(), &step); QCOMPARE(option3->parent(), &step); - QCOMPARE(step.options().count(), 3); + QCOMPARE(option4->parent(), &step); + QCOMPARE(option5->parent(), &step); + QCOMPARE(step.options().count(), 5); QVERIFY(step.options().contains(option1)); QVERIFY(step.options().contains(option2)); QVERIFY(step.options().contains(option3)); + QVERIFY(step.options().contains(option4)); + QVERIFY(step.options().contains(option5)); QCOMPARE(mDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 0); emit dummySignal(); emit anotherDummySignal(); QCOMPARE(mDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 0); step.setActive(true); emit anotherDummySignal(); QCOMPARE(mDummySlotCallCount, 1); + QCOMPARE(nextStepRequestedSpy.count(), 1); + assertStepId(nextStepRequestedSpy, 0, "lullThePenguinStep"); emit dummySignal(); QCOMPARE(mDummySlotCallCount, 3); + QCOMPARE(nextStepRequestedSpy.count(), 2); + assertStepId(nextStepRequestedSpy, 1, "pamperTheTasmanianDevilStep"); } void StepTest::testAddOptionDuringSetup() { @@ -333,12 +385,12 @@ step.addOption(option1, this, SLOT(dummySlot())); connect(this, SIGNAL(dummySignal()), option1, SIGNAL(selected())); - //This second option isn't really needed, but it is used to be sure that no - //strange side effects occur after adding the first option again Option* option2 = new Option("Feed a toucan"); - step.addOption(option2, this, SLOT(dummySlot())); + step.addOption(option2, "feedAToucanStep"); + connect(this, SIGNAL(dummySignal()), option2, SIGNAL(selected())); step.addOption(option1, this, SLOT(anotherDummySlot())); + step.addOption(option2, "feedAPigeonStep"); QCOMPARE(option1->parent(), &step); QCOMPARE(option2->parent(), &step); @@ -346,10 +398,14 @@ QVERIFY(step.options().contains(option1)); QVERIFY(step.options().contains(option2)); + QSignalSpy nextStepRequestedSpy(&step, SIGNAL(nextStepRequested(QString))); + step.setActive(true); emit dummySignal(); QCOMPARE(mDummySlotCallCount, 1); QCOMPARE(mAnotherDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 1); + assertStepId(nextStepRequestedSpy, 0, "feedAToucanStep"); } void StepTest::testAddOptionDifferentOptionsWithSameName() { @@ -359,29 +415,37 @@ step.addOption(option1, this, SLOT(dummySlot())); connect(this, SIGNAL(dummySignal()), option1, SIGNAL(selected())); - //This second option isn't really needed, but it is used to be sure that no - //strange side effects occur after adding the option with the repeated name Option* option2 = new Option("Feed a toucan"); - step.addOption(option2, this, SLOT(dummySlot())); + step.addOption(option2, "feedAToucanStep"); + connect(this, SIGNAL(dummySignal()), option2, SIGNAL(selected())); - //It will not be added and thus not deleted by parent Step, so it is created - //in stack + //They will not be added and thus not deleted by parent Step, so they are + //created in stack Option option3("Bathe your iguana"); + Option option4("Feed a toucan"); step.addOption(&option3, this, SLOT(anotherDummySlot())); connect(this, SIGNAL(dummySignal()), &option3, SIGNAL(selected())); + step.addOption(&option4, "feedAToucanStep2"); + connect(this, SIGNAL(dummySignal()), &option4, SIGNAL(selected())); + QCOMPARE(option1->parent(), &step); QCOMPARE(option2->parent(), &step); QCOMPARE(option3.parent(), (QObject*)0); + QCOMPARE(option4.parent(), (QObject*)0); QCOMPARE(step.options().count(), 2); QVERIFY(step.options().contains(option1)); QVERIFY(step.options().contains(option2)); + QSignalSpy nextStepRequestedSpy(&step, SIGNAL(nextStepRequested(QString))); + step.setActive(true); emit dummySignal(); QCOMPARE(mDummySlotCallCount, 1); QCOMPARE(mAnotherDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 1); + assertStepId(nextStepRequestedSpy, 0, "feedAToucanStep"); } void StepTest::testAddWaitFor() { @@ -424,6 +488,29 @@ QCOMPARE(mDummySlotCallCount, 1); } +void StepTest::testAddWaitForAssociatedToStepId() { + Step step("doSomethingConstructive"); + + WaitFor* waitFor1 = new WaitForSignal(this, SIGNAL(dummySignal())); + + step.addWaitFor(waitFor1, "batheYourIguanaStep"); + + QSignalSpy nextStepRequestedSpy(&step, SIGNAL(nextStepRequested(QString))); + + QCOMPARE(waitFor1->parent(), &step); + QCOMPARE(step.mWaitsFor.count(), 1); + QVERIFY(step.mWaitsFor.contains(waitFor1)); + QCOMPARE(nextStepRequestedSpy.count(), 0); + + emit dummySignal(); + QCOMPARE(nextStepRequestedSpy.count(), 0); + + step.setActive(true); + emit dummySignal(); + QCOMPARE(nextStepRequestedSpy.count(), 1); + assertStepId(nextStepRequestedSpy, 0, "batheYourIguanaStep"); +} + void StepTest::testAddWaitForSeveralWaitFors() { Step step("doSomethingConstructive"); @@ -434,31 +521,50 @@ step.addWaitFor(waitFor2, this, SLOT(dummySlot())); WaitFor* waitFor3 = new WaitForSignal(this, SIGNAL(thirdDummySignal())); - step.addWaitFor(waitFor3, this, SLOT(dummySlot())); + step.addWaitFor(waitFor3, "batheYourIguanaStep"); + WaitFor* waitFor4 = new WaitForSignal(this, SIGNAL(fourthDummySignal())); + step.addWaitFor(waitFor4, "feedAToucanStep"); + + QSignalSpy nextStepRequestedSpy(&step, SIGNAL(nextStepRequested(QString))); + QCOMPARE(waitFor1->parent(), &step); QCOMPARE(waitFor2->parent(), &step); QCOMPARE(waitFor3->parent(), &step); - QCOMPARE(step.mWaitsFor.count(), 3); + QCOMPARE(waitFor4->parent(), &step); + QCOMPARE(step.mWaitsFor.count(), 4); QVERIFY(step.mWaitsFor.contains(waitFor1)); QVERIFY(step.mWaitsFor.contains(waitFor2)); QVERIFY(step.mWaitsFor.contains(waitFor3)); + QVERIFY(step.mWaitsFor.contains(waitFor4)); QCOMPARE(mDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 0); emit dummySignal(); emit anotherDummySignal(); emit thirdDummySignal(); + emit fourthDummySignal(); QCOMPARE(mDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 0); step.setActive(true); emit anotherDummySignal(); QCOMPARE(mDummySlotCallCount, 1); + QCOMPARE(nextStepRequestedSpy.count(), 0); emit dummySignal(); QCOMPARE(mDummySlotCallCount, 2); + QCOMPARE(nextStepRequestedSpy.count(), 0); emit thirdDummySignal(); - QCOMPARE(mDummySlotCallCount, 3); + QCOMPARE(mDummySlotCallCount, 2); + QCOMPARE(nextStepRequestedSpy.count(), 1); + assertStepId(nextStepRequestedSpy, 0, "batheYourIguanaStep"); + + emit fourthDummySignal(); + QCOMPARE(mDummySlotCallCount, 2); + QCOMPARE(nextStepRequestedSpy.count(), 2); + assertStepId(nextStepRequestedSpy, 1, "feedAToucanStep"); } void StepTest::testAddWaitForDuringSetup() { @@ -516,12 +622,11 @@ WaitFor* waitFor1 = new WaitForSignal(this, SIGNAL(dummySignal())); step.addWaitFor(waitFor1, this, SLOT(dummySlot())); - //This second WaitFor isn't really needed, but it is used to be sure that no - //strange side effects occur after adding the first WaitFor again WaitFor* waitFor2 = new WaitForSignal(this, SIGNAL(anotherDummySignal())); - step.addWaitFor(waitFor2, this, SLOT(dummySlot())); + step.addWaitFor(waitFor2, "batheYourIguanaStep"); step.addWaitFor(waitFor1, this, SLOT(anotherDummySlot())); + step.addWaitFor(waitFor2, "batheYourChameleonStep"); QCOMPARE(waitFor1->parent(), &step); QCOMPARE(waitFor2->parent(), &step); @@ -533,6 +638,12 @@ emit dummySignal(); QCOMPARE(mDummySlotCallCount, 1); QCOMPARE(mAnotherDummySlotCallCount, 0); + + QSignalSpy nextStepRequestedSpy(&step, SIGNAL(nextStepRequested(QString))); + + emit anotherDummySignal(); + QCOMPARE(nextStepRequestedSpy.count(), 1); + assertStepId(nextStepRequestedSpy, 0, "batheYourIguanaStep"); } void StepTest::testRemoveOption() { @@ -564,6 +675,36 @@ QCOMPARE(mAnotherDummySlotCallCount, 0); } +void StepTest::testRemoveOptionAssociatedToStepId() { + Step step("doSomethingConstructive"); + + Option* option1 = new Option("Bathe your iguana"); + step.addOption(option1, "batheYourIguanaStep"); + connect(this, SIGNAL(dummySignal()), option1, SIGNAL(selected())); + + //It will be removed and not deleted by parent Step, so it is created in + //stack + Option option2("Feed a toucan"); + step.addOption(&option2, "feedAToucanStep"); + connect(this, SIGNAL(dummySignal()), &option2, SIGNAL(selected())); + + step.removeOption(&option2); + + QSignalSpy nextStepRequestedSpy(&step, SIGNAL(nextStepRequested(QString))); + + QCOMPARE(option1->parent(), &step); + QCOMPARE(option2.parent(), (QObject*)0); + QCOMPARE(step.options().count(), 1); + QVERIFY(step.options().contains(option1)); + QVERIFY(!step.options().contains(&option2)); + QCOMPARE(nextStepRequestedSpy.count(), 0); + + step.setActive(true); + emit dummySignal(); + QCOMPARE(nextStepRequestedSpy.count(), 1); + assertStepId(nextStepRequestedSpy, 0, "batheYourIguanaStep"); +} + void StepTest::testRemoveOptionSeveralOptions() { Step step("doSomethingConstructive"); @@ -581,33 +722,65 @@ step.addOption(&option3, this, SLOT(anotherDummySlot())); connect(this, SIGNAL(dummySignal()), &option3, SIGNAL(selected())); + Option option4("Lull the penguin"); + step.addOption(&option4, "lullThePenguinStep"); + connect(this, SIGNAL(dummySignal()), &option4, SIGNAL(selected())); + + Option option5("Pamper the Tasmanian Devil"); + step.addOption(&option5, "pamperTheTasmanianDevilStep"); + connect(this, SIGNAL(dummySignal()), &option5, SIGNAL(selected())); + + QSignalSpy nextStepRequestedSpy(&step, SIGNAL(nextStepRequested(QString))); + step.removeOption(&option1); step.removeOption(&option3); + step.removeOption(&option5); QCOMPARE(option1.parent(), (QObject*)0); QCOMPARE(option2.parent(), &step); QCOMPARE(option3.parent(), (QObject*)0); - QCOMPARE(step.options().count(), 1); + QCOMPARE(option4.parent(), &step); + QCOMPARE(option5.parent(), (QObject*)0); + QCOMPARE(step.options().count(), 2); QVERIFY(step.options().contains(&option2)); + QVERIFY(step.options().contains(&option4)); QVERIFY(!step.options().contains(&option1)); QVERIFY(!step.options().contains(&option3)); + QVERIFY(!step.options().contains(&option5)); QCOMPARE(mDummySlotCallCount, 0); QCOMPARE(mAnotherDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 0); step.setActive(true); emit dummySignal(); QCOMPARE(mDummySlotCallCount, 1); QCOMPARE(mAnotherDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 1); + assertStepId(nextStepRequestedSpy, 0, "lullThePenguinStep"); step.removeOption(&option2); QCOMPARE(option2.parent(), (QObject*)0); - QCOMPARE(step.options().count(), 0); + QCOMPARE(step.options().count(), 1); + QVERIFY(step.options().contains(&option4)); QVERIFY(!step.options().contains(&option2)); emit dummySignal(); QCOMPARE(mDummySlotCallCount, 1); QCOMPARE(mAnotherDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 2); + assertStepId(nextStepRequestedSpy, 1, "lullThePenguinStep"); + + step.removeOption(&option4); + + QCOMPARE(option4.parent(), (QObject*)0); + QCOMPARE(step.options().count(), 0); + QVERIFY(!step.options().contains(&option4)); + + emit dummySignal(); + QCOMPARE(mDummySlotCallCount, 1); + QCOMPARE(mAnotherDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 2); } void StepTest::testRemoveWaitFor() { @@ -642,6 +815,39 @@ QCOMPARE(mAnotherDummySlotCallCount, 0); } +void StepTest::testRemoveWaitForAssociatedToStepId() { + Step step("doSomethingConstructive"); + + WaitForSignal* waitFor1 = new WaitForSignal(this, SIGNAL(dummySignal())); + step.addWaitFor(waitFor1, "batheYourIguanaStep"); + + //It will be removed and not deleted by parent Step, so it is created in + //stack + WaitForSignal waitFor2(this, SIGNAL(anotherDummySignal())); + step.addWaitFor(&waitFor2, "feedAToucanStep"); + + QSignalSpy nextStepRequestedSpy(&step, SIGNAL(nextStepRequested(QString))); + + step.setActive(true); + + step.removeWaitFor(&waitFor2); + + QCOMPARE(waitFor1->parent(), &step); + QCOMPARE(waitFor2.parent(), (QObject*)0); + QCOMPARE(step.mWaitsFor.count(), 1); + QVERIFY(step.mWaitsFor.contains(waitFor1)); + QVERIFY(!step.mWaitsFor.contains(&waitFor2)); + QVERIFY(waitFor1->isActive()); + QVERIFY(!waitFor2.isActive()); + QCOMPARE(nextStepRequestedSpy.count(), 0); + + waitFor2.setActive(true); + emit dummySignal(); + emit anotherDummySignal(); + QCOMPARE(nextStepRequestedSpy.count(), 1); + assertStepId(nextStepRequestedSpy, 0, "batheYourIguanaStep"); +} + void StepTest::testRemoveWaitForSeveralWaitFors() { Step step("doSomethingConstructive"); @@ -654,8 +860,13 @@ step.addWaitFor(&waitFor2, this, SLOT(dummySlot())); WaitForSignal waitFor3(this, SIGNAL(thirdDummySignal())); - step.addWaitFor(&waitFor3, this, SLOT(anotherDummySlot())); + step.addWaitFor(&waitFor3, "batheYourIguanaStep"); + WaitForSignal waitFor4(this, SIGNAL(fourthDummySignal())); + step.addWaitFor(&waitFor4, "feedAToucanStep"); + + QSignalSpy nextStepRequestedSpy(&step, SIGNAL(nextStepRequested(QString))); + step.setActive(true); step.removeWaitFor(&waitFor1); @@ -664,15 +875,19 @@ QCOMPARE(waitFor1.parent(), (QObject*)0); QCOMPARE(waitFor2.parent(), &step); QCOMPARE(waitFor3.parent(), (QObject*)0); - QCOMPARE(step.mWaitsFor.count(), 1); + QCOMPARE(waitFor4.parent(), &step); + QCOMPARE(step.mWaitsFor.count(), 2); QVERIFY(step.mWaitsFor.contains(&waitFor2)); + QVERIFY(step.mWaitsFor.contains(&waitFor4)); QVERIFY(!step.mWaitsFor.contains(&waitFor1)); QVERIFY(!step.mWaitsFor.contains(&waitFor3)); QVERIFY(!waitFor1.isActive()); QVERIFY(waitFor2.isActive()); QVERIFY(!waitFor3.isActive()); + QVERIFY(waitFor4.isActive()); QCOMPARE(mDummySlotCallCount, 0); QCOMPARE(mAnotherDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 0); step.setActive(true); waitFor1.setActive(true); @@ -680,21 +895,45 @@ emit dummySignal(); emit anotherDummySignal(); emit thirdDummySignal(); + emit fourthDummySignal(); QCOMPARE(mDummySlotCallCount, 1); QCOMPARE(mAnotherDummySlotCallCount, 0); + QCOMPARE(nextStepRequestedSpy.count(), 1); + assertStepId(nextStepRequestedSpy, 0, "feedAToucanStep"); step.removeWaitFor(&waitFor2); QCOMPARE(waitFor2.parent(), (QObject*)0); - QCOMPARE(step.mWaitsFor.count(), 0); + QCOMPARE(step.mWaitsFor.count(), 1); + QVERIFY(step.mWaitsFor.contains(&waitFor4)); QVERIFY(!step.mWaitsFor.contains(&waitFor2)); QVERIFY(!waitFor2.isActive()); waitFor2.setActive(true); emit dummySignal(); QCOMPARE(mDummySlotCallCount, 1); + + step.removeWaitFor(&waitFor4); + + QCOMPARE(waitFor4.parent(), (QObject*)0); + QCOMPARE(step.mWaitsFor.count(), 0); + QVERIFY(!step.mWaitsFor.contains(&waitFor4)); + QVERIFY(!waitFor4.isActive()); + + waitFor4.setActive(true); + emit fourthDummySignal(); + QCOMPARE(nextStepRequestedSpy.count(), 1); } +/////////////////////////////////// Helpers //////////////////////////////////// + +void StepTest::assertStepId(const QSignalSpy& spy, int index, + const QString& stepId) { + QVariant argument = spy.at(index).at(0); + QCOMPARE(argument.type(), QVariant::String); + QCOMPARE(argument.toString(), stepId); +} + QTEST_MAIN(StepTest) #include "StepTest.moc" Modified: trunk/ktutorial/ktutorial-library/test/TutorialTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/TutorialTest.cpp 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-library/test/TutorialTest.cpp 2010-02-26 18:55:44 UTC (rev 108) @@ -44,6 +44,7 @@ void testStartNoStartStep(); void testNextStepId(); + void testNextStepIdRequestedFromStep(); void testNextStepIdWithInvalidId(); void testNextStepStep(); @@ -53,6 +54,18 @@ }; +class StepToRequestNextStep: public Step { +public: + + StepToRequestNextStep(const QString& id): Step(id) { + } + + void emitNextStepRequested(const QString& nextStepId) { + emit nextStepRequested(nextStepId); + } + +}; + class MockTutorial: public Tutorial { public: @@ -255,6 +268,35 @@ QVERIFY(step1->isActive()); } +void TutorialTest::testNextStepIdRequestedFromStep() { + Tutorial tutorial(new TutorialInformation("pearlOrientation")); + + StepToRequestNextStep* stepStart = new StepToRequestNextStep("start"); + tutorial.addStep(stepStart); + + Step* step1 = new Step("record"); + tutorial.addStep(step1); + + tutorial.addStep(new Step("roll")); + tutorial.addStep(new Step("send")); + + tutorial.start(); + + //Step* must be registered in order to be used with QSignalSpy + int stepStarType = qRegisterMetaType<Step*>("Step*"); + QSignalSpy stepActivatedSpy(&tutorial, SIGNAL(stepActivated(Step*))); + + stepStart->emitNextStepRequested("record"); + + QCOMPARE(stepActivatedSpy.count(), 1); + QVariant argument = stepActivatedSpy.at(0).at(0); + QCOMPARE(argument.userType(), stepStarType); + QCOMPARE(qvariant_cast<Step*>(argument), step1); + QCOMPARE(tutorial.mCurrentStep, step1); + QVERIFY(!stepStart->isActive()); + QVERIFY(step1->isActive()); +} + void TutorialTest::testNextStepIdWithInvalidId() { Tutorial tutorial(new TutorialInformation("pearlOrientation")); Modified: trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp 2010-02-26 18:55:44 UTC (rev 108) @@ -207,8 +207,7 @@ out << "function option1Selected() { tutorial.nextStep(\"first\"); }\n"; out << "startStep.addOption(option1, self, \"option1Selected()\");\n"; - out << "function option2Selected() { tutorial.nextStep(\"second\"); }\n"; - out << "startStep.addOption(option2, self, \"option2Selected()\");\n"; + out << "startStep.addOption(option2, \"second\");\n"; out.flush(); ScriptedTutorial scriptedTutorial(mTemporaryFile->fileName()); @@ -243,11 +242,15 @@ out << "tutorial.addStep(startStep);\n"; out << "firstStep = ktutorial.newStep(\"first\");\n"; out << "tutorial.addStep(firstStep);\n"; + out << "secondStep = ktutorial.newStep(\"second\");\n"; + out << "tutorial.addStep(secondStep);\n"; out << "waitForDummy = ktutorial.newWaitFor(\"WaitForSignal\");\n"; out << "waitForDummy.setSignal(testObject, \"dummySignal()\");\n"; out << "waitForOtherDummy = ktutorial.newWaitFor(\"WaitForSignal\");\n"; out << "waitForOtherDummy.setSignal(testObject, \"otherDummySignal()\");\n"; + out << "waitForAnotherDummy = ktutorial.newWaitFor(\"WaitForSignal\");\n"; + out << "waitForAnotherDummy.setSignal(testObject, \"anotherDummySignal()\");\n"; out << "startStep.addWaitFor(waitForDummy, testObject, \"dummySlot()\");\n"; @@ -257,6 +260,8 @@ out << " }\n"; out << "};\n"; out << "startStep.addWaitFor(waitForOtherDummy, self, \"checkEnded()\");\n"; + + out << "firstStep.addWaitFor(waitForAnotherDummy, \"second\");\n"; out.flush(); ScriptedTutorial scriptedTutorial(mTemporaryFile->fileName()); @@ -283,6 +288,10 @@ QCOMPARE(scriptedTutorial.mCurrentStep->id(), QString("first")); QCOMPARE(mDummySlotCallCount, 1); + + emit anotherDummySignal(); + + QCOMPARE(scriptedTutorial.mCurrentStep->id(), QString("second")); } void ScriptingTest::fullTutorial() { @@ -342,11 +351,7 @@ out << "waitForChildAddedEvent = ktutorial.newWaitFor(\"WaitForEvent\");\n"; out << "waitForChildAddedEvent.setEvent(testObject, \"ChildAdded\");\n"; - out << "function thirdDone() {\n"; - out << " tutorial.nextStep(\"end\");\n"; - out << "};\n"; - out << "thirdStep.addWaitFor(waitForChildAddedEvent, \ -self, \"thirdDone\");\n"; + out << "thirdStep.addWaitFor(waitForChildAddedEvent, \"end\");\n"; out.flush(); Modified: trunk/ktutorial/ktutorial-test-app/TutorialClearText.cpp =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialClearText.cpp 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-test-app/TutorialClearText.cpp 2010-02-26 18:55:44 UTC (rev 108) @@ -49,7 +49,7 @@ QObject* clearAction = KTutorial::self()->findObject<QObject*>("clear"); clearTextStep->addWaitFor(new WaitForSignal(clearAction, SIGNAL(triggered(bool))), - this, SLOT(clearTextDone())); + "end"); addStep(clearTextStep); @@ -70,7 +70,3 @@ nextStep("clearText"); } } - -void TutorialClearText::clearTextDone() { - nextStep("end"); -} Modified: trunk/ktutorial/ktutorial-test-app/TutorialClearText.h =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialClearText.h 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-test-app/TutorialClearText.h 2010-02-26 18:55:44 UTC (rev 108) @@ -31,8 +31,6 @@ void startDone(); - void clearTextDone(); - }; #endif Modified: trunk/ktutorial/ktutorial-test-app/TutorialClearText.js =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialClearText.js 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-test-app/TutorialClearText.js 2010-02-26 18:55:44 UTC (rev 108) @@ -47,12 +47,8 @@ waitForClearTriggered = ktutorial.newWaitFor("WaitForSignal"); waitForClearTriggered.setSignal(clearAction, "triggered(bool)"); -clearTextStep.addWaitFor(waitForClearTriggered, self, "clearTextDone()"); +clearTextStep.addWaitFor(waitForClearTriggered, "end"); -function clearTextDone() { - tutorial.nextStep("end"); -} - tutorial.addStep(clearTextStep); //Step 3 Modified: trunk/ktutorial/ktutorial-test-app/TutorialClearText.py =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialClearText.py 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-test-app/TutorialClearText.py 2010-02-26 18:55:44 UTC (rev 108) @@ -48,11 +48,8 @@ waitForClearTriggered = ktutorial.newWaitFor("WaitForSignal") waitForClearTriggered.setSignal(clearAction, "triggered(bool)") -clearTextStep.addWaitFor(waitForClearTriggered, self, "clearTextDone()") +clearTextStep.addWaitFor(waitForClearTriggered, "end") -def clearTextDone(): - tutorial.nextStep("end") - tutorial.addStep(clearTextStep) #Step 3 Modified: trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp 2010-02-26 18:55:44 UTC (rev 108) @@ -95,7 +95,7 @@ KAction* cutAction = KTutorial::self()->findObject<KAction*>("edit_cut"); keyboardCutStep->addWaitFor(new WaitForSignal(cutAction, SIGNAL(triggered(bool))), - this, SLOT(keyboardCut())); + "keyboardMoveCursor"); addStep(keyboardCutStep); @@ -123,7 +123,7 @@ mousePressStep->setText(i18nc("@info", "Press with the left button of the mouse on the selected text. You must press on it, or the selection will change, and you will have to select it again. Don't release the button yet.")); mousePressStep->addWaitFor(new WaitForLeftMouseButtonPressed(mTextArea->viewport()), - this, SLOT(mousePress())); + "mouseRelease"); addStep(mousePressStep); @@ -141,7 +141,7 @@ showOtherWayStep->setText(i18nc("@info", "As explained, there are two ways to move text in a text area: using the mouse and using the keyboard. Do you want to see the other way?")); showOtherWayStep->addOption(new Option(i18n("Yes, please")), this, SLOT(showOtherWay())); - showOtherWayStep->addOption(new Option(i18n("No, thanks")), this, SLOT(end())); + showOtherWayStep->addOption(new Option(i18n("No, thanks")), "end"); addStep(showOtherWayStep); @@ -182,10 +182,6 @@ } } -void TutorialMoveText::keyboardCut() { - nextStep("keyboardMoveCursor"); -} - void TutorialMoveText::keyboardMoveCursor() { if (mTextArea->textCursor().position() == 0) { nextStep("keyboardPaste"); @@ -200,10 +196,6 @@ } } -void TutorialMoveText::mousePress() { - nextStep("mouseRelease"); -} - void TutorialMoveText::mouseRelease() { if (mSecondPath) { nextStep("end"); @@ -221,10 +213,6 @@ nextStep("write"); } -void TutorialMoveText::end() { - nextStep("end"); -} - //protected: void TutorialMoveText::setup() { Modified: trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h 2010-02-26 18:55:44 UTC (rev 108) @@ -39,20 +39,14 @@ void select(); - void keyboardCut(); - void keyboardMoveCursor(); void keyboardPaste(); - void mousePress(); - void mouseRelease(); void showOtherWay(); - void end(); - protected: void setup(); Modified: trunk/ktutorial/ktutorial-test-app/TutorialMoveText.py =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialMoveText.py 2010-02-25 06:02:45 UTC (rev 107) +++ trunk/ktutorial/ktutorial-test-app/TutorialMoveText.py 2010-02-26 18:55:44 UTC (rev 108) @@ -117,11 +117,8 @@ cutAction = ktutorial.findObject("edit_cut") waitForCutTriggered = ktutorial.newWaitFor("WaitForSignal") waitForCutTriggered.setSignal(cutAction, "triggered(bool)") -keyboardCutStep.addWaitFor(waitForCutTriggered, self, "keyboardCut()") +keyboardCutStep.addWaitFor(waitForCutTriggered, "keyboardMoveCursor") -def keyboardCut(): - tutorial.nextStep("keyboardMoveCursor") - tutorial.addStep(keyboardCutStep) #Step keyboardMoveCursor @@ -163,11 +160,8 @@ waitForMousePressed = ktutorial.newWaitFor("WaitForSignal") waitForMousePressed.setSignal(mouseFilter, "mousePressed()") -mousePressStep.addWaitFor(waitForMousePressed, self, "mousePress()") +mousePressStep.addWaitFor(waitForMousePressed, "mouseRelease") -def mousePress(): - tutorial.nextStep("mouseRelease") - tutorial.addStep(mousePressStep) #Step mouseRelease @@ -200,11 +194,8 @@ flags["mousePathSelected"] = not flags["mousePathSelected"] tutorial.nextStep("write") -showOtherWayStep.addOption(ktutorial.newOption(t.i18n("No, thanks")), self, "end()") +showOtherWayStep.addOption(ktutorial.newOption(t.i18n("No, thanks")), "end") -def end(): - tutorial.nextStep("end") - tutorial.addStep(showOtherWayStep) #Step end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |