[Ktutorial-commits] SF.net SVN: ktutorial:[149] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-12 17:10:59
|
Revision: 149 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=149&view=rev Author: danxuliu Date: 2010-03-12 17:10:49 +0000 (Fri, 12 Mar 2010) Log Message: ----------- Add TreeItems to represents WaitFor subclasses. 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/WaitForComposedTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForComposedTreeItem.h trunk/ktutorial/ktutorial-editor/src/view/WaitForNotTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForNotTreeItem.h trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalTreeItem.h trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.h trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForComposedTreeItemTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForNotTreeItemTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForSignalTreeItemTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-12 17:05:56 UTC (rev 148) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-12 17:10:49 UTC (rev 149) @@ -16,6 +16,10 @@ TutorialInformationWidget.cpp TutorialTreeItem.cpp TutorialTreeSelectionManager.cpp + WaitForComposedTreeItem.cpp + WaitForNotTreeItem.cpp + WaitForSignalTreeItem.cpp + WaitForTreeItem.cpp ) kde4_add_ui_files(ktutorial_editor_view_SRCS Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForComposedTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForComposedTreeItem.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForComposedTreeItem.cpp 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,85 @@ +/*************************************************************************** + * 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 "WaitForComposedTreeItem.h" + +#include <KLocalizedString> + +#include "../WaitForComposed.h" + +//public: + +WaitForComposedTreeItem::WaitForComposedTreeItem( + WaitForComposed* waitForComposed, TreeItem* parent): + WaitForTreeItem(waitForComposed, parent) { + mCompositionType = waitForComposed->compositionType(); + + foreach (WaitFor* waitFor, waitForComposed->waitFors()) { + addWaitFor(waitFor); + } + + connect(waitForComposed, SIGNAL(dataChanged(WaitFor*)), + this, SLOT(update(WaitFor*))); + connect(waitForComposed, SIGNAL(waitForAdded(WaitFor*)), + this, SLOT(addWaitFor(WaitFor*))); + connect(waitForComposed, SIGNAL(waitForRemoved(WaitFor*)), + this, SLOT(removeWaitFor(WaitFor*))); +} + +QString WaitForComposedTreeItem::text() const { + if (mCompositionType == WaitForComposed::And) { + return i18nc("@item", "When all the contained conditions match"); + } + + return i18nc("@item", "When any of the contained conditions match"); +} + +//private: + +WaitForTreeItem* WaitForComposedTreeItem::treeItemForWaitFor(WaitFor* waitFor) { + foreach (WaitForTreeItem* waitForTreeItem, mWaitForTreeItems) { + if (waitForTreeItem->waitFor() == waitFor) { + return waitForTreeItem; + } + } + + return 0; +} + +//private slots: + +void WaitForComposedTreeItem::update(WaitFor* waitFor) { + mCompositionType = + static_cast<WaitForComposed*>(waitFor)->compositionType(); + + emit dataChanged(this); +} + +void WaitForComposedTreeItem::addWaitFor(WaitFor* waitFor) { + WaitForTreeItem* item = WaitForTreeItem::treeItemForWaitFor(waitFor, this); + appendChild(item); + mWaitForTreeItems.append(item); +} + +void WaitForComposedTreeItem::removeWaitFor(WaitFor* waitFor) { + WaitForTreeItem* item = treeItemForWaitFor(waitFor); + + removeChild(item); + mWaitForTreeItems.removeOne(item); + delete item; +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForComposedTreeItem.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForComposedTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForComposedTreeItem.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForComposedTreeItem.h 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,110 @@ +/*************************************************************************** + * 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 WAITFORCOMPOSEDTREEITEM_H +#define WAITFORCOMPOSEDTREEITEM_H + +#include "WaitForTreeItem.h" +#include "../WaitForComposed.h" + +/** + * A TreeItem that represents a WaitForComposed. + * The tree representation of a WaitForComposed is: + * TextThatDependsOnTheTypeOfWaitForComposed + * |-Representation of first WaitFor child + * |-Representation of second WaitFor child + * ... + * + * The text that depends on the type of the WaitForComposed is + * -"When all the contained conditions match" for And type + * -"When any of the contained conditions match" for Or type + * + * Whenever the WaitForComposed data changes, a child is added or a child is + * removed, the WaitForComposedTreeItem and its child items are updated as + * needed. + */ +class WaitForComposedTreeItem: public WaitForTreeItem { +Q_OBJECT +public: + + /** + * Creates a new WaitForComposedTreeItem for the given WaitForComposed and + * with the given parent. + * + * @param waitForComposed The WaitForComposed to represent. + * @param parent The parent TreeItem. + */ + explicit WaitForComposedTreeItem(WaitForComposed* waitForComposed, + TreeItem* parent = 0); + + /** + * Returns the appropriate text for the type of the WaitForComposed. + * + * @return The text for this TreeItem. + */ + virtual QString text() const; + +private: + + /** + * The composition type of the WaitForComposed. + */ + WaitForComposed::CompositionType mCompositionType; + + /** + * The WaitForTreeItem for each child of the WaitForComposed. + */ + QList<WaitForTreeItem*> mWaitForTreeItems; + + /** + * Returns the WaitForTreeItem for the given WaitFor. + * + * @param waitFor The WaitFor to get its WaitForTreeItem. + * @return The WaitForTreeItem. + */ + WaitForTreeItem* treeItemForWaitFor(WaitFor* waitFor); + +private Q_SLOTS: + + /** + * Updates this WaitForComposedTreeItem when the data of its WaitForComposed + * changed. + * + * @param waitFor The WaitForComposed. + */ + void update(WaitFor* waitFor); + + /** + * Adds a new WaitForTreeItem when a WaitFor is added to the + * WaitForComposed. + * + * @param waitFor The WaitFor added in the WaitForComposed. + */ + void addWaitFor(WaitFor* waitFor); + + /** + * Removes the WaitForTreeItem for the WaitFor removed from the + * WaitForComposed. + * + * @param waitFor The WaitFor removed from the WaitForComposed. + */ + void removeWaitFor(WaitFor* waitFor); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForComposedTreeItem.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForNotTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForNotTreeItem.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForNotTreeItem.cpp 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,59 @@ +/*************************************************************************** + * 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 "WaitForNotTreeItem.h" + +#include <KLocalizedString> + +#include "../WaitForNot.h" + +//public: + +WaitForNotTreeItem::WaitForNotTreeItem(WaitForNot* waitForNot, + TreeItem* parent): + WaitForTreeItem(waitForNot, parent), + mNegatedWaitForItem(0) { + + update(waitForNot); + + connect(waitForNot, SIGNAL(dataChanged(WaitFor*)), + this, SLOT(update(WaitFor*))); +} + +QString WaitForNotTreeItem::text() const { + return i18nc("@item", "The contained condition can't have been met"); +} + +//private slots: + +void WaitForNotTreeItem::update(WaitFor* waitFor) { + if (mNegatedWaitForItem) { + removeChild(mNegatedWaitForItem); + delete mNegatedWaitForItem; + mNegatedWaitForItem = 0; + } + + WaitForNot* waitForNot = static_cast<WaitForNot*>(waitFor); + WaitFor* negatedWaitFor = waitForNot->negatedWaitFor(); + if (negatedWaitFor) { + mNegatedWaitForItem = WaitForTreeItem::treeItemForWaitFor( + negatedWaitFor, this); + + appendChild(mNegatedWaitForItem); + } +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForNotTreeItem.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForNotTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForNotTreeItem.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForNotTreeItem.h 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,74 @@ +/*************************************************************************** + * 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 WAITFORNOTTREEITEM_H +#define WAITFORNOTTREEITEM_H + +#include "WaitForTreeItem.h" + +class WaitForNot; + +/** + * A TreeItem that represents a WaitForNot. + * The tree representation of a WaitForNot is: + * The contained condition can't have been met + * -Representation of the negated WaitFor + * + * Whenever another negated WaitFor is set, the child item of the + * WaitForNotTreeItem is updated as needed. + */ +class WaitForNotTreeItem: public WaitForTreeItem { +Q_OBJECT +public: + + /** + * Creates a new WaitForNotTreeItem for the given WaitForNot and with the + * given parent. + * + * @param waitForNot The WaitForNot to represent. + * @param parent The parent TreeItem. + */ + explicit WaitForNotTreeItem(WaitForNot* waitForNot, TreeItem* parent = 0); + + /** + * Returns "The contained condition can't have been met". + * + * @return The text for this TreeItem. + */ + virtual QString text() const; + +private: + + /** + * The representation of the negated WaitFor. + */ + WaitForTreeItem* mNegatedWaitForItem; + +private Q_SLOTS: + + /** + * Updates the child WaitForTreeItem when the negated WaitFor changes in the + * given WaitFor. + * + * @param waitFor The WaitForNot. + */ + void update(WaitFor* waitFor); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForNotTreeItem.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalTreeItem.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalTreeItem.cpp 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,64 @@ +/*************************************************************************** + * 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 "WaitForSignalTreeItem.h" + +#include <KLocalizedString> + +#include "../WaitForSignal.h" + +//public: + +WaitForSignalTreeItem::WaitForSignalTreeItem(WaitForSignal* waitForSignal, + TreeItem* parent): + WaitForTreeItem(waitForSignal, parent) { + mEmitterName = waitForSignal->emitterName(); + mSignalName = waitForSignal->signalName(); + + connect(waitForSignal, SIGNAL(dataChanged(WaitFor*)), + this, SLOT(update(WaitFor*))); +} + +QString WaitForSignalTreeItem::text() const { + QString emitterName; + if (mEmitterName.isEmpty()) { + emitterName = i18nc("@item", "(object not set)"); + } else { + emitterName = "\"" + mEmitterName + "\""; + } + + QString signalName; + if (mSignalName.isEmpty()) { + signalName = i18nc("@item", "(signal not set)"); + } else { + signalName = "\"" + mSignalName + "\""; + } + + return i18nc("@item", "When the signal %1 is emitted by object %2", + signalName, emitterName); +} + +//private: + +void WaitForSignalTreeItem::update(WaitFor* waitFor) { + WaitForSignal* waitForSignal = static_cast<WaitForSignal*>(waitFor); + mEmitterName = waitForSignal->emitterName(); + mSignalName = waitForSignal->signalName(); + + emit dataChanged(this); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalTreeItem.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalTreeItem.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalTreeItem.h 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,84 @@ +/*************************************************************************** + * 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 WAITFORSIGNALTREEITEM_H +#define WAITFORSIGNALTREEITEM_H + +#include "WaitForTreeItem.h" + +class WaitForSignal; + +/** + * A TreeItem that represents a WaitForSignal. + * The tree representation of a WaitForSignal is a plain text: + * When the signal "signal name" is emitted by the object "object name" + * + * If the signal or the emitter name aren't set yet, a placeholder is put + * instead. Signal placeholder is "(signal not set)", and the emitter name + * placeholder is "(object name not set)" (without quotes, but with + * parenthesis). + * + * Whenever the WaitForSignal data changes, the WaitForSignalTreeItem text is + * updated as needed. + */ +class WaitForSignalTreeItem: public WaitForTreeItem { +Q_OBJECT +public: + + /** + * Creates a new WaitForSignalTreeItem for the given WaitForSignal and with + * the given parent. + * + * @param waitForSignal The WaitForSignal to represent. + * @param parent The parent TreeItem. + */ + explicit WaitForSignalTreeItem(WaitForSignal* waitForSignal, + TreeItem* parent = 0); + + /** + * Returns the description of the WaitForSignal. + * + * @return The text for this TreeItem. + */ + virtual QString text() const; + +private: + + /** + * The emitter name of the WaitForSignal. + */ + QString mEmitterName; + + /** + * The signal name of the WaitForSignal. + */ + QString mSignalName; + +private Q_SLOTS: + + /** + * Updates this WaitForSignalTreeItem when the data of its WaitForSignal + * changed. + * + * @param waitFor The WaitForSignal. + */ + void update(WaitFor* waitFor); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalTreeItem.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,57 @@ +/*************************************************************************** + * 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 "WaitForTreeItem.h" +#include "WaitForComposedTreeItem.h" +#include "WaitForNotTreeItem.h" +#include "WaitForSignalTreeItem.h" +#include "../WaitForComposed.h" +#include "../WaitForNot.h" +#include "../WaitForSignal.h" + +//public: + +WaitForTreeItem* WaitForTreeItem::treeItemForWaitFor(WaitFor* waitFor, + TreeItem* parent) { + if (qobject_cast<WaitForComposed*>(waitFor)) { + return new WaitForComposedTreeItem( + static_cast<WaitForComposed*>(waitFor), parent); + } + + if (qobject_cast<WaitForNot*>(waitFor)) { + return new WaitForNotTreeItem(static_cast<WaitForNot*>(waitFor), + parent); + } + + if (qobject_cast<WaitForSignal*>(waitFor)) { + return new WaitForSignalTreeItem(static_cast<WaitForSignal*>(waitFor), + parent); + } + + Q_ASSERT(false); + return 0; +} + +WaitForTreeItem::WaitForTreeItem(WaitFor* waitFor, TreeItem* parent): + TreeItem(parent), + mWaitFor(waitFor) { +} + +WaitFor* WaitForTreeItem::waitFor() const { + return mWaitFor; +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.h 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,73 @@ +/*************************************************************************** + * 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 WAITFORTREEITEM_H +#define WAITFORTREEITEM_H + +#include "TreeItem.h" + +class WaitFor; + +/** + * Abstract base class for TreeItems that represent WaitFors. + * It provides a static method, treeItemForWaitFor(WaitFor*), to create a new + * WaitForTreeItem subclass object suitable for the given WaitFor. + * + * Subclasses must provide the full representation of its WaitFor, implementing + * text() method and adding the necessary child tree items. + */ +class WaitForTreeItem: public TreeItem { +Q_OBJECT +public: + + /** + * Returns a new TreeItem that represents the given WaitFor. + * + * @param waitFor The WaitFor to create its representation. + * @param parent The parent TreeItem. + * @return The new WaitForTreeItem to represent the given WaitFor. + */ + static WaitForTreeItem* treeItemForWaitFor(WaitFor* waitFor, + TreeItem* parent); + + /** + * Creates a new WaitForTreeItem for the given WaitFor and with the given + * parent. + * + * @param waitFor The WaitFor to represent. + * @param parent The parent TreeItem. + */ + explicit WaitForTreeItem(WaitFor* waitFor, TreeItem* parent = 0); + + /** + * Returns the WaitFor. + * + * @return The WaitFor. + */ + WaitFor* waitFor() const; + +private: + + /** + * The WaitFor. + */ + WaitFor* mWaitFor; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.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-12 17:05:56 UTC (rev 148) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-12 17:10:49 UTC (rev 149) @@ -31,6 +31,10 @@ TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager + WaitForComposedTreeItem + WaitForNotTreeItem + WaitForSignalTreeItem + WaitForTreeItem ) MACRO(MEM_TESTS) @@ -54,4 +58,8 @@ TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager + WaitForComposedTreeItem + WaitForNotTreeItem + WaitForSignalTreeItem + WaitForTreeItem ) Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForComposedTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForComposedTreeItemTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForComposedTreeItemTest.cpp 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,212 @@ +/*************************************************************************** + * 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 "WaitForComposedTreeItem.h" + +#include <KLocalizedString> + +#include "WaitForSignalTreeItem.h" +#include "../WaitForComposed.h" +#include "../WaitForSignal.h" + +class WaitForComposedTreeItemTest: public QObject { +Q_OBJECT + +private slots: + + void initTestCase(); + + void testConstructor(); + void testConstructorFull(); + + void testWaitForComposedSetAndType(); + void testWaitForComposedSetOrType(); + void testWaitForComposedSetTypeChange(); + + void testWaitForAddWaitFor(); + + void testWaitForRemoveWaitFor(); + +private: + + int mTreeItemStarType; + + void assertSignalItem(TreeItem* item, WaitForSignal* waitForSignal) const; + + void assertDataChanged(const QSignalSpy& spy, int index, + TreeItem* item) const; + +}; + +class StubTreeItem: public TreeItem { +public: + virtual QString text() const { + return ""; + } +}; + +void WaitForComposedTreeItemTest::initTestCase() { + //TreeItem* must be registered in order to be used with QSignalSpy + mTreeItemStarType = qRegisterMetaType<TreeItem*>("TreeItem*"); +} + +void WaitForComposedTreeItemTest::testConstructor() { + WaitForComposed waitForComposed; + + StubTreeItem parent; + WaitForComposedTreeItem item(&waitForComposed, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.waitFor(), &waitForComposed); + QCOMPARE(item.childCount(), 0); +} + +void WaitForComposedTreeItemTest::testConstructorFull() { + WaitForComposed waitForComposed; + + WaitForSignal* waitFor1 = new WaitForSignal(); + waitForComposed.addWaitFor(waitFor1); + + WaitForSignal* waitFor2 = new WaitForSignal(); + waitForComposed.addWaitFor(waitFor2); + + WaitForSignal* waitFor3 = new WaitForSignal(); + waitForComposed.addWaitFor(waitFor3); + + StubTreeItem parent; + WaitForComposedTreeItem item(&waitForComposed, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.waitFor(), &waitForComposed); + QCOMPARE(item.childCount(), 3); + assertSignalItem(item.child(0), waitFor1); + assertSignalItem(item.child(1), waitFor2); + assertSignalItem(item.child(2), waitFor3); +} + +void WaitForComposedTreeItemTest::testWaitForComposedSetAndType() { + WaitForComposed waitForComposed; + waitForComposed.setCompositionType(WaitForComposed::And); + + WaitForComposedTreeItem item(&waitForComposed); + + QCOMPARE(item.text(), i18nc("@item", + "When all the contained conditions match")); + QCOMPARE(item.childCount(), 0); +} + +void WaitForComposedTreeItemTest::testWaitForComposedSetOrType() { + WaitForComposed waitForComposed; + waitForComposed.setCompositionType(WaitForComposed::Or); + + WaitForComposedTreeItem item(&waitForComposed); + + QCOMPARE(item.text(), i18nc("@item", + "When any of the contained conditions match")); + QCOMPARE(item.childCount(), 0); +} + +void WaitForComposedTreeItemTest::testWaitForComposedSetTypeChange() { + WaitForComposed waitForComposed; + waitForComposed.setCompositionType(WaitForComposed::And); + + WaitForComposedTreeItem item(&waitForComposed); + + QSignalSpy dataChangedSpy(&item, SIGNAL(dataChanged(TreeItem*))); + + waitForComposed.setCompositionType(WaitForComposed::Or); + + QCOMPARE(item.text(), i18nc("@item", + "When any of the contained conditions match")); + QCOMPARE(item.childCount(), 0); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, &item); +} + +void WaitForComposedTreeItemTest::testWaitForAddWaitFor() { + WaitForComposed waitForComposed; + WaitForSignal* waitFor1 = new WaitForSignal(); + WaitForSignal* waitFor2 = new WaitForSignal(); + WaitForSignal* waitFor3 = new WaitForSignal(); + + WaitForComposedTreeItem item(&waitForComposed); + + waitForComposed.addWaitFor(waitFor1); + waitForComposed.addWaitFor(waitFor2); + waitForComposed.addWaitFor(waitFor3); + + QCOMPARE(item.childCount(), 3); + assertSignalItem(item.child(0), waitFor1); + assertSignalItem(item.child(1), waitFor2); + assertSignalItem(item.child(2), waitFor3); +} + +void WaitForComposedTreeItemTest::testWaitForRemoveWaitFor() { + WaitForComposed waitForComposed; + + //They will be removed and not deleted by the WaitForComposed, so they are + //created in stack + WaitForSignal waitFor1; + WaitForSignal waitFor2; + WaitForSignal waitFor3; + + WaitForComposedTreeItem item(&waitForComposed); + + waitForComposed.addWaitFor(&waitFor1); + waitForComposed.addWaitFor(&waitFor2); + waitForComposed.addWaitFor(&waitFor3); + + waitForComposed.removeWaitFor(&waitFor2); + + QCOMPARE(item.childCount(), 2); + assertSignalItem(item.child(0), &waitFor1); + assertSignalItem(item.child(1), &waitFor3); + + waitForComposed.removeWaitFor(&waitFor1); + waitForComposed.removeWaitFor(&waitFor3); + + QCOMPARE(item.childCount(), 0); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +void WaitForComposedTreeItemTest::assertSignalItem(TreeItem* item, + WaitForSignal* waitForSignal) const { + QVERIFY(qobject_cast<WaitForSignalTreeItem*>(item)); + QCOMPARE(static_cast<WaitForSignalTreeItem*>(item)->waitFor(), + waitForSignal); +} + +//TreeItem* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(TreeItem*); + +void WaitForComposedTreeItemTest::assertDataChanged(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(WaitForComposedTreeItemTest) + +#include "WaitForComposedTreeItemTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForComposedTreeItemTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForNotTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForNotTreeItemTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForNotTreeItemTest.cpp 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,134 @@ +/*************************************************************************** + * 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 "WaitForNotTreeItem.h" + +#include <KLocalizedString> + +#include "WaitForSignalTreeItem.h" +#include "../WaitForNot.h" +#include "../WaitForSignal.h" + +class WaitForNotTreeItemTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + void testConstructorFull(); + + void testWaitForNotSetNegatedWaitFor(); + void testWaitForNotSetNegatedWaitForChange(); + void testWaitForNotSetNegatedWaitForEmpty(); + +private: + + void assertSignalItem(TreeItem* item, WaitForSignal* waitForSignal) const; + +}; + +class StubTreeItem: public TreeItem { +public: + virtual QString text() const { + return ""; + } +}; + +void WaitForNotTreeItemTest::testConstructor() { + WaitForNot waitForNot; + + StubTreeItem parent; + WaitForNotTreeItem item(&waitForNot, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.waitFor(), &waitForNot); + QCOMPARE(item.text(), + i18nc("@item", "The contained condition can't have been met")); + QCOMPARE(item.childCount(), 0); +} + +void WaitForNotTreeItemTest::testConstructorFull() { + WaitForNot waitForNot; + WaitForSignal* waitForSignal = new WaitForSignal(); + waitForNot.setNegatedWaitFor(waitForSignal); + + StubTreeItem parent; + WaitForNotTreeItem item(&waitForNot, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.waitFor(), &waitForNot); + QCOMPARE(item.text(), + i18nc("@item", "The contained condition can't have been met")); + QCOMPARE(item.childCount(), 1); + assertSignalItem(item.child(0), waitForSignal); +} + +void WaitForNotTreeItemTest::testWaitForNotSetNegatedWaitFor() { + WaitForNot waitForNot; + WaitForSignal* waitForSignal = new WaitForSignal(); + WaitForNotTreeItem item(&waitForNot); + + waitForNot.setNegatedWaitFor(waitForSignal); + + QCOMPARE(item.childCount(), 1); + assertSignalItem(item.child(0), waitForSignal); +} + +void WaitForNotTreeItemTest::testWaitForNotSetNegatedWaitForChange() { + WaitForNot waitForNot; + //It will be removed and not deleted by the WaitForNot, so it is created in + //stack + WaitForSignal waitForSignal1; + WaitForNotTreeItem item(&waitForNot); + + waitForNot.setNegatedWaitFor(&waitForSignal1); + + WaitForSignal* waitForSignal2 = new WaitForSignal(); + waitForNot.setNegatedWaitFor(waitForSignal2); + + QCOMPARE(item.childCount(), 1); + assertSignalItem(item.child(0), waitForSignal2); +} + +void WaitForNotTreeItemTest::testWaitForNotSetNegatedWaitForEmpty() { + WaitForNot waitForNot; + //It will be removed and not deleted by the WaitForNot, so it is created in + //stack + WaitForSignal waitForSignal; + WaitForNotTreeItem item(&waitForNot); + + waitForNot.setNegatedWaitFor(&waitForSignal); + waitForNot.setNegatedWaitFor(0); + + QCOMPARE(item.childCount(), 0); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +void WaitForNotTreeItemTest::assertSignalItem(TreeItem* item, + WaitForSignal* waitForSignal) const { + QVERIFY(qobject_cast<WaitForSignalTreeItem*>(item)); + QCOMPARE(static_cast<WaitForSignalTreeItem*>(item)->waitFor(), + waitForSignal); +} + +QTEST_MAIN(WaitForNotTreeItemTest) + +#include "WaitForNotTreeItemTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForNotTreeItemTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForSignalTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForSignalTreeItemTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForSignalTreeItemTest.cpp 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,161 @@ +/*************************************************************************** + * 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 "WaitForSignalTreeItem.h" + +#include <KLocalizedString> + +#include "../WaitForSignal.h" + +class WaitForSignalTreeItemTest: public QObject { +Q_OBJECT + +private slots: + + void initTestCase(); + + void testConstructor(); + void testConstructorFull(); + + void testWaitForSignalSetEmitterName(); + void testWaitForSignalSetEmitterNameChange(); + + void testWaitForSignalSetSignalName(); + void testWaitForSignalSetSignalNameChange(); + +private: + + int mTreeItemStarType; + + void assertDataChanged(const QSignalSpy& spy, int index, + TreeItem* item) const; + +}; + +class StubTreeItem: public TreeItem { +public: + virtual QString text() const { + return ""; + } +}; + +void WaitForSignalTreeItemTest::initTestCase() { + //TreeItem* must be registered in order to be used with QSignalSpy + mTreeItemStarType = qRegisterMetaType<TreeItem*>("TreeItem*"); +} + +void WaitForSignalTreeItemTest::testConstructor() { + WaitForSignal waitForSignal; + + StubTreeItem parent; + WaitForSignalTreeItem item(&waitForSignal, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.waitFor(), &waitForSignal); + QCOMPARE(item.text(), i18nc("@item", "When the signal (signal not set) is " + "emitted by object (object not set)")); +} + +void WaitForSignalTreeItemTest::testConstructorFull() { + WaitForSignal waitForSignal; + waitForSignal.setEmitterName("emitterName"); + waitForSignal.setSignalName("signalName"); + + StubTreeItem parent; + WaitForSignalTreeItem item(&waitForSignal, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.waitFor(), &waitForSignal); + QCOMPARE(item.text(), i18nc("@item", "When the signal \"signalName\" is " + "emitted by object \"emitterName\"")); +} + +void WaitForSignalTreeItemTest::testWaitForSignalSetEmitterName() { + WaitForSignal waitForSignal; + waitForSignal.setEmitterName("emitterName"); + + WaitForSignalTreeItem item(&waitForSignal); + + QCOMPARE(item.text(), i18nc("@item", "When the signal (signal not set) is " + "emitted by object \"emitterName\"")); +} + +void WaitForSignalTreeItemTest::testWaitForSignalSetEmitterNameChange() { + WaitForSignal waitForSignal; + WaitForSignalTreeItem item(&waitForSignal); + + waitForSignal.setEmitterName("emitterName"); + + QSignalSpy dataChangedSpy(&item, SIGNAL(dataChanged(TreeItem*))); + + waitForSignal.setEmitterName("emitterNameChanged"); + + QCOMPARE(item.text(), i18nc("@item", "When the signal (signal not set) is " + "emitted by object " + "\"emitterNameChanged\"")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, &item); +} + +void WaitForSignalTreeItemTest::testWaitForSignalSetSignalName() { + WaitForSignal waitForSignal; + waitForSignal.setSignalName("signalName"); + + WaitForSignalTreeItem item(&waitForSignal); + + QCOMPARE(item.text(), i18nc("@item", "When the signal \"signalName\" is " + "emitted by object (object not set)")); +} + +void WaitForSignalTreeItemTest::testWaitForSignalSetSignalNameChange() { + WaitForSignal waitForSignal; + WaitForSignalTreeItem item(&waitForSignal); + + waitForSignal.setSignalName("signalName"); + + QSignalSpy dataChangedSpy(&item, SIGNAL(dataChanged(TreeItem*))); + + waitForSignal.setSignalName("signalNameChanged"); + + QCOMPARE(item.text(), i18nc("@item", "When the signal " + "\"signalNameChanged\" is emitted by " + "object (object not set)")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, &item); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +//TreeItem* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(TreeItem*); + +void WaitForSignalTreeItemTest::assertDataChanged(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(WaitForSignalTreeItemTest) + +#include "WaitForSignalTreeItemTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForSignalTreeItemTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp 2010-03-12 17:10:49 UTC (rev 149) @@ -0,0 +1,123 @@ +/*************************************************************************** + * 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 "WaitForTreeItem.h" + +#include "WaitForComposedTreeItem.h" +#include "WaitForNotTreeItem.h" +#include "WaitForSignalTreeItem.h" +#include "../WaitFor.h" +#include "../WaitForComposed.h" +#include "../WaitForNot.h" +#include "../WaitForSignal.h" + +class WaitForTreeItemTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testTreeItemForWaitForComposed(); + void testTreeItemForWaitForNot(); + void testTreeItemForWaitForSignal(); + +}; + +class StubTreeItem: public TreeItem { +public: + virtual QString text() const { + return ""; + } +}; + +class StubWaitForTreeItem: public WaitForTreeItem { +public: + StubWaitForTreeItem(WaitFor* waitFor, TreeItem* parent = 0): + WaitForTreeItem(waitFor, parent) { + } + + virtual QString text() const { + return ""; + } +}; + +class StubWaitFor: public WaitFor { +public: + StubWaitFor(QObject* parent = 0): WaitFor(parent) { + } +}; + +void WaitForTreeItemTest::testConstructor() { + StubWaitFor waitFor; + + StubTreeItem parent; + StubWaitForTreeItem item(&waitFor, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.waitFor(), &waitFor); + QCOMPARE(item.childCount(), 0); +} + +void WaitForTreeItemTest::testTreeItemForWaitForComposed() { + WaitForComposed waitFor; + StubTreeItem parent; + + WaitForTreeItem* item = WaitForTreeItem::treeItemForWaitFor(&waitFor, + &parent); + + QVERIFY(qobject_cast<WaitForComposedTreeItem*>(item)); + QCOMPARE(item->parent(), &parent); + QCOMPARE(item->waitFor(), &waitFor); + + delete item; +} + +void WaitForTreeItemTest::testTreeItemForWaitForNot() { + WaitForNot waitFor; + StubTreeItem parent; + + WaitForTreeItem* item = WaitForTreeItem::treeItemForWaitFor(&waitFor, + &parent); + + QVERIFY(qobject_cast<WaitForNotTreeItem*>(item)); + QCOMPARE(item->parent(), &parent); + QCOMPARE(item->waitFor(), &waitFor); + + delete item; +} + +void WaitForTreeItemTest::testTreeItemForWaitForSignal() { + WaitForSignal waitFor; + StubTreeItem parent; + + WaitForTreeItem* item = WaitForTreeItem::treeItemForWaitFor(&waitFor, + &parent); + + QVERIFY(qobject_cast<WaitForSignalTreeItem*>(item)); + QCOMPARE(item->parent(), &parent); + QCOMPARE(item->waitFor(), &waitFor); + + delete item; +} + +QTEST_MAIN(WaitForTreeItemTest) + +#include "WaitForTreeItemTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |