[Ktutorial-commits] SF.net SVN: ktutorial:[315] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2011-05-28 04:00:22
|
Revision: 315 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=315&view=rev Author: danxuliu Date: 2011-05-28 04:00:15 +0000 (Sat, 28 May 2011) Log Message: ----------- Provide completion in the step id line edits. StepDataWidget proposes the unused ids from all the reactions (except for the reactions of the own step), and ReactionWidget proposes the ids of all the steps (except for the step that the reaction belongs to). Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/EditActions.cpp trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.h trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.h trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/StepDataWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/EditActions.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/EditActions.cpp 2011-05-25 03:00:55 UTC (rev 314) +++ trunk/ktutorial/ktutorial-editor/src/EditActions.cpp 2011-05-28 04:00:15 UTC (rev 315) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -264,7 +264,8 @@ parentCommand->setText(i18nc("@action", "Add step")); TutorialCommands(mTutorialEditor->tutorial()).addStep(step, parentCommand); - CommandWidget* widget = new StepDataWidget(step); + StepDataWidget* widget = new StepDataWidget(step); + widget->enableStepIdCompletion(mTutorialEditor->tutorial()); widget->setParentUndoCommand(parentCommand); if (showEditionDialog(widget) == QDialog::Rejected) { delete parentCommand; @@ -274,7 +275,9 @@ void EditActions::setStepData() { Q_ASSERT(mCurrentStep); - showEditionDialog(new StepDataWidget(mCurrentStep)); + StepDataWidget* widget = new StepDataWidget(mCurrentStep); + widget->enableStepIdCompletion(mTutorialEditor->tutorial()); + showEditionDialog(widget); } void EditActions::setStepSetup() { @@ -303,7 +306,8 @@ parentCommand->setText(i18nc("@action", "Add reaction")); StepCommands(mCurrentStep).addReaction(reaction, parentCommand); - CommandWidget* widget = new ReactionWidget(reaction); + ReactionWidget* widget = new ReactionWidget(reaction); + widget->enableStepIdCompletion(mTutorialEditor->tutorial(), mCurrentStep); widget->setParentUndoCommand(parentCommand); if (showEditionDialog(widget) == QDialog::Rejected) { delete parentCommand; @@ -313,7 +317,9 @@ void EditActions::setReactionData() { Q_ASSERT(mCurrentReaction); - showEditionDialog(new ReactionWidget(mCurrentReaction)); + ReactionWidget* widget = new ReactionWidget(mCurrentReaction); + widget->enableStepIdCompletion(mTutorialEditor->tutorial()); + showEditionDialog(widget); } void EditActions::removeReaction() { Modified: trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp 2011-05-25 03:00:55 UTC (rev 314) +++ trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp 2011-05-28 04:00:15 UTC (rev 315) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -22,6 +22,8 @@ #include "WaitForWidget.h" #include "../commands/ReactionCommands.h" #include "../data/Reaction.h" +#include "../data/Step.h" +#include "../data/Tutorial.h" #include "../data/WaitFor.h" //public: @@ -75,6 +77,20 @@ delete ui; } +void ReactionWidget::enableStepIdCompletion(const Tutorial* tutorial, + const Step* ownStep /*= 0*/) { + QStringList stepIds; + + foreach (Step* step, tutorial->steps()) { + if (step != ownStep && !step->reactions().contains(mReaction) && + !step->id().isEmpty()) { + stepIds.append(step->id()); + } + } + + ui->responseStepLineEdit->completionObject()->setItems(stepIds); +} + //protected: QList<QUndoCommand*> ReactionWidget::createSaveCommands(QUndoCommand* parent) { Modified: trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.h 2011-05-25 03:00:55 UTC (rev 314) +++ trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.h 2011-05-28 04:00:15 UTC (rev 315) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -24,6 +24,8 @@ #include "CommandWidget.h" #include "../data/Reaction.h" +class Step; +class Tutorial; class WaitFor; class WaitForWidget; @@ -51,6 +53,17 @@ */ virtual ~ReactionWidget(); + /** + * Enables the text completion for the id of the next step. + * The proposed ids are the ids of every step, except for the one that the + * reaction belongs to or is going to be added to. + * + * @param tutorial The tutorial to get the step ids from. + * @param ownStep The step that the reaction is going to be added to. + */ + void enableStepIdCompletion(const Tutorial* tutorial, + const Step* ownStep = 0); + protected: /** Modified: trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.cpp 2011-05-25 03:00:55 UTC (rev 314) +++ trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.cpp 2011-05-28 04:00:15 UTC (rev 315) @@ -24,7 +24,9 @@ #include "ui_StepDataWidget.h" #include "SemanticMarkupEdition.h" #include "../commands/StepCommands.h" +#include "../data/Reaction.h" #include "../data/Step.h" +#include "../data/Tutorial.h" //public: @@ -53,6 +55,37 @@ delete ui; } +void StepDataWidget::enableStepIdCompletion(const Tutorial* tutorial) { + QStringList usedStepIds; + QStringList nextStepIds; + + foreach (Step* step, tutorial->steps()) { + if (!step->id().isEmpty()) { + usedStepIds.append(step->id()); + } + + if (step == mStep) { + continue; + } + + foreach (Reaction* reaction, step->reactions()) { + if (!reaction->nextStepId().isEmpty()) { + nextStepIds.append(reaction->nextStepId()); + } + } + } + + QStringList unusedStepIds; + + foreach (QString nextStepId, nextStepIds) { + if (!usedStepIds.contains(nextStepId)) { + unusedStepIds.append(nextStepId); + } + } + + ui->idLineEdit->completionObject()->setItems(unusedStepIds); +} + //protected: QList<QUndoCommand*> StepDataWidget::createSaveCommands(QUndoCommand* parent) { Modified: trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.h 2011-05-25 03:00:55 UTC (rev 314) +++ trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.h 2011-05-28 04:00:15 UTC (rev 315) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -22,6 +22,7 @@ #include "CommandWidget.h" class Step; +class Tutorial; namespace Ui { class StepDataWidget; @@ -47,6 +48,16 @@ */ virtual ~StepDataWidget(); + /** + * Enables the text completion for the id of the step. + * The proposed ids are the unused ids from all the reactions, except for + * those that belong to the step of this StepDataWidget. + * An id is unused if it is not the id of any step added in the tutorial. + * + * @param tutorial The tutorial to get the step ids from. + */ + void enableStepIdCompletion(const Tutorial* tutorial); + protected: /** Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp 2011-05-25 03:00:55 UTC (rev 314) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp 2011-05-28 04:00:15 UTC (rev 315) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -31,9 +31,11 @@ #include <KTextEdit> #include "WaitForWidget.h" +#include "../data/Reaction.h" +#include "../data/Step.h" +#include "../data/Tutorial.h" #include "../data/WaitForComposed.h" #include "../data/WaitForSignal.h" -#include "../data/Reaction.h" class ReactionWidgetTest: public QObject { Q_OBJECT @@ -43,6 +45,8 @@ void testConstructor(); void testConstructorWithRichText(); + void testEnableStepIdCompletion(); + void testSelectTriggerTypeOption(); void testSelectTriggerTypeCondition(); @@ -132,6 +136,48 @@ QString("<p>The custom code</p>")); } +void ReactionWidgetTest::testEnableStepIdCompletion() { + Reaction* reaction = new Reaction(); + + ReactionWidget widget(reaction); + + Tutorial tutorial; + + Step* emptyIdStep = new Step(); + emptyIdStep->setId(""); + tutorial.addStep(emptyIdStep); + + Step* firstStep = new Step(); + firstStep->setId("First step"); + tutorial.addStep(firstStep); + + Step* secondStep = new Step(); + secondStep->setId("Second step"); + tutorial.addStep(secondStep); + + Step* thirdStep = new Step(); + thirdStep->setId("Third step"); + tutorial.addStep(thirdStep); + + widget.enableStepIdCompletion(&tutorial, firstStep); + + QStringList completionItems = + responseStepLineEdit(&widget)->completionObject()->items(); + QCOMPARE(completionItems.count(), 2); + QVERIFY(completionItems.contains("Second step")); + QVERIFY(completionItems.contains("Third step")); + + secondStep->addReaction(reaction); + + widget.enableStepIdCompletion(&tutorial); + + completionItems = + responseStepLineEdit(&widget)->completionObject()->items(); + QCOMPARE(completionItems.count(), 2); + QVERIFY(completionItems.contains("First step")); + QVERIFY(completionItems.contains("Third step")); +} + void ReactionWidgetTest::testSelectTriggerTypeOption() { Reaction reaction; reaction.setTriggerType(Reaction::ConditionMet); Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/StepDataWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/StepDataWidgetTest.cpp 2011-05-25 03:00:55 UTC (rev 314) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/StepDataWidgetTest.cpp 2011-05-28 04:00:15 UTC (rev 315) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -23,7 +23,9 @@ #include <KLineEdit> #include <KTextEdit> +#include "../data/Reaction.h" #include "../data/Step.h" +#include "../data/Tutorial.h" class StepDataWidgetTest: public QObject { Q_OBJECT @@ -33,6 +35,8 @@ void testConstructor(); void testConstructorWithRichText(); + void testEnableStepIdCompletion(); + void testSaveChanges(); private: @@ -68,6 +72,63 @@ QCOMPARE(textTextEdit(widget)->toPlainText(), QString("<p>The text</p>")); } +void StepDataWidgetTest::testEnableStepIdCompletion() { + Step* step = new Step; + + StepDataWidget widget(step); + + Tutorial tutorial; + tutorial.addStep(step); + + Reaction* stepFirstReaction = new Reaction(); + stepFirstReaction->setNextStepId("Unused id in the step of the widget"); + step->addReaction(stepFirstReaction); + + Step* emptyStep = new Step(); + emptyStep->setId(""); + tutorial.addStep(emptyStep); + + Step* firstStep = new Step(); + firstStep->setId("First step"); + tutorial.addStep(firstStep); + + Reaction* firstStepFirstReaction = new Reaction(); + firstStepFirstReaction->setNextStepId("Second step"); + firstStep->addReaction(firstStepFirstReaction); + + Reaction* firstStepSecondReaction = new Reaction(); + firstStepSecondReaction->setNextStepId("Unused id"); + firstStep->addReaction(firstStepSecondReaction); + + Reaction* firstStepThirdReaction = new Reaction(); + firstStepThirdReaction->setNextStepId("Duplicated unused id"); + firstStep->addReaction(firstStepThirdReaction); + + Reaction* firstStepEmptyReaction = new Reaction(); + firstStep->addReaction(firstStepEmptyReaction); + + Step* secondStep = new Step(); + secondStep->setId("Second step"); + tutorial.addStep(secondStep); + + Reaction* secondStepFirstReaction = new Reaction(); + secondStepFirstReaction->setNextStepId("Duplicated unused id"); + secondStep->addReaction(secondStepFirstReaction); + + Reaction* secondStepSecondReaction = new Reaction(); + secondStepSecondReaction->setNextStepId("Another unused id"); + secondStep->addReaction(secondStepSecondReaction); + + widget.enableStepIdCompletion(&tutorial); + + QStringList completionItems = + idLineEdit(&widget)->completionObject()->items(); + QCOMPARE(completionItems.count(), 3); + QVERIFY(completionItems.contains("Unused id")); + QVERIFY(completionItems.contains("Duplicated unused id")); + QVERIFY(completionItems.contains("Another unused id")); +} + void StepDataWidgetTest::testSaveChanges() { Step step; step.setId("The id"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |