[Ktutorial-commits] SF.net SVN: ktutorial:[161] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-16 03:00:41
|
Revision: 161 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=161&view=rev Author: danxuliu Date: 2010-03-16 03:00:35 +0000 (Tue, 16 Mar 2010) Log Message: ----------- -Add actions to add, edit and remove reactions. -Adapt TutorialTreeSelectionManager to emit reactionSelected(Reaction*) when a reaction is selected. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.cpp trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.h trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-16 03:00:35 UTC (rev 161) @@ -26,11 +26,13 @@ #include <KApplication> #include <KLocalizedString> +#include "Reaction.h" #include "Step.h" #include "Tutorial.h" #include "view/ActionListWidget.h" #include "view/EditionDialog.h" #include "view/LicenseWidget.h" +#include "view/ReactionWidget.h" #include "view/StepCustomCodeWidget.h" #include "view/StepDataWidget.h" #include "view/TreeModel.h" @@ -71,6 +73,8 @@ new TutorialTreeSelectionManager(mTreeView->selectionModel(), this); connect(selectionManager, SIGNAL(stepSelected(Step*)), this, SLOT(selectStep(Step*))); + connect(selectionManager, SIGNAL(reactionSelected(Reaction*)), + this, SLOT(selectReaction(Reaction*))); } void KTutorialEditor::setupDocks() { @@ -82,6 +86,11 @@ mStepActionDock = new QDockWidget(i18nc("@title", "Edit step"), this); mStepActionDock->setObjectName("editStepDock"); addDockWidget(Qt::RightDockWidgetArea, mStepActionDock); + + mReactionActionDock = new QDockWidget(i18nc("@title", "Edit reaction"), + this); + mReactionActionDock->setObjectName("editReactionDock"); + addDockWidget(Qt::RightDockWidgetArea, mReactionActionDock); } void KTutorialEditor::setupActions() { @@ -181,11 +190,46 @@ actionListWidget->addAction(action); mStepActionDock->setWidget(actionListWidget); + actionListWidget = new ActionListWidget(mReactionActionDock); + action = new KAction(this); + action->setText(i18nc("@action", "Add reaction...")); + action->setStatusTip(i18nc("@info:status", "Add a new reaction to the " +"selected step.")); + action->setIcon(KIcon("list-add")); + action->setEnabled(false); + actionCollection()->addAction("addReaction", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(addReaction())); + actionListWidget->addAction(action); + + action = new KAction(this); + action->setText(i18nc("@action", "Set reaction data...")); + action->setStatusTip(i18nc("@info:status", "Set the trigger and the " +"response of the currently selected reaction.")); + action->setIcon(KIcon("document-edit")); + action->setEnabled(false); + actionCollection()->addAction("setReactionData", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setReactionData())); + actionListWidget->addAction(action); + + action = new KAction(this); + action->setText(i18nc("@action", "Remove reaction")); + action->setStatusTip(i18nc("@info:status", "Removes the currently selected " +"reaction from its step.")); + action->setIcon(KIcon("list-remove")); + action->setEnabled(false); + actionCollection()->addAction("removeReaction", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(removeReaction())); + actionListWidget->addAction(action); + + mReactionActionDock->setWidget(actionListWidget); + actionCollection()->addAction("showEditTutorialDock", mTutorialActionDock->toggleViewAction()); actionCollection()->addAction("showEditStepDock", mStepActionDock->toggleViewAction()); + actionCollection()->addAction("showEditReactionDock", + mReactionActionDock->toggleViewAction()); } void KTutorialEditor::showEditionDialog(EditionWidget* editionWidget) { @@ -205,14 +249,28 @@ actionCollection()->action("setStepSetup")->setEnabled(true); actionCollection()->action("setStepTearDown")->setEnabled(true); actionCollection()->action("removeStep")->setEnabled(true); + actionCollection()->action("addReaction")->setEnabled(true); } else { actionCollection()->action("setStepData")->setEnabled(false); actionCollection()->action("setStepSetup")->setEnabled(false); actionCollection()->action("setStepTearDown")->setEnabled(false); actionCollection()->action("removeStep")->setEnabled(false); + actionCollection()->action("addReaction")->setEnabled(false); } } +void KTutorialEditor::selectReaction(Reaction* reaction) { + mCurrentReaction = reaction; + + if (mCurrentReaction) { + actionCollection()->action("setReactionData")->setEnabled(true); + actionCollection()->action("removeReaction")->setEnabled(true); + } else { + actionCollection()->action("setReactionData")->setEnabled(false); + actionCollection()->action("removeReaction")->setEnabled(false); + } +} + void KTutorialEditor::setTutorialInformation() { showEditionDialog(new TutorialInformationWidget(mTutorial)); } @@ -264,3 +322,30 @@ mTutorial->removeStep(stepToRemove); stepToRemove->deleteLater(); } + +void KTutorialEditor::addReaction() { + Q_ASSERT(mCurrentStep); + + Reaction* reaction = new Reaction(); + mCurrentStep->addReaction(reaction); + + showEditionDialog(new ReactionWidget(reaction)); +} + +void KTutorialEditor::setReactionData() { + Q_ASSERT(mCurrentReaction); + + showEditionDialog(new ReactionWidget(mCurrentReaction)); +} + +void KTutorialEditor::removeReaction() { + Q_ASSERT(mCurrentStep); + + //When the reaction is removed, mCurrentReaction is changed because the + //selected item in the tree view changes. As mCurrentReaction is one of the + //valid reactions in the step, deleting it leads to a crash the next time it + //is used. + Reaction* reactionToRemove = mCurrentReaction; + mCurrentStep->removeReaction(reactionToRemove); + reactionToRemove->deleteLater(); +} Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-16 03:00:35 UTC (rev 161) @@ -23,6 +23,7 @@ class EditionWidget; class QTreeView; +class Reaction; class Step; class Tutorial; @@ -57,6 +58,11 @@ QDockWidget* mStepActionDock; /** + * Dock with the actions to edit a reaction. + */ + QDockWidget* mReactionActionDock; + + /** * The tutorial being edited. */ Tutorial* mTutorial; @@ -67,6 +73,11 @@ Step* mCurrentStep; /** + * The currently selected reaction. + */ + Reaction* mCurrentReaction; + + /** * Sets up the tutorial to be edited. * It creates a new tutorial, prepares the tree view to represent it and * handles the selection of items. @@ -101,6 +112,15 @@ void selectStep(Step* step); /** + * Sets the current reaction and enables or disables the actions that depend + * on a reaction as needed. + * + * @param reaction The reaction to select, or null to deselect the current + * one. + */ + void selectReaction(Reaction* reaction); + + /** * Shows a TutorialInformationWidget for the tutorial. */ void setTutorialInformation(); @@ -145,6 +165,22 @@ */ void removeStep(); + /** + * Adds a new reaction to the current step and shows a ReactionWidget for + * it. + */ + void addReaction(); + + /** + * Shows a ReactionWidget for the current reaction. + */ + void setReactionData(); + + /** + * Removes the current reaction from its step. + */ + void removeReaction(); + }; #endif Modified: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-16 03:00:35 UTC (rev 161) @@ -18,12 +18,19 @@ <Action name="setStepTearDown"/> <Action name="removeStep"/> </Menu> + <Menu name="editReactions"> + <Text context="@title:menu Noun, a reaction in a step">Reaction</Text> + <Action name="addReaction"/> + <Action name="setReactionData"/> + <Action name="removeReaction"/> + </Menu> </Menu> <Menu name="view"> <Menu name="panels"> <Text context="@title:menu">Panels</Text> <Action name="showEditTutorialDock"/> <Action name="showEditStepDock"/> + <Action name="showEditReactionDock"/> </Menu> </Menu> </MenuBar> Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.cpp 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.cpp 2010-03-16 03:00:35 UTC (rev 161) @@ -18,6 +18,7 @@ #include "TutorialTreeSelectionManager.h" +#include "ReactionTreeItem.h" #include "StepTreeItem.h" #include "TreeItem.h" @@ -62,6 +63,34 @@ return getStepForTreeItem(item->parent()); } +void TutorialTreeSelectionManager::updateReactionSelection(TreeItem* selected, + TreeItem* deselected) { + Reaction* selectedReaction = getReactionForTreeItem(selected); + Reaction* deselectedReaction = getReactionForTreeItem(deselected); + + if (selectedReaction && selectedReaction != deselectedReaction) { + emit reactionSelected(selectedReaction); + return; + } + + if (!selectedReaction && deselectedReaction) { + emit reactionSelected(0); + return; + } +} + +Reaction* TutorialTreeSelectionManager::getReactionForTreeItem(TreeItem* item) { + if (qobject_cast<ReactionTreeItem*>(item)) { + return static_cast<ReactionTreeItem*>(item)->reaction(); + } + + if (item == 0 || item->parent() == 0) { + return 0; + } + + return getReactionForTreeItem(item->parent()); +} + //private slots: void TutorialTreeSelectionManager::handleSelectionChanged( @@ -89,4 +118,5 @@ } updateStepSelection(selectedItem, deselectedItem); + updateReactionSelection(selectedItem, deselectedItem); } Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.h 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.h 2010-03-16 03:00:35 UTC (rev 161) @@ -22,14 +22,20 @@ #include <QItemSelectionModel> #include <QObject> +class Reaction; class Step; class TreeItem; /** * Watches the QItemSelectionModel of a TreeModel for changes in the selection. * When an item is selected in the TreeModel, it is checked what kind of data it - * represents. If it is a Step, stepSelected(Step*) signal is emitted. + * represents. An item can represent several types of data (for example, a + * reaction item represents a reaction, but also a step as it is part of it). * + * When the data represented by the item is a Step, stepSelected(Step*) signal + * is emitted. When it is a Reaction, reactionSelected(Reaction*) signal is + * emitted. + * * Only single item selections are supported. */ class TutorialTreeSelectionManager: public QObject { @@ -60,6 +66,17 @@ */ void stepSelected(Step* step); + /** + * Emitted when a Reaction (or any of its child items) is selected. + * If the Reaction is deselected and the new selected item isn't a Reaction, + * the signal is emitted with a null pointer. + * No signal is emitted if the selected item changes to another item that + * selects the same Reaction already selected. + * + * @param reaction The selected Reaction, or null if it was deselected. + */ + void reactionSelected(Reaction* reaction); + private: /** @@ -84,6 +101,28 @@ */ Step* getStepForTreeItem(TreeItem* item); + /** + * Emits reactionSelected(Reaction*) signal based on the selected and + * deselected items. + * + * @param selected The selected item, if any. + * @param deselected The deselected item, if any. + */ + void updateReactionSelection(TreeItem* selected, TreeItem* deselected); + + /** + * Returns the Reaction represented by the given item. + * Any recursive child item of a ReactionTreeItem, or a ReactionTreeItem + * itself, represents a Reaction. + * + * If the item doesn't represent a Reaction or there is no item, a null + * pointer is returned. + * + * @param item The item to get its represented Reaction. + * @return The Reaction. + */ + Reaction* getReactionForTreeItem(TreeItem* item); + private Q_SLOTS: /** Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp 2010-03-16 03:00:35 UTC (rev 161) @@ -22,8 +22,10 @@ #include "TreeModel.h" #include "TutorialTreeItem.h" +#include "../Reaction.h" #include "../Step.h" #include "../Tutorial.h" +#include "../WaitForComposed.h" class TutorialTreeSelectionManagerTest: public QObject { Q_OBJECT @@ -43,22 +45,34 @@ void testSelectStepOrChildrenWithoutChangingStep(); void testSelectStepOrChildrenChangingToAnotherStep(); + void testSelectReactionOrChildrenChangingToOtherItems(); + void testSelectReactionOrChildrenWithoutChangingReaction(); + void testSelectReactionOrChildrenChangingToAnotherReaction(); + private: int mStepStarType; + int mReactionStarType; Tutorial* mTutorial; Step* mStep1; + Reaction* mReaction1; + WaitForComposed* mWaitFor1; + WaitForComposed* mWaitFor1_1; Step* mStep2; + Reaction* mReaction2; TreeModel* mTreeModel; QItemSelectionModel* mSelectionModel; TutorialTreeSelectionManager* mSelectionManager; QSignalSpy* mStepSelectedSpy; + QSignalSpy* mReactionSelectedSpy; void select(const QModelIndex& index); void assertStepSignal(const QSignalSpy* spy, int index, Step* step) const; + void assertReactionSignal(const QSignalSpy* spy, int index, + Reaction* reaction) const; }; @@ -66,6 +80,9 @@ //Step* must be registered in order to be used with QSignalSpy mStepStarType = qRegisterMetaType<Step*>("Step*"); + //Reaction* must be registered in order to be used with QSignalSpy + mReactionStarType = qRegisterMetaType<Reaction*>("Reaction*"); + mTutorial = new Tutorial(); mTutorial->setName("The name"); mTutorial->setDescription("The description"); @@ -80,6 +97,16 @@ mStep1->setCustomTearDownCode("Tear down 1"); mTutorial->addStep(mStep1); + mReaction1 = new Reaction(); + mReaction1->setTriggerType(Reaction::ConditionMet); + mReaction1->setResponseType(Reaction::CustomCode); + mStep1->addReaction(mReaction1); + + mWaitFor1 = new WaitForComposed(); + mWaitFor1_1 = new WaitForComposed(); + mWaitFor1->addWaitFor(mWaitFor1_1); + mReaction1->setWaitFor(mWaitFor1); + mStep2 = new Step(); mStep2->setId("Second step"); mStep2->setText("Text 2"); @@ -87,6 +114,9 @@ mStep2->setCustomTearDownCode("Tear down 2"); mTutorial->addStep(mStep2); + mReaction2 = new Reaction(); + mStep2->addReaction(mReaction2); + mTreeModel = new TreeModel(new TutorialTreeItem(mTutorial)); } @@ -96,9 +126,13 @@ mStepSelectedSpy = new QSignalSpy(mSelectionManager, SIGNAL(stepSelected(Step*))); + + mReactionSelectedSpy = new QSignalSpy(mSelectionManager, + SIGNAL(reactionSelected(Reaction*))); } void TutorialTreeSelectionManagerTest::cleanup() { + delete mReactionSelectedSpy; delete mStepSelectedSpy; delete mSelectionManager; delete mSelectionModel; @@ -133,6 +167,7 @@ select(mTreeModel->index(0, 0, mTreeModel->index(4, 0))); QCOMPARE(mStepSelectedSpy->count(), 0); + QCOMPARE(mReactionSelectedSpy->count(), 0); } void TutorialTreeSelectionManagerTest:: @@ -204,6 +239,17 @@ QCOMPARE(mStepSelectedSpy->count(), 12); assertStepSignal(mStepSelectedSpy, 11, 0); + + //Reaction + select(mTreeModel->index(3, 0, step1Index)); + + QCOMPARE(mStepSelectedSpy->count(), 13); + assertStepSignal(mStepSelectedSpy, 12, mStep1); + + select(mTreeModel->index(0, 0)); + + QCOMPARE(mStepSelectedSpy->count(), 14); + assertStepSignal(mStepSelectedSpy, 13, 0); } void TutorialTreeSelectionManagerTest:: @@ -239,6 +285,11 @@ select(mTreeModel->index(0, 0, mTreeModel->index(2, 0, step1Index))); QCOMPARE(mStepSelectedSpy->count(), 1); + + //Reaction + select(mTreeModel->index(3, 0, step1Index)); + + QCOMPARE(mStepSelectedSpy->count(), 1); } void TutorialTreeSelectionManagerTest:: @@ -310,8 +361,173 @@ QCOMPARE(mStepSelectedSpy->count(), 12); assertStepSignal(mStepSelectedSpy, 11, mStep2); + + //Reaction + select(mTreeModel->index(3, 0, step1Index)); + + QCOMPARE(mStepSelectedSpy->count(), 13); + assertStepSignal(mStepSelectedSpy, 12, mStep1); + + select(mTreeModel->index(3, 0, step2Index)); + + QCOMPARE(mStepSelectedSpy->count(), 14); + assertStepSignal(mStepSelectedSpy, 13, mStep2); } +void TutorialTreeSelectionManagerTest:: + testSelectReactionOrChildrenChangingToOtherItems() { + QModelIndex step1Index = mTreeModel->index(5, 0); + QModelIndex reaction1_1Index = mTreeModel->index(3, 0, step1Index); + + select(reaction1_1Index); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + assertReactionSignal(mReactionSelectedSpy, 0, mReaction1); + + //Tutorial name + select(mTreeModel->index(0, 0)); + + QCOMPARE(mReactionSelectedSpy->count(), 2); + assertReactionSignal(mReactionSelectedSpy, 1, 0); + + //Reaction trigger + select(mTreeModel->index(0, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 3); + assertReactionSignal(mReactionSelectedSpy, 2, mReaction1); + + select(mTreeModel->index(0, 0)); + + QCOMPARE(mReactionSelectedSpy->count(), 4); + assertReactionSignal(mReactionSelectedSpy, 3, 0); + + //Reaction child condition trigger + select(mTreeModel->index(0, 0, mTreeModel->index(0, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 5); + assertReactionSignal(mReactionSelectedSpy, 4, mReaction1); + + select(mTreeModel->index(0, 0)); + + QCOMPARE(mReactionSelectedSpy->count(), 6); + assertReactionSignal(mReactionSelectedSpy, 5, 0); + + //Reaction response + select(mTreeModel->index(1, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 7); + assertReactionSignal(mReactionSelectedSpy, 6, mReaction1); + + select(mTreeModel->index(0, 0)); + + QCOMPARE(mReactionSelectedSpy->count(), 8); + assertReactionSignal(mReactionSelectedSpy, 7, 0); + + //Reaction custom code response + select(mTreeModel->index(0, 0, mTreeModel->index(1, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 9); + assertReactionSignal(mReactionSelectedSpy, 8, mReaction1); + + select(mTreeModel->index(0, 0)); + + QCOMPARE(mReactionSelectedSpy->count(), 10); + assertReactionSignal(mReactionSelectedSpy, 9, 0); +} + +void TutorialTreeSelectionManagerTest:: + testSelectReactionOrChildrenWithoutChangingReaction() { + QModelIndex step1Index = mTreeModel->index(5, 0); + QModelIndex reaction1_1Index = mTreeModel->index(3, 0, step1Index); + + select(reaction1_1Index); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + assertReactionSignal(mReactionSelectedSpy, 0, mReaction1); + + //Reaction trigger + select(mTreeModel->index(0, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + + //Reaction child condition trigger + select(mTreeModel->index(0, 0, mTreeModel->index(0, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + + //Reaction response + select(mTreeModel->index(1, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + + //Reaction custom code response + select(mTreeModel->index(0, 0, mTreeModel->index(1, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 1); +} + +void TutorialTreeSelectionManagerTest:: + testSelectReactionOrChildrenChangingToAnotherReaction() { + QModelIndex step1Index = mTreeModel->index(5, 0); + QModelIndex reaction1_1Index = mTreeModel->index(3, 0, step1Index); + QModelIndex step2Index = mTreeModel->index(6, 0); + QModelIndex reaction2_1Index = mTreeModel->index(3, 0, step2Index); + + select(reaction1_1Index); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + assertReactionSignal(mReactionSelectedSpy, 0, mReaction1); + + select(reaction2_1Index); + + QCOMPARE(mReactionSelectedSpy->count(), 2); + assertReactionSignal(mReactionSelectedSpy, 1, mReaction2); + + //Reaction trigger + select(mTreeModel->index(0, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 3); + assertReactionSignal(mReactionSelectedSpy, 2, mReaction1); + + select(mTreeModel->index(0, 0, reaction2_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 4); + assertReactionSignal(mReactionSelectedSpy, 3, mReaction2); + + //Reaction nested condition trigger + select(mTreeModel->index(0, 0, mTreeModel->index(0, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 5); + assertReactionSignal(mReactionSelectedSpy, 4, mReaction1); + + select(mTreeModel->index(0, 0, reaction2_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 6); + assertReactionSignal(mReactionSelectedSpy, 5, mReaction2); + + //Reaction response + select(mTreeModel->index(1, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 7); + assertReactionSignal(mReactionSelectedSpy, 6, mReaction1); + + select(mTreeModel->index(1, 0, reaction2_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 8); + assertReactionSignal(mReactionSelectedSpy, 7, mReaction2); + + //Reaction custom code response + select(mTreeModel->index(0, 0, mTreeModel->index(1, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 9); + assertReactionSignal(mReactionSelectedSpy, 8, mReaction1); + + select(reaction2_1Index); + + QCOMPARE(mReactionSelectedSpy->count(), 10); + assertReactionSignal(mReactionSelectedSpy, 9, mReaction2); +} + /////////////////////////////////// Helpers //////////////////////////////////// void TutorialTreeSelectionManagerTest::select(const QModelIndex& index) { @@ -331,6 +547,20 @@ QCOMPARE(qvariant_cast<Step*>(argument), step); } +//Reaction* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(Reaction*); + +void TutorialTreeSelectionManagerTest::assertReactionSignal( + const QSignalSpy* spy, + int index, + Reaction* reaction) const { + QCOMPARE(spy->at(index).count(), 1); + + QVariant argument = spy->at(index).at(0); + QCOMPARE(argument.userType(), mReactionStarType); + QCOMPARE(qvariant_cast<Reaction*>(argument), reaction); +} + QTEST_MAIN(TutorialTreeSelectionManagerTest) #include "TutorialTreeSelectionManagerTest.moc" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |