ktutorial-commits Mailing List for KTutorial (Page 12)
Status: Alpha
Brought to you by:
danxuliu
You can subscribe to this list here.
2010 |
Jan
(1) |
Feb
(36) |
Mar
(117) |
Apr
(11) |
May
(8) |
Jun
(1) |
Jul
|
Aug
(2) |
Sep
(21) |
Oct
(16) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2011 |
Jan
(1) |
Feb
|
Mar
(6) |
Apr
(6) |
May
(15) |
Jun
(15) |
Jul
(6) |
Aug
|
Sep
(1) |
Oct
(4) |
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(10) |
Jul
(4) |
Aug
(29) |
Sep
(4) |
Oct
|
Nov
|
Dec
(2) |
From: <dan...@us...> - 2010-03-06 17:11:33
|
Revision: 112 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=112&view=rev Author: danxuliu Date: 2010-03-06 17:11:26 +0000 (Sat, 06 Mar 2010) Log Message: ----------- Emit signals when the structure or data of a TreeItem is modified, so the TreeModel can watch those signals and notify its views to be updated. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/TreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/TreeItem.h trunk/ktutorial/ktutorial-editor/tests/unit/view/TextTreeItemTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeItemTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.cpp 2010-03-05 23:48:40 UTC (rev 111) +++ trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.cpp 2010-03-06 17:11:26 UTC (rev 112) @@ -27,4 +27,6 @@ void TextTreeItem::setText(const QString& text) { mText = text; + + emit dataChanged(this); } Modified: trunk/ktutorial/ktutorial-editor/src/view/TreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TreeItem.cpp 2010-03-05 23:48:40 UTC (rev 111) +++ trunk/ktutorial/ktutorial-editor/src/view/TreeItem.cpp 2010-03-06 17:11:26 UTC (rev 112) @@ -38,21 +38,33 @@ Q_ASSERT(!mChildren.contains(child)); Q_ASSERT(child->parent() == this); + emit childAboutToBeInserted(child, mChildren.count()); + mChildren.append(child); + + emit childInserted(child); } void TreeItem::insertChild(TreeItem* child, int index) { Q_ASSERT(!mChildren.contains(child)); Q_ASSERT(child->parent() == this); + emit childAboutToBeInserted(child, index); + mChildren.insert(index, child); + + emit childInserted(child); } void TreeItem::removeChild(TreeItem* child) { Q_ASSERT(mChildren.contains(child)); Q_ASSERT(child->parent() == this); + emit childAboutToBeRemoved(child); + mChildren.removeAt(mChildren.indexOf(child)); + + emit childRemoved(child); } TreeItem* TreeItem::parent() { Modified: trunk/ktutorial/ktutorial-editor/src/view/TreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TreeItem.h 2010-03-05 23:48:40 UTC (rev 111) +++ trunk/ktutorial/ktutorial-editor/src/view/TreeItem.h 2010-03-06 17:11:26 UTC (rev 112) @@ -34,13 +34,19 @@ * the name of the person and two child TreeItems, one that contains the age and * one that contains the profession. * + * The structure of a tree can be modified after being added to a TreeModel. + * Changes in the layout (adding or removing child items) or the data are + * notified to the TreeModel, which notifies the views to be updated as needed. + * * TreeItem is an abstract class. Subclasses must implement its text() method, * that provides the data for that item to the TreeModel when DisplayRole is - * used. + * used. They also have to emit dataChanged(TreeItem*) signal when the data to + * be shown is modified. * * @see TreeModel */ -class TreeItem { +class TreeItem: public QObject { +Q_OBJECT public: /** @@ -116,6 +122,52 @@ */ int childIndex() const; +Q_SIGNALS: + + /** + * Emitted just before a child is inserted or appended. + * It is used to notify the TreeModel in order to update the views. + * + * @param child The child to be added. + * @param index The position to insert it (if the item is appended, the + * index is equal to the child count). + */ + void childAboutToBeInserted(TreeItem* child, int index); + + /** + * Emitted after a child is inserted or appended. + * It is used to notify the TreeModel in order to update the views. + * + * @param child The child added. + */ + void childInserted(TreeItem* child); + + /** + * Emitted just before a child is removed. + * It is used to notify the TreeModel in order to update the views. + * + * @param child The child to be removed. + */ + void childAboutToBeRemoved(TreeItem* child); + + /** + * Emitted after a child is removed. + * It is used to notify the TreeModel in order to update the views. + * + * @param child The child removed. + */ + void childRemoved(TreeItem* child); + + /** + * Emitted when the data to be used by the TreeModel changes. + * It is used to notify the TreeModel in order to update the views. + * + * It must be emitted by subclasses as needed. + * + * @param item This TreeItem. + */ + void dataChanged(TreeItem* item); + private: /** Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/TextTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/TextTreeItemTest.cpp 2010-03-05 23:48:40 UTC (rev 111) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TextTreeItemTest.cpp 2010-03-06 17:11:26 UTC (rev 112) @@ -39,11 +39,23 @@ QCOMPARE(treeItem.parent(), &parent); } +//TreeItem* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(TreeItem*); + void TextTreeItemTest::testSetText() { TextTreeItem item; + + //TreeItem* must be registered in order to be used with QSignalSpy + int treeItemStarType = qRegisterMetaType<TreeItem*>("TreeItem*"); + QSignalSpy dataChangedSpy(&item, SIGNAL(dataChanged(TreeItem*))); + item.setText("Hello world"); QCOMPARE(item.text(), QString("Hello world")); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), treeItemStarType); + QCOMPARE(qvariant_cast<TreeItem*>(argument), &item); } QTEST_MAIN(TextTreeItemTest) Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeItemTest.cpp 2010-03-05 23:48:40 UTC (rev 111) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeItemTest.cpp 2010-03-06 17:11:26 UTC (rev 112) @@ -25,6 +25,8 @@ private slots: + void initTestCase(); + void testConstructor(); void testAppendChild(); @@ -36,6 +38,15 @@ void testRemoveChild(); void testRemoveChildSeveralChildren(); +private: + + int mTreeItemStarType; + + void assertAboutToBeInsertedSignal(const QSignalSpy& spy, int index, + TreeItem* item, int itemIndex) const; + + void assertSignal(const QSignalSpy& spy, int index, TreeItem* item) const; + }; class StubTreeItem: public TreeItem { @@ -52,6 +63,11 @@ }; +void TreeItemTest::initTestCase() { + //TreeItem* must be registered in order to be used with QSignalSpy + mTreeItemStarType = qRegisterMetaType<TreeItem*>("TreeItem*"); +} + void TreeItemTest::testConstructor() { StubTreeItem parent; StubTreeItem treeItem(&parent); @@ -60,16 +76,32 @@ QCOMPARE(treeItem.parent(), &parent); } +//TreeItem* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(TreeItem*); + void TreeItemTest::testAppendChild() { StubTreeItem treeItem; TreeItem* child = new StubTreeItem(&treeItem); + QSignalSpy aboutToBeInsertedSpy(&treeItem, + SIGNAL(childAboutToBeInserted(TreeItem*, int))); + QSignalSpy insertedSpy(&treeItem, SIGNAL(childInserted(TreeItem*))); + treeItem.appendChild(child); QCOMPARE(treeItem.childCount(), 1); QCOMPARE(treeItem.child(0), child); QCOMPARE(child->childIndex(), 0); QCOMPARE(child->parent(), &treeItem); + + //The proper way to check this would be asserting not only that the signals + //were emitted, but that when they were emitted the item wasn't and was + //already added (depending on the signal). However, that is too much effort + //for little gain. + QCOMPARE(aboutToBeInsertedSpy.count(), 1); + assertAboutToBeInsertedSignal(aboutToBeInsertedSpy, 0, child, 0); + QCOMPARE(insertedSpy.count(), 1); + assertSignal(insertedSpy, 0, child); } void TreeItemTest::testAppendChildSeveralChildren() { @@ -78,6 +110,10 @@ TreeItem* child2 = new StubTreeItem(&treeItem); TreeItem* child3 = new StubTreeItem(&treeItem); + QSignalSpy aboutToBeInsertedSpy(&treeItem, + SIGNAL(childAboutToBeInserted(TreeItem*, int))); + QSignalSpy insertedSpy(&treeItem, SIGNAL(childInserted(TreeItem*))); + treeItem.appendChild(child1); treeItem.appendChild(child2); treeItem.appendChild(child3); @@ -92,18 +128,36 @@ QCOMPARE(child2->parent(), &treeItem); QCOMPARE(child3->childIndex(), 2); QCOMPARE(child3->parent(), &treeItem); + + QCOMPARE(aboutToBeInsertedSpy.count(), 3); + assertAboutToBeInsertedSignal(aboutToBeInsertedSpy, 0, child1, 0); + assertAboutToBeInsertedSignal(aboutToBeInsertedSpy, 1, child2, 1); + assertAboutToBeInsertedSignal(aboutToBeInsertedSpy, 2, child3, 2); + QCOMPARE(insertedSpy.count(), 3); + assertSignal(insertedSpy, 0, child1); + assertSignal(insertedSpy, 1, child2); + assertSignal(insertedSpy, 2, child3); } void TreeItemTest::testInsertChild() { StubTreeItem treeItem; TreeItem* child = new StubTreeItem(&treeItem); + QSignalSpy aboutToBeInsertedSpy(&treeItem, + SIGNAL(childAboutToBeInserted(TreeItem*, int))); + QSignalSpy insertedSpy(&treeItem, SIGNAL(childInserted(TreeItem*))); + treeItem.insertChild(child, 0); QCOMPARE(treeItem.childCount(), 1); QCOMPARE(treeItem.child(0), child); QCOMPARE(child->childIndex(), 0); QCOMPARE(child->parent(), &treeItem); + + QCOMPARE(aboutToBeInsertedSpy.count(), 1); + assertAboutToBeInsertedSignal(aboutToBeInsertedSpy, 0, child, 0); + QCOMPARE(insertedSpy.count(), 1); + assertSignal(insertedSpy, 0, child); } void TreeItemTest::testInsertChildSeveralChildren() { @@ -113,6 +167,10 @@ TreeItem* child3 = new StubTreeItem(&treeItem); TreeItem* child4 = new StubTreeItem(&treeItem); + QSignalSpy aboutToBeInsertedSpy(&treeItem, + SIGNAL(childAboutToBeInserted(TreeItem*, int))); + QSignalSpy insertedSpy(&treeItem, SIGNAL(childInserted(TreeItem*))); + treeItem.insertChild(child2, 0); treeItem.insertChild(child1, 0); treeItem.insertChild(child4, 2); @@ -131,6 +189,17 @@ QCOMPARE(child3->parent(), &treeItem); QCOMPARE(child4->childIndex(), 3); QCOMPARE(child4->parent(), &treeItem); + + QCOMPARE(aboutToBeInsertedSpy.count(), 4); + assertAboutToBeInsertedSignal(aboutToBeInsertedSpy, 0, child2, 0); + assertAboutToBeInsertedSignal(aboutToBeInsertedSpy, 1, child1, 0); + assertAboutToBeInsertedSignal(aboutToBeInsertedSpy, 2, child4, 2); + assertAboutToBeInsertedSignal(aboutToBeInsertedSpy, 3, child3, 2); + QCOMPARE(insertedSpy.count(), 4); + assertSignal(insertedSpy, 0, child2); + assertSignal(insertedSpy, 1, child1); + assertSignal(insertedSpy, 2, child4); + assertSignal(insertedSpy, 3, child3); } void TreeItemTest::testRemoveChild() { @@ -139,12 +208,21 @@ //stack StubTreeItem child(&treeItem); + QSignalSpy aboutToBeRemovedSpy(&treeItem, + SIGNAL(childAboutToBeRemoved(TreeItem*))); + QSignalSpy removedSpy(&treeItem, SIGNAL(childRemoved(TreeItem*))); + treeItem.appendChild(&child); treeItem.removeChild(&child); QCOMPARE(treeItem.childCount(), 0); QCOMPARE(child.childIndex(), -1); QCOMPARE(child.parent(), &treeItem); + + QCOMPARE(aboutToBeRemovedSpy.count(), 1); + assertSignal(aboutToBeRemovedSpy, 0, &child); + QCOMPARE(removedSpy.count(), 1); + assertSignal(removedSpy, 0, &child); } void TreeItemTest::testRemoveChildSeveralChildren() { @@ -155,6 +233,10 @@ StubTreeItem child2(&treeItem); StubTreeItem child3(&treeItem); + QSignalSpy aboutToBeRemovedSpy(&treeItem, + SIGNAL(childAboutToBeRemoved(TreeItem*))); + QSignalSpy removedSpy(&treeItem, SIGNAL(childRemoved(TreeItem*))); + treeItem.appendChild(&child1); treeItem.appendChild(&child2); treeItem.appendChild(&child3); @@ -171,6 +253,11 @@ QCOMPARE(child3.childIndex(), 1); QCOMPARE(child3.parent(), &treeItem); + QCOMPARE(aboutToBeRemovedSpy.count(), 1); + assertSignal(aboutToBeRemovedSpy, 0, &child2); + QCOMPARE(removedSpy.count(), 1); + assertSignal(removedSpy, 0, &child2); + treeItem.removeChild(&child1); treeItem.removeChild(&child3); @@ -181,8 +268,40 @@ QCOMPARE(child2.parent(), &treeItem); QCOMPARE(child3.childIndex(), -1); QCOMPARE(child3.parent(), &treeItem); + + QCOMPARE(aboutToBeRemovedSpy.count(), 3); + assertSignal(aboutToBeRemovedSpy, 1, &child1); + assertSignal(aboutToBeRemovedSpy, 2, &child3); + QCOMPARE(removedSpy.count(), 3); + assertSignal(removedSpy, 1, &child1); + assertSignal(removedSpy, 2, &child3); } +/////////////////////////////////// Helpers //////////////////////////////////// + +void TreeItemTest::assertAboutToBeInsertedSignal(const QSignalSpy& spy, + int index, TreeItem* item, + int itemIndex) const { + QCOMPARE(spy.at(index).count(), 2); + + QVariant argument = spy.at(index).at(0); + QCOMPARE(argument.userType(), mTreeItemStarType); + QCOMPARE(qvariant_cast<TreeItem*>(argument), item); + + argument = spy.at(index).at(1); + QCOMPARE(argument.type(), QVariant::Int); + QCOMPARE(argument.toInt(), itemIndex); +} + +void TreeItemTest::assertSignal(const QSignalSpy& spy, int index, + TreeItem* item) const { + QCOMPARE(spy.at(index).count(), 1); + + QVariant argument = spy.at(index).at(0); + QCOMPARE(argument.userType(), mTreeItemStarType); + QCOMPARE(qvariant_cast<TreeItem*>(argument), item); +} + QTEST_MAIN(TreeItemTest) #include "TreeItemTest.moc" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-05 23:48:53
|
Revision: 111 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=111&view=rev Author: danxuliu Date: 2010-03-05 23:48:40 +0000 (Fri, 05 Mar 2010) Log Message: ----------- Add TextTreeItem class, that represents a plain string in a TreeModel. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.h trunk/ktutorial/ktutorial-editor/tests/unit/view/TextTreeItemTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-05 23:35:28 UTC (rev 110) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-05 23:48:40 UTC (rev 111) @@ -1,6 +1,7 @@ include_directories(${KDE4_INCLUDES}) set(ktutorial_editor_view_SRCS + TextTreeItem.cpp TreeItem.cpp TreeModel.cpp ) Added: trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.cpp 2010-03-05 23:48:40 UTC (rev 111) @@ -0,0 +1,30 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "TextTreeItem.h" + +TextTreeItem::TextTreeItem(TreeItem* parent): TreeItem(parent) { +} + +QString TextTreeItem::text() const { + return mText; +} + +void TextTreeItem::setText(const QString& text) { + mText = text; +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.h 2010-03-05 23:48:40 UTC (rev 111) @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef TEXTTREEITEM_H +#define TEXTTREEITEM_H + +#include "TreeItem.h" + +/** + * A simple TreeItem that represents a plain string. + */ +class TextTreeItem: public TreeItem { +public: + + /** + * Creates a new TextTreeItem with the given parent. + * + * @param parent The parent TreeItem. + */ + explicit TextTreeItem(TreeItem* parent = 0); + + /** + * The text to be shown for this node of the tree, + * + * @return The text for this TreeItem. + */ + virtual QString text() const; + + /** + * Sets the text of this TextTreeItem. + * + * @param text The text to set. + */ + void setText(const QString& text); + +private: + + /** + * The text to show. + */ + QString mText; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/TextTreeItem.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-05 23:35:28 UTC (rev 110) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-05 23:48:40 UTC (rev 111) @@ -16,7 +16,7 @@ ENDFOREACH(_className) ENDMACRO(UNIT_TESTS) -unit_tests(TreeItem TreeModel) +unit_tests(TextTreeItem TreeItem TreeModel) MACRO(MEM_TESTS) FOREACH(_testname ${ARGN}) @@ -24,4 +24,4 @@ ENDFOREACH(_testname) ENDMACRO(MEM_TESTS) -mem_tests(TreeItem TreeModel) +mem_tests(TextTreeItem TreeItem TreeModel) Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/TextTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/TextTreeItemTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TextTreeItemTest.cpp 2010-03-05 23:48:40 UTC (rev 111) @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QtTest> + +#include "TextTreeItem.h" + +class TextTreeItemTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testSetText(); + +}; + +void TextTreeItemTest::testConstructor() { + TextTreeItem parent; + TextTreeItem treeItem(&parent); + + QCOMPARE(parent.parent(), (TreeItem*)0); + QCOMPARE(treeItem.parent(), &parent); +} + +void TextTreeItemTest::testSetText() { + TextTreeItem item; + item.setText("Hello world"); + + QCOMPARE(item.text(), QString("Hello world")); +} + +QTEST_MAIN(TextTreeItemTest) + +#include "TextTreeItemTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/TextTreeItemTest.cpp ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-05 23:35:37
|
Revision: 110 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=110&view=rev Author: danxuliu Date: 2010-03-05 23:35:28 +0000 (Fri, 05 Mar 2010) Log Message: ----------- Add the foundations to show a Tutorial in a QTreeView. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/view/ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/view/TreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/TreeItem.h trunk/ktutorial/ktutorial-editor/src/view/TreeModel.cpp trunk/ktutorial/ktutorial-editor/src/view/TreeModel.h trunk/ktutorial/ktutorial-editor/tests/ trunk/ktutorial/ktutorial-editor/tests/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/ trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/runMemcheck.py trunk/ktutorial/ktutorial-editor/tests/unit/view/ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeItemTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeModelTest.cpp Modified: trunk/ktutorial/ktutorial-editor/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/CMakeLists.txt 2010-03-05 23:32:03 UTC (rev 109) +++ trunk/ktutorial/ktutorial-editor/CMakeLists.txt 2010-03-05 23:35:28 UTC (rev 110) @@ -5,3 +5,4 @@ include(KDE4Defaults) add_subdirectory(src) +add_subdirectory(tests) Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-05 23:32:03 UTC (rev 109) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-05 23:35:28 UTC (rev 110) @@ -2,6 +2,8 @@ # In order to work, they must be compiled using -fPIC add_definitions("-fPIC") +add_subdirectory(view) + include_directories(${KDE4_INCLUDES}) set(ktutorial_editor_SRCS @@ -14,6 +16,7 @@ # As everything but a tiny initialization code is in a library, the build system # for the tests can be easily set up. kde4_add_library(ktutorial_editor ${ktutorial_editor_SRCS}) +target_link_libraries(ktutorial_editor ktutorial_editor_view) kde4_add_executable(ktutorial-editor main.cpp) target_link_libraries(ktutorial-editor ktutorial_editor ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS}) Added: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-05 23:35:28 UTC (rev 110) @@ -0,0 +1,10 @@ +include_directories(${KDE4_INCLUDES}) + +set(ktutorial_editor_view_SRCS + TreeItem.cpp + TreeModel.cpp +) + +kde4_add_library(ktutorial_editor_view ${ktutorial_editor_view_SRCS}) + +target_link_libraries(ktutorial_editor_view ${KDE4_KDEUI_LIBS}) Property changes on: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/TreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TreeItem.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/TreeItem.cpp 2010-03-05 23:35:28 UTC (rev 110) @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "TreeItem.h" + +TreeItem::TreeItem(TreeItem* parent): + mParent(parent) { +} + +TreeItem::~TreeItem() { + qDeleteAll(mChildren); +} + +TreeItem* TreeItem::child(int index) { + return mChildren.value(index); +} + +int TreeItem::childCount() const { + return mChildren.count(); +} + +void TreeItem::appendChild(TreeItem* child) { + Q_ASSERT(!mChildren.contains(child)); + Q_ASSERT(child->parent() == this); + + mChildren.append(child); +} + +void TreeItem::insertChild(TreeItem* child, int index) { + Q_ASSERT(!mChildren.contains(child)); + Q_ASSERT(child->parent() == this); + + mChildren.insert(index, child); +} + +void TreeItem::removeChild(TreeItem* child) { + Q_ASSERT(mChildren.contains(child)); + Q_ASSERT(child->parent() == this); + + mChildren.removeAt(mChildren.indexOf(child)); +} + +TreeItem* TreeItem::parent() { + return mParent; +} + +int TreeItem::childIndex() const { + for (int i = 0; i < mParent->childCount(); ++i) { + if (mParent->child(i) == this) { + return i; + } + } + + return -1; +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/TreeItem.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/TreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TreeItem.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/TreeItem.h 2010-03-05 23:35:28 UTC (rev 110) @@ -0,0 +1,133 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef TREEITEM_H +#define TREEITEM_H + +#include <QString> +#include <QVariant> + +/** + * An item in a TreeModel. + * TreeItems form tree structures that provide the data to TreeModels. The + * TreeItems act as an adapter between the model and the real data: through + * TreeItem custom subclasses a source of data can be represented as several + * nested TreeItem objects that expose the data in some specific structure. + * + * For example, an object of a Person class with name, age and profession + * attributes can be represented as a tree with a parent TreeItem that contains + * the name of the person and two child TreeItems, one that contains the age and + * one that contains the profession. + * + * TreeItem is an abstract class. Subclasses must implement its text() method, + * that provides the data for that item to the TreeModel when DisplayRole is + * used. + * + * @see TreeModel + */ +class TreeItem { +public: + + /** + * Creates a new TreeItem with the given parent. + * + * @param parent The parent TreeItem. + */ + explicit TreeItem(TreeItem* parent = 0); + + /** + * Destroys this TreeItem and all its children. + */ + virtual ~TreeItem(); + + /** + * The text to be shown for this node of the tree, + * This method must be implemented by subclasses. + * + * @return The text for this TreeItem. + */ + virtual QString text() const = 0; + + /** + * Returns the child tree item with the given index. + * + * @param index The index of the child to get. + * @return The child with the given index. + */ + TreeItem* child(int index); + + /** + * Returns the number of child tree items. + * + * @return The number of children. + */ + int childCount() const; + + /** + * Adds a child at the end of the child list. + * + * @param child The child to add. + */ + void appendChild(TreeItem* child); + + /** + * Inserts a child at the given position of the child list. + * + * @param child The child to insert. + * @param index The position to insert the child into. + */ + void insertChild(TreeItem* child, int index); + + /** + * Removes the given child from the child list. + * + * @param child The child to remove. + */ + void removeChild(TreeItem* child); + + /** + * The parent of this TreeItem. + * + * @return The parent of this TreeItem. + */ + TreeItem* parent(); + + /** + * The index of this TreeItem in the child list of its parent. + * If this TreeItem was not added or was removed from its parent, -1 is + * returned. + * + * @return The index of this TreeItem. + */ + int childIndex() const; + +private: + + /** + * The parent of this TreeItem. + */ + TreeItem* mParent; + + /** + * The children of this TreeItem. + */ + QList<TreeItem*> mChildren; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/TreeItem.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/TreeModel.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TreeModel.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/TreeModel.cpp 2010-03-05 23:35:28 UTC (rev 110) @@ -0,0 +1,116 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "TreeModel.h" + +#include "TreeItem.h" + +//public: + +TreeModel::TreeModel(TreeItem* rootItem, QObject* parent): + QAbstractItemModel(parent), + mRootItem(rootItem) { + Q_ASSERT(rootItem); +} + +TreeModel::~TreeModel() { + delete mRootItem; +} + +QVariant TreeModel::data(const QModelIndex& index, int role) const { + if (!index.isValid()) { + return QVariant(); + } + + if (role != Qt::DisplayRole) { + return QVariant(); + } + + TreeItem* item = static_cast<TreeItem*>(index.internalPointer()); + + return item->text(); +} + +Qt::ItemFlags TreeModel::flags(const QModelIndex& index) const { + if (!index.isValid()) { + return Qt::NoItemFlags; + } + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant TreeModel::headerData(int section, Qt::Orientation orientation, + int role) const { + if (section == 0 && orientation == Qt::Horizontal && + role == Qt::DisplayRole) { + return mRootItem->text(); + } + + return QVariant(); +} + +QModelIndex TreeModel::index(int row, int column, + const QModelIndex& parent) const { + if (!hasIndex(row, column, parent)) { + return QModelIndex(); + } + + TreeItem* parentItem; + + if (!parent.isValid()) { + parentItem = mRootItem; + } else { + parentItem = static_cast<TreeItem*>(parent.internalPointer()); + } + + TreeItem* childItem = parentItem->child(row); + + return createIndex(row, column, childItem); +} + +QModelIndex TreeModel::parent(const QModelIndex& index) const { + if (!index.isValid()) { + return QModelIndex(); + } + + TreeItem* childItem = static_cast<TreeItem*>(index.internalPointer()); + TreeItem* parentItem = childItem->parent(); + + if (parentItem == mRootItem) { + return QModelIndex(); + } + + return createIndex(parentItem->childIndex(), 0, parentItem); +} + +int TreeModel::rowCount(const QModelIndex& parent) const { + TreeItem* parentItem; + if (!parent.isValid()) { + parentItem = mRootItem; + } else { + parentItem = static_cast<TreeItem*>(parent.internalPointer()); + } + + return parentItem->childCount(); +} + +int TreeModel::columnCount(const QModelIndex& parent) const { + Q_UNUSED(parent); + + return 1; +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/TreeModel.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/TreeModel.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TreeModel.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/TreeModel.h 2010-03-05 23:35:28 UTC (rev 110) @@ -0,0 +1,150 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef TREEMODEL_H +#define TREEMODEL_H + +#include <QAbstractItemModel> + +class TreeItem; + +/** + * A read only model to represent nested data in a single column tree. + * The model gets its data from a tree structure made of TreeItems. The root + * item provides the data for the header and its children (and the children of + * its children, and the children of the children of...) the data for the + * contents. + * + * TreeItem objects are mapped one to one to items in the model. Each TreeItem + * (but the root item) has its own index in the model. Top level items (direct + * children of root item) have no parent indexes. For child items, their parent + * index is the index of its parent item. The row count for any index is the + * number of children of its TreeItem. There is only one column in any index (as + * it is a single column tree). + * + * Each TreeItem provides the data to be shown by its associated model item. + * Display role shows the text of the TreeItem. + * + * @see TreeItem + */ +class TreeModel: public QAbstractItemModel { +Q_OBJECT +public: + + /** + * Creates a new TreeModel for the given root TreeItem. + * + * @param rootItem The root of the tree. + * @param parent The parent object. + */ + explicit TreeModel(TreeItem* rootItem, QObject* parent = 0); + + /** + * Destroys this TreeModel and its tree of items. + */ + virtual ~TreeModel(); + + /** + * Returns the data for the given index and role. + * Display role with valid index returns the text of the TreeItem referred + * to by the index. An invalid variant is returned otherwise. + * + * @param index The index. + * @param role The role. + * @return The data for the given index and role, or an invalid variant if + * there is no data. + */ + virtual QVariant data(const QModelIndex& index, + int role = Qt::DisplayRole) const; + + /** + * Returns the flags for the given index. + * If the index is valid, the flags enable the item and allow it to be + * selected. + * + * @return The flags for the given index. + */ + virtual Qt::ItemFlags flags(const QModelIndex& index) const; + + /** + * Returns the data for the given role and section in the header with the + * specified orientation. + * Display role in section 0 and horizontal orientation returns the text of + * the root item. An invalid variant is returned otherwise. + * + * @param section The section of the header. + * @param orientation The orientation of the header. + * @param role The role of the header. + * @return The data for the header. + */ + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + /** + * Returns the index of the item in the model specified by the given row, + * column and parent index. + * If the row or column is out of bounds for the given parent, an invalid + * index is returned. + * + * @param row The row of the index. + * @param column The column of the index. + * @param parent The parent of the index. + * @return The index for the given row, column and parent. + */ + virtual QModelIndex index(int row, int column, + const QModelIndex& parent = QModelIndex()) const; + + /** + * Returns the index for the parent of the model item with the given index. + * If the index has no parent (it is invalid, or a top level index), an + * invalid index is returned. + * + * @param index The index to get its parent. + * @return The parent index of the given index. + */ + virtual QModelIndex parent(const QModelIndex& index) const; + + /** + * Returns the number of rows under the given parent. + * It is the number of children of the TreeItem referred to by the index. If + * the index is invalid, it is the number of top level items. + * + * @param parent The parent index. + * @return The number of child rows. + */ + virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; + + /** + * Returns the number of columns for the children of the given parent. + * As this model is a single column model, it always returns 1. + * + * @param parent The parent index. + * @return The number of columns for the children. + */ + virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; + +private: + + /** + * The root item. + */ + TreeItem* mRootItem; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/TreeModel.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/CMakeLists.txt 2010-03-05 23:35:28 UTC (rev 110) @@ -0,0 +1 @@ +add_subdirectory(unit) Property changes on: trunk/ktutorial/ktutorial-editor/tests/CMakeLists.txt ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-05 23:35:28 UTC (rev 110) @@ -0,0 +1 @@ +add_subdirectory(view) Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/runMemcheck.py =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/runMemcheck.py (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/runMemcheck.py 2010-03-05 23:35:28 UTC (rev 110) @@ -0,0 +1,173 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# run valgrind's memory error checker on all tests. +# filter uninteresting errors and known false positives +# eg staticly initialized memory from libraries like libfontconfig +# + + +# Modified from Coverage plugin tests for KDevelop 4 +# http://websvn.kde.org/trunk/KDE/kdevelop/tools/coverage/tests/runMemcheck.py?revision=926694&view=markup +# which is licensed under GPL 2 or later +# http://websvn.kde.org/trunk/KDE/kdevelop/tools/coverage/coverageplugin.cpp?revision=926694&view=markup + + +from os import system, remove +from sys import exit, stdout +from subprocess import Popen, PIPE +from xml.dom.minidom import parse, parseString + +def garbage(line): + ''' filter for valgridn output''' + return not line.startswith('<unknown program name>') and \ + not line.startswith('profiling:') and \ + line.find('</valgrindoutput>') # problem is that valgrind erroneously puts multiple of these end-document entries if processes are spawned _inside_ the exe under investigation + +def memcheck(test): + ''' run valgrind-memcheck on test in testdir. return xml output as string ''' + #proc = Popen("valgrind --tool=memcheck --leak-check=full --xml=yes " + test, stdout=PIPE, stderr=PIPE, shell=True, executable="/bin/bash") + #proc.wait() + #out = proc.stderr.readlines() + system("valgrind --tool=memcheck --leak-check=full --xml=yes --xml-file=.memcheck.tmp --num-callers=50 " + test + " 1>/dev/null") + out = open(".memcheck.tmp").readlines() + remove(".memcheck.tmp") + out = filter(garbage, out) + return ''.join(out) + "\n</valgrindoutput>\n" + +def xml_child_data(dom,tag): + ''' extract child data for tag. return None if not found''' + elem = dom.getElementsByTagName(tag) + val = None + if len(elem) != 0: + val = elem[0].firstChild.data + return val + +class Frame: + ''' single entry in a memory error backtrace ''' + def __init__(self, dom_frame): + '''<frame> + <ip>0x62ACDBF</ip> + <obj>/home/nix/KdeDev/kde4/lib/libkdevplatformlanguage.so.1.0.0</obj> + <fn>KDevelop::ParamIterator::ParamIterator(QString, QString, int)</fn> + <dir>/home/nix/KdeDev/kdevplatform/language/duchain</dir> + <file>stringhelpers.cpp</file> + <line>292</line> + </frame>''' + self.obj = xml_child_data(dom_frame, 'obj') + self.func = xml_child_data(dom_frame, 'fn') + self.sfile = xml_child_data(dom_frame, 'file') + self.sline = xml_child_data(dom_frame, 'line') + + def __str__(self): + out = "" + if self.func: + out += "\t" + self.func + if self.sfile and self.sline: + out += " (" + self.sfile + ":" + self.sline + ")" + #if self.obj: + #out += "\t" + self.obj + "\n" + out += "\n" + return out + +class BackTrace: + ''' valgrind memcheck stack trace ''' + def __init__(self, errordom): + self.dom = errordom + self.kind = self.dom.getElementsByTagName('kind')[0].firstChild.data + stack = self.dom.getElementsByTagName('frame') + self.stack = [] + for frame in stack: + if xml_child_data(frame, 'fn'): # filter anonymous frames out + self.stack.append(Frame(frame)) + self.what = xml_child_data(self.dom, 'what') + if self.dom.getElementsByTagName('xwhat').length > 0: + self.what = xml_child_data(self.dom.getElementsByTagName('xwhat')[0], 'text') + + def is_definitely_lost(self): + return self.kind == u'Leak_DefinitelyLost' + + def is_qtest(self): + is_interesting = False + for frame in self.stack: + if frame.func: + if frame.func.find("QTest") != -1 or frame.func.find("Veritas") != -1: + is_interesting = True + if frame.func.find('XcursorXcFileLoadImages') != -1: + return False # something deep in X server, not interested in this + if frame.func.find('XRegisterIMInstantiateCallback') != -1: + return False # X-related static memory allocation, no leak + if frame.func.find('FcDefaultSubstitute') != -1: + return False # something Qt-Font related, not interested in this + if frame.func.find('__nss_database_lookup') != -1: + return False # more crap + if frame.sfile: + if frame.sfile.find("xtest") != -1 or frame.sfile.find("veritas") != -1: + is_interesting = True + return is_interesting + + def __str__(self): + out = self.what + "\n" + for frame in self.stack: + out += str(frame) + return out + +def parse_errors(out): + ''' extract the interesting memcheck errors from the xml-string input 'out'. + return these as a list ''' + xmldoc = parseString(out) + errors = xmldoc.getElementsByTagName('error') + errors_ = [] + for error in errors: + bt = BackTrace(error) + if bt.is_definitely_lost() and bt.is_qtest(): + errors_.append(bt) + return errors_ + +def run_single_test(exe_name): + print ">> running valgrind memcheck on " + exe_name + system("export LD_LIBRARY_PATH="+sys.argv[2]+"/lib/:$LD_LIBRARY_PATH") + count = 0 + import xml + while count < 5: + try: + out = memcheck(exe_name) + errors = parse_errors(out) + if len(errors) == 0: + print "PASS" + exit(0) + else: + for trace in errors: + print trace, + print "---------------------------------------------------" + exit(-1) + except xml.parsers.expat.ExpatError: + print "Valgrind fooked up, retry" + count += 1 + pass + print "5 retries, no luck: aborting :(" + exit(-1) + +################### ENTRY #################################################### + + +def isValgrind3_5OrHigher(): + process = Popen("valgrind --version", stdout=PIPE, shell=True) + process.wait() + valgrindOutput = process.stdout.read().strip() + + import re, string + version = re.search("[0-9]+(.[0-9]+)*", valgrindOutput).group(0) + version = string.split(version, ".") + + if map(int, version) < [3, 5]: + return False + else: + return True + +if __name__ == '__main__': + if not isValgrind3_5OrHigher(): + print "Valgrind 3.5.0 or higher is needed. No mem check will be run." + exit(-1) + + import sys + run_single_test(sys.argv[1]) Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/runMemcheck.py ___________________________________________________________________ Added: svn:executable + * Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-05 23:35:28 UTC (rev 110) @@ -0,0 +1,27 @@ +# Used by kde4_add_unit_test to set the full path to test executables +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) + +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ktutorial-editor_SOURCE_DIR}/src/view ${ktutorial-editor_BINARY_DIR}/src/view ${KDE4_INCLUDES}) + +# Since Qt 4.6.0, this definition is needed for GUI testing. +# It is backwards compatible with previous Qt versions, unlike the alternative +# which is to add #include <QTestGui> in the test files. +add_definitions(-DQT_GUI_LIB) + +MACRO(UNIT_TESTS) + FOREACH(_className ${ARGN}) + set(_testName ${_className}Test) + kde4_add_unit_test(${_testName} TESTNAME ktutorial-editor-unit-${_testName} ${_testName}.cpp) + target_link_libraries(${_testName} ktutorial_editor_view ${QT_QTTEST_LIBRARY}) + ENDFOREACH(_className) +ENDMACRO(UNIT_TESTS) + +unit_tests(TreeItem TreeModel) + +MACRO(MEM_TESTS) + FOREACH(_testname ${ARGN}) + add_test(ktutorial-editor-unit-mem-${_testname} ${CMAKE_CURRENT_SOURCE_DIR}/../runMemcheck.py ${CMAKE_CURRENT_BINARY_DIR}/${_testname}Test ${CMAKE_CURRENT_BINARY_DIR}) + ENDFOREACH(_testname) +ENDMACRO(MEM_TESTS) + +mem_tests(TreeItem TreeModel) Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeItemTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeItemTest.cpp 2010-03-05 23:35:28 UTC (rev 110) @@ -0,0 +1,188 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QtTest> + +#include "TreeItem.h" + +class TreeItemTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testAppendChild(); + void testAppendChildSeveralChildren(); + + void testInsertChild(); + void testInsertChildSeveralChildren(); + + void testRemoveChild(); + void testRemoveChildSeveralChildren(); + +}; + +class StubTreeItem: public TreeItem { +public: + + QString mText; + + StubTreeItem(TreeItem* parent = 0): TreeItem(parent) { + } + + virtual QString text() const { + return mText; + } + +}; + +void TreeItemTest::testConstructor() { + StubTreeItem parent; + StubTreeItem treeItem(&parent); + + QCOMPARE(parent.parent(), (TreeItem*)0); + QCOMPARE(treeItem.parent(), &parent); +} + +void TreeItemTest::testAppendChild() { + StubTreeItem treeItem; + TreeItem* child = new StubTreeItem(&treeItem); + + treeItem.appendChild(child); + + QCOMPARE(treeItem.childCount(), 1); + QCOMPARE(treeItem.child(0), child); + QCOMPARE(child->childIndex(), 0); + QCOMPARE(child->parent(), &treeItem); +} + +void TreeItemTest::testAppendChildSeveralChildren() { + StubTreeItem treeItem; + TreeItem* child1 = new StubTreeItem(&treeItem); + TreeItem* child2 = new StubTreeItem(&treeItem); + TreeItem* child3 = new StubTreeItem(&treeItem); + + treeItem.appendChild(child1); + treeItem.appendChild(child2); + treeItem.appendChild(child3); + + QCOMPARE(treeItem.childCount(), 3); + QCOMPARE(treeItem.child(0), child1); + QCOMPARE(treeItem.child(1), child2); + QCOMPARE(treeItem.child(2), child3); + QCOMPARE(child1->childIndex(), 0); + QCOMPARE(child1->parent(), &treeItem); + QCOMPARE(child2->childIndex(), 1); + QCOMPARE(child2->parent(), &treeItem); + QCOMPARE(child3->childIndex(), 2); + QCOMPARE(child3->parent(), &treeItem); +} + +void TreeItemTest::testInsertChild() { + StubTreeItem treeItem; + TreeItem* child = new StubTreeItem(&treeItem); + + treeItem.insertChild(child, 0); + + QCOMPARE(treeItem.childCount(), 1); + QCOMPARE(treeItem.child(0), child); + QCOMPARE(child->childIndex(), 0); + QCOMPARE(child->parent(), &treeItem); +} + +void TreeItemTest::testInsertChildSeveralChildren() { + StubTreeItem treeItem; + TreeItem* child1 = new StubTreeItem(&treeItem); + TreeItem* child2 = new StubTreeItem(&treeItem); + TreeItem* child3 = new StubTreeItem(&treeItem); + TreeItem* child4 = new StubTreeItem(&treeItem); + + treeItem.insertChild(child2, 0); + treeItem.insertChild(child1, 0); + treeItem.insertChild(child4, 2); + treeItem.insertChild(child3, 2); + + QCOMPARE(treeItem.childCount(), 4); + QCOMPARE(treeItem.child(0), child1); + QCOMPARE(treeItem.child(1), child2); + QCOMPARE(treeItem.child(2), child3); + QCOMPARE(treeItem.child(3), child4); + QCOMPARE(child1->childIndex(), 0); + QCOMPARE(child1->parent(), &treeItem); + QCOMPARE(child2->childIndex(), 1); + QCOMPARE(child2->parent(), &treeItem); + QCOMPARE(child3->childIndex(), 2); + QCOMPARE(child3->parent(), &treeItem); + QCOMPARE(child4->childIndex(), 3); + QCOMPARE(child4->parent(), &treeItem); +} + +void TreeItemTest::testRemoveChild() { + StubTreeItem treeItem; + //It will be removed and not deleted by parent TreeItem, so it is created in + //stack + StubTreeItem child(&treeItem); + + treeItem.appendChild(&child); + treeItem.removeChild(&child); + + QCOMPARE(treeItem.childCount(), 0); + QCOMPARE(child.childIndex(), -1); + QCOMPARE(child.parent(), &treeItem); +} + +void TreeItemTest::testRemoveChildSeveralChildren() { + StubTreeItem treeItem; + //They will be removed and not deleted by parent TreeItem, so they are + //created in stack + StubTreeItem child1(&treeItem); + StubTreeItem child2(&treeItem); + StubTreeItem child3(&treeItem); + + treeItem.appendChild(&child1); + treeItem.appendChild(&child2); + treeItem.appendChild(&child3); + + treeItem.removeChild(&child2); + + QCOMPARE(treeItem.childCount(), 2); + QCOMPARE(treeItem.child(0), &child1); + QCOMPARE(treeItem.child(1), &child3); + QCOMPARE(child1.childIndex(), 0); + QCOMPARE(child1.parent(), &treeItem); + QCOMPARE(child2.childIndex(), -1); + QCOMPARE(child2.parent(), &treeItem); + QCOMPARE(child3.childIndex(), 1); + QCOMPARE(child3.parent(), &treeItem); + + treeItem.removeChild(&child1); + treeItem.removeChild(&child3); + + QCOMPARE(treeItem.childCount(), 0); + QCOMPARE(child1.childIndex(), -1); + QCOMPARE(child1.parent(), &treeItem); + QCOMPARE(child2.childIndex(), -1); + QCOMPARE(child2.parent(), &treeItem); + QCOMPARE(child3.childIndex(), -1); + QCOMPARE(child3.parent(), &treeItem); +} + +QTEST_MAIN(TreeItemTest) + +#include "TreeItemTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeItemTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeModelTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeModelTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeModelTest.cpp 2010-03-05 23:35:28 UTC (rev 110) @@ -0,0 +1,295 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QtTest> + +#include "TreeModel.h" + +#include "TreeItem.h" + +class TreeModelTest: public QObject { +Q_OBJECT + +private slots: + + void init(); + void cleanup(); + + void testConstructorEmptyRootItem(); + void testConstructorSingleItem(); + void testConstructorSeveralFlatItems(); + void testConstructorSingleNestedItem(); + void testConstructorSeveralNestedItems(); + + void testDataWithInvalidIndex(); + void testDataWithInvalidRole(); + + void testFlagsWithInvalidIndex(); + + void testHeaderDataWithInvalidSection(); + void testHeaderDataWithInvalidOrientation(); + void testHeaderDataWithInvalidRole(); + + void testIndexOutOfBounds(); + + void testParentWithInvalidIndex(); + +private: + + TreeItem* mEmptyRootItem; + TreeItem* mSingleItem; + TreeItem* mSeveralFlatItems; + TreeItem* mSingleNestedItem; + TreeItem* mSeveralNestedItems; + + void assertItem(const QModelIndex& index, const QString& displayRoleData, + int childrenCount, const QModelIndex& parent) const; + +}; + +class StubTreeItem: public TreeItem { +public: + + QString mText; + + StubTreeItem(QString text, TreeItem* parent = 0): + TreeItem(parent), + mText(text) { + } + + virtual QString text() const { + return mText; + } + +}; + +void TreeModelTest::init() { + mEmptyRootItem = new StubTreeItem("root"); + + mSingleItem = new StubTreeItem("root"); + TreeItem* parent = mSingleItem; + mSingleItem->appendChild(new StubTreeItem("root-1", parent)); + + mSeveralFlatItems = new StubTreeItem("root"); + parent = mSeveralFlatItems; + mSeveralFlatItems->appendChild(new StubTreeItem("root-1", parent)); + mSeveralFlatItems->appendChild(new StubTreeItem("root-2", parent)); + mSeveralFlatItems->appendChild(new StubTreeItem("root-3", parent)); + + mSingleNestedItem = new StubTreeItem("root"); + parent = mSingleNestedItem; + mSingleNestedItem->appendChild(new StubTreeItem("root-1", parent)); + parent = mSingleNestedItem->child(0); + mSingleNestedItem->child(0)->appendChild(new StubTreeItem("root-1-1", parent)); + + mSeveralNestedItems = new StubTreeItem("root"); + parent = mSeveralNestedItems; + mSeveralNestedItems->appendChild(new StubTreeItem("root-1", parent)); + parent = mSeveralNestedItems->child(0); + mSeveralNestedItems->child(0)->appendChild(new StubTreeItem("root-1-1", parent)); + parent = mSeveralNestedItems; + mSeveralNestedItems->appendChild(new StubTreeItem("root-2", parent)); + mSeveralNestedItems->appendChild(new StubTreeItem("root-3", parent)); + parent = mSeveralNestedItems->child(2); + mSeveralNestedItems->child(2)->appendChild(new StubTreeItem("root-3-1", parent)); + mSeveralNestedItems->child(2)->appendChild(new StubTreeItem("root-3-2", parent)); +} + +void TreeModelTest::cleanup() { + delete mEmptyRootItem; + delete mSingleItem; + delete mSeveralFlatItems; + delete mSingleNestedItem; + delete mSeveralNestedItems; +} + +void TreeModelTest::testConstructorEmptyRootItem() { + TreeModel model(mEmptyRootItem); + mEmptyRootItem = 0; + + QCOMPARE(model.rowCount(), 0); + QCOMPARE(model.columnCount(), 1); + QCOMPARE(model.headerData(0, Qt::Horizontal).toString(), QString("root")); +} + +void TreeModelTest::testConstructorSingleItem() { + TreeModel model(mSingleItem); + mSingleItem = 0; + + QCOMPARE(model.rowCount(), 1); + QCOMPARE(model.columnCount(), 1); + QCOMPARE(model.headerData(0, Qt::Horizontal).toString(), QString("root")); + + QModelIndex index = model.index(0, 0); + assertItem(index, "root-1", 0, QModelIndex()); +} + +void TreeModelTest::testConstructorSeveralFlatItems() { + TreeModel model(mSeveralFlatItems); + mSeveralFlatItems = 0; + + QCOMPARE(model.rowCount(), 3); + QCOMPARE(model.columnCount(), 1); + QCOMPARE(model.headerData(0, Qt::Horizontal).toString(), QString("root")); + + QModelIndex index = model.index(0, 0); + assertItem(index, "root-1", 0, QModelIndex()); + + index = model.index(1, 0); + assertItem(index, "root-2", 0, QModelIndex()); + + index = model.index(2, 0); + assertItem(index, "root-3", 0, QModelIndex()); +} + +void TreeModelTest::testConstructorSingleNestedItem() { + TreeModel model(mSingleNestedItem); + mSingleNestedItem = 0; + + QCOMPARE(model.rowCount(), 1); + QCOMPARE(model.columnCount(), 1); + QCOMPARE(model.headerData(0, Qt::Horizontal).toString(), QString("root")); + + QModelIndex index = model.index(0, 0); + assertItem(index, "root-1", 1, QModelIndex()); + + QModelIndex parent = index; + index = model.index(0, 0, parent); + assertItem(index, "root-1-1", 0, parent); +} + +void TreeModelTest::testConstructorSeveralNestedItems() { + TreeModel model(mSeveralNestedItems); + mSeveralNestedItems = 0; + + QCOMPARE(model.rowCount(), 3); + QCOMPARE(model.columnCount(), 1); + QCOMPARE(model.headerData(0, Qt::Horizontal).toString(), QString("root")); + + QModelIndex index = model.index(0, 0); + assertItem(index, "root-1", 1, QModelIndex()); + + QModelIndex parent = index; + index = model.index(0, 0, parent); + assertItem(index, "root-1-1", 0, parent); + + index = model.index(1, 0); + assertItem(index, "root-2", 0, QModelIndex()); + + index = model.index(2, 0); + assertItem(index, "root-3", 2, QModelIndex()); + + parent = index; + index = model.index(0, 0, parent); + assertItem(index, "root-3-1", 0, parent); + + index = model.index(1, 0, parent); + assertItem(index, "root-3-2", 0, parent); +} + +void TreeModelTest::testDataWithInvalidIndex() { + TreeModel model(mSingleItem); + mSingleItem = 0; + + QCOMPARE(model.data(QModelIndex()), QVariant()); +} + +void TreeModelTest::testDataWithInvalidRole() { + TreeModel model(mSingleItem); + mSingleItem = 0; + + QCOMPARE(model.data(model.index(0, 0), Qt::DecorationRole), QVariant()); + QCOMPARE(model.data(model.index(0, 0), Qt::EditRole), QVariant()); + QCOMPARE(model.data(model.index(0, 0), Qt::ToolTipRole), QVariant()); + QCOMPARE(model.data(model.index(0, 0), Qt::StatusTipRole), QVariant()); + QCOMPARE(model.data(model.index(0, 0), Qt::WhatsThisRole), QVariant()); + QCOMPARE(model.data(model.index(0, 0), Qt::SizeHintRole), QVariant()); +} + +void TreeModelTest::testFlagsWithInvalidIndex() { + TreeModel model(mSingleItem); + mSingleItem = 0; + + QCOMPARE(model.flags(QModelIndex()), Qt::NoItemFlags); +} + +void TreeModelTest::testHeaderDataWithInvalidSection() { + TreeModel model(mEmptyRootItem); + mEmptyRootItem = 0; + + QCOMPARE(model.headerData(1, Qt::Horizontal), QVariant()); +} + +void TreeModelTest::testHeaderDataWithInvalidOrientation() { + TreeModel model(mEmptyRootItem); + mEmptyRootItem = 0; + + QCOMPARE(model.headerData(0, Qt::Vertical), QVariant()); +} + +void TreeModelTest::testHeaderDataWithInvalidRole() { + TreeModel model(mEmptyRootItem); + mEmptyRootItem = 0; + + QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::DecorationRole), QVariant()); + QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::EditRole), QVariant()); + QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::ToolTipRole), QVariant()); + QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::StatusTipRole), QVariant()); + QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::WhatsThisRole), QVariant()); + QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::SizeHintRole), QVariant()); +} + +void TreeModelTest::testIndexOutOfBounds() { + TreeModel model(mSingleNestedItem); + mSingleNestedItem = 0; + + QCOMPARE(model.index(0, 1), QModelIndex()); + QCOMPARE(model.index(1, 0), QModelIndex()); + + QModelIndex parent = model.index(0, 0); + QVERIFY(parent.isValid()); + QCOMPARE(model.index(0, 1, parent), QModelIndex()); + QCOMPARE(model.index(1, 0, parent), QModelIndex()); +} + +void TreeModelTest::testParentWithInvalidIndex() { + TreeModel model(mSingleItem); + mSingleItem = 0; + + QCOMPARE(model.parent(QModelIndex()), QModelIndex()); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +void TreeModelTest::assertItem(const QModelIndex& index, + const QString& displayRoleData, + int childrenCount, + const QModelIndex& parent) const { + const QAbstractItemModel* model = index.model(); + + QVERIFY(index.isValid()); + QCOMPARE(model->data(index).toString(), displayRoleData); + QCOMPARE(model->flags(index), Qt::ItemIsEnabled | Qt::ItemIsSelectable); + QCOMPARE(model->parent(index), parent); + QCOMPARE(model->rowCount(index), childrenCount); + QCOMPARE(model->columnCount(index), 1); +} + +QTEST_MAIN(TreeModelTest) + +#include "TreeModelTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeModelTest.cpp ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-05 23:32:10
|
Revision: 109 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=109&view=rev Author: danxuliu Date: 2010-03-05 23:32:03 +0000 (Fri, 05 Mar 2010) Log Message: ----------- Initial import for KTutorial editor, with a basic directory layout and a dummy main window. Modified Paths: -------------- trunk/ktutorial/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/ trunk/ktutorial/ktutorial-editor/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 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/main.cpp Modified: trunk/ktutorial/CMakeLists.txt =================================================================== --- trunk/ktutorial/CMakeLists.txt 2010-02-26 18:55:44 UTC (rev 108) +++ trunk/ktutorial/CMakeLists.txt 2010-03-05 23:32:03 UTC (rev 109) @@ -4,5 +4,6 @@ enable_testing() +macro_optional_add_subdirectory(ktutorial-editor) macro_optional_add_subdirectory(ktutorial-library) macro_optional_add_subdirectory(ktutorial-test-app) Added: trunk/ktutorial/ktutorial-editor/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-editor/CMakeLists.txt 2010-03-05 23:32:03 UTC (rev 109) @@ -0,0 +1,7 @@ +project(ktutorial-editor) + +find_package(KDE4 REQUIRED) + +include(KDE4Defaults) + +add_subdirectory(src) Property changes on: trunk/ktutorial/ktutorial-editor/CMakeLists.txt ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-05 23:32:03 UTC (rev 109) @@ -0,0 +1,24 @@ +# In x86_64, linking fails when a static library is added to a shared library. +# In order to work, they must be compiled using -fPIC +add_definitions("-fPIC") + +include_directories(${KDE4_INCLUDES}) + +set(ktutorial_editor_SRCS + KTutorialEditor.cpp +) + +# Instead of compiling the executable directly from the sources, the sources are +# compiled to a static library that is linked (and, being static, also embedded) +# in the editor executable. +# As everything but a tiny initialization code is in a library, the build system +# for the tests can be easily set up. +kde4_add_library(ktutorial_editor ${ktutorial_editor_SRCS}) + +kde4_add_executable(ktutorial-editor main.cpp) +target_link_libraries(ktutorial-editor ktutorial_editor ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS}) + +####### Install the editor ####### + +install(TARGETS ktutorial-editor DESTINATION ${BIN_INSTALL_DIR}) +install(FILES ktutorial-editorui.rc DESTINATION ${DATA_INSTALL_DIR}/ktutorial-editor) Property changes on: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-05 23:32:03 UTC (rev 109) @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "KTutorialEditor.h" + +#include <QTreeView> + +#include <KAction> +#include <KActionCollection> +#include <KApplication> + +//public: + +KTutorialEditor::KTutorialEditor(): KXmlGuiWindow(0) { + QTreeView* treeView = new QTreeView(); + treeView->setObjectName("centralTreeView"); + treeView->setHeaderHidden(true); + + setCentralWidget(treeView); + + setupActions(); + + //Don't use a status bar (which is setupGUI default behavior) + setupGUI(ToolBar | Keys | Save | Create); +} + +//private: + +void KTutorialEditor::setupActions() { + KStandardAction::quit(kapp, SLOT(quit()), actionCollection()); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-05 23:32:03 UTC (rev 109) @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef KTUTORIALEDITOR_H +#define KTUTORIALEDITOR_H + +#include <KXmlGuiWindow> + +/** + * KTutorial editor main window. + * It wires up all the components in the application. + */ +class KTutorialEditor: public KXmlGuiWindow { +Q_OBJECT +public: + + /** + * Creates a new KTutorialEditor. + */ + KTutorialEditor(); + +private: + + /** + * Sets up all the actions used in the application. + */ + void setupActions(); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-05 23:32:03 UTC (rev 109) @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<gui name="ktutorial-editor" version="1"> +</gui> Property changes on: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc ___________________________________________________________________ Added: svn:executable + * Added: trunk/ktutorial/ktutorial-editor/src/main.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/main.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/main.cpp 2010-03-05 23:32:03 UTC (rev 109) @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <KApplication> +#include <KAboutData> +#include <KCmdLineArgs> + +#include "KTutorialEditor.h" + +int main (int argc, char *argv[]) { + KAboutData aboutData("ktutorial-editor", 0, + ki18nc("@title", "KTutorial"), + "0.1", + ki18nc("@info", "An editor to create tutorials for " + "<application>KTutorial</application>."), + KAboutData::License_GPL_V3, + ki18nc("@info:credit", "Copyright (c) 2010 Daniel Calviño Sánchez")); + aboutData.addAuthor(ki18nc("@info:credit", "Daniel Calviño Sánchez"), + ki18nc("@info:credit", "Main developer"), + "dan...@gm..."); + KCmdLineArgs::init(argc, argv, &aboutData); + + KApplication app; + + KTutorialEditor* window = new KTutorialEditor(); + window->show(); + + return app.exec(); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/main.cpp ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <dan...@us...> - 2010-02-25 06:02:52
|
Revision: 107 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=107&view=rev Author: danxuliu Date: 2010-02-25 06:02:45 +0000 (Thu, 25 Feb 2010) Log Message: ----------- Added WaitForEvent class to wait for events of some type sent to an object. It is used now in UsingKTutorial and TutorialMoveText tutorials. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt trunk/ktutorial/ktutorial-library/src/scripting/ScriptingModule.cpp trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp trunk/ktutorial/ktutorial-library/test/CMakeLists.txt trunk/ktutorial/ktutorial-library/test/scripting/ScriptingModuleTest.cpp trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h Added Paths: ----------- trunk/ktutorial/ktutorial-library/src/WaitForEvent.cpp trunk/ktutorial/ktutorial-library/src/WaitForEvent.h trunk/ktutorial/ktutorial-library/test/WaitForEventTest.cpp Modified: trunk/ktutorial/ktutorial-library/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-25 05:40:00 UTC (rev 106) +++ trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-25 06:02:45 UTC (rev 107) @@ -18,6 +18,7 @@ WaitFor.cpp WaitForAnd.cpp WaitForComposed.cpp + WaitForEvent.cpp WaitForNot.cpp WaitForOr.cpp WaitForSignal.cpp @@ -42,6 +43,7 @@ WaitFor.h WaitForAnd.h WaitForComposed.h + WaitForEvent.h WaitForNot.h WaitForOr.h WaitForSignal.h Added: trunk/ktutorial/ktutorial-library/src/WaitForEvent.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/WaitForEvent.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/src/WaitForEvent.cpp 2010-02-25 06:02:45 UTC (rev 107) @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "WaitForEvent.h" + +#include <QMetaEnum> + +#include <KDebug> + +//public: + +WaitForEvent::WaitForEvent(): + mObject(0), + mEventType(QEvent::None), + mConditionMet(false) { +} + +WaitForEvent::WaitForEvent(QObject* object, QEvent::Type type): + mObject(object), + mEventType(type), + mConditionMet(false) { + + object->installEventFilter(this); +} + +void WaitForEvent::setEvent(QObject* object, const QString& typeName) { + int index = QEvent::staticMetaObject.indexOfEnumerator("Type"); + QMetaEnum eventTypeEnumerator = QEvent::staticMetaObject.enumerator(index); + + int eventTypeValue = eventTypeEnumerator.keyToValue(qPrintable(typeName)); + if (eventTypeValue == -1) { + kWarning() << "QEvent::Type named \"" << typeName << "\" is unknown"; + return; + } + + mObject = object; + mEventType = static_cast<QEvent::Type>(eventTypeValue); + + mObject->installEventFilter(this); +} + +bool WaitForEvent::eventFilter(QObject* object, QEvent* event) { + if (!isActive()) { + return false; + } + + if (object == mObject && event->type() == mEventType) { + handleEvent(event); + } + + return false; +} + +bool WaitForEvent::conditionMet() const { + return mConditionMet; +} + +void WaitForEvent::setActive(bool active) { + WaitFor::setActive(active); + + if (active) { + mConditionMet = false; + } +} + +//protected: + +void WaitForEvent::handleEvent(QEvent* event) { + Q_UNUSED(event); + + mConditionMet = true; + emit waitEnded(this); +} + +#include "WaitForEvent.moc" Property changes on: trunk/ktutorial/ktutorial-library/src/WaitForEvent.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/WaitForEvent.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/WaitForEvent.h (rev 0) +++ trunk/ktutorial/ktutorial-library/src/WaitForEvent.h 2010-02-25 06:02:45 UTC (rev 107) @@ -0,0 +1,154 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef WAITFOREVENT_H +#define WAITFOREVENT_H + +#include <QEvent> + +#include "ktutorial_export.h" + +#include "WaitFor.h" + +/** + * Waits for an event of some specific type to be sent to an object. + * When an event of the expected type is sent and the WaitForEvent is active, + * the wait ends. + * + * Note that if the event is sent while the WaitFor isn't active, it won't + * be registered and the condition won't be met. In order to met the condition, + * the event must be sent while the WaitForEvent is active. + * + * In some cases, just waiting for an event of some type isn't enough. For + * example, you may want to end the waiting if a QEvent::MouseButtonPress is + * sent, but only if the button pressed is the left. To do this, you can create + * a subclass of WaitForEvent and redefine handleEvent(QEvent*) method. + * \code + * void WaitForEventSubclass::handleEvent(QEvent* event) { + * QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); + * + * if (mouseEvent->button() == Qt::LeftButton) { + * WaitForEvent::handleEvent(event); + * } + * } + * \endcode + */ +class KTUTORIAL_EXPORT WaitForEvent: public WaitFor { +Q_OBJECT +public: + + /** + * Creates a new WaitForEvent. + * This constructor is needed to dynamically create WaitForEvent objects in + * scripts using ScriptingModule::newWaitFor(const QString&). Method + * setEvent(QObject*, const QString&) must be called to finish setting up + * the object. For C++ tutorials, use + * WaitForEvent(QObject*, QEvent::Type) constructor instead of this one. + */ + Q_INVOKABLE WaitForEvent(); + + /** + * Creates a new WaitForEvent. + * + * @param object The object to watch. + * @param typeName The name of the event type to wait for. + */ + WaitForEvent(QObject* object, QEvent::Type type); + + /** + * Sets the event to wait for. + * Note that the QEvent::Type has to be passed as a string. For example, to + * wait for a QEvent::Close you have to pass "Close" as the second + * parameter. + * This method can be invoked from a script. + * + * In fact, you should only invoke this method from a script, and only once, + * to set up the object. For C++ tutorials, use + * WaitForEvent(QObject*, QEvent::Type) constructor when creating this + * WaitForEvent. + * + * The type is passed as a string with its name instead of using a pure + * QEvent::Type due to a current limitation of Kross (enumeration in QObject + * classes seem supported. However, QEvent is not a QObject but a Q_GADGET). + * + * @param object The object to watch. + * @param typeName The name of the event type to wait for. + */ + Q_INVOKABLE void setEvent(QObject* object, const QString& typeName); + + /** + * Inspects the events sent to the watched object. + * If the event has the type expected by this WaitFor it is handled by + * handleEvent(QEvent*) which, by default, ends the waiting. + * + * @param object The object that the event was sent to. + * @param event The event sent. + * @return False, so the event can be handled further. + */ + virtual bool eventFilter(QObject* object, QEvent* event); + + /** + * Returns true if the event was received while active, false otherwise. + * + * @return True if the event was received while active, false otherwise. + */ + virtual bool conditionMet() const; + + /** + * Sets this WaitForEvent active or inactive. + * Activating it resets its condition. + * + * @param active True to set it active, false otherwise. + */ + virtual void setActive(bool active); + +protected: + + /** + * Handles the event ending the wait (if this WaitForEvent is active). + * WaitForEvent subclasses can redefine this method if just receiving an + * event of the type expected isn't enough to end the waiting and some + * special check has to be done. + * + * The event is assured to have the type expected by this WaitForEvent and + * to be sent to the watched object. + * + * @param event The event. + */ + virtual void handleEvent(QEvent* event); + +private: + + /** + * The watched object. + */ + QObject* mObject; + + /** + * The type of event expected. + */ + QEvent::Type mEventType; + + /** + * Whether the event was received when active or not. + */ + bool mConditionMet; + +}; + +#endif \ No newline at end of file Property changes on: trunk/ktutorial/ktutorial-library/src/WaitForEvent.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-library/src/scripting/ScriptingModule.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/scripting/ScriptingModule.cpp 2010-02-25 05:40:00 UTC (rev 106) +++ trunk/ktutorial/ktutorial-library/src/scripting/ScriptingModule.cpp 2010-02-25 06:02:45 UTC (rev 107) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Daniel Calviño Sánchez * + * Copyright (C) 2009-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -24,6 +24,7 @@ #include "../Option.h" #include "../WaitFor.h" #include "../WaitForAnd.h" +#include "../WaitForEvent.h" #include "../WaitForNot.h" #include "../WaitForOr.h" #include "../WaitForSignal.h" @@ -34,6 +35,7 @@ if (sSelf == 0) { sSelf = new ScriptingModule(); sSelf->registerWaitForMetaObject(WaitForAnd::staticMetaObject); + sSelf->registerWaitForMetaObject(WaitForEvent::staticMetaObject); sSelf->registerWaitForMetaObject(WaitForNot::staticMetaObject); sSelf->registerWaitForMetaObject(WaitForOr::staticMetaObject); sSelf->registerWaitForMetaObject(WaitForSignal::staticMetaObject); Modified: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-25 05:40:00 UTC (rev 106) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-25 06:02:45 UTC (rev 107) @@ -27,9 +27,29 @@ #include "../Option.h" #include "../Step.h" #include "../TutorialInformation.h" +#include "../WaitForEvent.h" #include "../WaitForSignal.h" #include "../view/StepWidget.h" +class WaitForLeftMouseButtonPressed: public WaitForEvent { +Q_OBJECT +public: + + WaitForLeftMouseButtonPressed(QObject* object): + WaitForEvent(object, QEvent::MouseButtonPress) { + } + +protected: + + virtual void handleEvent(QEvent* event) { + QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); + if (mouseEvent->button() == Qt::LeftButton) { + WaitForEvent::handleEvent(event); + } + } + +}; + class ClearTextStep: public Step { public: @@ -69,27 +89,11 @@ virtual void setup() { QTextEdit* textEdit = KTutorial::self()->findObject<QTextEdit*>( "usingKTutorialTextEdit"); - //The filter is removed when the text edit is deleted, that is, when it - //is closed. - textEdit->installEventFilter(this); - addWaitFor(new WaitForSignal(this, SIGNAL(textEditClosed())), + addWaitFor(new WaitForEvent(textEdit, QEvent::Close), mUsingKTutorial, SLOT(closeTextEditDone())); } - bool eventFilter(QObject* object, QEvent* event) { - Q_UNUSED(object); - if (event->type() == QEvent::Close) { - emit textEditClosed(); - } - - return false; - } - -Q_SIGNALS: - - void textEditClosed(); - private: UsingKTutorial* mUsingKTutorial; @@ -108,30 +112,11 @@ virtual void setup() { QWidget* mStepWidget = KTutorial::self()-> findObject<view::StepWidget*>("ktutorial_StepWidget"); - //The filter is removed when the widget is deleted, that is, when the - //tutorial is closed. - mStepWidget->installEventFilter(this); - addWaitFor(new WaitForSignal(this, SIGNAL(mousePressedOnWidget())), + addWaitFor(new WaitForLeftMouseButtonPressed(mStepWidget), mUsingKTutorial, SLOT(moveWidgetPressDone())); } - bool eventFilter(QObject* object, QEvent* event) { - Q_UNUSED(object); - if (event->type() == QEvent::MouseButtonPress) { - QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); - if (mouseEvent->button() == Qt::LeftButton) { - emit mousePressedOnWidget(); - } - } - - return false; - } - -Q_SIGNALS: - - void mousePressedOnWidget(); - private: UsingKTutorial* mUsingKTutorial; @@ -150,27 +135,11 @@ virtual void setup() { QWidget* mStepWidget = KTutorial::self()-> findObject<view::StepWidget*>("ktutorial_StepWidget"); - //The filter is removed when the widget is deleted, that is, when the - //tutorial is closed. - mStepWidget->installEventFilter(this); - addWaitFor(new WaitForSignal(this, SIGNAL(mouseReleasedOnWidget())), + addWaitFor(new WaitForEvent(mStepWidget, QEvent::MouseButtonRelease), mUsingKTutorial, SLOT(moveWidgetReleaseDone())); } - bool eventFilter(QObject* object, QEvent* event) { - Q_UNUSED(object); - if (event->type() == QEvent::MouseButtonRelease) { - emit mouseReleasedOnWidget(); - } - - return false; - } - -Q_SIGNALS: - - void mouseReleasedOnWidget(); - private: UsingKTutorial* mUsingKTutorial; Modified: trunk/ktutorial/ktutorial-library/test/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/test/CMakeLists.txt 2010-02-25 05:40:00 UTC (rev 106) +++ trunk/ktutorial/ktutorial-library/test/CMakeLists.txt 2010-02-25 06:02:45 UTC (rev 107) @@ -14,7 +14,7 @@ ENDFOREACH(_className) ENDMACRO(UNIT_TESTS) -unit_tests(Option Step Tutorial TutorialInformation TutorialManager WaitFor WaitForAnd WaitForComposed WaitForNot WaitForOr WaitForSignal) +unit_tests(Option Step Tutorial TutorialInformation TutorialManager WaitFor WaitForAnd WaitForComposed WaitForEvent WaitForNot WaitForOr WaitForSignal) MACRO(MEM_TESTS) FOREACH(_testname ${ARGN}) @@ -22,4 +22,4 @@ ENDFOREACH(_testname) ENDMACRO(MEM_TESTS) -mem_tests(Option Step Tutorial TutorialInformation TutorialManager WaitFor WaitForAnd WaitForComposed WaitForNot WaitForOr WaitForSignal) +mem_tests(Option Step Tutorial TutorialInformation TutorialManager WaitFor WaitForAnd WaitForComposed WaitForEvent WaitForNot WaitForOr WaitForSignal) Added: trunk/ktutorial/ktutorial-library/test/WaitForEventTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/WaitForEventTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/test/WaitForEventTest.cpp 2010-02-25 06:02:45 UTC (rev 107) @@ -0,0 +1,221 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QtTest> + +#define protected public +#define private public +#include "WaitForEvent.h" +#undef private +#undef protected + +class WaitForEventTest: public QObject { +Q_OBJECT +private slots: + + void testConstructor(); + void testConstructorDefault(); + + void testSetActive(); + + void testWaitEnded(); + void testWaitEndedWithDefaultConstructor(); + void testWaitEndedNotActive(); + + void testHandleEvent(); + void testHandleEventNotActive(); + void testHandleEventEventTypeNotExpected(); + + void testEventSentAfterWaitForDestruction(); + +}; + +class WaitForEventWithCustomHandling: public WaitForEvent { +public: + + QEvent::Type mType; + int mHandledEventsCount; + + WaitForEventWithCustomHandling(QObject* object, QEvent::Type type): + WaitForEvent(object, type), + mType(type), + mHandledEventsCount(0) { + } + +protected: + + virtual void handleEvent(QEvent* event) { + QCOMPARE(event->type(), mType); + + mHandledEventsCount++; + } + +}; + +void WaitForEventTest::testConstructor() { + WaitForEvent waitForEvent(this, QEvent::ChildAdded); + + QVERIFY(!waitForEvent.isActive()); + QVERIFY(!waitForEvent.conditionMet()); +} + +void WaitForEventTest::testConstructorDefault() { + WaitForEvent waitForEvent; + waitForEvent.setEvent(this, "ChildAdded"); + + QVERIFY(!waitForEvent.isActive()); + QVERIFY(!waitForEvent.conditionMet()); +} + +void WaitForEventTest::testSetActive() { + WaitForEvent waitForEvent(this, QEvent::ChildAdded); + waitForEvent.mConditionMet = true; + + waitForEvent.setActive(true); + + QVERIFY(waitForEvent.isActive()); + QVERIFY(!waitForEvent.conditionMet()); +} + +//WaitFor* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(WaitFor*); + +void WaitForEventTest::testWaitEnded() { + QObject parentObject; + + WaitForEvent waitForEvent(&parentObject, QEvent::ChildAdded); + waitForEvent.setActive(true); + + //WaitFor* must be registered in order to be used with QSignalSpy + int waitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); + QSignalSpy waitEndedSpy(&waitForEvent, SIGNAL(waitEnded(WaitFor*))); + + QObject* childObject = new QObject(); + childObject->setParent(&parentObject); + + QVERIFY(waitForEvent.conditionMet()); + QCOMPARE(waitEndedSpy.count(), 1); + QVariant argument = waitEndedSpy.at(0).at(0); + QCOMPARE(argument.userType(), waitForStarType); + QCOMPARE(qvariant_cast<WaitFor*>(argument), &waitForEvent); +} + +void WaitForEventTest::testWaitEndedWithDefaultConstructor() { + QObject parentObject; + + WaitForEvent waitForEvent; + waitForEvent.setEvent(&parentObject, "ChildAdded"); + waitForEvent.setActive(true); + + //WaitFor* must be registered in order to be used with QSignalSpy + int waitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); + QSignalSpy waitEndedSpy(&waitForEvent, SIGNAL(waitEnded(WaitFor*))); + + QObject* childObject = new QObject(); + childObject->setParent(&parentObject); + + QVERIFY(waitForEvent.conditionMet()); + QCOMPARE(waitEndedSpy.count(), 1); + QVariant argument = waitEndedSpy.at(0).at(0); + QCOMPARE(argument.userType(), waitForStarType); + QCOMPARE(qvariant_cast<WaitFor*>(argument), &waitForEvent); +} + +void WaitForEventTest::testWaitEndedNotActive() { + QObject parentObject; + + WaitForEvent waitForEvent(&parentObject, QEvent::ChildAdded); + + qRegisterMetaType<WaitFor*>("WaitFor*"); + QSignalSpy waitEndedSpy(&waitForEvent, SIGNAL(waitEnded(WaitFor*))); + + QObject* childObject = new QObject(); + childObject->setParent(&parentObject); + + QVERIFY(!waitForEvent.conditionMet()); + QCOMPARE(waitEndedSpy.count(), 0); +} + +void WaitForEventTest::testHandleEvent() { + QObject parentObject; + + WaitForEventWithCustomHandling waitForEvent(&parentObject, + QEvent::ChildAdded); + waitForEvent.setActive(true); + + QObject* childObject = new QObject(); + childObject->setParent(&parentObject); + + QCOMPARE(waitForEvent.mHandledEventsCount, 1); +} + +void WaitForEventTest::testHandleEventNotActive() { + QObject parentObject; + + WaitForEventWithCustomHandling waitForEvent(&parentObject, + QEvent::ChildAdded); + + QObject* childObject = new QObject(); + childObject->setParent(&parentObject); + + QCOMPARE(waitForEvent.mHandledEventsCount, 0); +} + +void WaitForEventTest::testHandleEventEventTypeNotExpected() { + QObject parentObject; + + WaitForEventWithCustomHandling waitForEvent(&parentObject, + QEvent::ChildRemoved); + waitForEvent.setActive(true); + + QObject* childObject = new QObject(); + childObject->setParent(&parentObject); + + QCOMPARE(waitForEvent.mHandledEventsCount, 0); + + childObject->setParent(0); + + QCOMPARE(waitForEvent.mHandledEventsCount, 1); + + childObject->setParent(&parentObject); + + QCOMPARE(waitForEvent.mHandledEventsCount, 1); +} + +void WaitForEventTest::testEventSentAfterWaitForDestruction() { + QObject parentObject; + + WaitForEvent* waitForEvent = new WaitForEvent(&parentObject, + QEvent::ChildAdded); + waitForEvent->setActive(true); + + QObject* childObject = new QObject(); + childObject->setParent(&parentObject); + + delete waitForEvent; + + QObject* anotherChildObject = new QObject(); + anotherChildObject->setParent(&parentObject); + + //Nothing is checked explicitly. Implicitly, it is checked if deleting the + //event filter object and then sending another event crashes the application +} + +QTEST_MAIN(WaitForEventTest) + +#include "WaitForEventTest.moc" Property changes on: trunk/ktutorial/ktutorial-library/test/WaitForEventTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-library/test/scripting/ScriptingModuleTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/scripting/ScriptingModuleTest.cpp 2010-02-25 05:40:00 UTC (rev 106) +++ trunk/ktutorial/ktutorial-library/test/scripting/ScriptingModuleTest.cpp 2010-02-25 06:02:45 UTC (rev 107) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Daniel Calviño Sánchez * + * Copyright (C) 2009-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -30,6 +30,7 @@ #include "../Option.h" #include "../WaitFor.h" #include "../WaitForAnd.h" +#include "../WaitForEvent.h" #include "../WaitForNot.h" #include "../WaitForOr.h" #include "../WaitForSignal.h" @@ -155,6 +156,10 @@ QMetaObject& type = metaObject(scriptingModule, "WaitForAnd"); QCOMPARE(type.className(), WaitForAnd::staticMetaObject.className()); + QVERIFY(containsMetaObject(scriptingModule, "WaitForEvent")); + type = metaObject(scriptingModule, "WaitForEvent"); + QCOMPARE(type.className(), WaitForEvent::staticMetaObject.className()); + QVERIFY(containsMetaObject(scriptingModule, "WaitForNot")); type = metaObject(scriptingModule, "WaitForNot"); QCOMPARE(type.className(), WaitForNot::staticMetaObject.className()); Modified: trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp 2010-02-25 05:40:00 UTC (rev 106) +++ trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp 2010-02-25 06:02:45 UTC (rev 107) @@ -303,6 +303,8 @@ out << "tutorial.addStep(firstStep);\n"; out << "secondStep = ktutorial.newStep(\"second\");\n"; out << "tutorial.addStep(secondStep);\n"; + out << "thirdStep = ktutorial.newStep(\"third\");\n"; + out << "tutorial.addStep(thirdStep);\n"; out << "endStep = ktutorial.newStep(\"end\");\n"; out << "endStep.setText(\"The tutorial has ended.\");\n"; out << "tutorial.addStep(endStep);\n"; @@ -330,13 +332,22 @@ out << "waitForAnd.add(waitForAnotherDummy);\n"; out << "waitForAnd.add(waitForOr);\n"; - out << "function checkEnded() {\n"; + out << "function checkThird() {\n"; out << " if (testObject.booleanValue()) {\n"; - out << " tutorial.nextStep(\"end\");\n"; + out << " tutorial.nextStep(\"third\");\n"; out << " }\n"; out << "};\n"; - out << "secondStep.addWaitFor(waitForAnd, self, \"checkEnded\");\n"; + out << "secondStep.addWaitFor(waitForAnd, self, \"checkThird\");\n"; + 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.flush(); ScriptedTutorial scriptedTutorial(mTemporaryFile->fileName()); @@ -376,6 +387,11 @@ emit anotherDummySignal(); + QCOMPARE(scriptedTutorial.mCurrentStep->id(), QString("third")); + + QObject* childObject = new QObject(); + childObject->setParent(this); + QCOMPARE(scriptedTutorial.mCurrentStep->id(), QString("end")); QCOMPARE(scriptedTutorial.mCurrentStep->text(), QString("The tutorial has ended.")); Modified: trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp 2010-02-25 05:40:00 UTC (rev 106) +++ trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp 2010-02-25 06:02:45 UTC (rev 107) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Daniel Calviño Sánchez * + * Copyright (C) 2008-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -29,9 +29,28 @@ #include <ktutorial/Step.h> #include <ktutorial/TutorialInformation.h> #include <ktutorial/WaitForAnd.h> +#include <ktutorial/WaitForEvent.h> #include <ktutorial/WaitForNot.h> #include <ktutorial/WaitForSignal.h> +class WaitForLeftMouseButtonPressed: public WaitForEvent { +public: + + WaitForLeftMouseButtonPressed(QObject* object): + WaitForEvent(object, QEvent::MouseButtonPress) { + } + +protected: + + virtual void handleEvent(QEvent* event) { + QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); + if (mouseEvent->button() == Qt::LeftButton) { + WaitForEvent::handleEvent(event); + } + } + +}; + //public: TutorialMoveText::TutorialMoveText(): Tutorial(0) { @@ -40,7 +59,6 @@ mTutorialInformation->setDescription(i18n("This tutorial shows how to move text in the text area")); mTextArea = KTutorial::self()->findObject<KTextEdit*>("textArea"); - mTextArea->viewport()->installEventFilter(this); mSecondPath = false; @@ -104,7 +122,7 @@ Step* mousePressStep = new Step("mousePress"); 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 WaitForSignal(this, SIGNAL(mousePressed())), + mousePressStep->addWaitFor(new WaitForLeftMouseButtonPressed(mTextArea->viewport()), this, SLOT(mousePress())); addStep(mousePressStep); @@ -113,7 +131,7 @@ Step* mouseReleaseStep = new Step("mouseRelease"); mouseReleaseStep->setText(i18nc("@info", "Without releasing the mouse button, move the cursor to the desired position, for example the beginning of the text.<nl/>Once the cursor is there, you can release the mouse button, and the text will be moved.")); - mouseReleaseStep->addWaitFor(new WaitForSignal(this, SIGNAL(mouseReleased())), + mouseReleaseStep->addWaitFor(new WaitForEvent(mTextArea->viewport(), QEvent::Drop), this, SLOT(mouseRelease())); addStep(mouseReleaseStep); @@ -134,20 +152,6 @@ addStep(endStep); } -bool TutorialMoveText::eventFilter(QObject* object, QEvent* event) { - if (event->type() == QEvent::MouseButtonPress) { - QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); - if (mouseEvent->button() == Qt::LeftButton) { - emit mousePressed(); - } - } else if (event->type() == QEvent::Drop) { - QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); - emit mouseReleased(); - } - - return false; -} - //public slots: void TutorialMoveText::startKeyboardMove() { Modified: trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h 2010-02-25 05:40:00 UTC (rev 106) +++ trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h 2010-02-25 06:02:45 UTC (rev 107) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Daniel Calviño Sánchez * + * Copyright (C) 2008-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -29,8 +29,6 @@ TutorialMoveText(); - bool eventFilter(QObject* object, QEvent* event); - public slots: void startKeyboardMove(); @@ -55,12 +53,6 @@ void end(); -signals: - - void mousePressed(); - - void mouseReleased(); - protected: void setup(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-25 05:40:06
|
Revision: 106 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=106&view=rev Author: danxuliu Date: 2010-02-25 05:40:00 +0000 (Thu, 25 Feb 2010) Log Message: ----------- Now it isn't needed to manually remove the WaitFor added in setup(). Anyway, verify that tearDown() "method" was executed. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp Modified: trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp 2010-02-25 05:02:43 UTC (rev 105) +++ trunk/ktutorial/ktutorial-library/test/scripting/ScriptingTest.cpp 2010-02-25 05:40:00 UTC (rev 106) @@ -48,6 +48,10 @@ return mBooleanValue; } + void setBooleanValue(bool booleanValue) { + mBooleanValue = booleanValue; + } + void dummySlot() { mDummySlotCallCount++; } @@ -144,17 +148,13 @@ void ScriptingTest::stepWithCustomSetup() { QTextStream out(mTemporaryFile); - out << "waitFor = null;\n"; - out << "function startStepSetup(step) {\n"; out << " waitFor = ktutorial.newWaitFor(\"WaitForSignal\");\n"; out << " waitFor.setSignal(testObject, \"dummySignal()\");\n"; out << " step.addWaitFor(waitFor, self, \"setFirstStep()\");\n"; out << "}\n"; out << "function startStepTearDown(step) {\n"; - out << " step.removeWaitFor(waitFor);\n"; - out << " waitFor.deleteLater();\n"; - out << " waitFor = null;\n"; + out << " testObject.setBooleanValue(true);\n"; out << "}\n"; out << "function setFirstStep() { tutorial.nextStep(\"first\"); }\n"; @@ -182,6 +182,7 @@ QCOMPARE(scriptedTutorial.mCurrentStep->id(), QString("first")); QCOMPARE(startStep->mWaitsFor.size(), 0); + QVERIFY(mBooleanValue); } void ScriptingTest::stepsWithOptions() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-25 05:02:51
|
Revision: 105 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=105&view=rev Author: danxuliu Date: 2010-02-25 05:02:43 +0000 (Thu, 25 Feb 2010) Log Message: ----------- Ensure that there are no conflicts between WaitFor and Options added to a Step in the normal way and during its setup. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/test/StepTest.cpp Modified: trunk/ktutorial/ktutorial-library/test/StepTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/StepTest.cpp 2010-02-25 01:16:52 UTC (rev 104) +++ trunk/ktutorial/ktutorial-library/test/StepTest.cpp 2010-02-25 05:02:43 UTC (rev 105) @@ -71,6 +71,7 @@ void testAddOptionWithoutSlotMacro(); void testAddOptionSeveralOptions(); void testAddOptionDuringSetup(); + void testAddOptionNormalAndDuringSetup(); void testAddOptionTwice(); void testAddOptionDifferentOptionsWithSameName(); @@ -78,6 +79,7 @@ void testAddWaitForWithoutSlotMacro(); void testAddWaitForSeveralWaitFors(); void testAddWaitForDuringSetup(); + void testAddWaitForNormalAndDuringSetup(); void testAddWaitForTwice(); void testRemoveOption(); @@ -295,6 +297,35 @@ QCOMPARE(destroyedSpy.count(), 1); } +void StepTest::testAddOptionNormalAndDuringSetup() { + StepWithOptionAddedInSetup step("doSomethingConstructive", this); + + Option* option1 = new Option("Feed a toucan"); + + step.addOption(option1, this, SLOT(anotherDummySlot())); + connect(this, SIGNAL(anotherDummySignal()), option1, SIGNAL(selected())); + + step.setActive(true); + + connect(this, SIGNAL(dummySignal()), step.mOption, SIGNAL(selected())); + + emit dummySignal(); + QCOMPARE(mDummySlotCallCount, 1); + + emit anotherDummySignal(); + QCOMPARE(mAnotherDummySlotCallCount, 1); + + QSignalSpy destroyedSpy(step.mOption, SIGNAL(destroyed(QObject*))); + + step.setActive(false); + + QCOMPARE(step.options().count(), 1); + QVERIFY(step.options().contains(option1)); + QCOMPARE(step.mWaitsForToBeDeletedInTearDown.count(), 0); + QCOMPARE(step.mOptionsToBeDeletedInTearDown.count(), 0); + QCOMPARE(destroyedSpy.count(), 1); +} + void StepTest::testAddOptionTwice() { Step step("doSomethingConstructive"); @@ -453,6 +484,32 @@ QCOMPARE(destroyedSpy.count(), 1); } +void StepTest::testAddWaitForNormalAndDuringSetup() { + StepWithWaitForAddedInSetup step("doSomethingConstructive", this); + + WaitFor* waitFor1 = new WaitForSignal(this, SIGNAL(anotherDummySignal())); + + step.addWaitFor(waitFor1, this, SLOT(anotherDummySlot())); + + step.setActive(true); + + emit dummySignal(); + QCOMPARE(mDummySlotCallCount, 1); + + emit anotherDummySignal(); + QCOMPARE(mAnotherDummySlotCallCount, 1); + + QSignalSpy destroyedSpy(step.mWaitFor, SIGNAL(destroyed(QObject*))); + + step.setActive(false); + + QCOMPARE(step.mWaitsFor.count(), 1); + QVERIFY(step.mWaitsFor.contains(waitFor1)); + QCOMPARE(step.mWaitsForToBeDeletedInTearDown.count(), 0); + QCOMPARE(step.mOptionsToBeDeletedInTearDown.count(), 0); + QCOMPARE(destroyedSpy.count(), 1); +} + void StepTest::testAddWaitForTwice() { Step step("doSomethingConstructive"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-25 01:16:58
|
Revision: 104 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=104&view=rev Author: danxuliu Date: 2010-02-25 01:16:52 +0000 (Thu, 25 Feb 2010) Log Message: ----------- Fix typo in test. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/test/scripting/ScriptingModuleTest.cpp Modified: trunk/ktutorial/ktutorial-library/test/scripting/ScriptingModuleTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/scripting/ScriptingModuleTest.cpp 2010-02-24 05:25:56 UTC (rev 103) +++ trunk/ktutorial/ktutorial-library/test/scripting/ScriptingModuleTest.cpp 2010-02-25 01:16:52 UTC (rev 104) @@ -159,7 +159,7 @@ type = metaObject(scriptingModule, "WaitForNot"); QCOMPARE(type.className(), WaitForNot::staticMetaObject.className()); - QVERIFY(containsMetaObject(scriptingModule, "WaitForNot")); + QVERIFY(containsMetaObject(scriptingModule, "WaitForOr")); type = metaObject(scriptingModule, "WaitForOr"); QCOMPARE(type.className(), WaitForOr::staticMetaObject.className()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-24 05:26:02
|
Revision: 103 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=103&view=rev Author: danxuliu Date: 2010-02-24 05:25:56 +0000 (Wed, 24 Feb 2010) Log Message: ----------- Fix compiler warning about initialization order. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/test/StepTest.cpp Modified: trunk/ktutorial/ktutorial-library/test/StepTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/StepTest.cpp 2010-02-24 02:51:12 UTC (rev 102) +++ trunk/ktutorial/ktutorial-library/test/StepTest.cpp 2010-02-24 05:25:56 UTC (rev 103) @@ -114,8 +114,8 @@ class StepWithWaitForAddedInSetup: public Step { public: + StepTest* mStepTest; WaitFor* mWaitFor; - StepTest* mStepTest; StepWithWaitForAddedInSetup(const QString& id, StepTest* stepTest): Step(id), @@ -135,8 +135,8 @@ class StepWithOptionAddedInSetup: public Step { public: + StepTest* mStepTest; Option* mOption; - StepTest* mStepTest; StepWithOptionAddedInSetup(const QString& id, StepTest* stepTest): Step(id), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-24 02:51:18
|
Revision: 102 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=102&view=rev Author: danxuliu Date: 2010-02-24 02:51:12 +0000 (Wed, 24 Feb 2010) Log Message: ----------- Order alphabetically WaitFor files in CMakeLists.txt. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt Modified: trunk/ktutorial/ktutorial-library/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-24 02:24:04 UTC (rev 101) +++ trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-24 02:51:12 UTC (rev 102) @@ -15,9 +15,9 @@ Tutorial.cpp TutorialInformation.cpp TutorialManager.cpp + WaitFor.cpp WaitForAnd.cpp WaitForComposed.cpp - WaitFor.cpp WaitForNot.cpp WaitForOr.cpp WaitForSignal.cpp @@ -39,9 +39,9 @@ Tutorial.h TutorialInformation.h TutorialManager.h + WaitFor.h WaitForAnd.h WaitForComposed.h - WaitFor.h WaitForNot.h WaitForOr.h WaitForSignal.h This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-24 02:24:10
|
Revision: 101 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=101&view=rev Author: danxuliu Date: 2010-02-24 02:24:04 +0000 (Wed, 24 Feb 2010) Log Message: ----------- WaitFors and Options added in the setup() method of a Step derived class are now removed and deleted automatically when the step is deactivated. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/Step.cpp trunk/ktutorial/ktutorial-library/src/Step.h trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp trunk/ktutorial/ktutorial-library/test/StepTest.cpp Modified: trunk/ktutorial/ktutorial-library/src/Step.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/Step.cpp 2010-02-23 18:33:39 UTC (rev 100) +++ trunk/ktutorial/ktutorial-library/src/Step.cpp 2010-02-24 02:24:04 UTC (rev 101) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2009 by Daniel Calviño Sánchez * + * Copyright (C) 2008-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -27,9 +27,9 @@ void Step::setActive(bool active) { if (active) { - setup(); + setupWrapper(); } else { - tearDown(); + tearDownWrapper(); } mActive = active; @@ -58,10 +58,21 @@ mOptions.append(option); + + bool deleteAddedObjectsInTearDownValue = mDeleteAddedObjectsInTearDown; + mDeleteAddedObjectsInTearDown = false; + WaitForSignal* waitFor = new WaitForSignal(option, SIGNAL(selected())); addWaitFor(waitFor, receiver, slot); mOptionsWaitsFor.append(waitFor); + + mDeleteAddedObjectsInTearDown = deleteAddedObjectsInTearDownValue; + + + if (mDeleteAddedObjectsInTearDown) { + mOptionsToBeDeletedInTearDown.append(option); + } } void Step::addWaitFor(WaitFor* waitFor, QObject* receiver, const QString& slot) { @@ -76,6 +87,10 @@ mWaitsFor.append(waitFor); connectWaitFor(waitFor, receiver, slot); + + if (mDeleteAddedObjectsInTearDown) { + mWaitsForToBeDeletedInTearDown.append(waitFor); + } } void Step::removeOption(Option* option) { @@ -126,3 +141,27 @@ void Step::disconnectWaitFor(WaitFor* waitFor) { disconnect(waitFor, SIGNAL(waitEnded(WaitFor*)), 0, 0); } + +//private: + +void Step::setupWrapper() { + mDeleteAddedObjectsInTearDown = true; + setup(); + mDeleteAddedObjectsInTearDown = false; +} + +void Step::tearDownWrapper() { + tearDown(); + + foreach (Option* option, mOptionsToBeDeletedInTearDown) { + removeOption(option); + delete option; + } + mOptionsToBeDeletedInTearDown.clear(); + + foreach (WaitFor* waitFor, mWaitsForToBeDeletedInTearDown) { + removeWaitFor(waitFor); + delete waitFor; + } + mWaitsForToBeDeletedInTearDown.clear(); +} Modified: trunk/ktutorial/ktutorial-library/src/Step.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/Step.h 2010-02-23 18:33:39 UTC (rev 100) +++ trunk/ktutorial/ktutorial-library/src/Step.h 2010-02-24 02:24:04 UTC (rev 101) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2009 by Daniel Calviño Sánchez * + * Copyright (C) 2008-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -105,8 +105,9 @@ * This may be needed, for example, when a Step needs to use an object that * didn't exist when the Tutorial was created (like something in a dialog * deleted every time it is closed). In this case, a subclass of Step should be - * made with setup() and tearDown() methods adding and removing the WaitFor for - * the "volatile" object. + * made with a setup() method adding the WaitFor for the "volatile" object. + * Note, however, that you don't have to remove nor delete the WaitFor added in + * the setup() method. It is done automatically when the step is deactivated. * * \code * void StepSubclass::setup() { @@ -115,11 +116,6 @@ * waitForAttribute = new WaitForSignal(textArea, SIGNAL(textChanged())); * addWaitFor(waitForAttribute, this, SLOT(startDone())); * } - * - * void StepSubclass::tearDown() { - * removeWaitFor(waitForAttribute); - * delete waitForAttribute; - * } * \endcode */ class KTUTORIAL_EXPORT Step: public QObject { @@ -134,7 +130,8 @@ */ explicit Step(const QString& id): QObject(), mId(id), - mActive(false) { + mActive(false), + mDeleteAddedObjectsInTearDown(false) { } /** @@ -202,7 +199,10 @@ * Note that the slot name can be set with or without using the SLOT macro. * * The Option is reparented to this Step, and thus deleted when this Step - * is deleted. + * is deleted. However, if the Option is added in the setup() method of a + * Step derived class, the Option is automatically removed and deleted when + * the Step is deactivated (that is, you don't have to do it explicitly in + * the tearDown() method). * * If you try to add the same Option (or different ones with the same name) * twice, nothing will happen. Only the Option added in first place and its @@ -224,7 +224,10 @@ * Note that the slot name can be set with or without using the SLOT macro. * * The WaitFor is reparented to this Step, and thus deleted when this Step - * is deleted. + * is deleted. However, if the WaitFor is added in the setup() method of a + * Step derived class, the WaitFor is automatically removed and deleted when + * the Step is deactivated (that is, you don't have to do it explicitly in + * the tearDown() method). * * If you try to add the same WaitFor twice, nothing will happen. Only the * WaitFor added in first place and its associated slot will be taken in @@ -328,11 +331,22 @@ bool mActive; /** + * When this flag is on, the conditions and conditions to wait for added are + * removed and deleted the next time this Step is deactivated. + */ + bool mDeleteAddedObjectsInTearDown; + + /** * The Options for this Step. */ QList<Option*> mOptions; /** + * The Options added in the setup to be deleted in the tearDown. + */ + QList<Option*> mOptionsToBeDeletedInTearDown; + + /** * The conditions to wait for in each Option. * The order of both lists is the same, so the index in the Options list * is the index of it associated WaitFor. @@ -344,6 +358,26 @@ */ QList<WaitFor*> mWaitsFor; + /** + * The conditions to wait for added in the setup to be deleted in the + * tearDown. + */ + QList<WaitFor*> mWaitsForToBeDeletedInTearDown; + + /** + * Wraps setup method to ensure that some code is executed before and after + * inherited setup method. + * It follows a Template Design Pattern. + */ + void setupWrapper(); + + /** + * Wraps tearDown method to ensure that some code is executed before and + * after inherited tearDown method. + * It follows a Template Design Pattern. + */ + void tearDownWrapper(); + }; #endif Modified: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-23 18:33:39 UTC (rev 100) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-24 02:24:04 UTC (rev 101) @@ -47,21 +47,13 @@ "Look at me! I am the text area!")); textEdit->show(); - mWaitForTextChanged = new WaitForSignal(textEdit, - SIGNAL(textChanged())); - addWaitFor(mWaitForTextChanged, + addWaitFor(new WaitForSignal(textEdit, SIGNAL(textChanged())), mUsingKTutorial, SLOT(clearTextTextModified())); } - virtual void tearDown() { - removeWaitFor(mWaitForTextChanged); - delete mWaitForTextChanged; - } - private: UsingKTutorial* mUsingKTutorial; - WaitFor* mWaitForTextChanged; }; @@ -81,17 +73,10 @@ //is closed. textEdit->installEventFilter(this); - mWaitForWidgetClosed = new WaitForSignal(this, - SIGNAL(textEditClosed())); - addWaitFor(mWaitForWidgetClosed, + addWaitFor(new WaitForSignal(this, SIGNAL(textEditClosed())), mUsingKTutorial, SLOT(closeTextEditDone())); } - virtual void tearDown() { - removeWaitFor(mWaitForWidgetClosed); - delete mWaitForWidgetClosed; - } - bool eventFilter(QObject* object, QEvent* event) { Q_UNUSED(object); if (event->type() == QEvent::Close) { @@ -108,7 +93,6 @@ private: UsingKTutorial* mUsingKTutorial; - WaitFor* mWaitForWidgetClosed; }; @@ -128,17 +112,10 @@ //tutorial is closed. mStepWidget->installEventFilter(this); - mWaitForMousePressed = new WaitForSignal(this, - SIGNAL(mousePressedOnWidget())); - addWaitFor(mWaitForMousePressed, + addWaitFor(new WaitForSignal(this, SIGNAL(mousePressedOnWidget())), mUsingKTutorial, SLOT(moveWidgetPressDone())); } - virtual void tearDown() { - removeWaitFor(mWaitForMousePressed); - delete mWaitForMousePressed; - } - bool eventFilter(QObject* object, QEvent* event) { Q_UNUSED(object); if (event->type() == QEvent::MouseButtonPress) { @@ -158,7 +135,6 @@ private: UsingKTutorial* mUsingKTutorial; - WaitFor* mWaitForMousePressed; }; @@ -178,17 +154,10 @@ //tutorial is closed. mStepWidget->installEventFilter(this); - mWaitForMouseReleased = new WaitForSignal(this, - SIGNAL(mouseReleasedOnWidget())); - addWaitFor(mWaitForMouseReleased, + addWaitFor(new WaitForSignal(this, SIGNAL(mouseReleasedOnWidget())), mUsingKTutorial, SLOT(moveWidgetReleaseDone())); } - virtual void tearDown() { - removeWaitFor(mWaitForMouseReleased); - delete mWaitForMouseReleased; - } - bool eventFilter(QObject* object, QEvent* event) { Q_UNUSED(object); if (event->type() == QEvent::MouseButtonRelease) { @@ -205,7 +174,6 @@ private: UsingKTutorial* mUsingKTutorial; - WaitFor* mWaitForMouseReleased; }; Modified: trunk/ktutorial/ktutorial-library/test/StepTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/StepTest.cpp 2010-02-23 18:33:39 UTC (rev 100) +++ trunk/ktutorial/ktutorial-library/test/StepTest.cpp 2010-02-24 02:24:04 UTC (rev 101) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2009 by Daniel Calviño Sánchez * + * Copyright (C) 2008-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -70,12 +70,14 @@ void testAddOption(); void testAddOptionWithoutSlotMacro(); void testAddOptionSeveralOptions(); + void testAddOptionDuringSetup(); void testAddOptionTwice(); void testAddOptionDifferentOptionsWithSameName(); void testAddWaitFor(); void testAddWaitForWithoutSlotMacro(); void testAddWaitForSeveralWaitFors(); + void testAddWaitForDuringSetup(); void testAddWaitForTwice(); void testRemoveOption(); @@ -109,6 +111,48 @@ }; +class StepWithWaitForAddedInSetup: public Step { +public: + + WaitFor* mWaitFor; + StepTest* mStepTest; + + StepWithWaitForAddedInSetup(const QString& id, StepTest* stepTest): + Step(id), + mStepTest(stepTest), + mWaitFor(0) { + } + +protected: + + virtual void setup() { + mWaitFor = new WaitForSignal(mStepTest, SIGNAL(dummySignal())); + addWaitFor(mWaitFor, mStepTest, SLOT(dummySlot())); + } + +}; + +class StepWithOptionAddedInSetup: public Step { +public: + + Option* mOption; + StepTest* mStepTest; + + StepWithOptionAddedInSetup(const QString& id, StepTest* stepTest): + Step(id), + mStepTest(stepTest), + mOption(0) { + } + +protected: + + virtual void setup() { + mOption = new Option("Bathe your iguana"); + addOption(mOption, mStepTest, SLOT(dummySlot())); + } + +}; + void StepTest::testConstructor() { InspectedStep step("doSomethingConstructive"); @@ -226,6 +270,31 @@ QCOMPARE(mDummySlotCallCount, 3); } +void StepTest::testAddOptionDuringSetup() { + StepWithOptionAddedInSetup step("doSomethingConstructive", this); + + step.setActive(true); + + connect(this, SIGNAL(dummySignal()), step.mOption, SIGNAL(selected())); + + QCOMPARE(step.mOption->parent(), &step); + QCOMPARE(step.options().count(), 1); + QVERIFY(step.options().contains(step.mOption)); + QCOMPARE(mDummySlotCallCount, 0); + + emit dummySignal(); + QCOMPARE(mDummySlotCallCount, 1); + + QSignalSpy destroyedSpy(step.mOption, SIGNAL(destroyed(QObject*))); + + step.setActive(false); + + QCOMPARE(step.options().count(), 0); + QCOMPARE(step.mWaitsForToBeDeletedInTearDown.count(), 0); + QCOMPARE(step.mOptionsToBeDeletedInTearDown.count(), 0); + QCOMPARE(destroyedSpy.count(), 1); +} + void StepTest::testAddOptionTwice() { Step step("doSomethingConstructive"); @@ -361,6 +430,29 @@ QCOMPARE(mDummySlotCallCount, 3); } +void StepTest::testAddWaitForDuringSetup() { + StepWithWaitForAddedInSetup step("doSomethingConstructive", this); + + step.setActive(true); + + QCOMPARE(step.mWaitFor->parent(), &step); + QCOMPARE(step.mWaitsFor.count(), 1); + QVERIFY(step.mWaitsFor.contains(step.mWaitFor)); + QCOMPARE(mDummySlotCallCount, 0); + + emit dummySignal(); + QCOMPARE(mDummySlotCallCount, 1); + + QSignalSpy destroyedSpy(step.mWaitFor, SIGNAL(destroyed(QObject*))); + + step.setActive(false); + + QCOMPARE(step.mWaitsFor.count(), 0); + QCOMPARE(step.mWaitsForToBeDeletedInTearDown.count(), 0); + QCOMPARE(step.mOptionsToBeDeletedInTearDown.count(), 0); + QCOMPARE(destroyedSpy.count(), 1); +} + void StepTest::testAddWaitForTwice() { Step step("doSomethingConstructive"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-23 18:33:48
|
Revision: 100 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=100&view=rev Author: danxuliu Date: 2010-02-23 18:33:39 +0000 (Tue, 23 Feb 2010) Log Message: ----------- Change the ui object in StepWidget and TutorialManagerDialog to a pointer, so ui_XXX.h files aren't included in the header file of these classes. The binary view directory no longer has to be included to find the ui_XXX.h files where the headers of these classes were used. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt trunk/ktutorial/ktutorial-library/src/view/StepWidget.cpp trunk/ktutorial/ktutorial-library/src/view/StepWidget.h trunk/ktutorial/ktutorial-library/src/view/TutorialManagerDialog.cpp trunk/ktutorial/ktutorial-library/src/view/TutorialManagerDialog.h trunk/ktutorial/ktutorial-library/test/view/StepWidgetTest.cpp trunk/ktutorial/ktutorial-library/test/view/TutorialManagerDialogTest.cpp Modified: trunk/ktutorial/ktutorial-library/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-23 17:44:42 UTC (rev 99) +++ trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-23 18:33:39 UTC (rev 100) @@ -6,7 +6,7 @@ add_subdirectory(tutorials) add_subdirectory(view) -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/view ${KDE4_INCLUDES}) +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${KDE4_INCLUDES}) set(ktutorial_LIB_SRCS KTutorial.cpp @@ -25,10 +25,6 @@ kde4_add_library(ktutorial SHARED ${ktutorial_LIB_SRCS}) -# ktutorial_view must be built before, so ui_TutorialManagerDialog.h is created -# (needed in KTutorial.cpp as it includes view/TutorialManagerDialog.h) -add_dependencies(ktutorial ktutorial_view) - target_link_libraries(ktutorial ktutorial_scripting ktutorial_tutorials ktutorial_view) ####### Install the library ####### Modified: trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt 2010-02-23 17:44:42 UTC (rev 99) +++ trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt 2010-02-23 18:33:39 UTC (rev 100) @@ -1,4 +1,4 @@ -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../view ${KDE4_INCLUDES}) +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${KDE4_INCLUDES}) set(ktutorial_tutorials_SRCS UsingKTutorial.cpp Modified: trunk/ktutorial/ktutorial-library/src/view/StepWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/view/StepWidget.cpp 2010-02-23 17:44:42 UTC (rev 99) +++ trunk/ktutorial/ktutorial-library/src/view/StepWidget.cpp 2010-02-23 18:33:39 UTC (rev 100) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Daniel Calviño Sánchez * + * Copyright (C) 2008-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -24,6 +24,7 @@ #include <klocalizedstring.h> #include "StepWidget.h" +#include "ui_StepWidget.h" #include "../Option.h" #include "../Step.h" @@ -38,28 +39,33 @@ setFrameShape(QFrame::Panel); setLineWidth(1); - ui.setupUi(this); + ui = new Ui::StepWidget(); + ui->setupUi(this); setWindowTitle(i18nc("@title:window", "Tutorial: %1", tutorialName)); - ui.closeButton->setIcon(KIcon("dialog-close")); + ui->closeButton->setIcon(KIcon("dialog-close")); - QSize buttonSize = ui.closeButton->size(); + QSize buttonSize = ui->closeButton->size(); buttonSize.setWidth(buttonSize.height()); // buttonSize.setWidth(ui.closeButton->iconSize().width()); // buttonSize.setHeight(ui.closeButton->iconSize().height()); - ui.closeButton->setFixedSize(buttonSize); + ui->closeButton->setFixedSize(buttonSize); - connect(ui.closeButton, SIGNAL(clicked()), this, SLOT(close())); + connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); - mOptionsLayout = new QHBoxLayout(ui.optionsWidget); + mOptionsLayout = new QHBoxLayout(ui->optionsWidget); } +StepWidget::~StepWidget() { + delete ui; +} + //public slots: void StepWidget::setStep(Step* step) { - ui.textLabel->setText(step->text()); + ui->textLabel->setText(step->text()); setOptions(step->options()); adjustSize(); @@ -82,7 +88,7 @@ void StepWidget::keyPressEvent(QKeyEvent* event) { if (event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_Escape) { - ui.closeButton->animateClick(); + ui->closeButton->animateClick(); event->accept(); return; } else if (event->modifiers() == Qt::ShiftModifier && @@ -131,7 +137,7 @@ //private: void StepWidget::setOptions(const QList<Option*>& options) { - QList<KPushButton*> buttons = ui.optionsWidget->findChildren<KPushButton*>(); + QList<KPushButton*> buttons = ui->optionsWidget->findChildren<KPushButton*>(); QListIterator<KPushButton*> itButtons(buttons); while (itButtons.hasNext()) { KPushButton* button = itButtons.next(); @@ -143,7 +149,7 @@ while (it.hasNext()) { Option* option = it.next(); - KPushButton* button = new KPushButton(ui.optionsWidget); + KPushButton* button = new KPushButton(ui->optionsWidget); button->setText(option->name()); mOptionsLayout->addWidget(button); Modified: trunk/ktutorial/ktutorial-library/src/view/StepWidget.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/view/StepWidget.h 2010-02-23 17:44:42 UTC (rev 99) +++ trunk/ktutorial/ktutorial-library/src/view/StepWidget.h 2010-02-23 18:33:39 UTC (rev 100) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Daniel Calviño Sánchez * + * Copyright (C) 2008-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -22,8 +22,6 @@ #include <QFrame> #include <QList> -#include "ui_StepWidget.h" - class QCloseEvent; class QHBoxLayout; class QKeyEvent; @@ -33,6 +31,10 @@ class Option; class Step; +namespace Ui { +class StepWidget; +} + namespace view { /** @@ -62,6 +64,11 @@ */ explicit StepWidget(const QString& tutorialName, QWidget* parent = 0); + /** + * Destroys this StepWidget. + */ + virtual ~StepWidget(); + public slots: /** @@ -166,7 +173,7 @@ /** * The user interface elements. */ - Ui::StepWidget ui; + Ui::StepWidget* ui; /** * The layout where buttons for Options are added. Modified: trunk/ktutorial/ktutorial-library/src/view/TutorialManagerDialog.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/view/TutorialManagerDialog.cpp 2010-02-23 17:44:42 UTC (rev 99) +++ trunk/ktutorial/ktutorial-library/src/view/TutorialManagerDialog.cpp 2010-02-23 18:33:39 UTC (rev 100) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Daniel Calviño Sánchez * + * Copyright (C) 2008-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -18,6 +18,7 @@ #include "TutorialManagerDialog.h" #include "TutorialListModel.h" +#include "ui_TutorialManagerDialog.h" #include "../TutorialInformation.h" #include "../TutorialManager.h" @@ -32,14 +33,15 @@ mCurrentTutorialInformation(0) { QWidget *widget = new QWidget(this); - ui.setupUi(widget); + ui = new Ui::TutorialManagerDialog(); + ui->setupUi(widget); setMainWidget(widget); setCaption(i18nc("@title:window", "Tutorial manager")); setButtons(KDialog::User1 | KDialog::Close); - ui.tutorialsList->setModel(new TutorialListModel(tutorialManager, this)); + ui->tutorialsList->setModel(new TutorialListModel(tutorialManager, this)); setButtonIcon(User1, KIcon("dialog-ok")); setButtonText(User1, i18nc("@action:button", "Start")); @@ -48,7 +50,7 @@ setDefaultButton(User1); enableButton(User1, false); - connect(ui.tutorialsList->selectionModel(), + connect(ui->tutorialsList->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(select(QItemSelection))); connect(this, SIGNAL(user1Clicked()), this, SLOT(start())); @@ -56,6 +58,10 @@ connect(mTutorialManager, SIGNAL(finished()), this, SLOT(finish())); } +TutorialManagerDialog::~TutorialManagerDialog() { + delete ui; +} + //public slots: void TutorialManagerDialog::finish() { @@ -71,7 +77,7 @@ enableButton(User1, true); - ui.descriptionLabel->setText(tutorialInformation->description()); + ui->descriptionLabel->setText(tutorialInformation->description()); mCurrentTutorialInformation = tutorialInformation; } Modified: trunk/ktutorial/ktutorial-library/src/view/TutorialManagerDialog.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/view/TutorialManagerDialog.h 2010-02-23 17:44:42 UTC (rev 99) +++ trunk/ktutorial/ktutorial-library/src/view/TutorialManagerDialog.h 2010-02-23 18:33:39 UTC (rev 100) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Daniel Calviño Sánchez * + * Copyright (C) 2008-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -19,14 +19,18 @@ #ifndef VIEW_TUTORIALMANAGERDIALOG_H #define VIEW_TUTORIALMANAGERDIALOG_H +#include <QItemSelection> + #include <kdialog.h> #include <klocalizedstring.h> -#include "ui_TutorialManagerDialog.h" - class TutorialInformation; class TutorialManager; +namespace Ui { +class TutorialManagerDialog; +} + namespace view { /** @@ -53,6 +57,11 @@ explicit TutorialManagerDialog(TutorialManager* tutorialManager, QWidget* parent = 0); + /** + * Destroys this TutorialManagerDialog. + */ + virtual ~TutorialManagerDialog(); + public slots: /** @@ -71,7 +80,7 @@ /** * The user interface elements. */ - Ui::TutorialManagerDialog ui; + Ui::TutorialManagerDialog* ui; /** * The TutorialInformation of the last activated tutorial in the list. Modified: trunk/ktutorial/ktutorial-library/test/view/StepWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/view/StepWidgetTest.cpp 2010-02-23 17:44:42 UTC (rev 99) +++ trunk/ktutorial/ktutorial-library/test/view/StepWidgetTest.cpp 2010-02-23 18:33:39 UTC (rev 100) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Daniel Calviño Sánchez * + * Copyright (C) 2009-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -27,6 +27,7 @@ #undef private #undef protected +#include "ui_StepWidget.h" #include "../Option.h" #include "../Step.h" @@ -312,11 +313,11 @@ /////////////////////////////////// Helpers //////////////////////////////////// QLabel* StepWidgetTest::textLabel(StepWidget* stepWidget) { - return stepWidget->ui.textLabel; + return stepWidget->ui->textLabel; } KPushButton* StepWidgetTest::closeButton(StepWidget* stepWidget) { - return stepWidget->ui.closeButton; + return stepWidget->ui->closeButton; } } Modified: trunk/ktutorial/ktutorial-library/test/view/TutorialManagerDialogTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/view/TutorialManagerDialogTest.cpp 2010-02-23 17:44:42 UTC (rev 99) +++ trunk/ktutorial/ktutorial-library/test/view/TutorialManagerDialogTest.cpp 2010-02-23 18:33:39 UTC (rev 100) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Daniel Calviño Sánchez * + * Copyright (C) 2009-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -27,6 +27,7 @@ #undef private #undef protected +#include "ui_TutorialManagerDialog.h" #include "../Step.h" #include "../Tutorial.h" #include "../TutorialInformation.h" @@ -312,12 +313,12 @@ QAbstractItemView* TutorialManagerDialogTest::tutorialList( TutorialManagerDialog* tutorialManagerDialog) { - return tutorialManagerDialog->ui.tutorialsList; + return tutorialManagerDialog->ui->tutorialsList; } QLabel* TutorialManagerDialogTest::descriptionLabel( TutorialManagerDialog* tutorialManagerDialog) { - return tutorialManagerDialog->ui.descriptionLabel; + return tutorialManagerDialog->ui->descriptionLabel; } KPushButton* TutorialManagerDialogTest::startButton( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-23 17:44:49
|
Revision: 99 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=99&view=rev Author: danxuliu Date: 2010-02-23 17:44:42 +0000 (Tue, 23 Feb 2010) Log Message: ----------- Delete the QTextEdit created by the tutorial when it is finished if the QTextEdit is still alive (this happens when the user closes the tutorial before closing the QTextEdit). Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h Modified: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-23 17:42:05 UTC (rev 98) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-23 17:44:42 UTC (rev 99) @@ -403,5 +403,15 @@ nextStep("end"); } +//protected: + +void UsingKTutorial::tearDown() { + QTextEdit* textEdit = KTutorial::self()->findObject<QTextEdit*>( + "usingKTutorialTextEdit"); + if (textEdit) { + textEdit->deleteLater(); + } +} + #include "moc_UsingKTutorial.cpp" #include "UsingKTutorial.moc" Modified: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h 2010-02-23 17:42:05 UTC (rev 98) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h 2010-02-23 17:44:42 UTC (rev 99) @@ -47,6 +47,10 @@ void moveWidgetReleaseDone(); +protected: + + void tearDown(); + }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-23 17:42:12
|
Revision: 98 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=98&view=rev Author: danxuliu Date: 2010-02-23 17:42:05 +0000 (Tue, 23 Feb 2010) Log Message: ----------- The text area says that it is "the" text area, not "a" text area. Honour this in the step text. Spanish localization is also updated to reflect this. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/po/es.po trunk/ktutorial/ktutorial-library/po/ktutorial.pot trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp Modified: trunk/ktutorial/ktutorial-library/po/es.po =================================================================== --- trunk/ktutorial/ktutorial-library/po/es.po 2010-02-23 17:34:50 UTC (rev 97) +++ trunk/ktutorial/ktutorial-library/po/es.po 2010-02-23 17:42:05 UTC (rev 98) @@ -8,8 +8,8 @@ "Project-Id-Version: es\n" "Report-Msgid-Bugs-To: http://sourceforge." "net/tracker/?group_id=301227&atid=1270278\n" -"POT-Creation-Date: 2010-02-23 18:21+0100\n" -"PO-Revision-Date: 2010-02-23 18:25-0500\n" +"POT-Creation-Date: 2010-02-23 18:35+0100\n" +"PO-Revision-Date: 2010-02-23 18:35-0500\n" "Last-Translator: Daniel Calviño Sánchez <dan...@gm...>\n" "Language-Team: Spanish <>\n" "MIME-Version: 1.0\n" @@ -64,9 +64,8 @@ "to the next step.</para>" msgstr "" "<para>Un tutorial se compone de varios pasos. Cada paso contiene un poco de " -"información.</para><para>Hay varias formas de avanzar desde un " -"paso a otro. Por ejemplo, haciendo click en el botón de debajo el tutorial " -"cambiará al " +"información.</para><para>Hay varias formas de avanzar desde un paso a otro. " +"Por ejemplo, haciendo click en el botón de debajo el tutorial cambiará al " "siguiente paso.</para>" #: tutorials/UsingKTutorial.cpp:250 @@ -109,12 +108,12 @@ msgctxt "@info" msgid "" "<para>Do you see the new window that has appeared? Yes, the one that says " -"that it is a text area. Well, the last way to advance from one step to " +"that it is the text area. Well, the last way to advance from one step to " "another is just doing what you are asked for.</para><para>In this case, " "empty the text area erasing all its text and once you have done it look " "again to the tutorial.</para>" msgstr "" -"<para>¿Ves la nueva ventana que ha aparecido? Sí, la que dice que es un área " +"<para>¿Ves la nueva ventana que ha aparecido? Sí, la que dice que es el área " "de texto. Bien, la última forma de avanzar de un paso a otro es simplemente " "haciendo lo que se te pide.</para><para>En este caso, vacía el área de texto " "borrando todo su texto y una vez lo hayas hecho fíjate de nuevo en el " @@ -153,8 +152,7 @@ "lugar distinto. Veamos cómo.</para><para>Sobre estos párrafos puedes ver un " "espacio vacío, al lado del botón de la esquina. Presiona con el botón " "izquierdo de tu ratón en dicho espacio vacío. Simplemente presiona, no " -"sueltes el botón del ratón aún.</" -"para>" +"sueltes el botón del ratón aún.</para>" #: tutorials/UsingKTutorial.cpp:338 msgctxt "@info" Modified: trunk/ktutorial/ktutorial-library/po/ktutorial.pot =================================================================== --- trunk/ktutorial/ktutorial-library/po/ktutorial.pot 2010-02-23 17:34:50 UTC (rev 97) +++ trunk/ktutorial/ktutorial-library/po/ktutorial.pot 2010-02-23 17:42:05 UTC (rev 98) @@ -9,7 +9,7 @@ "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: http://sourceforge.net/tracker/?" "group_id=301227&atid=1270278\n" -"POT-Creation-Date: 2010-02-23 18:21+0100\n" +"POT-Creation-Date: 2010-02-23 18:35+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL...@li...>\n" @@ -91,7 +91,7 @@ msgctxt "@info" msgid "" "<para>Do you see the new window that has appeared? Yes, the one that says " -"that it is a text area. Well, the last way to advance from one step to " +"that it is the text area. Well, the last way to advance from one step to " "another is just doing what you are asked for.</para><para>In this case, " "empty the text area erasing all its text and once you have done it look " "again to the tutorial.</para>" Modified: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-23 17:34:50 UTC (rev 97) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-23 17:42:05 UTC (rev 98) @@ -290,7 +290,7 @@ Step* clearTextStep = new ClearTextStep(this); clearTextStep->setText(i18nc("@info", "<para>Do you see the new window that has appeared? Yes, the one that says " -"that it is a text area. Well, the last way to advance from one step to " +"that it is the text area. Well, the last way to advance from one step to " "another is just doing what you are asked for.</para>" "<para>In this case, empty the text area erasing all its text and once you " "have done it look again to the tutorial.</para>")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-23 17:34:57
|
Revision: 97 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=97&view=rev Author: danxuliu Date: 2010-02-23 17:34:50 +0000 (Tue, 23 Feb 2010) Log Message: ----------- Spanish translation updated. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/po/es.po trunk/ktutorial/ktutorial-library/po/ktutorial.pot Modified: trunk/ktutorial/ktutorial-library/po/es.po =================================================================== --- trunk/ktutorial/ktutorial-library/po/es.po 2010-02-23 17:21:39 UTC (rev 96) +++ trunk/ktutorial/ktutorial-library/po/es.po 2010-02-23 17:34:50 UTC (rev 97) @@ -2,26 +2,193 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # -# Daniel Calviño Sánchez <dan...@gm...>, 2008. +# Daniel Calviño Sánchez <dan...@gm...>, 2008, 2010. msgid "" msgstr "" "Project-Id-Version: es\n" -"Report-Msgid-Bugs-To: http://sourceforge.net/tracker/?" -"group_id=301227&atid=1270278\n" -"POT-Creation-Date: 2010-02-06 17:57+0100\n" -"PO-Revision-Date: 2008-03-16 19:00+0100\n" +"Report-Msgid-Bugs-To: http://sourceforge." +"net/tracker/?group_id=301227&atid=1270278\n" +"POT-Creation-Date: 2010-02-23 18:21+0100\n" +"PO-Revision-Date: 2010-02-23 18:25-0500\n" "Last-Translator: Daniel Calviño Sánchez <dan...@gm...>\n" -"Language-Team: Español\n" +"Language-Team: Spanish <>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: KBabel 1.11.4\n" +"X-Generator: Lokalize 1.0\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: KTutorial.cpp:52 +#: KTutorial.cpp:57 msgctxt "@action:inmenu" msgid "Tutorials..." msgstr "Tutoriales..." +#: tutorials/UsingKTutorial.cpp:47 +msgctxt "Plain text in a QTextEdit" +msgid "Look at me! I am the text area!" +msgstr "¡Mírame! ¡Soy el área de texto!" + +#: tutorials/UsingKTutorial.cpp:216 +msgid "Using the tutorials" +msgstr "Utilización de los tutoriales" + +#: tutorials/UsingKTutorial.cpp:217 +msgid "This tutorial shows how the tutorial system works" +msgstr "Este tutorial muestra cómo funciona el sistema de tutoriales" + +#: tutorials/UsingKTutorial.cpp:223 +msgctxt "@info" +msgid "" +"<para>Welcome to the tutorial to learn how to use tutorials ;)</" +"para><para>But, what is a tutorial? A tutorial is a little guide to help you " +"to learn how to use an application. For example, it shows you how some " +"feature works, or how to accomplish some task.</para>" +msgstr "" +"<para>Bienvenido al tutorial para aprender cómo utilizar los tutoriales :)</" +"para><para>Pero, ¿qué es un tutorial? Un tutorial es una pequeña guía para " +"ayudarte a aprender cómo usar una aplicación. Por ejemplo, te muestra cómo " +"funciona cierta característica, o cómo llevar a cabo cierta tarea.</para>" + +#: tutorials/UsingKTutorial.cpp:228 tutorials/UsingKTutorial.cpp:242 +#: tutorials/UsingKTutorial.cpp:270 tutorials/UsingKTutorial.cpp:284 +msgctxt "@action" +msgid "Continue" +msgstr "Continuar" + +#: tutorials/UsingKTutorial.cpp:236 +msgctxt "@info" +msgid "" +"<para>A tutorial is composed of several steps. Each step contains a bit of " +"information.</para><para>There are several ways to advance from one step to " +"another. For example, clicking on the button below the tutorial will change " +"to the next step.</para>" +msgstr "" +"<para>Un tutorial se compone de varios pasos. Cada paso contiene un poco de " +"información.</para><para>Hay varias formas de avanzar desde un " +"paso a otro. Por ejemplo, haciendo click en el botón de debajo el tutorial " +"cambiará al " +"siguiente paso.</para>" + +#: tutorials/UsingKTutorial.cpp:250 +msgctxt "@info" +msgid "" +"<para>In other steps you may have more than one option to select. This can " +"be used, for example, to follow one path or another in the tutorial, skip " +"some part of the tutorial, etcetera. Which option do you prefer?</para>" +msgstr "" +"<para>En otros pasos puedes tener más de una opción para seleccionar. Esto " +"puede usarse, por ejemplo, para seguir un camino u otro en el tutorial, " +"saltarse cierta parte del tutorial, etcétera. ¿Qué opción prefieres?</para>" + +#: tutorials/UsingKTutorial.cpp:254 tutorials/UsingKTutorial.cpp:268 +msgctxt "@action" +msgid "Option 1" +msgstr "Opción 1" + +#: tutorials/UsingKTutorial.cpp:256 tutorials/UsingKTutorial.cpp:282 +msgctxt "@action" +msgid "Option 2" +msgstr "Opción 2" + +#: tutorials/UsingKTutorial.cpp:264 tutorials/UsingKTutorial.cpp:278 +msgctxt "@info" +msgid "" +"<para>You have selected <emphasis>%1</emphasis>. Don't worry, as this is " +"just an example, selecting one option or the other makes no difference.</" +"para><para>In the next step you will learn the last way to advance from one " +"step to another. To show this to you I will open a new window where text can " +"be written.</para>" +msgstr "" +"<para>Has seleccionado <emphasis>%1</emphasis>. No te preocupes, dado que " +"esto es sólo un ejemplo, no hay ninguna diferencia entre seleccionar una " +"opción u otra.</para><para>En el siguiente paso aprenderás la última forma " +"de avanzar de un paso a otro. Para mostrártelo abriré una nueva ventana en " +"la que puede escribirse texto.</para>" + +#: tutorials/UsingKTutorial.cpp:292 +msgctxt "@info" +msgid "" +"<para>Do you see the new window that has appeared? Yes, the one that says " +"that it is a text area. Well, the last way to advance from one step to " +"another is just doing what you are asked for.</para><para>In this case, " +"empty the text area erasing all its text and once you have done it look " +"again to the tutorial.</para>" +msgstr "" +"<para>¿Ves la nueva ventana que ha aparecido? Sí, la que dice que es un área " +"de texto. Bien, la última forma de avanzar de un paso a otro es simplemente " +"haciendo lo que se te pide.</para><para>En este caso, vacía el área de texto " +"borrando todo su texto y una vez lo hayas hecho fíjate de nuevo en el " +"tutorial.</para>" + +#: tutorials/UsingKTutorial.cpp:306 +msgctxt "@info" +msgid "" +"<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 " +"options. The tutorial advanced automatically when you erased the text as " +"requested. This will be the most common way to advance from one step to " +"another.</para><para>Ok, close the window with the text area to continue " +"with the tutorial.</para>" +msgstr "" +"<para>¿Ves? Estás en un nuevo paso, pero no le dijiste al tutorial que " +"continuase al siguiente paso, ni tampoco tuviste que seleccionar entre " +"varias opciones. El tutorial avanzó automáticamente cuando borraste el texto " +"como se te pidió. Ésta será la forma más común de avanzar de un paso a otro." +"</para><para>Bien, cierra la ventana del área de texto para continuar con el " +"tutorial.</para>" + +#: tutorials/UsingKTutorial.cpp:322 +msgctxt "@info" +msgid "" +"<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 " +"like any other window, but pressing in a different place. Let's see how.</" +"para><para>Above these paragraphs you can see an empty space, next to the " +"button at the corner. Press with the left button of your mouse on that empty " +"space. Just press, don't release the mouse button yet.</para>" +msgstr "" +"<para>Puede que te hayas dado cuenta de que la ventana del tutorial no tiene " +"borde. ¿Eso significa que no se puede mover? En absoluto. Puede arrastrarse " +"utilizando el ratón como cualquier otra ventana, pero presionando en un " +"lugar distinto. Veamos cómo.</para><para>Sobre estos párrafos puedes ver un " +"espacio vacío, al lado del botón de la esquina. Presiona con el botón " +"izquierdo de tu ratón en dicho espacio vacío. Simplemente presiona, no " +"sueltes el botón del ratón aún.</" +"para>" + +#: tutorials/UsingKTutorial.cpp:338 +msgctxt "@info" +msgid "" +"<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 " +"place it was. Of course, you can move it again dragging it like you have " +"just done.</para>" +msgstr "" +"<para>Ahora, y sin soltar el botón, mueve el ratón y la ventana se moverá. " +"Cuando sueltes el botón, la ventana permanecerá en la posición en la que " +"estaba. Por supuesto, puedes moverla de nuevo arrastrándola como acabas de " +"hacer.</para>" + +#: tutorials/UsingKTutorial.cpp:351 +msgctxt "@info" +msgid "" +"<para>And that's all. You can now close the tutorial. In fact, you could " +"have closed the tutorial in any other of the previous steps, but if you do " +"that when the tutorial is started again it won't remember what you did. It " +"will start from the beginning again.</para><para>But how do you close the " +"tutorial? Well, do you see that button above this text, in the corner, with " +"an icon that looks like a close icon? Do you guess what it does? ;) Just " +"click on it and you will return to the tutorial selection dialog. Bye!</para>" +msgstr "" +"<para>Y eso es todo. Ahora ya puedes cerrar el tutorial. De hecho, podrías " +"haber cerrado el tutorial en cualquiera de los pasos previos, pero si lo " +"haces cuando el tutorial empiece de nuevo no recordará lo que hiciste. " +"Empezará desde el principio otra vez.</para><para>¿Pero cómo puedes cerrar " +"el tutorial? Bien, ¿ves ese botón sobre este texto, en la esquina, con un " +"icono que parece un icono de cerrar? ¿Adivinas qué hace? ;) Simplemente haz " +"click en él y volverás al diálogo de selección de tutoriales. ¡Hasta luego!</" +"para>" + #: view/StepWidget.cpp:43 msgctxt "@title:window" msgid "Tutorial: %1" @@ -118,3 +285,4 @@ msgctxt "EMAIL OF TRANSLATORS" msgid "Your emails" msgstr "dan...@gm..." + Modified: trunk/ktutorial/ktutorial-library/po/ktutorial.pot =================================================================== --- trunk/ktutorial/ktutorial-library/po/ktutorial.pot 2010-02-23 17:21:39 UTC (rev 96) +++ trunk/ktutorial/ktutorial-library/po/ktutorial.pot 2010-02-23 17:34:50 UTC (rev 97) @@ -9,7 +9,7 @@ "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: http://sourceforge.net/tracker/?" "group_id=301227&atid=1270278\n" -"POT-Creation-Date: 2010-02-06 17:57+0100\n" +"POT-Creation-Date: 2010-02-23 18:21+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL...@li...>\n" @@ -17,11 +17,129 @@ "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: KTutorial.cpp:52 +#: KTutorial.cpp:57 msgctxt "@action:inmenu" msgid "Tutorials..." msgstr "" +#: tutorials/UsingKTutorial.cpp:47 +msgctxt "Plain text in a QTextEdit" +msgid "Look at me! I am the text area!" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:216 +msgid "Using the tutorials" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:217 +msgid "This tutorial shows how the tutorial system works" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:223 +msgctxt "@info" +msgid "" +"<para>Welcome to the tutorial to learn how to use tutorials ;)</" +"para><para>But, what is a tutorial? A tutorial is a little guide to help you " +"to learn how to use an application. For example, it shows you how some " +"feature works, or how to accomplish some task.</para>" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:228 tutorials/UsingKTutorial.cpp:242 +#: tutorials/UsingKTutorial.cpp:270 tutorials/UsingKTutorial.cpp:284 +msgctxt "@action" +msgid "Continue" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:236 +msgctxt "@info" +msgid "" +"<para>A tutorial is composed of several steps. Each step contains a bit of " +"information.</para><para>There are several ways to advance from one step to " +"another. For example, clicking on the button below the tutorial will change " +"to the next step.</para>" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:250 +msgctxt "@info" +msgid "" +"<para>In other steps you may have more than one option to select. This can " +"be used, for example, to follow one path or another in the tutorial, skip " +"some part of the tutorial, etcetera. Which option do you prefer?</para>" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:254 tutorials/UsingKTutorial.cpp:268 +msgctxt "@action" +msgid "Option 1" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:256 tutorials/UsingKTutorial.cpp:282 +msgctxt "@action" +msgid "Option 2" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:264 tutorials/UsingKTutorial.cpp:278 +msgctxt "@info" +msgid "" +"<para>You have selected <emphasis>%1</emphasis>. Don't worry, as this is " +"just an example, selecting one option or the other makes no difference.</" +"para><para>In the next step you will learn the last way to advance from one " +"step to another. To show this to you I will open a new window where text can " +"be written.</para>" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:292 +msgctxt "@info" +msgid "" +"<para>Do you see the new window that has appeared? Yes, the one that says " +"that it is a text area. Well, the last way to advance from one step to " +"another is just doing what you are asked for.</para><para>In this case, " +"empty the text area erasing all its text and once you have done it look " +"again to the tutorial.</para>" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:306 +msgctxt "@info" +msgid "" +"<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 " +"options. The tutorial advanced automatically when you erased the text as " +"requested. This will be the most common way to advance from one step to " +"another.</para><para>Ok, close the window with the text area to continue " +"with the tutorial.</para>" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:322 +msgctxt "@info" +msgid "" +"<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 " +"like any other window, but pressing in a different place. Let's see how.</" +"para><para>Above these paragraphs you can see an empty space, next to the " +"button at the corner. Press with the left button of your mouse on that empty " +"space. Just press, don't release the mouse button yet.</para>" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:338 +msgctxt "@info" +msgid "" +"<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 " +"place it was. Of course, you can move it again dragging it like you have " +"just done.</para>" +msgstr "" + +#: tutorials/UsingKTutorial.cpp:351 +msgctxt "@info" +msgid "" +"<para>And that's all. You can now close the tutorial. In fact, you could " +"have closed the tutorial in any other of the previous steps, but if you do " +"that when the tutorial is started again it won't remember what you did. It " +"will start from the beginning again.</para><para>But how do you close the " +"tutorial? Well, do you see that button above this text, in the corner, with " +"an icon that looks like a close icon? Do you guess what it does? ;) Just " +"click on it and you will return to the tutorial selection dialog. Bye!</para>" +msgstr "" + #: view/StepWidget.cpp:43 msgctxt "@title:window" msgid "Tutorial: %1" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-23 17:21:46
|
Revision: 96 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=96&view=rev Author: danxuliu Date: 2010-02-23 17:21:39 +0000 (Tue, 23 Feb 2010) Log Message: ----------- Minor tweaks in the text of some steps of UsingKTutorial. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp Modified: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-23 16:50:40 UTC (rev 95) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-23 17:21:39 UTC (rev 96) @@ -233,10 +233,11 @@ //Step singleOption Step* singleOptionStep = new Step("singleOption"); singleOptionStep->setText(i18nc("@info", -"<para>A tutorial is composed of several steps, each one containing a bit of " +"<para>A tutorial is composed of several steps. Each step contains a bit of " "information.</para>" "<para>There are several ways to advance from one step to another. For " -"example, clicking on the button below will change to the next step.</para>")); +"example, clicking on the button below the tutorial will change to the next " +"step.</para>")); singleOptionStep->addOption(new Option(i18nc("@action", "Continue")), this, SLOT(singleOptionDone())); @@ -323,8 +324,8 @@ "like any other window, but pressing in a different place. Let's see " "how.</para>" "<para>Above these paragraphs you can see an empty space, next to the button " -"at the corner. Press with the left button of your mouse on it. Just press, " -"don't release the button yet.</para>")); +"at the corner. Press with the left button of your mouse on that empty space. " +"Just press, don't release the mouse button yet.</para>")); //WaitFor is added in step setup, as it uses an object that isn't available //when the tutorial is created This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-23 16:50:48
|
Revision: 95 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=95&view=rev Author: danxuliu Date: 2010-02-23 16:50:40 +0000 (Tue, 23 Feb 2010) Log Message: ----------- Set a user friendlier name for the tutorial (a user doesn't have to know that the tutorial system is called KTutorial). Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp Modified: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-23 16:43:06 UTC (rev 94) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-23 16:50:40 UTC (rev 95) @@ -213,7 +213,7 @@ UsingKTutorial::UsingKTutorial(): Tutorial(0) { mTutorialInformation = new TutorialInformation("usingKTutorial"); - mTutorialInformation->setName(i18n("Using KTutorial")); + mTutorialInformation->setName(i18n("Using the tutorials")); mTutorialInformation->setDescription(i18n("This tutorial shows how the " "tutorial system works")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-23 16:43:49
|
Revision: 94 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=94&view=rev Author: danxuliu Date: 2010-02-23 16:43:06 +0000 (Tue, 23 Feb 2010) Log Message: ----------- Add a bundled tutorial that shows how tutorials are used. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt trunk/ktutorial/ktutorial-library/src/KTutorial.cpp Added Paths: ----------- trunk/ktutorial/ktutorial-library/src/tutorials/ trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h Modified: trunk/ktutorial/ktutorial-library/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-23 16:20:14 UTC (rev 93) +++ trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-23 16:43:06 UTC (rev 94) @@ -3,6 +3,7 @@ add_definitions("-fPIC") add_subdirectory(scripting) +add_subdirectory(tutorials) add_subdirectory(view) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/view ${KDE4_INCLUDES}) @@ -28,7 +29,7 @@ # (needed in KTutorial.cpp as it includes view/TutorialManagerDialog.h) add_dependencies(ktutorial ktutorial_view) -target_link_libraries(ktutorial ktutorial_scripting ktutorial_view) +target_link_libraries(ktutorial ktutorial_scripting ktutorial_tutorials ktutorial_view) ####### Install the library ####### Modified: trunk/ktutorial/ktutorial-library/src/KTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/KTutorial.cpp 2010-02-23 16:20:14 UTC (rev 93) +++ trunk/ktutorial/ktutorial-library/src/KTutorial.cpp 2010-02-23 16:43:06 UTC (rev 94) @@ -25,6 +25,7 @@ #include "TutorialInformation.h" #include "scripting/ScriptingModule.h" #include "scripting/ScriptManager.h" +#include "tutorials/UsingKTutorial.h" #include "view/StepWidget.h" #include "view/TutorialManagerDialog.h" @@ -68,6 +69,8 @@ mParent = window; + registerTutorial(new UsingKTutorial()); + ScriptManager().loadTutorials(mTutorialmanager); } Added: trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt 2010-02-23 16:43:06 UTC (rev 94) @@ -0,0 +1,7 @@ +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../view ${KDE4_INCLUDES}) + +set(ktutorial_tutorials_SRCS + UsingKTutorial.cpp +) + +kde4_add_library(ktutorial_tutorials ${ktutorial_tutorials_SRCS}) Property changes on: trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-23 16:43:06 UTC (rev 94) @@ -0,0 +1,406 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "UsingKTutorial.h" + +#include <QMouseEvent> +#include <QTextEdit> + +#include <KLocalizedString> + +#include "../KTutorial.h" +#include "../Option.h" +#include "../Step.h" +#include "../TutorialInformation.h" +#include "../WaitForSignal.h" +#include "../view/StepWidget.h" + +class ClearTextStep: public Step { +public: + + ClearTextStep(UsingKTutorial* usingKTutorial): + Step("clearText"), + mUsingKTutorial(usingKTutorial) { + } + + virtual void setup() { + QTextEdit* textEdit = new QTextEdit(KTutorial::self()->parentWidget()); + textEdit->setAttribute(Qt::WA_DeleteOnClose); + textEdit->setWindowFlags(Qt::Window); + textEdit->setObjectName("usingKTutorialTextEdit"); + textEdit->setText(i18nc("Plain text in a QTextEdit", + "Look at me! I am the text area!")); + textEdit->show(); + + mWaitForTextChanged = new WaitForSignal(textEdit, + SIGNAL(textChanged())); + addWaitFor(mWaitForTextChanged, + mUsingKTutorial, SLOT(clearTextTextModified())); + } + + virtual void tearDown() { + removeWaitFor(mWaitForTextChanged); + delete mWaitForTextChanged; + } + +private: + + UsingKTutorial* mUsingKTutorial; + WaitFor* mWaitForTextChanged; + +}; + +class CloseTextEditStep: public Step { +Q_OBJECT +public: + + CloseTextEditStep(UsingKTutorial* usingKTutorial): + Step("closeTextEdit"), + mUsingKTutorial(usingKTutorial) { + } + + virtual void setup() { + QTextEdit* textEdit = KTutorial::self()->findObject<QTextEdit*>( + "usingKTutorialTextEdit"); + //The filter is removed when the text edit is deleted, that is, when it + //is closed. + textEdit->installEventFilter(this); + + mWaitForWidgetClosed = new WaitForSignal(this, + SIGNAL(textEditClosed())); + addWaitFor(mWaitForWidgetClosed, + mUsingKTutorial, SLOT(closeTextEditDone())); + } + + virtual void tearDown() { + removeWaitFor(mWaitForWidgetClosed); + delete mWaitForWidgetClosed; + } + + bool eventFilter(QObject* object, QEvent* event) { + Q_UNUSED(object); + if (event->type() == QEvent::Close) { + emit textEditClosed(); + } + + return false; + } + +Q_SIGNALS: + + void textEditClosed(); + +private: + + UsingKTutorial* mUsingKTutorial; + WaitFor* mWaitForWidgetClosed; + +}; + +class MoveWidgetPressStep: public Step { +Q_OBJECT +public: + + MoveWidgetPressStep(UsingKTutorial* usingKTutorial): + Step("moveWidgetPress"), + mUsingKTutorial(usingKTutorial) { + } + + virtual void setup() { + QWidget* mStepWidget = KTutorial::self()-> + findObject<view::StepWidget*>("ktutorial_StepWidget"); + //The filter is removed when the widget is deleted, that is, when the + //tutorial is closed. + mStepWidget->installEventFilter(this); + + mWaitForMousePressed = new WaitForSignal(this, + SIGNAL(mousePressedOnWidget())); + addWaitFor(mWaitForMousePressed, + mUsingKTutorial, SLOT(moveWidgetPressDone())); + } + + virtual void tearDown() { + removeWaitFor(mWaitForMousePressed); + delete mWaitForMousePressed; + } + + bool eventFilter(QObject* object, QEvent* event) { + Q_UNUSED(object); + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); + if (mouseEvent->button() == Qt::LeftButton) { + emit mousePressedOnWidget(); + } + } + + return false; + } + +Q_SIGNALS: + + void mousePressedOnWidget(); + +private: + + UsingKTutorial* mUsingKTutorial; + WaitFor* mWaitForMousePressed; + +}; + +class MoveWidgetReleaseStep: public Step { +Q_OBJECT +public: + + MoveWidgetReleaseStep(UsingKTutorial* usingKTutorial): + Step("moveWidgetRelease"), + mUsingKTutorial(usingKTutorial) { + } + + virtual void setup() { + QWidget* mStepWidget = KTutorial::self()-> + findObject<view::StepWidget*>("ktutorial_StepWidget"); + //The filter is removed when the widget is deleted, that is, when the + //tutorial is closed. + mStepWidget->installEventFilter(this); + + mWaitForMouseReleased = new WaitForSignal(this, + SIGNAL(mouseReleasedOnWidget())); + addWaitFor(mWaitForMouseReleased, + mUsingKTutorial, SLOT(moveWidgetReleaseDone())); + } + + virtual void tearDown() { + removeWaitFor(mWaitForMouseReleased); + delete mWaitForMouseReleased; + } + + bool eventFilter(QObject* object, QEvent* event) { + Q_UNUSED(object); + if (event->type() == QEvent::MouseButtonRelease) { + emit mouseReleasedOnWidget(); + } + + return false; + } + +Q_SIGNALS: + + void mouseReleasedOnWidget(); + +private: + + UsingKTutorial* mUsingKTutorial; + WaitFor* mWaitForMouseReleased; + +}; + +//public: + +UsingKTutorial::UsingKTutorial(): Tutorial(0) { + mTutorialInformation = new TutorialInformation("usingKTutorial"); + mTutorialInformation->setName(i18n("Using KTutorial")); + mTutorialInformation->setDescription(i18n("This tutorial shows how the " + "tutorial system works")); + + //Step start + Step* startStep = new Step("start"); + startStep->setText(i18nc("@info", +"<para>Welcome to the tutorial to learn how to use tutorials ;)</para>" +"<para>But, what is a tutorial? A tutorial is a little guide to help you to " +"learn how to use an application. For example, it shows you how some feature " +"works, or how to accomplish some task.</para>")); + + startStep->addOption(new Option(i18nc("@action", "Continue")), + this, SLOT(startDone())); + + addStep(startStep); + + //Step singleOption + Step* singleOptionStep = new Step("singleOption"); + singleOptionStep->setText(i18nc("@info", +"<para>A tutorial is composed of several steps, each one containing a bit of " +"information.</para>" +"<para>There are several ways to advance from one step to another. For " +"example, clicking on the button below will change to the next step.</para>")); + + singleOptionStep->addOption(new Option(i18nc("@action", "Continue")), + this, SLOT(singleOptionDone())); + + addStep(singleOptionStep); + + //Step severalOptions + Step* severalOptionsStep = new Step("severalOptions"); + severalOptionsStep->setText(i18nc("@info", +"<para>In other steps you may have more than one option to select. This can be " +"used, for example, to follow one path or another in the tutorial, skip some " +"part of the tutorial, etcetera. Which option do you prefer?</para>")); + + severalOptionsStep->addOption(new Option(i18nc("@action", "Option 1")), + this, SLOT(severalOptionsOption1Selected())); + severalOptionsStep->addOption(new Option(i18nc("@action", "Option 2")), + this, SLOT(severalOptionsOption2Selected())); + + addStep(severalOptionsStep); + + //Step option1Selected + Step* option1SelectedStep = new Step("option1Selected"); + option1SelectedStep->setText(i18nc("@info", +"<para>You have selected <emphasis>%1</emphasis>. Don't worry, as this is just " +"an example, selecting one option or the other makes no difference.</para>" +"<para>In the next step you will learn the last way to advance from one step " +"to another. To show this to you I will open a new window where text can be " +"written.</para>", i18nc("@action", "Option 1"))); + + option1SelectedStep->addOption(new Option(i18nc("@action", "Continue")), + this, SLOT(optionSelectedDone())); + + addStep(option1SelectedStep); + + //Step option2Selected + Step* option2SelectedStep = new Step("option2Selected"); + option2SelectedStep->setText(i18nc("@info", +"<para>You have selected <emphasis>%1</emphasis>. Don't worry, as this is just " +"an example, selecting one option or the other makes no difference.</para>" +"<para>In the next step you will learn the last way to advance from one step " +"to another. To show this to you I will open a new window where text can be " +"written.</para>", i18nc("@action", "Option 2"))); + + option2SelectedStep->addOption(new Option(i18nc("@action", "Continue")), + this, SLOT(optionSelectedDone())); + + addStep(option2SelectedStep); + + //Step clearText + Step* clearTextStep = new ClearTextStep(this); + clearTextStep->setText(i18nc("@info", +"<para>Do you see the new window that has appeared? Yes, the one that says " +"that it is a text area. Well, the last way to advance from one step to " +"another is just doing what you are asked for.</para>" +"<para>In this case, empty the text area erasing all its text and once you " +"have done it look again to the tutorial.</para>")); + + //WaitFor is added in step setup, as it has to create a QTextEdit when the + //step is activated + + addStep(clearTextStep); + + //Step closeTextEdit + Step* closeTextEditStep = new CloseTextEditStep(this); + 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 " +"options. The tutorial advanced automatically when you erased the text as " +"requested. This will be the most common way to advance from one step to " +"another.</para>" +"<para>Ok, close the window with the text area to continue with the " +"tutorial.</para>")); + + //WaitFor is added in step setup, as it uses an object that isn't available + //when the tutorial is created + + addStep(closeTextEditStep); + + //Step moveWidgetPress + Step* moveWidgetPressStep = new MoveWidgetPressStep(this); + 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 " +"like any other window, but pressing in a different place. Let's see " +"how.</para>" +"<para>Above these paragraphs you can see an empty space, next to the button " +"at the corner. Press with the left button of your mouse on it. Just press, " +"don't release the button yet.</para>")); + + //WaitFor is added in step setup, as it uses an object that isn't available + //when the tutorial is created + + addStep(moveWidgetPressStep); + + //Step moveWidgetRelease + Step* moveWidgetReleaseStep = new MoveWidgetReleaseStep(this); + 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 " +"place it was. Of course, you can move it again dragging it like you " +"have just done.</para>")); + + //WaitFor is added in step setup, as it uses an object that isn't available + //when the tutorial is created + + addStep(moveWidgetReleaseStep); + + //Step end + Step* endStep = new Step("end"); + endStep->setText(i18nc("@info", +"<para>And that's all. You can now close the tutorial. In fact, you could have " +"closed the tutorial in any other of the previous steps, but if you do that " +"when the tutorial is started again it won't remember what you did. It will " +"start from the beginning again.</para>" +"<para>But how do you close the tutorial? Well, do you see that button above " +"this text, in the corner, with an icon that looks like a close icon? Do you " +"guess what it does? ;) Just click on it and you will return to the tutorial " +"selection dialog. Bye!</para>")); + + addStep(endStep); +} + +//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"); + + if (textEdit->toPlainText().isEmpty()) { + nextStep("closeTextEdit"); + } +} + +void UsingKTutorial::closeTextEditDone() { + nextStep("moveWidgetPress"); +} + +void UsingKTutorial::moveWidgetPressDone() { + nextStep("moveWidgetRelease"); +} + +void UsingKTutorial::moveWidgetReleaseDone() { + nextStep("end"); +} + +#include "moc_UsingKTutorial.cpp" +#include "UsingKTutorial.moc" Property changes on: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h (rev 0) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h 2010-02-23 16:43:06 UTC (rev 94) @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef USINGKTUTORIAL_H +#define USINGKTUTORIAL_H + +#include "../Tutorial.h" + +class UsingKTutorial: public Tutorial { +Q_OBJECT +public: + + UsingKTutorial(); + +public Q_SLOTS: + + void startDone(); + + void singleOptionDone(); + + void severalOptionsOption1Selected(); + + void severalOptionsOption2Selected(); + + void optionSelectedDone(); + + void clearTextTextModified(); + + void closeTextEditDone(); + + void moveWidgetPressDone(); + + void moveWidgetReleaseDone(); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-23 16:20:20
|
Revision: 93 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=93&view=rev Author: danxuliu Date: 2010-02-23 16:20:14 +0000 (Tue, 23 Feb 2010) Log Message: ----------- Give a name to the tutorial selection dialog and the step widget objects. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/KTutorial.cpp Modified: trunk/ktutorial/ktutorial-library/src/KTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/KTutorial.cpp 2010-02-23 16:16:57 UTC (rev 92) +++ trunk/ktutorial/ktutorial-library/src/KTutorial.cpp 2010-02-23 16:20:14 UTC (rev 93) @@ -79,6 +79,7 @@ QDialog* dialog = new TutorialManagerDialog(mTutorialmanager, mParent); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setModal(true); + dialog->setObjectName("ktutorial_TutorialManagerDialog"); dialog->show(); } @@ -87,6 +88,7 @@ QString tutorialName = tutorial->tutorialInformation()->name(); StepWidget* stepWidget = new StepWidget(tutorialName, mParent); + stepWidget->setObjectName("ktutorial_StepWidget"); connect(tutorial, SIGNAL(stepActivated(Step*)), stepWidget, SLOT(setStep(Step*))); connect(stepWidget, SIGNAL(finished()), tutorial, SLOT(finish())); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-23 16:17:04
|
Revision: 92 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=92&view=rev Author: danxuliu Date: 2010-02-23 16:16:57 +0000 (Tue, 23 Feb 2010) Log Message: ----------- Fix base path to extract messages (it should have been modified when the directories were restructured). Modified Paths: -------------- trunk/ktutorial/ktutorial-library/po/Messages.sh trunk/ktutorial/ktutorial-test-app/po/Messages.sh Modified: trunk/ktutorial/ktutorial-library/po/Messages.sh =================================================================== --- trunk/ktutorial/ktutorial-library/po/Messages.sh 2010-02-23 06:28:13 UTC (rev 91) +++ trunk/ktutorial/ktutorial-library/po/Messages.sh 2010-02-23 16:16:57 UTC (rev 92) @@ -1,6 +1,6 @@ #!/bin/sh -BASEDIR="../../src/" # root of translatable sources +BASEDIR="../src/" # root of translatable sources PROJECT="ktutorial" # project name BUGADDR="http://sourceforge.net/tracker/?group_id=301227&atid=1270278" # MSGID-Bugs WDIR=`pwd` # working dir Modified: trunk/ktutorial/ktutorial-test-app/po/Messages.sh =================================================================== --- trunk/ktutorial/ktutorial-test-app/po/Messages.sh 2010-02-23 06:28:13 UTC (rev 91) +++ trunk/ktutorial/ktutorial-test-app/po/Messages.sh 2010-02-23 16:16:57 UTC (rev 92) @@ -1,6 +1,6 @@ #!/bin/sh -BASEDIR="../../test-app/" # root of translatable sources +BASEDIR="../" # root of translatable sources PROJECT="ktutorial-test-app" # project name BUGADDR="http://sourceforge.net/tracker/?group_id=301227&atid=1270278" # MSGID-Bugs WDIR=`pwd` # working dir This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-23 06:28:20
|
Revision: 91 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=91&view=rev Author: danxuliu Date: 2010-02-23 06:28:13 +0000 (Tue, 23 Feb 2010) Log Message: ----------- When a tutorial is finished the current step shouldn't be remembered. If remembered and the tutorial is started again, its tearDown method would be executed again when changing back to start step. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/Tutorial.cpp trunk/ktutorial/ktutorial-library/test/TutorialTest.cpp Modified: trunk/ktutorial/ktutorial-library/src/Tutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/Tutorial.cpp 2010-02-13 19:41:09 UTC (rev 90) +++ trunk/ktutorial/ktutorial-library/src/Tutorial.cpp 2010-02-23 06:28:13 UTC (rev 91) @@ -87,6 +87,7 @@ void Tutorial::finish() { if (mCurrentStep != 0) { mCurrentStep->setActive(false); + mCurrentStep = 0; } tearDown(); Modified: trunk/ktutorial/ktutorial-library/test/TutorialTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/test/TutorialTest.cpp 2010-02-13 19:41:09 UTC (rev 90) +++ trunk/ktutorial/ktutorial-library/test/TutorialTest.cpp 2010-02-23 06:28:13 UTC (rev 91) @@ -350,6 +350,7 @@ tutorial.start(); tutorial.finish(); + QCOMPARE(tutorial.mCurrentStep, (Step*)0); QVERIFY(!stepStart->isActive()); QCOMPARE(finishedSpy.count(), 1); QCOMPARE(tutorial.mTearDownCount, 1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-13 19:41:15
|
Revision: 90 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=90&view=rev Author: danxuliu Date: 2010-02-13 19:41:09 +0000 (Sat, 13 Feb 2010) Log Message: ----------- Fix testing with the new layout (generate CTestTestfile.cmake in the root project build directory, fix included directories in tests). Modified Paths: -------------- trunk/ktutorial/CMakeLists.txt trunk/ktutorial/ktutorial-library/test/CMakeLists.txt trunk/ktutorial/ktutorial-library/test/scripting/CMakeLists.txt trunk/ktutorial/ktutorial-library/test/view/CMakeLists.txt Modified: trunk/ktutorial/CMakeLists.txt =================================================================== --- trunk/ktutorial/CMakeLists.txt 2010-02-13 19:19:22 UTC (rev 89) +++ trunk/ktutorial/CMakeLists.txt 2010-02-13 19:41:09 UTC (rev 90) @@ -2,5 +2,7 @@ find_package(KDE4 REQUIRED) +enable_testing() + macro_optional_add_subdirectory(ktutorial-library) macro_optional_add_subdirectory(ktutorial-test-app) Modified: trunk/ktutorial/ktutorial-library/test/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/test/CMakeLists.txt 2010-02-13 19:19:22 UTC (rev 89) +++ trunk/ktutorial/ktutorial-library/test/CMakeLists.txt 2010-02-13 19:41:09 UTC (rev 90) @@ -4,7 +4,7 @@ # Used by kde4_add_unit_test to set the full path to test executables set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ktutorial_SOURCE_DIR}/src ${KDE4_INCLUDES}) +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ktutorial-library_SOURCE_DIR}/src ${KDE4_INCLUDES}) MACRO(UNIT_TESTS) FOREACH(_className ${ARGN}) Modified: trunk/ktutorial/ktutorial-library/test/scripting/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/test/scripting/CMakeLists.txt 2010-02-13 19:19:22 UTC (rev 89) +++ trunk/ktutorial/ktutorial-library/test/scripting/CMakeLists.txt 2010-02-13 19:41:09 UTC (rev 90) @@ -1,7 +1,7 @@ # Used by kde4_add_unit_test to set the full path to test executables set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ktutorial_SOURCE_DIR}/src/scripting ${KDE4_INCLUDES}) +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ktutorial-library_SOURCE_DIR}/src/scripting ${KDE4_INCLUDES}) MACRO(UNIT_TESTS) FOREACH(_className ${ARGN}) Modified: trunk/ktutorial/ktutorial-library/test/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/test/view/CMakeLists.txt 2010-02-13 19:19:22 UTC (rev 89) +++ trunk/ktutorial/ktutorial-library/test/view/CMakeLists.txt 2010-02-13 19:41:09 UTC (rev 90) @@ -1,7 +1,7 @@ # Used by kde4_add_unit_test to set the full path to test executables set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ktutorial_SOURCE_DIR}/src/view ${ktutorial_BINARY_DIR}/src/view ${KDE4_INCLUDES}) +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ktutorial-library_SOURCE_DIR}/src/view ${ktutorial-library_BINARY_DIR}/src/view ${KDE4_INCLUDES}) # Since Qt 4.6.0, this definition is needed for GUI testing. # It is backwards compatible with previous Qt versions, unlike the alternative This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-13 19:19:29
|
Revision: 89 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=89&view=rev Author: danxuliu Date: 2010-02-13 19:19:22 +0000 (Sat, 13 Feb 2010) Log Message: ----------- -Adjust CMakeLists.txt's to the new directory layout. -KTutorial test app can now be built without KTutorial library sources. However, in most cases the whole KTutorial project will be available, so KTutorial test app is built against a built but not installed yet KTutorial library. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/CMakeLists.txt trunk/ktutorial/ktutorial-library/src/CMakeLists.txt trunk/ktutorial/ktutorial-test-app/CMakeLists.txt trunk/ktutorial/ktutorial-test-app/TestApp.cpp trunk/ktutorial/ktutorial-test-app/TutorialClearText.cpp trunk/ktutorial/ktutorial-test-app/TutorialClearText.h trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h Added Paths: ----------- trunk/ktutorial/CMakeLists.txt Added: trunk/ktutorial/CMakeLists.txt =================================================================== --- trunk/ktutorial/CMakeLists.txt (rev 0) +++ trunk/ktutorial/CMakeLists.txt 2010-02-13 19:19:22 UTC (rev 89) @@ -0,0 +1,6 @@ +project(ktutorial) + +find_package(KDE4 REQUIRED) + +macro_optional_add_subdirectory(ktutorial-library) +macro_optional_add_subdirectory(ktutorial-test-app) Property changes on: trunk/ktutorial/CMakeLists.txt ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-library/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/CMakeLists.txt 2010-02-13 19:08:14 UTC (rev 88) +++ trunk/ktutorial/ktutorial-library/CMakeLists.txt 2010-02-13 19:19:22 UTC (rev 89) @@ -1,4 +1,4 @@ -project(ktutorial) +project(ktutorial-library) set(QT_MIN_VERSION "4.5.3") find_package(KDE4 REQUIRED) @@ -9,4 +9,3 @@ add_subdirectory(po) add_subdirectory(src) add_subdirectory(test) -add_subdirectory(test-app) Modified: trunk/ktutorial/ktutorial-library/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-13 19:08:14 UTC (rev 88) +++ trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-13 19:19:22 UTC (rev 89) @@ -50,6 +50,12 @@ WaitForSignal.h ) +# Hack to make headers available to other ktutorial modules (like +# ktutorial-test-app) when the library is built but not installed yet. +foreach(header ${ktutorial_LIB_HEADERS}) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${header} ${ktutorial-library_BINARY_DIR}/includes/ktutorial/${header} COPYONLY) +endforeach(header) + install(FILES ${ktutorial_LIB_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/ktutorial) install(FILES ktutorialui.rc DESTINATION ${DATA_INSTALL_DIR}/ktutorial) Modified: trunk/ktutorial/ktutorial-test-app/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-test-app/CMakeLists.txt 2010-02-13 19:08:14 UTC (rev 88) +++ trunk/ktutorial/ktutorial-test-app/CMakeLists.txt 2010-02-13 19:19:22 UTC (rev 89) @@ -1,5 +1,26 @@ -include_directories(${ktutorial_SOURCE_DIR}/src ${KDE4_INCLUDES}) +project(ktutorial-test-app) +find_package(KDE4 REQUIRED) +include_directories(${KDE4_INCLUDES}) + +add_subdirectory(po) + +# When KTutorial is built, the library isn't installed yet when the test-app is +# built. In that case, use the headers and libraries in the build directory +# of the library. +if(ktutorial-library_BINARY_DIR) + set(KTUTORIAL_FOUND TRUE) + include_directories(${ktutorial-library_BINARY_DIR}/includes) + set(KTUTORIAL_LIBRARIES ktutorial) +endif(ktutorial-library_BINARY_DIR) + +# If ktutorial-test-app is built in standalone mode, look for an installed +# KTutorial library. +if(NOT KTUTORIAL_FOUND) + find_package(KTutorial REQUIRED) + include_directories(${KTUTORIAL_INCLUDE_DIRS}) +endif(NOT KTUTORIAL_FOUND) + set(ktutorial_test_app_SRCS main.cpp TestApp.cpp @@ -9,7 +30,7 @@ kde4_add_executable(ktutorial-test-app ${ktutorial_test_app_SRCS}) -target_link_libraries(ktutorial-test-app ktutorial ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS}) +target_link_libraries(ktutorial-test-app ${KTUTORIAL_LIBRARIES} ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS}) ####### Install the test application ####### Modified: trunk/ktutorial/ktutorial-test-app/TestApp.cpp =================================================================== --- trunk/ktutorial/ktutorial-test-app/TestApp.cpp 2010-02-13 19:08:14 UTC (rev 88) +++ trunk/ktutorial/ktutorial-test-app/TestApp.cpp 2010-02-13 19:19:22 UTC (rev 89) @@ -27,7 +27,7 @@ #include <KSaveFile> #include <QTextStream> -#include "KTutorial.h" +#include <ktutorial/KTutorial.h> #include "TestApp.h" #include "TutorialClearText.h" Modified: trunk/ktutorial/ktutorial-test-app/TutorialClearText.cpp =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialClearText.cpp 2010-02-13 19:08:14 UTC (rev 88) +++ trunk/ktutorial/ktutorial-test-app/TutorialClearText.cpp 2010-02-13 19:19:22 UTC (rev 89) @@ -20,11 +20,12 @@ #include <ktextedit.h> #include "TutorialClearText.h" -#include "KTutorial.h" -#include "Step.h" -#include "TutorialInformation.h" -#include "WaitForSignal.h" +#include <ktutorial/KTutorial.h> +#include <ktutorial/Step.h> +#include <ktutorial/TutorialInformation.h> +#include <ktutorial/WaitForSignal.h> + //public: TutorialClearText::TutorialClearText(): Tutorial(0) { Modified: trunk/ktutorial/ktutorial-test-app/TutorialClearText.h =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialClearText.h 2010-02-13 19:08:14 UTC (rev 88) +++ trunk/ktutorial/ktutorial-test-app/TutorialClearText.h 2010-02-13 19:19:22 UTC (rev 89) @@ -19,7 +19,7 @@ #ifndef TUTORIALCLEARTEXT_H #define TUTORIALCLEARTEXT_H -#include "Tutorial.h" +#include <ktutorial/Tutorial.h> class TutorialClearText: public Tutorial { Q_OBJECT Modified: trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp 2010-02-13 19:08:14 UTC (rev 88) +++ trunk/ktutorial/ktutorial-test-app/TutorialMoveText.cpp 2010-02-13 19:19:22 UTC (rev 89) @@ -23,14 +23,15 @@ #include <ktextedit.h> #include "TutorialMoveText.h" -#include "KTutorial.h" -#include "Option.h" -#include "Step.h" -#include "TutorialInformation.h" -#include "WaitForAnd.h" -#include "WaitForNot.h" -#include "WaitForSignal.h" +#include <ktutorial/KTutorial.h> +#include <ktutorial/Option.h> +#include <ktutorial/Step.h> +#include <ktutorial/TutorialInformation.h> +#include <ktutorial/WaitForAnd.h> +#include <ktutorial/WaitForNot.h> +#include <ktutorial/WaitForSignal.h> + //public: TutorialMoveText::TutorialMoveText(): Tutorial(0) { Modified: trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h =================================================================== --- trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h 2010-02-13 19:08:14 UTC (rev 88) +++ trunk/ktutorial/ktutorial-test-app/TutorialMoveText.h 2010-02-13 19:19:22 UTC (rev 89) @@ -19,7 +19,7 @@ #ifndef TUTORIALMOVETEXT_H #define TUTORIALMOVETEXT_H -#include "Tutorial.h" +#include <ktutorial/Tutorial.h> class KTextEdit; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-02-13 19:08:21
|
Revision: 88 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=88&view=rev Author: danxuliu Date: 2010-02-13 19:08:14 +0000 (Sat, 13 Feb 2010) Log Message: ----------- Restructure directories: separate library and test-app (CMakeLists.txt's will be adapted in the next commit). Added Paths: ----------- trunk/ktutorial/ktutorial-library/ trunk/ktutorial/ktutorial-library/CMakeLists.txt trunk/ktutorial/ktutorial-library/cmake/ trunk/ktutorial/ktutorial-library/po/ trunk/ktutorial/ktutorial-library/src/ trunk/ktutorial/ktutorial-library/test/ trunk/ktutorial/ktutorial-test-app/ trunk/ktutorial/ktutorial-test-app/po/ Removed Paths: ------------- trunk/ktutorial/CMakeLists.txt trunk/ktutorial/cmake/ trunk/ktutorial/po/ trunk/ktutorial/src/ trunk/ktutorial/test/ trunk/ktutorial/test-app/ Deleted: trunk/ktutorial/CMakeLists.txt =================================================================== --- trunk/ktutorial/CMakeLists.txt 2010-02-10 18:29:49 UTC (rev 87) +++ trunk/ktutorial/CMakeLists.txt 2010-02-13 19:08:14 UTC (rev 88) @@ -1,12 +0,0 @@ -project(ktutorial) - -set(QT_MIN_VERSION "4.5.3") -find_package(KDE4 REQUIRED) - -enable_testing() - -add_subdirectory(cmake) -add_subdirectory(po) -add_subdirectory(src) -add_subdirectory(test) -add_subdirectory(test-app) Copied: trunk/ktutorial/ktutorial-library/CMakeLists.txt (from rev 87, trunk/ktutorial/CMakeLists.txt) =================================================================== --- trunk/ktutorial/ktutorial-library/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-library/CMakeLists.txt 2010-02-13 19:08:14 UTC (rev 88) @@ -0,0 +1,12 @@ +project(ktutorial) + +set(QT_MIN_VERSION "4.5.3") +find_package(KDE4 REQUIRED) + +enable_testing() + +add_subdirectory(cmake) +add_subdirectory(po) +add_subdirectory(src) +add_subdirectory(test) +add_subdirectory(test-app) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |