[Ktutorial-commits] SF.net SVN: ktutorial:[175] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-03-22 18:13:57
|
Revision: 175
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=175&view=rev
Author: danxuliu
Date: 2010-03-22 18:13:49 +0000 (Mon, 22 Mar 2010)
Log Message:
-----------
When mandatory data in tutorial and step isn't set (name and information in tutorial, and id and text in step), show a placeholder instead of completly hidding it in the tree view to keep consistency with how mandatory data is shown in reactions and conditions to wait for.
Modified Paths:
--------------
trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp
trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h
trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp
trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h
trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp
trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp
Modified: trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-21 16:08:40 UTC (rev 174)
+++ trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-22 18:13:49 UTC (rev 175)
@@ -32,7 +32,8 @@
mStep(step) {
Q_ASSERT(step);
- mTextItem = 0;
+ mTextItem = new TextTreeItem(this);
+ appendChild(mTextItem);
mSetupItem = 0;
mTearDownItem = 0;
@@ -50,11 +51,12 @@
}
QString StepTreeItem::text() const {
+ QString id = mStepId;
if (mStepId.isEmpty()) {
- return i18nc("@item Noun, a step in a tutorial", "Step");
+ id = i18nc("@item", "(id not set)");
}
- return i18nc("@item Noun, a step in a tutorial", "Step %1", mStepId);
+ return i18nc("@item Noun, a step in a tutorial", "Step %1", id);
}
Step* StepTreeItem::step() const {
@@ -77,8 +79,6 @@
//private slots:
void StepTreeItem::update(Step* step) {
- int childIndex = 0;
-
if (step->id().isEmpty()) {
if (!mStepId.isEmpty()) {
mStepId.clear();
@@ -89,15 +89,16 @@
emit dataChanged(this);
}
+ QString text;
if (step->text().isEmpty()) {
- TreeItemUtil::removeFlatItemIfNeeded(mTextItem);
+ text = i18nc("@item", "(text not set)");
} else {
- TreeItemUtil::addFlatItemIfNeeded(this, mTextItem, childIndex);
- mTextItem->setText(i18nc("@item", "Text: %1", step->text()));
-
- childIndex++;
+ text = step->text();
}
+ mTextItem->setText(i18nc("@item", "Text: %1", text));
+ int childIndex = 1;
+
if (step->customSetupCode().isEmpty()) {
TreeItemUtil::removeNestedItemIfNeeded(mSetupItem);
} else {
Modified: trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h 2010-03-21 16:08:40 UTC (rev 174)
+++ trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h 2010-03-22 18:13:49 UTC (rev 175)
@@ -41,9 +41,13 @@
* | ...
* ...
*
- * The items only appear if they have some data to show. For example, if only
- * the text of the Step is set, its representation is:
- * Step
+ * If the id or the text aren't set yet, a placeholder is used instead. Id
+ * placeholder is "(id not set)", and the text placeholder is "(text not set)"
+ * (without quotes, but with parenthesis).
+ *
+ * The other items only appear if they have some data to show. For example, if
+ * only the text of the Step is set, its representation is:
+ * Step (id not set)
* -The text
*
* Note that composed elements like custom setup code don't appear at all, not
@@ -53,8 +57,8 @@
* are updated as needed.
*
* Also note that the order of the child elements is always the same. Even if,
- * for example, the setup code is set first and then the text, the text item
- * will appear first and then the setup code item.
+ * for example, the tear down code is set first and then the setup code, the
+ * setup code item will appear first and then the tear down code item.
*
* @see ReactionTreeItem
*/
@@ -72,8 +76,8 @@
explicit StepTreeItem(Step* step, TreeItem* parent = 0);
/**
- * Returns "Step " and the id of the step, or just "Step" if
- * there is no id.
+ * Returns "Step " and the id of the step, or "Step (id not set)" if there
+ * is no id.
*
* @return The text for this TreeItem.
*/
Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-21 16:08:40 UTC (rev 174)
+++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-22 18:13:49 UTC (rev 175)
@@ -31,8 +31,10 @@
TreeItem(parent) {
Q_ASSERT(tutorial);
- mNameItem = 0;
- mDescriptionItem = 0;
+ mNameItem = new TextTreeItem(this);
+ appendChild(mNameItem);
+ mDescriptionItem = new TextTreeItem(this);
+ appendChild(mDescriptionItem);
mLicenseItem = 0;
mSetupItem = 0;
mTearDownItem = 0;
@@ -73,36 +75,33 @@
//private slots:
void TutorialTreeItem::update(Tutorial* tutorial) {
- int childIndex = 0;
-
+ QString name;
if (tutorial->name().isEmpty()) {
- TreeItemUtil::removeFlatItemIfNeeded(mNameItem);
+ name = i18nc("@item", "(name not set)");
if (!mTutorialId.isEmpty()) {
mTutorialId.clear();
emit dataChanged(this);
}
} else {
- TreeItemUtil::addFlatItemIfNeeded(this, mNameItem, childIndex);
- mNameItem->setText(i18nc("@item Noun, the name of a tutorial",
- "Name: %1", tutorial->name()));
+ name = tutorial->name();
mTutorialId = tutorial->id();
emit dataChanged(this);
-
- childIndex++;
}
+ mNameItem->setText(i18nc("@item Noun, the name of a tutorial",
+ "Name: %1", name));
+ QString description;
if (tutorial->description().isEmpty()) {
- TreeItemUtil::removeFlatItemIfNeeded(mDescriptionItem);
+ description = i18nc("@item", "(description not set)");
} else {
- TreeItemUtil::addFlatItemIfNeeded(this, mDescriptionItem, childIndex);
- mDescriptionItem->setText(i18nc("@item", "Description: %1",
- tutorial->description()));
-
- childIndex++;
+ description = tutorial->description();
}
+ mDescriptionItem->setText(i18nc("@item", "Description: %1", description));
+ int childIndex = 2;
+
if (tutorial->licenseText().isEmpty()) {
TreeItemUtil::removeNestedItemIfNeeded(mLicenseItem);
} else {
Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h 2010-03-21 16:08:40 UTC (rev 174)
+++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h 2010-03-22 18:13:49 UTC (rev 175)
@@ -44,10 +44,15 @@
* | ...
* ...
*
- * 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:
- * Tutorial theId
+ * If the name or the description aren't set yet, a placeholder is used instead.
+ * Name placeholder is "(name not set)", and the description placeholder is
+ * "(description not set)" (without quotes, but with parenthesis).
+ *
+ * The other items only appear if they have some data to show. For example, if
+ * only the name of the Tutorial is set, its representation is:
+ * Tutorial theName
* -Name: the name
+ * -Description: (description not set)
*
* Note that composed elements like license don't appear at all, not even the
* parent item with just "License:".
@@ -56,8 +61,8 @@
* are updated as needed.
*
* Also note that the order of the child elements is always the same. Even if,
- * for example, the setup code is set first and then the name, the name item
- * will appear first and then the setup code item.
+ * for example, the tear down code is set first and then the license, the
+ * license item will appear first and then the tear down code item.
*
* @see StepTreeItem
*/
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp 2010-03-21 16:08:40 UTC (rev 174)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp 2010-03-22 18:13:49 UTC (rev 175)
@@ -63,6 +63,7 @@
int mTreeItemStarType;
+ void assertEmptyText(TreeItem* textItem) const;
void assertText(TreeItem* textItem, const QString& licenseText) const;
void assertCustomSetupCode(TreeItem* setupItem, const QString& code) const;
void assertCustomTearDownCode(TreeItem* tearDownItem,
@@ -93,9 +94,10 @@
StepTreeItem item(&step, &parent);
QCOMPARE(item.parent(), &parent);
- QCOMPARE(item.text(), i18nc("@item", "Step"));
+ QCOMPARE(item.text(), i18nc("@item", "Step (id not set)"));
QCOMPARE(item.step(), &step);
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 1);
+ assertEmptyText(item.child(0));
}
void StepTreeItemTest::testConstructorFullStep() {
@@ -139,7 +141,8 @@
step.setId("The id");
QCOMPARE(item.text(), i18nc("@item", "Step %1", "The id"));
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 1);
+ assertEmptyText(item.child(0));
QCOMPARE(dataChangedSpy.count(), 1);
assertDataChanged(dataChangedSpy, 0, &item);
}
@@ -155,7 +158,8 @@
step.setId("The id changed");
QCOMPARE(item.text(), i18nc("@item", "Step %1", "The id changed"));
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 1);
+ assertEmptyText(item.child(0));
QCOMPARE(dataChangedSpy.count(), 1);
assertDataChanged(dataChangedSpy, 0, &item);
}
@@ -170,8 +174,9 @@
step.setId("");
- QCOMPARE(item.text(), i18nc("@item", "Step"));
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.text(), i18nc("@item", "Step (id not set)"));
+ QCOMPARE(item.childCount(), 1);
+ assertEmptyText(item.child(0));
QCOMPARE(dataChangedSpy.count(), 1);
assertDataChanged(dataChangedSpy, 0, &item);
}
@@ -180,10 +185,14 @@
Step step;
StepTreeItem item(&step);
+ QSignalSpy dataChangedSpy(item.child(0), SIGNAL(dataChanged(TreeItem*)));
+
step.setText("The text");
QCOMPARE(item.childCount(), 1);
assertText(item.child(0), "The text");
+ QCOMPARE(dataChangedSpy.count(), 1);
+ assertDataChanged(dataChangedSpy, 0, item.child(0));
}
void StepTreeItemTest::testStepSetTextChange() {
@@ -207,9 +216,15 @@
StepTreeItem item(&step);
step.setText("The text");
+
+ QSignalSpy dataChangedSpy(item.child(0), SIGNAL(dataChanged(TreeItem*)));
+
step.setText("");
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 1);
+ assertEmptyText(item.child(0));
+ QCOMPARE(dataChangedSpy.count(), 1);
+ assertDataChanged(dataChangedSpy, 0, item.child(0));
}
void StepTreeItemTest::testStepSetCustomSetupCode() {
@@ -218,8 +233,9 @@
step.setCustomSetupCode("The setup code");
- QCOMPARE(item.childCount(), 1);
- assertCustomSetupCode(item.child(0), "The setup code");
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyText(item.child(0));
+ assertCustomSetupCode(item.child(1), "The setup code");
}
void StepTreeItemTest::testStepSetCustomSetupCodeChange() {
@@ -228,15 +244,16 @@
step.setCustomSetupCode("The setup code");
- QSignalSpy dataChangedSpy(item.child(0)->child(0),
+ QSignalSpy dataChangedSpy(item.child(1)->child(0),
SIGNAL(dataChanged(TreeItem*)));
step.setCustomSetupCode("The setup code changed");
- QCOMPARE(item.childCount(), 1);
- assertCustomSetupCode(item.child(0), "The setup code changed");
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyText(item.child(0));
+ assertCustomSetupCode(item.child(1), "The setup code changed");
QCOMPARE(dataChangedSpy.count(), 1);
- assertDataChanged(dataChangedSpy, 0, item.child(0)->child(0));
+ assertDataChanged(dataChangedSpy, 0, item.child(1)->child(0));
}
void StepTreeItemTest::testStepSetCustomSetupCodeEmpty() {
@@ -246,7 +263,8 @@
step.setCustomSetupCode("The setup code");
step.setCustomSetupCode("");
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 1);
+ assertEmptyText(item.child(0));
}
void StepTreeItemTest::testStepSetCustomTearDownCode() {
@@ -255,8 +273,9 @@
step.setCustomTearDownCode("The tear down code");
- QCOMPARE(item.childCount(), 1);
- assertCustomTearDownCode(item.child(0), "The tear down code");
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyText(item.child(0));
+ assertCustomTearDownCode(item.child(1), "The tear down code");
}
void StepTreeItemTest::testStepSetCustomTearDownCodeChange() {
@@ -265,15 +284,16 @@
step.setCustomTearDownCode("The tear down code");
- QSignalSpy dataChangedSpy(item.child(0)->child(0),
+ QSignalSpy dataChangedSpy(item.child(1)->child(0),
SIGNAL(dataChanged(TreeItem*)));
step.setCustomTearDownCode("The tear down code changed");
- QCOMPARE(item.childCount(), 1);
- assertCustomTearDownCode(item.child(0), "The tear down code changed");
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyText(item.child(0));
+ assertCustomTearDownCode(item.child(1), "The tear down code changed");
QCOMPARE(dataChangedSpy.count(), 1);
- assertDataChanged(dataChangedSpy, 0, item.child(0)->child(0));
+ assertDataChanged(dataChangedSpy, 0, item.child(1)->child(0));
}
void StepTreeItemTest::testStepSetCustomTearDownCodeEmpty() {
@@ -283,7 +303,8 @@
step.setCustomTearDownCode("The tear down code");
step.setCustomTearDownCode("");
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 1);
+ assertEmptyText(item.child(0));
}
void StepTreeItemTest::testStepAddReaction() {
@@ -293,8 +314,9 @@
Reaction* reaction = new Reaction();
step.addReaction(reaction);
- QCOMPARE(item.childCount(), 1);
- assertReaction(item.child(0), reaction);
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyText(item.child(0));
+ assertReaction(item.child(1), reaction);
}
void StepTreeItemTest::testStepRemoveReaction() {
@@ -307,7 +329,8 @@
step.addReaction(&reaction);
step.removeReaction(&reaction);
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 1);
+ assertEmptyText(item.child(0));
}
void StepTreeItemTest::testChildOrderWhenSettingDataInStep() {
@@ -316,13 +339,14 @@
step.setCustomSetupCode("The setup code");
- QCOMPARE(item.text(), i18nc("@item", "Step"));
- QCOMPARE(item.childCount(), 1);
- assertCustomSetupCode(item.child(0), "The setup code");
+ QCOMPARE(item.text(), i18nc("@item", "Step (id not set)"));
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyText(item.child(0));
+ assertCustomSetupCode(item.child(1), "The setup code");
step.setText("The text");
- QCOMPARE(item.text(), i18nc("@item", "Step"));
+ QCOMPARE(item.text(), i18nc("@item", "Step (id not set)"));
QCOMPARE(item.childCount(), 2);
assertText(item.child(0), "The text");
assertCustomSetupCode(item.child(1), "The setup code");
@@ -330,7 +354,7 @@
Reaction* reaction1 = new Reaction();
step.addReaction(reaction1);
- QCOMPARE(item.text(), i18nc("@item", "Step"));
+ QCOMPARE(item.text(), i18nc("@item", "Step (id not set)"));
QCOMPARE(item.childCount(), 3);
assertText(item.child(0), "The text");
assertCustomSetupCode(item.child(1), "The setup code");
@@ -338,7 +362,7 @@
step.setCustomTearDownCode("The tear down code");
- QCOMPARE(item.text(), i18nc("@item", "Step"));
+ QCOMPARE(item.text(), i18nc("@item", "Step (id not set)"));
QCOMPARE(item.childCount(), 4);
assertText(item.child(0), "The text");
assertCustomSetupCode(item.child(1), "The setup code");
@@ -348,7 +372,7 @@
Reaction* reaction2 = new Reaction();
step.addReaction(reaction2);
- QCOMPARE(item.text(), i18nc("@item", "Step"));
+ QCOMPARE(item.text(), i18nc("@item", "Step (id not set)"));
QCOMPARE(item.childCount(), 5);
assertText(item.child(0), "The text");
assertCustomSetupCode(item.child(1), "The setup code");
@@ -385,48 +409,58 @@
step.setText("");
QCOMPARE(item.text(), i18nc("@item", "Step %1", "The id"));
- QCOMPARE(item.childCount(), 4);
- assertCustomSetupCode(item.child(0), "The setup code");
- assertCustomTearDownCode(item.child(1), "The tear down code");
- assertReaction(item.child(2), &reaction1);
- assertReaction(item.child(3), &reaction2);
+ QCOMPARE(item.childCount(), 5);
+ assertEmptyText(item.child(0));
+ assertCustomSetupCode(item.child(1), "The setup code");
+ assertCustomTearDownCode(item.child(2), "The tear down code");
+ assertReaction(item.child(3), &reaction1);
+ assertReaction(item.child(4), &reaction2);
step.removeReaction(&reaction1);
QCOMPARE(item.text(), i18nc("@item", "Step %1", "The id"));
- QCOMPARE(item.childCount(), 3);
- assertCustomSetupCode(item.child(0), "The setup code");
- assertCustomTearDownCode(item.child(1), "The tear down code");
- assertReaction(item.child(2), &reaction2);
+ QCOMPARE(item.childCount(), 4);
+ assertEmptyText(item.child(0));
+ assertCustomSetupCode(item.child(1), "The setup code");
+ assertCustomTearDownCode(item.child(2), "The tear down code");
+ assertReaction(item.child(3), &reaction2);
step.setCustomTearDownCode("");
QCOMPARE(item.text(), i18nc("@item", "Step %1", "The id"));
- QCOMPARE(item.childCount(), 2);
- assertCustomSetupCode(item.child(0), "The setup code");
- assertReaction(item.child(1), &reaction2);
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyText(item.child(0));
+ assertCustomSetupCode(item.child(1), "The setup code");
+ assertReaction(item.child(2), &reaction2);
step.setId("");
- QCOMPARE(item.text(), i18nc("@item", "Step"));
- QCOMPARE(item.childCount(), 2);
- assertCustomSetupCode(item.child(0), "The setup code");
- assertReaction(item.child(1), &reaction2);
+ QCOMPARE(item.text(), i18nc("@item", "Step (id not set)"));
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyText(item.child(0));
+ assertCustomSetupCode(item.child(1), "The setup code");
+ assertReaction(item.child(2), &reaction2);
step.setCustomSetupCode("");
- QCOMPARE(item.text(), i18nc("@item", "Step"));
- QCOMPARE(item.childCount(), 1);
- assertReaction(item.child(0), &reaction2);
+ QCOMPARE(item.text(), i18nc("@item", "Step (id not set)"));
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyText(item.child(0));
+ assertReaction(item.child(1), &reaction2);
step.removeReaction(&reaction2);
- QCOMPARE(item.text(), i18nc("@item", "Step"));
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.text(), i18nc("@item", "Step (id not set)"));
+ QCOMPARE(item.childCount(), 1);
+ assertEmptyText(item.child(0));
}
/////////////////////////////////// Helpers ////////////////////////////////////
+void StepTreeItemTest::assertEmptyText(TreeItem* textItem) const {
+ QCOMPARE(textItem->text(), i18nc("@item", "Text: (text not set)"));
+}
+
void StepTreeItemTest::assertText(TreeItem* textItem,
const QString& name) const {
QCOMPARE(textItem->text(), i18nc("@item", "Text: %1", name));
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp 2010-03-21 16:08:40 UTC (rev 174)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp 2010-03-22 18:13:49 UTC (rev 175)
@@ -67,7 +67,9 @@
int mTreeItemStarType;
+ void assertEmptyName(TreeItem* nameItem) const;
void assertName(TreeItem* nameItem, const QString& name) const;
+ void assertEmptyDescription(TreeItem* descriptionItem) const;
void assertDescription(TreeItem* descriptionItem,
const QString& description) const;
void assertLicenseText(TreeItem* licenseItem,
@@ -102,7 +104,9 @@
QCOMPARE(item.parent(), &parent);
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
}
void TutorialTreeItemTest::testConstructorFullTutorial() {
@@ -145,15 +149,19 @@
//Setting the name changes the data returned by text() in the
//TutorialTreeItem itself, as the id is based on the name
- QSignalSpy dataChangedSpy(&item, SIGNAL(dataChanged(TreeItem*)));
+ QSignalSpy dataChangedRootSpy(&item, SIGNAL(dataChanged(TreeItem*)));
+ QSignalSpy dataChangedSpy(item.child(0), SIGNAL(dataChanged(TreeItem*)));
tutorial.setName("The name");
QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName"));
- QCOMPARE(item.childCount(), 1);
+ QCOMPARE(item.childCount(), 2);
assertName(item.child(0), "The name");
+ assertEmptyDescription(item.child(1));
+ QCOMPARE(dataChangedRootSpy.count(), 1);
+ assertDataChanged(dataChangedRootSpy, 0, &item);
QCOMPARE(dataChangedSpy.count(), 1);
- assertDataChanged(dataChangedSpy, 0, &item);
+ assertDataChanged(dataChangedSpy, 0, item.child(0));
}
void TutorialTreeItemTest::testTutorialSetNameChange() {
@@ -168,8 +176,9 @@
tutorial.setName("The name changed");
QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theNameChanged"));
- QCOMPARE(item.childCount(), 1);
+ QCOMPARE(item.childCount(), 2);
assertName(item.child(0), "The name changed");
+ assertEmptyDescription(item.child(1));
QCOMPARE(dataChangedRootSpy.count(), 1);
assertDataChanged(dataChangedRootSpy, 0, &item);
QCOMPARE(dataChangedSpy.count(), 1);
@@ -182,24 +191,34 @@
tutorial.setName("The name");
- QSignalSpy dataChangedSpy(&item, SIGNAL(dataChanged(TreeItem*)));
+ QSignalSpy dataChangedRootSpy(&item, SIGNAL(dataChanged(TreeItem*)));
+ QSignalSpy dataChangedSpy(item.child(0), SIGNAL(dataChanged(TreeItem*)));
tutorial.setName("");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ QCOMPARE(dataChangedRootSpy.count(), 1);
+ assertDataChanged(dataChangedRootSpy, 0, &item);
QCOMPARE(dataChangedSpy.count(), 1);
- assertDataChanged(dataChangedSpy, 0, &item);
+ assertDataChanged(dataChangedSpy, 0, item.child(0));
}
void TutorialTreeItemTest::testTutorialSetDescription() {
Tutorial tutorial;
TutorialTreeItem item(&tutorial);
+ QSignalSpy dataChangedSpy(item.child(1), SIGNAL(dataChanged(TreeItem*)));
+
tutorial.setDescription("The description");
- QCOMPARE(item.childCount(), 1);
- assertDescription(item.child(0), "The description");
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyName(item.child(0));
+ assertDescription(item.child(1), "The description");
+ QCOMPARE(dataChangedSpy.count(), 1);
+ assertDataChanged(dataChangedSpy, 0, item.child(1));
}
void TutorialTreeItemTest::testTutorialSetDescriptionChange() {
@@ -208,14 +227,15 @@
tutorial.setDescription("The description");
- QSignalSpy dataChangedSpy(item.child(0), SIGNAL(dataChanged(TreeItem*)));
+ QSignalSpy dataChangedSpy(item.child(1), SIGNAL(dataChanged(TreeItem*)));
tutorial.setDescription("The description changed");
- QCOMPARE(item.childCount(), 1);
- assertDescription(item.child(0), "The description changed");
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyName(item.child(0));
+ assertDescription(item.child(1), "The description changed");
QCOMPARE(dataChangedSpy.count(), 1);
- assertDataChanged(dataChangedSpy, 0, item.child(0));
+ assertDataChanged(dataChangedSpy, 0, item.child(1));
}
void TutorialTreeItemTest::testTutorialSetDescriptionEmpty() {
@@ -223,9 +243,16 @@
TutorialTreeItem item(&tutorial);
tutorial.setDescription("The description");
+
+ QSignalSpy dataChangedSpy(item.child(1), SIGNAL(dataChanged(TreeItem*)));
+
tutorial.setDescription("");
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ QCOMPARE(dataChangedSpy.count(), 1);
+ assertDataChanged(dataChangedSpy, 0, item.child(1));
}
void TutorialTreeItemTest::testTutorialSetLicenseText() {
@@ -234,8 +261,10 @@
tutorial.setLicenseText("The license text");
- QCOMPARE(item.childCount(), 1);
- assertLicenseText(item.child(0), "The license text");
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ assertLicenseText(item.child(2), "The license text");
}
void TutorialTreeItemTest::testTutorialSetLicenseTextChange() {
@@ -244,15 +273,17 @@
tutorial.setLicenseText("The license text");
- QSignalSpy dataChangedSpy(item.child(0)->child(0),
+ QSignalSpy dataChangedSpy(item.child(2)->child(0),
SIGNAL(dataChanged(TreeItem*)));
tutorial.setLicenseText("The license text changed");
- QCOMPARE(item.childCount(), 1);
- assertLicenseText(item.child(0), "The license text changed");
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ assertLicenseText(item.child(2), "The license text changed");
QCOMPARE(dataChangedSpy.count(), 1);
- assertDataChanged(dataChangedSpy, 0, item.child(0)->child(0));
+ assertDataChanged(dataChangedSpy, 0, item.child(2)->child(0));
}
void TutorialTreeItemTest::testTutorialSetLicenseTextEmpty() {
@@ -262,7 +293,9 @@
tutorial.setLicenseText("The license text");
tutorial.setLicenseText("");
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
}
void TutorialTreeItemTest::testTutorialSetCustomSetupCode() {
@@ -271,8 +304,10 @@
tutorial.setCustomSetupCode("The setup code");
- QCOMPARE(item.childCount(), 1);
- assertCustomSetupCode(item.child(0), "The setup code");
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ assertCustomSetupCode(item.child(2), "The setup code");
}
void TutorialTreeItemTest::testTutorialSetCustomSetupCodeChange() {
@@ -281,15 +316,17 @@
tutorial.setCustomSetupCode("The setup code");
- QSignalSpy dataChangedSpy(item.child(0)->child(0),
+ QSignalSpy dataChangedSpy(item.child(2)->child(0),
SIGNAL(dataChanged(TreeItem*)));
tutorial.setCustomSetupCode("The setup code changed");
- QCOMPARE(item.childCount(), 1);
- assertCustomSetupCode(item.child(0), "The setup code changed");
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ assertCustomSetupCode(item.child(2), "The setup code changed");
QCOMPARE(dataChangedSpy.count(), 1);
- assertDataChanged(dataChangedSpy, 0, item.child(0)->child(0));
+ assertDataChanged(dataChangedSpy, 0, item.child(2)->child(0));
}
void TutorialTreeItemTest::testTutorialSetCustomSetupCodeEmpty() {
@@ -299,7 +336,9 @@
tutorial.setCustomSetupCode("The setup code");
tutorial.setCustomSetupCode("");
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
}
void TutorialTreeItemTest::testTutorialSetCustomTearDownCode() {
@@ -308,8 +347,10 @@
tutorial.setCustomTearDownCode("The tear down code");
- QCOMPARE(item.childCount(), 1);
- assertCustomTearDownCode(item.child(0), "The tear down code");
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ assertCustomTearDownCode(item.child(2), "The tear down code");
}
void TutorialTreeItemTest::testTutorialSetCustomTearDownCodeChange() {
@@ -318,15 +359,17 @@
tutorial.setCustomTearDownCode("The tear down code");
- QSignalSpy dataChangedSpy(item.child(0)->child(0),
+ QSignalSpy dataChangedSpy(item.child(2)->child(0),
SIGNAL(dataChanged(TreeItem*)));
tutorial.setCustomTearDownCode("The tear down code changed");
- QCOMPARE(item.childCount(), 1);
- assertCustomTearDownCode(item.child(0), "The tear down code changed");
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ assertCustomTearDownCode(item.child(2), "The tear down code changed");
QCOMPARE(dataChangedSpy.count(), 1);
- assertDataChanged(dataChangedSpy, 0, item.child(0)->child(0));
+ assertDataChanged(dataChangedSpy, 0, item.child(2)->child(0));
}
void TutorialTreeItemTest::testTutorialSetCustomTearDownCodeEmpty() {
@@ -336,7 +379,9 @@
tutorial.setCustomTearDownCode("The tear down code");
tutorial.setCustomTearDownCode("");
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
}
void TutorialTreeItemTest::testTutorialAddStep() {
@@ -347,8 +392,10 @@
step->setId("Step id");
tutorial.addStep(step);
- QCOMPARE(item.childCount(), 1);
- assertStep(item.child(0), "Step id");
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ assertStep(item.child(2), "Step id");
}
void TutorialTreeItemTest::testTutorialRemoveStep() {
@@ -362,7 +409,9 @@
tutorial.addStep(&step);
tutorial.removeStep(&step);
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
}
void TutorialTreeItemTest::testChildOrderWhenSettingDataInTutorial() {
@@ -372,34 +421,39 @@
tutorial.setCustomSetupCode("The setup code");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 1);
- assertCustomSetupCode(item.child(0), "The setup code");
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ assertCustomSetupCode(item.child(2), "The setup code");
tutorial.setDescription("The description");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 2);
- assertDescription(item.child(0), "The description");
- assertCustomSetupCode(item.child(1), "The setup code");
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyName(item.child(0));
+ assertDescription(item.child(1), "The description");
+ assertCustomSetupCode(item.child(2), "The setup code");
tutorial.setCustomTearDownCode("The tear down code");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 3);
- assertDescription(item.child(0), "The description");
- assertCustomSetupCode(item.child(1), "The setup code");
- assertCustomTearDownCode(item.child(2), "The tear down code");
+ QCOMPARE(item.childCount(), 4);
+ assertEmptyName(item.child(0));
+ assertDescription(item.child(1), "The description");
+ assertCustomSetupCode(item.child(2), "The setup code");
+ assertCustomTearDownCode(item.child(3), "The tear down code");
Step* step1 = new Step();
step1->setId("First step");
tutorial.addStep(step1);
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 4);
- assertDescription(item.child(0), "The description");
- assertCustomSetupCode(item.child(1), "The setup code");
- assertCustomTearDownCode(item.child(2), "The tear down code");
- assertStep(item.child(3), "First step");
+ QCOMPARE(item.childCount(), 5);
+ assertEmptyName(item.child(0));
+ assertDescription(item.child(1), "The description");
+ assertCustomSetupCode(item.child(2), "The setup code");
+ assertCustomTearDownCode(item.child(3), "The tear down code");
+ assertStep(item.child(4), "First step");
tutorial.setName("The name");
@@ -471,56 +525,75 @@
tutorial.setName("");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- 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");
- assertStep(item.child(3), "First step");
- assertStep(item.child(4), "Second step");
+ QCOMPARE(item.childCount(), 6);
+ assertEmptyName(item.child(0));
+ assertDescription(item.child(1), "The description");
+ assertCustomSetupCode(item.child(2), "The setup code");
+ assertCustomTearDownCode(item.child(3), "The tear down code");
+ assertStep(item.child(4), "First step");
+ assertStep(item.child(5), "Second step");
tutorial.removeStep(&step1);
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 4);
- assertDescription(item.child(0), "The description");
- assertCustomSetupCode(item.child(1), "The setup code");
- assertCustomTearDownCode(item.child(2), "The tear down code");
- assertStep(item.child(3), "Second step");
+ QCOMPARE(item.childCount(), 5);
+ assertEmptyName(item.child(0));
+ assertDescription(item.child(1), "The description");
+ assertCustomSetupCode(item.child(2), "The setup code");
+ assertCustomTearDownCode(item.child(3), "The tear down code");
+ assertStep(item.child(4), "Second step");
tutorial.setCustomTearDownCode("");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 3);
- assertDescription(item.child(0), "The description");
- assertCustomSetupCode(item.child(1), "The setup code");
- assertStep(item.child(2), "Second step");
+ QCOMPARE(item.childCount(), 4);
+ assertEmptyName(item.child(0));
+ assertDescription(item.child(1), "The description");
+ assertCustomSetupCode(item.child(2), "The setup code");
+ assertStep(item.child(3), "Second step");
tutorial.setDescription("");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 2);
- assertCustomSetupCode(item.child(0), "The setup code");
- assertStep(item.child(1), "Second step");
+ QCOMPARE(item.childCount(), 4);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ assertCustomSetupCode(item.child(2), "The setup code");
+ assertStep(item.child(3), "Second step");
tutorial.setCustomSetupCode("");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 1);
- assertStep(item.child(0), "Second step");
+ QCOMPARE(item.childCount(), 3);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
+ assertStep(item.child(2), "Second step");
tutorial.removeStep(&step2);
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 0);
+ QCOMPARE(item.childCount(), 2);
+ assertEmptyName(item.child(0));
+ assertEmptyDescription(item.child(1));
}
/////////////////////////////////// Helpers ////////////////////////////////////
+void TutorialTreeItemTest::assertEmptyName(TreeItem* nameItem) const {
+ QCOMPARE(nameItem->text(), i18nc("@item", "Name: (name not set)"));
+}
+
void TutorialTreeItemTest::assertName(TreeItem* nameItem,
const QString& name) const {
QCOMPARE(nameItem->text(), i18nc("@item", "Name: %1", name));
}
+void TutorialTreeItemTest::assertEmptyDescription(
+ TreeItem* descriptionItem) const {
+ QCOMPARE(descriptionItem->text(),
+ i18nc("@item", "Description: (description not set)"));
+}
+
void TutorialTreeItemTest::assertDescription(TreeItem* descriptionItem,
const QString& description) const {
QCOMPARE(descriptionItem->text(),
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|