[Ktutorial-commits] SF.net SVN: ktutorial:[157] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-15 18:58:31
|
Revision: 157 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=157&view=rev Author: danxuliu Date: 2010-03-15 18:58:22 +0000 (Mon, 15 Mar 2010) Log Message: ----------- Remove "Steps" item that contained all the steps in a tutorial in its tree model. Now steps hang directly from the tutorial, as the intermediate item wasn't really useful. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-15 09:06:46 UTC (rev 156) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-15 18:58:22 UTC (rev 157) @@ -135,33 +135,15 @@ } void TutorialTreeItem::addStep(Step* step) { - TreeItem* rootStepItem; - - if (mStepTreeItems.isEmpty()) { - TextTreeItem* textRootStepItem = new TextTreeItem(this); - textRootStepItem->setText(i18nc("@item", "Steps:")); - appendChild(textRootStepItem); - - rootStepItem = textRootStepItem; - } else { - rootStepItem = mStepTreeItems.at(0)->parent(); - } - - StepTreeItem* stepTreeItem = new StepTreeItem(step, rootStepItem); - rootStepItem->appendChild(stepTreeItem); + StepTreeItem* stepTreeItem = new StepTreeItem(step, this); + appendChild(stepTreeItem); mStepTreeItems.append(stepTreeItem); } void TutorialTreeItem::removeStep(Step* step) { StepTreeItem* stepTreeItem = stepTreeItemForStep(step); - TreeItem* rootStepItem = stepTreeItem->parent(); - rootStepItem->removeChild(stepTreeItem); + removeChild(stepTreeItem); mStepTreeItems.removeOne(stepTreeItem); delete stepTreeItem; - - if (mStepTreeItems.isEmpty()) { - removeChild(rootStepItem); - delete rootStepItem; - } } Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h 2010-03-15 09:06:46 UTC (rev 156) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h 2010-03-15 18:58:22 UTC (rev 157) @@ -38,12 +38,11 @@ * | -The custom setup code * |-Tear down: * | -The custom tear down code - * --Steps: - * -Step first step added - * ... - * -Step second step added - * ... - * ... + * |-Step first step added + * | ... + * |-Step second step added + * | ... + * ... * * The items only appear if they have some data to show. For example, if only * the name of the Tutorial is set, its representation is: @@ -150,7 +149,6 @@ /** * Adds a new StepTreeItem when a Step is added in the tutorial. - * If there were no other steps yet, the parent "Steps:" item is also added. * * @param step The Step added in the Tutorial. */ @@ -158,7 +156,6 @@ /** * Removes the StepTreeItem for the Step removed in the tutorial. - * If there are no other steps, the parent "Steps:" item is also removed. * * @param step The Step removed in the Tutorial. */ Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp 2010-03-15 09:06:46 UTC (rev 156) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp 2010-03-15 18:58:22 UTC (rev 157) @@ -75,8 +75,7 @@ void assertCustomSetupCode(TreeItem* setupItem, const QString& code) const; void assertCustomTearDownCode(TreeItem* tearDownItem, const QString& code) const; - void assertStep(TreeItem* rootStepItem, int index, - const QString& stepId) const; + void assertStep(TreeItem* stepItem, const QString& stepId) const; void assertDataChanged(const QSignalSpy& spy, int index, TreeItem* item) const; @@ -127,15 +126,14 @@ QCOMPARE(item.parent(), &parent); QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName")); - QCOMPARE(item.childCount(), 6); + QCOMPARE(item.childCount(), 7); assertName(item.child(0), "The name"); assertDescription(item.child(1), "The description"); assertLicenseText(item.child(2), "The license text"); assertCustomSetupCode(item.child(3), "The setup code"); assertCustomTearDownCode(item.child(4), "The tear down code"); - QCOMPARE(item.child(5)->childCount(), 2); - assertStep(item.child(5), 0, "First step"); - assertStep(item.child(5), 1, "Second step"); + assertStep(item.child(5), "First step"); + assertStep(item.child(6), "Second step"); } //TreeItem* must be declared as a metatype to be used in qvariant_cast @@ -350,7 +348,7 @@ tutorial.addStep(step); QCOMPARE(item.childCount(), 1); - assertStep(item.child(0), 0, "Step id"); + assertStep(item.child(0), "Step id"); } void TutorialTreeItemTest::testTutorialRemoveStep() { @@ -401,8 +399,7 @@ assertDescription(item.child(0), "The description"); assertCustomSetupCode(item.child(1), "The setup code"); assertCustomTearDownCode(item.child(2), "The tear down code"); - QCOMPARE(item.child(3)->childCount(), 1); - assertStep(item.child(3), 0, "First step"); + assertStep(item.child(3), "First step"); tutorial.setName("The name"); @@ -412,35 +409,32 @@ assertDescription(item.child(1), "The description"); assertCustomSetupCode(item.child(2), "The setup code"); assertCustomTearDownCode(item.child(3), "The tear down code"); - QCOMPARE(item.child(4)->childCount(), 1); - assertStep(item.child(4), 0, "First step"); + assertStep(item.child(4), "First step"); Step* step2 = new Step(); step2->setId("Second step"); tutorial.addStep(step2); QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName")); - QCOMPARE(item.childCount(), 5); + QCOMPARE(item.childCount(), 6); assertName(item.child(0), "The name"); assertDescription(item.child(1), "The description"); assertCustomSetupCode(item.child(2), "The setup code"); assertCustomTearDownCode(item.child(3), "The tear down code"); - QCOMPARE(item.child(4)->childCount(), 2); - assertStep(item.child(4), 0, "First step"); - assertStep(item.child(4), 1, "Second step"); + assertStep(item.child(4), "First step"); + assertStep(item.child(5), "Second step"); tutorial.setLicenseText("The license text"); QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName")); - QCOMPARE(item.childCount(), 6); + QCOMPARE(item.childCount(), 7); assertName(item.child(0), "The name"); assertDescription(item.child(1), "The description"); assertLicenseText(item.child(2), "The license text"); assertCustomSetupCode(item.child(3), "The setup code"); assertCustomTearDownCode(item.child(4), "The tear down code"); - QCOMPARE(item.child(5)->childCount(), 2); - assertStep(item.child(5), 0, "First step"); - assertStep(item.child(5), 1, "Second step"); + assertStep(item.child(5), "First step"); + assertStep(item.child(6), "Second step"); } void TutorialTreeItemTest::testChildOrderWhenUnsettingDataInTutorial() { @@ -466,25 +460,23 @@ tutorial.setLicenseText(""); QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName")); - QCOMPARE(item.childCount(), 5); + QCOMPARE(item.childCount(), 6); assertName(item.child(0), "The name"); assertDescription(item.child(1), "The description"); assertCustomSetupCode(item.child(2), "The setup code"); assertCustomTearDownCode(item.child(3), "The tear down code"); - QCOMPARE(item.child(4)->childCount(), 2); - assertStep(item.child(4), 0, "First step"); - assertStep(item.child(4), 1, "Second step"); + assertStep(item.child(4), "First step"); + assertStep(item.child(5), "Second step"); tutorial.setName(""); QCOMPARE(item.text(), i18nc("@item", "Tutorial")); - QCOMPARE(item.childCount(), 4); + QCOMPARE(item.childCount(), 5); assertDescription(item.child(0), "The description"); assertCustomSetupCode(item.child(1), "The setup code"); assertCustomTearDownCode(item.child(2), "The tear down code"); - QCOMPARE(item.child(3)->childCount(), 2); - assertStep(item.child(3), 0, "First step"); - assertStep(item.child(3), 1, "Second step"); + assertStep(item.child(3), "First step"); + assertStep(item.child(4), "Second step"); tutorial.removeStep(&step1); @@ -493,8 +485,7 @@ assertDescription(item.child(0), "The description"); assertCustomSetupCode(item.child(1), "The setup code"); assertCustomTearDownCode(item.child(2), "The tear down code"); - QCOMPARE(item.child(3)->childCount(), 1); - assertStep(item.child(3), 0, "Second step"); + assertStep(item.child(3), "Second step"); tutorial.setCustomTearDownCode(""); @@ -502,23 +493,20 @@ QCOMPARE(item.childCount(), 3); assertDescription(item.child(0), "The description"); assertCustomSetupCode(item.child(1), "The setup code"); - QCOMPARE(item.child(2)->childCount(), 1); - assertStep(item.child(2), 0, "Second step"); + assertStep(item.child(2), "Second step"); tutorial.setDescription(""); QCOMPARE(item.text(), i18nc("@item", "Tutorial")); QCOMPARE(item.childCount(), 2); assertCustomSetupCode(item.child(0), "The setup code"); - QCOMPARE(item.child(1)->childCount(), 1); - assertStep(item.child(1), 0, "Second step"); + assertStep(item.child(1), "Second step"); tutorial.setCustomSetupCode(""); QCOMPARE(item.text(), i18nc("@item", "Tutorial")); QCOMPARE(item.childCount(), 1); - QCOMPARE(item.child(0)->childCount(), 1); - assertStep(item.child(0), 0, "Second step"); + assertStep(item.child(0), "Second step"); tutorial.removeStep(&step2); @@ -561,12 +549,10 @@ QCOMPARE(tearDownItem->child(0)->text(), i18nc("@item", code.toAscii())); } -void TutorialTreeItemTest::assertStep(TreeItem* rootStepItem, int index, +void TutorialTreeItemTest::assertStep(TreeItem* stepItem, const QString& stepId) const { - QCOMPARE(rootStepItem->text(), i18nc("@item", "Steps:")); - QVERIFY(qobject_cast<StepTreeItem*>(rootStepItem->child(index))); - QCOMPARE(rootStepItem->child(index)->text(), - i18nc("@item", "Step %1", stepId)); + QVERIFY(qobject_cast<StepTreeItem*>(stepItem)); + QCOMPARE(stepItem->text(), i18nc("@item", "Step %1", stepId)); } void TutorialTreeItemTest::assertDataChanged(const QSignalSpy& spy, int index, Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp 2010-03-15 09:06:46 UTC (rev 156) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp 2010-03-15 18:58:22 UTC (rev 157) @@ -131,23 +131,21 @@ //Tear down select(mTreeModel->index(4, 0)); select(mTreeModel->index(0, 0, mTreeModel->index(4, 0))); - //Steps root - select(mTreeModel->index(5, 0)); QCOMPARE(mStepSelectedSpy->count(), 0); } void TutorialTreeSelectionManagerTest:: testSelectStepOrChildrenChangingToOtherItems() { - QModelIndex step1Index = mTreeModel->index(0, 0, mTreeModel->index(5, 0)); + QModelIndex step1Index = mTreeModel->index(5, 0); select(step1Index); QCOMPARE(mStepSelectedSpy->count(), 1); assertStepSignal(mStepSelectedSpy, 0, mStep1); - //Steps root - select(mTreeModel->index(5, 0)); + //Tutorial name + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 2); assertStepSignal(mStepSelectedSpy, 1, 0); @@ -158,7 +156,7 @@ QCOMPARE(mStepSelectedSpy->count(), 3); assertStepSignal(mStepSelectedSpy, 2, mStep1); - select(mTreeModel->index(5, 0)); + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 4); assertStepSignal(mStepSelectedSpy, 3, 0); @@ -169,7 +167,7 @@ QCOMPARE(mStepSelectedSpy->count(), 5); assertStepSignal(mStepSelectedSpy, 4, mStep1); - select(mTreeModel->index(5, 0)); + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 6); assertStepSignal(mStepSelectedSpy, 5, 0); @@ -180,7 +178,7 @@ QCOMPARE(mStepSelectedSpy->count(), 7); assertStepSignal(mStepSelectedSpy, 6, mStep1); - select(mTreeModel->index(5, 0)); + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 8); assertStepSignal(mStepSelectedSpy, 7, 0); @@ -191,7 +189,7 @@ QCOMPARE(mStepSelectedSpy->count(), 9); assertStepSignal(mStepSelectedSpy, 8, mStep1); - select(mTreeModel->index(5, 0)); + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 10); assertStepSignal(mStepSelectedSpy, 9, 0); @@ -202,7 +200,7 @@ QCOMPARE(mStepSelectedSpy->count(), 11); assertStepSignal(mStepSelectedSpy, 10, mStep1); - select(mTreeModel->index(5, 0)); + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 12); assertStepSignal(mStepSelectedSpy, 11, 0); @@ -210,7 +208,7 @@ void TutorialTreeSelectionManagerTest:: testSelectStepOrChildrenWithoutChangingStep() { - QModelIndex step1Index = mTreeModel->index(0, 0, mTreeModel->index(5, 0)); + QModelIndex step1Index = mTreeModel->index(5, 0); select(step1Index); @@ -245,8 +243,8 @@ void TutorialTreeSelectionManagerTest:: testSelectStepOrChildrenChangingToAnotherStep() { - QModelIndex step1Index = mTreeModel->index(0, 0, mTreeModel->index(5, 0)); - QModelIndex step2Index = mTreeModel->index(1, 0, mTreeModel->index(5, 0)); + QModelIndex step1Index = mTreeModel->index(5, 0); + QModelIndex step2Index = mTreeModel->index(6, 0); select(step1Index); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |