ktutorial-commits Mailing List for KTutorial (Page 10)
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-16 05:43:03
|
Revision: 162 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=162&view=rev Author: danxuliu Date: 2010-03-16 05:42:56 +0000 (Tue, 16 Mar 2010) Log Message: ----------- Add WaitForEvent to store the data of conditions to wait for events. The classes and changes needed to make them work at application level are also included. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/WaitForEvent.cpp trunk/ktutorial/ktutorial-editor/src/WaitForEvent.h trunk/ktutorial/ktutorial-editor/src/view/WaitForEventTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForEventTreeItem.h trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.h trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.ui trunk/ktutorial/ktutorial-editor/tests/unit/WaitForEventTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventTreeItemTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-16 03:00:35 UTC (rev 161) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-16 05:42:56 UTC (rev 162) @@ -13,6 +13,7 @@ Tutorial.cpp WaitFor.cpp WaitForComposed.cpp + WaitForEvent.cpp WaitForNot.cpp WaitForSignal.cpp ) Added: trunk/ktutorial/ktutorial-editor/src/WaitForEvent.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForEvent.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForEvent.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -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 "WaitForEvent.h" + +//public: + +WaitForEvent::WaitForEvent(QObject* parent): WaitFor(parent) { +} + +WaitFor* WaitForEvent::clone() const { + WaitForEvent* cloned = new WaitForEvent(); + cloned->setReceiverName(mReceiverName); + cloned->setEventName(mEventName); + + return cloned; +} + +bool WaitForEvent::equals(const WaitFor& waitFor) const { + if (!qobject_cast<const WaitForEvent*>(&waitFor)) { + return false; + } + + const WaitForEvent* waitForEvent = + static_cast<const WaitForEvent*>(&waitFor); + if (waitForEvent->receiverName() != mReceiverName) { + return false; + } + + if (waitForEvent->eventName() != mEventName) { + return false; + } + + return true; +} + +QString WaitForEvent::receiverName() const { + return mReceiverName; +} + +void WaitForEvent::setReceiverName(const QString& receiverName) { + mReceiverName = receiverName; + + emit dataChanged(this); +} + +QString WaitForEvent::eventName() const { + return mEventName; +} + +void WaitForEvent::setEventName(const QString& eventName) { + mEventName = eventName; + + emit dataChanged(this); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForEvent.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForEvent.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForEvent.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForEvent.h 2010-03-16 05:42:56 UTC (rev 162) @@ -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 WAITFOREVENT_H +#define WAITFOREVENT_H + +#include "WaitFor.h" + +/** + * Container for conditions that wait for an event to be received data. + * It stores the data used in KTutorial WaitForEvent, but it has nothing to do + * with it (they don't even know each other). Its purpose is store the data + * needed to generate the code to initialize a true KTutorial::WaitForEvent + * object. + * + * When any attribute is modified, dataChanged(WaitFor*) signal is emitted. + */ +class WaitForEvent: public WaitFor { +Q_OBJECT +public: + + /** + * Creates a new WaitForEvent. + * + * @param parent The parent QObject. + */ + WaitForEvent(QObject* parent = 0); + + virtual WaitFor* clone() const; + virtual bool equals(const WaitFor& waitFor) const; + + QString receiverName() const; + void setReceiverName(const QString& receiverName); + + QString eventName() const; + void setEventName(const QString& eventName); + +private: + + QString mReceiverName; + QString mEventName; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForEvent.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-16 03:00:35 UTC (rev 161) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-16 05:42:56 UTC (rev 162) @@ -20,6 +20,8 @@ TutorialTreeItem.cpp TutorialTreeSelectionManager.cpp WaitForComposedTreeItem.cpp + WaitForEventTreeItem.cpp + WaitForEventWidget.cpp WaitForNotTreeItem.cpp WaitForSignalTreeItem.cpp WaitForSignalWidget.cpp @@ -34,6 +36,7 @@ ReactionWidget.ui StepDataWidget.ui TutorialInformationWidget.ui + WaitForEventWidget.ui WaitForSignalWidget.ui WaitForWidget.ui ) Modified: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp 2010-03-16 03:00:35 UTC (rev 161) +++ trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -20,6 +20,7 @@ #include "ui_NewWaitForWidget.h" #include "../WaitForComposed.h" +#include "../WaitForEvent.h" #include "../WaitForNot.h" #include "../WaitForSignal.h" @@ -49,6 +50,8 @@ return new WaitForNot(); } else if (index == 3) { return new WaitForSignal(); + } else if (index == 4) { + return new WaitForEvent(); } return 0; Modified: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui 2010-03-16 03:00:35 UTC (rev 161) +++ trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui 2010-03-16 05:42:56 UTC (rev 162) @@ -61,6 +61,11 @@ <string comment="@item:inlistbox">The specified signal is emitted</string> </property> </item> + <item> + <property name="text"> + <string comment="@item:inlistbox">The specified event is received</string> + </property> + </item> </widget> </item> </layout> Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForEventTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForEventTreeItem.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForEventTreeItem.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -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 "WaitForEventTreeItem.h" + +#include <KLocalizedString> + +#include "../WaitForEvent.h" + +//public: + +WaitForEventTreeItem::WaitForEventTreeItem(WaitForEvent* waitForEvent, + TreeItem* parent): + WaitForTreeItem(waitForEvent, parent) { + mReceiverName = waitForEvent->receiverName(); + mEventName = waitForEvent->eventName(); + + connect(waitForEvent, SIGNAL(dataChanged(WaitFor*)), + this, SLOT(update(WaitFor*))); +} + +QString WaitForEventTreeItem::text() const { + QString receiverName; + if (mReceiverName.isEmpty()) { + receiverName = i18nc("@item", "(object not set)"); + } else { + receiverName = "\"" + mReceiverName + "\""; + } + + QString eventName; + if (mEventName.isEmpty()) { + eventName = i18nc("@item", "(event not set)"); + } else { + eventName = "\"" + mEventName + "\""; + } + + return i18nc("@item", "When the event %1 is received by object %2", + eventName, receiverName); +} + +//private: + +void WaitForEventTreeItem::update(WaitFor* waitFor) { + WaitForEvent* waitForEvent = static_cast<WaitForEvent*>(waitFor); + mReceiverName = waitForEvent->receiverName(); + mEventName = waitForEvent->eventName(); + + emit dataChanged(this); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForEventTreeItem.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForEventTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForEventTreeItem.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForEventTreeItem.h 2010-03-16 05:42:56 UTC (rev 162) @@ -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 WAITFOREVENTTREEITEM_H +#define WAITFOREVENTTREEITEM_H + +#include "WaitForTreeItem.h" + +class WaitForEvent; + +/** + * A TreeItem that represents a WaitForEvent. + * The tree representation of a WaitForEvent is a plain text: + * When the event "event name" is received by the object "object name" + * + * If the event or the receiver name aren't set yet, a placeholder is put + * instead. Event placeholder is "(event not set)", and the receiver name + * placeholder is "(object name not set)" (without quotes, but with + * parenthesis). + * + * Whenever the WaitForEvent data changes, the WaitForEventTreeItem text is + * updated as needed. + */ +class WaitForEventTreeItem: public WaitForTreeItem { +Q_OBJECT +public: + + /** + * Creates a new WaitForEventTreeItem for the given WaitForEvent and with + * the given parent. + * + * @param waitForEvent The WaitForEvent to represent. + * @param parent The parent TreeItem. + */ + explicit WaitForEventTreeItem(WaitForEvent* waitForEvent, + TreeItem* parent = 0); + + /** + * Returns the description of the WaitForEvent. + * + * @return The text for this TreeItem. + */ + virtual QString text() const; + +private: + + /** + * The receiver name of the WaitForEvent. + */ + QString mReceiverName; + + /** + * The event name of the WaitForEvent. + */ + QString mEventName; + +private Q_SLOTS: + + /** + * Updates this WaitForEventTreeItem when the data of its WaitForEvent + * changed. + * + * @param waitFor The WaitForEvent. + */ + void update(WaitFor* waitFor); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForEventTreeItem.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -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/>. * + ***************************************************************************/ + +#include "WaitForEventWidget.h" + +#include "ui_WaitForEventWidget.h" +#include "../WaitForEvent.h" + +//public: + +WaitForEventWidget::WaitForEventWidget(WaitForEvent* waitForEvent, + QWidget* parent): + EditionWidget(parent), + mWaitForEvent(waitForEvent) { + + ui = new Ui::WaitForEventWidget(); + ui->setupUi(this); + + ui->receiverNameLineEdit->setText(waitForEvent->receiverName()); + ui->eventNameLineEdit->setText(waitForEvent->eventName()); +} + +WaitForEventWidget::~WaitForEventWidget() { + delete ui; +} + +void WaitForEventWidget::saveChanges() { + QString receiverName = ui->receiverNameLineEdit->text(); + if (mWaitForEvent->receiverName() != receiverName) { + mWaitForEvent->setReceiverName(receiverName); + } + + QString eventName = ui->eventNameLineEdit->text(); + if (mWaitForEvent->eventName() != eventName) { + mWaitForEvent->setEventName(eventName); + } +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.h 2010-03-16 05:42:56 UTC (rev 162) @@ -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/>. * + ***************************************************************************/ + +#ifndef WAITFOREVENTWIDGET_H +#define WAITFOREVENTWIDGET_H + +#include "EditionWidget.h" + +class WaitForEvent; + +namespace Ui { +class WaitForEventWidget; +} + +/** + * Edition widget for the condition to wait for an event. + */ +class WaitForEventWidget: public EditionWidget { +Q_OBJECT +public: + + /** + * Creates a new WaitForEventWidget for the given WaitForEvent. + * + * @param waitForEvent The WaitForEvent to set its data. + * @param parent The parent QWidget. + */ + explicit WaitForEventWidget(WaitForEvent* waitForEvent, + QWidget* parent = 0); + + /** + * Destroys this widget. + */ + virtual ~WaitForEventWidget(); + + /** + * Saves the receiver name and the event name in the WaitForEvent. + */ + virtual void saveChanges(); + +private: + + /** + * The WaitForEvent to edit. + */ + WaitForEvent* mWaitForEvent; + + /** + * The Ui Designer generated class. + */ + Ui::WaitForEventWidget* ui; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.ui (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.ui 2010-03-16 05:42:56 UTC (rev 162) @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>WaitForEventWidget</class> + <widget class="QWidget" name="WaitForEventWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string comment="@title">Edit event to wait for</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>Set the receiver name and the event to wait for.</para></string> + </property> + <layout class="QVBoxLayout" name="WaitForEventlVerticalLayout"> + <item> + <widget class="QGroupBox" name="waitForEventGroupBox"> + <property name="title"> + <string comment="@title:group">Wait for event</string> + </property> + <layout class="QHBoxLayout" name="waitForEventGroupBoxHorizontalLayout"> + <item> + <layout class="QVBoxLayout" name="labelVerticalLayout"> + <item> + <widget class="QLabel" name="receiverNameLabel"> + <property name="text"> + <string comment="@label:textbox">Receiver name:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>receiverNameLineEdit</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="eventNameLabel"> + <property name="text"> + <string comment="@label:textbox">Event name:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>eventNameLineEdit</cstring> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="lineEditVerticalLayout"> + <item> + <widget class="KLineEdit" name="receiverNameLineEdit"> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>The name of the QObject that receives the event.</para> +<para>Note that the name is not the class of the object, but the string returned by its objectName() method.</para></string> + </property> + </widget> + </item> + <item> + <widget class="KLineEdit" name="eventNameLineEdit"> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>The name of the event.</para> +<para>The name must not contain the "QEvent::" prefix, only the pure name of the event.</para></string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="waitForEventWidgetSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>182</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>KLineEdit</class> + <extends>QLineEdit</extends> + <header>klineedit.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp 2010-03-16 03:00:35 UTC (rev 161) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -18,9 +18,11 @@ #include "WaitForTreeItem.h" #include "WaitForComposedTreeItem.h" +#include "WaitForEventTreeItem.h" #include "WaitForNotTreeItem.h" #include "WaitForSignalTreeItem.h" #include "../WaitForComposed.h" +#include "../WaitForEvent.h" #include "../WaitForNot.h" #include "../WaitForSignal.h" @@ -33,6 +35,11 @@ static_cast<WaitForComposed*>(waitFor), parent); } + if (qobject_cast<WaitForEvent*>(waitFor)) { + return new WaitForEventTreeItem(static_cast<WaitForEvent*>(waitFor), + parent); + } + if (qobject_cast<WaitForNot*>(waitFor)) { return new WaitForNotTreeItem(static_cast<WaitForNot*>(waitFor), parent); Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp 2010-03-16 03:00:35 UTC (rev 161) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -23,9 +23,11 @@ #include "NewWaitForWidget.h" #include "TextTreeItem.h" #include "TreeModel.h" +#include "WaitForEventWidget.h" #include "WaitForSignalWidget.h" #include "WaitForTreeItem.h" #include "../WaitForComposed.h" +#include "../WaitForEvent.h" #include "../WaitForNot.h" #include "../WaitForSignal.h" @@ -107,6 +109,14 @@ return; } + if (qobject_cast<WaitForEvent*>(selectedWaitFor)) { + ui->addButton->setEnabled(false); + ui->editButton->setEnabled(true); + ui->removeButton->setEnabled(true); + + return; + } + if (qobject_cast<WaitForNot*>(selectedWaitFor)) { if (static_cast<WaitForNot*>(selectedWaitFor)->negatedWaitFor()) { ui->addButton->setEnabled(false); @@ -200,6 +210,12 @@ void WaitForWidget::editWaitFor() { EditionWidget* editionWidget = 0; + if (qobject_cast<WaitForEvent*>(mCurrentWaitFor)) { + WaitForEvent* waitForEvent = + static_cast<WaitForEvent*>(mCurrentWaitFor); + editionWidget = new WaitForEventWidget(waitForEvent, this); + } + if (qobject_cast<WaitForSignal*>(mCurrentWaitFor)) { WaitForSignal* waitForSignal = static_cast<WaitForSignal*>(mCurrentWaitFor); Modified: trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-16 03:00:35 UTC (rev 161) +++ trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-16 05:42:56 UTC (rev 162) @@ -20,6 +20,7 @@ Tutorial WaitFor WaitForComposed + WaitForEvent WaitForNot WaitForSignal ) @@ -36,6 +37,7 @@ Tutorial WaitFor WaitForComposed + WaitForEvent WaitForNot WaitForSignal ) Added: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForEventTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForEventTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForEventTest.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -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/>. * + ***************************************************************************/ + +#include <QtTest> + +#include "WaitForEvent.h" + +class WaitForEventTest: public QObject { +Q_OBJECT + +private slots: + + void initTestCase(); + + void testConstructor(); + + void testClone(); + + void testEquals(); + + void testSetReceiverName(); + + void testSetEventName(); + +private: + + int mWaitForStarType; + + void assertWaitForEvent(const QSignalSpy& spy, int index, + WaitFor* waitFor); + +}; + +class StubWaitFor: public WaitFor { +Q_OBJECT +public: + + int mValue; + + StubWaitFor(int value = 0): mValue(value) { + } + + virtual WaitFor* clone() const { + return new StubWaitFor(mValue); + } + + virtual bool equals(const WaitFor& waitFor) const { + if (!qobject_cast<const StubWaitFor*>(&waitFor)) { + return false; + } + + return mValue == static_cast<const StubWaitFor*>(&waitFor)->mValue; + } +}; + +void WaitForEventTest::initTestCase() { + //WaitFor* must be registered in order to be used with QSignalSpy + mWaitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); +} + +void WaitForEventTest::testConstructor() { + QObject parent; + WaitForEvent* waitForEvent = new WaitForEvent(&parent); + + QCOMPARE(waitForEvent->parent(), &parent); +} + +void WaitForEventTest::testClone() { + WaitForEvent waitForEvent; + + WaitForEvent* cloned = static_cast<WaitForEvent*>(waitForEvent.clone()); + + QVERIFY(cloned != &waitForEvent); + QCOMPARE(cloned->receiverName(), waitForEvent.receiverName()); + QCOMPARE(cloned->eventName(), waitForEvent.eventName()); + delete cloned; +} + +void WaitForEventTest::testEquals() { + WaitForEvent waitForEvent1; + waitForEvent1.setReceiverName("The receiver name"); + waitForEvent1.setEventName("The event name"); + WaitForEvent waitForEvent2; + + QCOMPARE(waitForEvent1 == waitForEvent2, false); + QCOMPARE(waitForEvent2 == waitForEvent1, false); + + waitForEvent2.setReceiverName("The receiver name"); + waitForEvent2.setEventName("The event name"); + + QCOMPARE(waitForEvent1 == waitForEvent2, true); + QCOMPARE(waitForEvent2 == waitForEvent1, true); + + StubWaitFor stubWaitFor; + + QCOMPARE(waitForEvent1 == stubWaitFor, false); +} + +void WaitForEventTest::testSetReceiverName() { + WaitForEvent waitForEvent; + + QSignalSpy dataChangedSpy(&waitForEvent, SIGNAL(dataChanged(WaitFor*))); + + waitForEvent.setReceiverName("The receiver name"); + + QCOMPARE(waitForEvent.receiverName(), QString("The receiver name")); + QCOMPARE(dataChangedSpy.count(), 1); + assertWaitForEvent(dataChangedSpy, 0, &waitForEvent); +} + +void WaitForEventTest::testSetEventName() { + WaitForEvent waitForEvent; + + QSignalSpy dataChangedSpy(&waitForEvent, SIGNAL(dataChanged(WaitFor*))); + + waitForEvent.setEventName("The event name"); + + QCOMPARE(waitForEvent.eventName(), QString("The event name")); + QCOMPARE(dataChangedSpy.count(), 1); + assertWaitForEvent(dataChangedSpy, 0, &waitForEvent); +} + +//WaitFor* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(WaitFor*); + +/////////////////////////////////// Helpers //////////////////////////////////// + +void WaitForEventTest::assertWaitForEvent(const QSignalSpy& spy, int index, + WaitFor* waitFor) { + QCOMPARE(spy.at(index).count(), 1); + + QVariant argument = spy.at(index).at(0); + QCOMPARE(argument.userType(), mWaitForStarType); + QCOMPARE(qvariant_cast<WaitFor*>(argument), waitFor); +} + +QTEST_MAIN(WaitForEventTest) + +#include "WaitForEventTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForEventTest.cpp ___________________________________________________________________ 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-16 03:00:35 UTC (rev 161) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-16 05:42:56 UTC (rev 162) @@ -35,6 +35,8 @@ TutorialTreeItem TutorialTreeSelectionManager WaitForComposedTreeItem + WaitForEventTreeItem + WaitForEventWidget WaitForNotTreeItem WaitForSignalTreeItem WaitForSignalWidget @@ -67,6 +69,8 @@ TutorialTreeItem TutorialTreeSelectionManager WaitForComposedTreeItem + WaitForEventTreeItem + WaitForEventWidget WaitForNotTreeItem WaitForSignalTreeItem WaitForSignalWidget Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp 2010-03-16 03:00:35 UTC (rev 161) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -23,6 +23,7 @@ #include <KComboBox> #include "../WaitForComposed.h" +#include "../WaitForEvent.h" #include "../WaitForNot.h" #include "../WaitForSignal.h" @@ -37,6 +38,7 @@ void testWaitForWhenOrConditionIsSelected(); void testWaitForWhenNotConditionIsSelected(); void testWaitForWhenSignalConditionIsSelected(); + void testWaitForWhenEventConditionIsSelected(); private: @@ -93,6 +95,16 @@ delete waitFor; } +void NewWaitForWidgetTest::testWaitForWhenEventConditionIsSelected() { + NewWaitForWidget widget; + + selectOption(&widget, 4); + + WaitForEvent* waitFor = qobject_cast<WaitForEvent*>(widget.waitFor()); + QVERIFY(waitFor); + delete waitFor; +} + /////////////////////////////////// Helpers //////////////////////////////////// void NewWaitForWidgetTest::selectOption(NewWaitForWidget* widget, Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventTreeItemTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventTreeItemTest.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -0,0 +1,164 @@ +/*************************************************************************** + * 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 "WaitForEventTreeItem.h" + +#include <KLocalizedString> + +#include "../WaitForEvent.h" + +class WaitForEventTreeItemTest: public QObject { +Q_OBJECT + +private slots: + + void initTestCase(); + + void testConstructor(); + void testConstructorFull(); + + void testWaitForEventSetReceiverName(); + void testWaitForEventSetReceiverNameChange(); + + void testWaitForEventSetEventName(); + void testWaitForEventSetEventNameChange(); + +private: + + int mTreeItemStarType; + + void assertDataChanged(const QSignalSpy& spy, int index, + TreeItem* item) const; + +}; + +class StubTreeItem: public TreeItem { +public: + virtual QString text() const { + return ""; + } +}; + +void WaitForEventTreeItemTest::initTestCase() { + //TreeItem* must be registered in order to be used with QSignalSpy + mTreeItemStarType = qRegisterMetaType<TreeItem*>("TreeItem*"); +} + +void WaitForEventTreeItemTest::testConstructor() { + WaitForEvent waitForEvent; + + StubTreeItem parent; + WaitForEventTreeItem item(&waitForEvent, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.waitFor(), &waitForEvent); + QCOMPARE(item.text(), i18nc("@item", "When the event (event not set) is " + "received by object (object not " + "set)")); +} + +void WaitForEventTreeItemTest::testConstructorFull() { + WaitForEvent waitForEvent; + waitForEvent.setReceiverName("receiverName"); + waitForEvent.setEventName("eventName"); + + StubTreeItem parent; + WaitForEventTreeItem item(&waitForEvent, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.waitFor(), &waitForEvent); + QCOMPARE(item.text(), i18nc("@item", "When the event \"eventName\" is " + "received by object " + "\"receiverName\"")); +} + +void WaitForEventTreeItemTest::testWaitForEventSetReceiverName() { + WaitForEvent waitForEvent; + waitForEvent.setReceiverName("receiverName"); + + WaitForEventTreeItem item(&waitForEvent); + + QCOMPARE(item.text(), i18nc("@item", "When the event (event not set) is " + "received by object \"receiverName\"")); +} + +void WaitForEventTreeItemTest::testWaitForEventSetReceiverNameChange() { + WaitForEvent waitForEvent; + WaitForEventTreeItem item(&waitForEvent); + + waitForEvent.setReceiverName("receiverName"); + + QSignalSpy dataChangedSpy(&item, SIGNAL(dataChanged(TreeItem*))); + + waitForEvent.setReceiverName("receiverNameChanged"); + + QCOMPARE(item.text(), i18nc("@item", "When the event (event not set) is " + "received by object " + "\"receiverNameChanged\"")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, &item); +} + +void WaitForEventTreeItemTest::testWaitForEventSetEventName() { + WaitForEvent waitForEvent; + waitForEvent.setEventName("eventName"); + + WaitForEventTreeItem item(&waitForEvent); + + QCOMPARE(item.text(), i18nc("@item", "When the event \"eventName\" is " + "received by object (object not " + "set)")); +} + +void WaitForEventTreeItemTest::testWaitForEventSetEventNameChange() { + WaitForEvent waitForEvent; + WaitForEventTreeItem item(&waitForEvent); + + waitForEvent.setEventName("eventName"); + + QSignalSpy dataChangedSpy(&item, SIGNAL(dataChanged(TreeItem*))); + + waitForEvent.setEventName("eventNameChanged"); + + QCOMPARE(item.text(), i18nc("@item", "When the event " + "\"eventNameChanged\" is received 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 WaitForEventTreeItemTest::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(WaitForEventTreeItemTest) + +#include "WaitForEventTreeItemTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventTreeItemTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventWidgetTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventWidgetTest.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -0,0 +1,86 @@ +/*************************************************************************** + * 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 "WaitForEventWidget.h" + +#include <KLineEdit> + +#include "../WaitForEvent.h" + +class WaitForEventWidgetTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testSaveChanges(); + +private: + + KLineEdit* receiverNameLineEdit(WaitForEventWidget* widget) const; + KLineEdit* eventNameLineEdit(WaitForEventWidget* widget) const; + +}; + +void WaitForEventWidgetTest::testConstructor() { + WaitForEvent waitFor; + waitFor.setReceiverName("The receiver name"); + waitFor.setEventName("The event name"); + + QWidget parent; + WaitForEventWidget* widget = new WaitForEventWidget(&waitFor, &parent); + + QCOMPARE(widget->parentWidget(), &parent); + QCOMPARE(receiverNameLineEdit(widget)->text(), + QString("The receiver name")); + QCOMPARE(eventNameLineEdit(widget)->text(), QString("The event name")); +} + +void WaitForEventWidgetTest::testSaveChanges() { + WaitForEvent waitFor; + waitFor.setReceiverName("The receiver name"); + waitFor.setEventName("The event name"); + + WaitForEventWidget widget(&waitFor); + receiverNameLineEdit(&widget)->setText("The new receiver name"); + eventNameLineEdit(&widget)->setText("The new event name"); + + widget.saveChanges(); + + QCOMPARE(waitFor.receiverName(), QString("The new receiver name")); + QCOMPARE(waitFor.eventName(), QString("The new event name")); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +KLineEdit* WaitForEventWidgetTest::receiverNameLineEdit( + WaitForEventWidget* widget) const { + return widget->findChild<KLineEdit*>("receiverNameLineEdit"); +} + +KLineEdit* WaitForEventWidgetTest::eventNameLineEdit( + WaitForEventWidget* widget) const { + return widget->findChild<KLineEdit*>("eventNameLineEdit"); +} + +QTEST_MAIN(WaitForEventWidgetTest) + +#include "WaitForEventWidgetTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventWidgetTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp 2010-03-16 03:00:35 UTC (rev 161) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -21,10 +21,12 @@ #include "WaitForTreeItem.h" #include "WaitForComposedTreeItem.h" +#include "WaitForEventTreeItem.h" #include "WaitForNotTreeItem.h" #include "WaitForSignalTreeItem.h" #include "../WaitFor.h" #include "../WaitForComposed.h" +#include "../WaitForEvent.h" #include "../WaitForNot.h" #include "../WaitForSignal.h" @@ -36,6 +38,7 @@ void testConstructor(); void testTreeItemForWaitForComposed(); + void testTreeItemForWaitForEvent(); void testTreeItemForWaitForNot(); void testTreeItemForWaitForSignal(); @@ -99,6 +102,20 @@ delete item; } +void WaitForTreeItemTest::testTreeItemForWaitForEvent() { + WaitForEvent waitFor; + StubTreeItem parent; + + WaitForTreeItem* item = WaitForTreeItem::treeItemForWaitFor(&waitFor, + &parent); + + QVERIFY(qobject_cast<WaitForEventTreeItem*>(item)); + QCOMPARE(item->parent(), &parent); + QCOMPARE(item->waitFor(), &waitFor); + + delete item; +} + void WaitForTreeItemTest::testTreeItemForWaitForNot() { WaitForNot waitFor; StubTreeItem parent; Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp 2010-03-16 03:00:35 UTC (rev 161) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp 2010-03-16 05:42:56 UTC (rev 162) @@ -28,6 +28,7 @@ #include "EditionDialog.h" #include "../WaitForComposed.h" +#include "../WaitForEvent.h" #include "../WaitForNot.h" #include "../WaitForSignal.h" @@ -38,6 +39,7 @@ void addWaitForSignal() const; void cancelAddWaitForDialog() const; + void setEventData() const; void setSignalData() const; private slots: @@ -52,6 +54,7 @@ void testSelectWaitForOr(); void testSelectWaitForNot(); void testSelectWaitForNotEmpty(); + void testSelectWaitForEvent(); void testSelectWaitForSignal(); void testClearSelection(); @@ -60,6 +63,7 @@ void testAddWaitForToWaitForNot(); void testAddWaitForCancellingDialog(); + void testEditWaitForEvent(); void testEditWaitForSignal(); void testRemoveWaitForFromRoot(); @@ -71,6 +75,7 @@ WaitForComposed* mWaitFor; WaitForSignal* mWaitFor1; WaitForComposed* mWaitFor2; + WaitForEvent* mWaitFor2_1; WaitForNot* mWaitFor3; WaitForSignal* mWaitFor3_1; WaitForNot* mWaitFor4; @@ -104,6 +109,11 @@ mWaitFor2->setCompositionType(WaitForComposed::Or); mWaitFor->addWaitFor(mWaitFor2); + mWaitFor2_1 = new WaitForEvent(); + mWaitFor2_1->setReceiverName("receiver"); + mWaitFor2_1->setEventName("event"); + mWaitFor2->addWaitFor(mWaitFor2_1); + mWaitFor3 = new WaitForNot(); mWaitFor->addWaitFor(mWaitFor3); @@ -165,6 +175,12 @@ assertButtonEnabled(true, false, true); } +void WaitForWidgetTest::testSelectWaitForEvent() { + selectItem(getIndex(0, getIndex(1, getIndex(0)))); + + assertButtonEnabled(false, true, true); +} + void WaitForWidgetTest::testSelectWaitForSignal() { selectItem(getIndex(0, getIndex(0))); @@ -219,9 +235,10 @@ QCOMPARE(mWaitFor->waitFors()[2], mWaitFor3); QCOMPARE(mWaitFor->waitFors()[3], mWaitFor4); QVERIFY(qobject_cast<WaitForSignal*>(mWaitFor->waitFors()[4])); - QCOMPARE(mWaitFor2->waitFors().count(), 1); - QVERIFY(qobject_cast<WaitForSignal*>(mWaitFor2->waitFors()[0])); - QVERIFY(mWaitFor->waitFors()[4] != mWaitFor2->waitFors()[0]); + QCOMPARE(mWaitFor2->waitFors().count(), 2); + QCOMPARE(mWaitFor2->waitFors()[0], mWaitFor2_1); + QVERIFY(qobject_cast<WaitForSignal*>(mWaitFor2->waitFors()[1])); + QVERIFY(mWaitFor->waitFors()[4] != mWaitFor2->waitFors()[1]); } void WaitForWidgetTest::testAddWaitForToWaitForNot() { @@ -262,6 +279,20 @@ assertButtonEnabled(true, false, false); } +void WaitForWidgetTest::testEditWaitForEvent() { + selectItem(getIndex(0, getIndex(1, getIndex(0)))); + + //The dialog is modal, so it won't return to the test code until it is + //closed. Thus, the commands to execute on the dialog must be "queued", + //as calling setEventData after the button click won't work. + QTimer::singleShot(500, this, SLOT(setEventData())); + + button("editButton")->click(); + + QCOMPARE(mWaitFor2_1->receiverName(), QString("The new receiver name")); + QCOMPARE(mWaitFor2_1->eventName(), QString("The new event name")); +} + void WaitForWidgetTest::testEditWaitForSignal() { selectItem(getIndex(0, getIndex(0))); @@ -329,6 +360,22 @@ dialog->button(KDialog::Cancel)->click(); } +void WaitForWidgetTest::setEventData() const { + KLineEdit* receiverNameLineEdit = + mWidget->findChild<KLineEdit*>("receiverNameLineEdit"); + QVERIFY(receiverNameLineEdit); + receiverNameLineEdit->setText("The new receiver name"); + + KLineEdit* eventNameLineEdit = + mWidget->findChild<KLineEdit*>("eventNameLineEdit"); + QVERIFY(eventNameLineEdit); + eventNameLineEdit->setText("The new event name"); + + EditionDialog* dialog = mWidget->findChild<EditionDialog*>("editionDialog"); + QVERIFY(dialog); + dialog->button(KDialog::Ok)->click(); +} + void WaitForWidgetTest::setSignalData() const { KLineEdit* emitterNameLineEdit = mWidget->findChild<KLineEdit*>("emitterNameLineEdit"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-16 03:00:41
|
Revision: 161 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=161&view=rev Author: danxuliu Date: 2010-03-16 03:00:35 +0000 (Tue, 16 Mar 2010) Log Message: ----------- -Add actions to add, edit and remove reactions. -Adapt TutorialTreeSelectionManager to emit reactionSelected(Reaction*) when a reaction is selected. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.cpp trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.h trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-16 03:00:35 UTC (rev 161) @@ -26,11 +26,13 @@ #include <KApplication> #include <KLocalizedString> +#include "Reaction.h" #include "Step.h" #include "Tutorial.h" #include "view/ActionListWidget.h" #include "view/EditionDialog.h" #include "view/LicenseWidget.h" +#include "view/ReactionWidget.h" #include "view/StepCustomCodeWidget.h" #include "view/StepDataWidget.h" #include "view/TreeModel.h" @@ -71,6 +73,8 @@ new TutorialTreeSelectionManager(mTreeView->selectionModel(), this); connect(selectionManager, SIGNAL(stepSelected(Step*)), this, SLOT(selectStep(Step*))); + connect(selectionManager, SIGNAL(reactionSelected(Reaction*)), + this, SLOT(selectReaction(Reaction*))); } void KTutorialEditor::setupDocks() { @@ -82,6 +86,11 @@ mStepActionDock = new QDockWidget(i18nc("@title", "Edit step"), this); mStepActionDock->setObjectName("editStepDock"); addDockWidget(Qt::RightDockWidgetArea, mStepActionDock); + + mReactionActionDock = new QDockWidget(i18nc("@title", "Edit reaction"), + this); + mReactionActionDock->setObjectName("editReactionDock"); + addDockWidget(Qt::RightDockWidgetArea, mReactionActionDock); } void KTutorialEditor::setupActions() { @@ -181,11 +190,46 @@ actionListWidget->addAction(action); mStepActionDock->setWidget(actionListWidget); + actionListWidget = new ActionListWidget(mReactionActionDock); + action = new KAction(this); + action->setText(i18nc("@action", "Add reaction...")); + action->setStatusTip(i18nc("@info:status", "Add a new reaction to the " +"selected step.")); + action->setIcon(KIcon("list-add")); + action->setEnabled(false); + actionCollection()->addAction("addReaction", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(addReaction())); + actionListWidget->addAction(action); + + action = new KAction(this); + action->setText(i18nc("@action", "Set reaction data...")); + action->setStatusTip(i18nc("@info:status", "Set the trigger and the " +"response of the currently selected reaction.")); + action->setIcon(KIcon("document-edit")); + action->setEnabled(false); + actionCollection()->addAction("setReactionData", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setReactionData())); + actionListWidget->addAction(action); + + action = new KAction(this); + action->setText(i18nc("@action", "Remove reaction")); + action->setStatusTip(i18nc("@info:status", "Removes the currently selected " +"reaction from its step.")); + action->setIcon(KIcon("list-remove")); + action->setEnabled(false); + actionCollection()->addAction("removeReaction", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(removeReaction())); + actionListWidget->addAction(action); + + mReactionActionDock->setWidget(actionListWidget); + actionCollection()->addAction("showEditTutorialDock", mTutorialActionDock->toggleViewAction()); actionCollection()->addAction("showEditStepDock", mStepActionDock->toggleViewAction()); + actionCollection()->addAction("showEditReactionDock", + mReactionActionDock->toggleViewAction()); } void KTutorialEditor::showEditionDialog(EditionWidget* editionWidget) { @@ -205,14 +249,28 @@ actionCollection()->action("setStepSetup")->setEnabled(true); actionCollection()->action("setStepTearDown")->setEnabled(true); actionCollection()->action("removeStep")->setEnabled(true); + actionCollection()->action("addReaction")->setEnabled(true); } else { actionCollection()->action("setStepData")->setEnabled(false); actionCollection()->action("setStepSetup")->setEnabled(false); actionCollection()->action("setStepTearDown")->setEnabled(false); actionCollection()->action("removeStep")->setEnabled(false); + actionCollection()->action("addReaction")->setEnabled(false); } } +void KTutorialEditor::selectReaction(Reaction* reaction) { + mCurrentReaction = reaction; + + if (mCurrentReaction) { + actionCollection()->action("setReactionData")->setEnabled(true); + actionCollection()->action("removeReaction")->setEnabled(true); + } else { + actionCollection()->action("setReactionData")->setEnabled(false); + actionCollection()->action("removeReaction")->setEnabled(false); + } +} + void KTutorialEditor::setTutorialInformation() { showEditionDialog(new TutorialInformationWidget(mTutorial)); } @@ -264,3 +322,30 @@ mTutorial->removeStep(stepToRemove); stepToRemove->deleteLater(); } + +void KTutorialEditor::addReaction() { + Q_ASSERT(mCurrentStep); + + Reaction* reaction = new Reaction(); + mCurrentStep->addReaction(reaction); + + showEditionDialog(new ReactionWidget(reaction)); +} + +void KTutorialEditor::setReactionData() { + Q_ASSERT(mCurrentReaction); + + showEditionDialog(new ReactionWidget(mCurrentReaction)); +} + +void KTutorialEditor::removeReaction() { + Q_ASSERT(mCurrentStep); + + //When the reaction is removed, mCurrentReaction is changed because the + //selected item in the tree view changes. As mCurrentReaction is one of the + //valid reactions in the step, deleting it leads to a crash the next time it + //is used. + Reaction* reactionToRemove = mCurrentReaction; + mCurrentStep->removeReaction(reactionToRemove); + reactionToRemove->deleteLater(); +} Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-16 03:00:35 UTC (rev 161) @@ -23,6 +23,7 @@ class EditionWidget; class QTreeView; +class Reaction; class Step; class Tutorial; @@ -57,6 +58,11 @@ QDockWidget* mStepActionDock; /** + * Dock with the actions to edit a reaction. + */ + QDockWidget* mReactionActionDock; + + /** * The tutorial being edited. */ Tutorial* mTutorial; @@ -67,6 +73,11 @@ Step* mCurrentStep; /** + * The currently selected reaction. + */ + Reaction* mCurrentReaction; + + /** * Sets up the tutorial to be edited. * It creates a new tutorial, prepares the tree view to represent it and * handles the selection of items. @@ -101,6 +112,15 @@ void selectStep(Step* step); /** + * Sets the current reaction and enables or disables the actions that depend + * on a reaction as needed. + * + * @param reaction The reaction to select, or null to deselect the current + * one. + */ + void selectReaction(Reaction* reaction); + + /** * Shows a TutorialInformationWidget for the tutorial. */ void setTutorialInformation(); @@ -145,6 +165,22 @@ */ void removeStep(); + /** + * Adds a new reaction to the current step and shows a ReactionWidget for + * it. + */ + void addReaction(); + + /** + * Shows a ReactionWidget for the current reaction. + */ + void setReactionData(); + + /** + * Removes the current reaction from its step. + */ + void removeReaction(); + }; #endif Modified: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-16 03:00:35 UTC (rev 161) @@ -18,12 +18,19 @@ <Action name="setStepTearDown"/> <Action name="removeStep"/> </Menu> + <Menu name="editReactions"> + <Text context="@title:menu Noun, a reaction in a step">Reaction</Text> + <Action name="addReaction"/> + <Action name="setReactionData"/> + <Action name="removeReaction"/> + </Menu> </Menu> <Menu name="view"> <Menu name="panels"> <Text context="@title:menu">Panels</Text> <Action name="showEditTutorialDock"/> <Action name="showEditStepDock"/> + <Action name="showEditReactionDock"/> </Menu> </Menu> </MenuBar> Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.cpp 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.cpp 2010-03-16 03:00:35 UTC (rev 161) @@ -18,6 +18,7 @@ #include "TutorialTreeSelectionManager.h" +#include "ReactionTreeItem.h" #include "StepTreeItem.h" #include "TreeItem.h" @@ -62,6 +63,34 @@ return getStepForTreeItem(item->parent()); } +void TutorialTreeSelectionManager::updateReactionSelection(TreeItem* selected, + TreeItem* deselected) { + Reaction* selectedReaction = getReactionForTreeItem(selected); + Reaction* deselectedReaction = getReactionForTreeItem(deselected); + + if (selectedReaction && selectedReaction != deselectedReaction) { + emit reactionSelected(selectedReaction); + return; + } + + if (!selectedReaction && deselectedReaction) { + emit reactionSelected(0); + return; + } +} + +Reaction* TutorialTreeSelectionManager::getReactionForTreeItem(TreeItem* item) { + if (qobject_cast<ReactionTreeItem*>(item)) { + return static_cast<ReactionTreeItem*>(item)->reaction(); + } + + if (item == 0 || item->parent() == 0) { + return 0; + } + + return getReactionForTreeItem(item->parent()); +} + //private slots: void TutorialTreeSelectionManager::handleSelectionChanged( @@ -89,4 +118,5 @@ } updateStepSelection(selectedItem, deselectedItem); + updateReactionSelection(selectedItem, deselectedItem); } Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.h 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeSelectionManager.h 2010-03-16 03:00:35 UTC (rev 161) @@ -22,14 +22,20 @@ #include <QItemSelectionModel> #include <QObject> +class Reaction; class Step; class TreeItem; /** * Watches the QItemSelectionModel of a TreeModel for changes in the selection. * When an item is selected in the TreeModel, it is checked what kind of data it - * represents. If it is a Step, stepSelected(Step*) signal is emitted. + * represents. An item can represent several types of data (for example, a + * reaction item represents a reaction, but also a step as it is part of it). * + * When the data represented by the item is a Step, stepSelected(Step*) signal + * is emitted. When it is a Reaction, reactionSelected(Reaction*) signal is + * emitted. + * * Only single item selections are supported. */ class TutorialTreeSelectionManager: public QObject { @@ -60,6 +66,17 @@ */ void stepSelected(Step* step); + /** + * Emitted when a Reaction (or any of its child items) is selected. + * If the Reaction is deselected and the new selected item isn't a Reaction, + * the signal is emitted with a null pointer. + * No signal is emitted if the selected item changes to another item that + * selects the same Reaction already selected. + * + * @param reaction The selected Reaction, or null if it was deselected. + */ + void reactionSelected(Reaction* reaction); + private: /** @@ -84,6 +101,28 @@ */ Step* getStepForTreeItem(TreeItem* item); + /** + * Emits reactionSelected(Reaction*) signal based on the selected and + * deselected items. + * + * @param selected The selected item, if any. + * @param deselected The deselected item, if any. + */ + void updateReactionSelection(TreeItem* selected, TreeItem* deselected); + + /** + * Returns the Reaction represented by the given item. + * Any recursive child item of a ReactionTreeItem, or a ReactionTreeItem + * itself, represents a Reaction. + * + * If the item doesn't represent a Reaction or there is no item, a null + * pointer is returned. + * + * @param item The item to get its represented Reaction. + * @return The Reaction. + */ + Reaction* getReactionForTreeItem(TreeItem* item); + private Q_SLOTS: /** Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp 2010-03-16 02:12:03 UTC (rev 160) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp 2010-03-16 03:00:35 UTC (rev 161) @@ -22,8 +22,10 @@ #include "TreeModel.h" #include "TutorialTreeItem.h" +#include "../Reaction.h" #include "../Step.h" #include "../Tutorial.h" +#include "../WaitForComposed.h" class TutorialTreeSelectionManagerTest: public QObject { Q_OBJECT @@ -43,22 +45,34 @@ void testSelectStepOrChildrenWithoutChangingStep(); void testSelectStepOrChildrenChangingToAnotherStep(); + void testSelectReactionOrChildrenChangingToOtherItems(); + void testSelectReactionOrChildrenWithoutChangingReaction(); + void testSelectReactionOrChildrenChangingToAnotherReaction(); + private: int mStepStarType; + int mReactionStarType; Tutorial* mTutorial; Step* mStep1; + Reaction* mReaction1; + WaitForComposed* mWaitFor1; + WaitForComposed* mWaitFor1_1; Step* mStep2; + Reaction* mReaction2; TreeModel* mTreeModel; QItemSelectionModel* mSelectionModel; TutorialTreeSelectionManager* mSelectionManager; QSignalSpy* mStepSelectedSpy; + QSignalSpy* mReactionSelectedSpy; void select(const QModelIndex& index); void assertStepSignal(const QSignalSpy* spy, int index, Step* step) const; + void assertReactionSignal(const QSignalSpy* spy, int index, + Reaction* reaction) const; }; @@ -66,6 +80,9 @@ //Step* must be registered in order to be used with QSignalSpy mStepStarType = qRegisterMetaType<Step*>("Step*"); + //Reaction* must be registered in order to be used with QSignalSpy + mReactionStarType = qRegisterMetaType<Reaction*>("Reaction*"); + mTutorial = new Tutorial(); mTutorial->setName("The name"); mTutorial->setDescription("The description"); @@ -80,6 +97,16 @@ mStep1->setCustomTearDownCode("Tear down 1"); mTutorial->addStep(mStep1); + mReaction1 = new Reaction(); + mReaction1->setTriggerType(Reaction::ConditionMet); + mReaction1->setResponseType(Reaction::CustomCode); + mStep1->addReaction(mReaction1); + + mWaitFor1 = new WaitForComposed(); + mWaitFor1_1 = new WaitForComposed(); + mWaitFor1->addWaitFor(mWaitFor1_1); + mReaction1->setWaitFor(mWaitFor1); + mStep2 = new Step(); mStep2->setId("Second step"); mStep2->setText("Text 2"); @@ -87,6 +114,9 @@ mStep2->setCustomTearDownCode("Tear down 2"); mTutorial->addStep(mStep2); + mReaction2 = new Reaction(); + mStep2->addReaction(mReaction2); + mTreeModel = new TreeModel(new TutorialTreeItem(mTutorial)); } @@ -96,9 +126,13 @@ mStepSelectedSpy = new QSignalSpy(mSelectionManager, SIGNAL(stepSelected(Step*))); + + mReactionSelectedSpy = new QSignalSpy(mSelectionManager, + SIGNAL(reactionSelected(Reaction*))); } void TutorialTreeSelectionManagerTest::cleanup() { + delete mReactionSelectedSpy; delete mStepSelectedSpy; delete mSelectionManager; delete mSelectionModel; @@ -133,6 +167,7 @@ select(mTreeModel->index(0, 0, mTreeModel->index(4, 0))); QCOMPARE(mStepSelectedSpy->count(), 0); + QCOMPARE(mReactionSelectedSpy->count(), 0); } void TutorialTreeSelectionManagerTest:: @@ -204,6 +239,17 @@ QCOMPARE(mStepSelectedSpy->count(), 12); assertStepSignal(mStepSelectedSpy, 11, 0); + + //Reaction + select(mTreeModel->index(3, 0, step1Index)); + + QCOMPARE(mStepSelectedSpy->count(), 13); + assertStepSignal(mStepSelectedSpy, 12, mStep1); + + select(mTreeModel->index(0, 0)); + + QCOMPARE(mStepSelectedSpy->count(), 14); + assertStepSignal(mStepSelectedSpy, 13, 0); } void TutorialTreeSelectionManagerTest:: @@ -239,6 +285,11 @@ select(mTreeModel->index(0, 0, mTreeModel->index(2, 0, step1Index))); QCOMPARE(mStepSelectedSpy->count(), 1); + + //Reaction + select(mTreeModel->index(3, 0, step1Index)); + + QCOMPARE(mStepSelectedSpy->count(), 1); } void TutorialTreeSelectionManagerTest:: @@ -310,8 +361,173 @@ QCOMPARE(mStepSelectedSpy->count(), 12); assertStepSignal(mStepSelectedSpy, 11, mStep2); + + //Reaction + select(mTreeModel->index(3, 0, step1Index)); + + QCOMPARE(mStepSelectedSpy->count(), 13); + assertStepSignal(mStepSelectedSpy, 12, mStep1); + + select(mTreeModel->index(3, 0, step2Index)); + + QCOMPARE(mStepSelectedSpy->count(), 14); + assertStepSignal(mStepSelectedSpy, 13, mStep2); } +void TutorialTreeSelectionManagerTest:: + testSelectReactionOrChildrenChangingToOtherItems() { + QModelIndex step1Index = mTreeModel->index(5, 0); + QModelIndex reaction1_1Index = mTreeModel->index(3, 0, step1Index); + + select(reaction1_1Index); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + assertReactionSignal(mReactionSelectedSpy, 0, mReaction1); + + //Tutorial name + select(mTreeModel->index(0, 0)); + + QCOMPARE(mReactionSelectedSpy->count(), 2); + assertReactionSignal(mReactionSelectedSpy, 1, 0); + + //Reaction trigger + select(mTreeModel->index(0, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 3); + assertReactionSignal(mReactionSelectedSpy, 2, mReaction1); + + select(mTreeModel->index(0, 0)); + + QCOMPARE(mReactionSelectedSpy->count(), 4); + assertReactionSignal(mReactionSelectedSpy, 3, 0); + + //Reaction child condition trigger + select(mTreeModel->index(0, 0, mTreeModel->index(0, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 5); + assertReactionSignal(mReactionSelectedSpy, 4, mReaction1); + + select(mTreeModel->index(0, 0)); + + QCOMPARE(mReactionSelectedSpy->count(), 6); + assertReactionSignal(mReactionSelectedSpy, 5, 0); + + //Reaction response + select(mTreeModel->index(1, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 7); + assertReactionSignal(mReactionSelectedSpy, 6, mReaction1); + + select(mTreeModel->index(0, 0)); + + QCOMPARE(mReactionSelectedSpy->count(), 8); + assertReactionSignal(mReactionSelectedSpy, 7, 0); + + //Reaction custom code response + select(mTreeModel->index(0, 0, mTreeModel->index(1, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 9); + assertReactionSignal(mReactionSelectedSpy, 8, mReaction1); + + select(mTreeModel->index(0, 0)); + + QCOMPARE(mReactionSelectedSpy->count(), 10); + assertReactionSignal(mReactionSelectedSpy, 9, 0); +} + +void TutorialTreeSelectionManagerTest:: + testSelectReactionOrChildrenWithoutChangingReaction() { + QModelIndex step1Index = mTreeModel->index(5, 0); + QModelIndex reaction1_1Index = mTreeModel->index(3, 0, step1Index); + + select(reaction1_1Index); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + assertReactionSignal(mReactionSelectedSpy, 0, mReaction1); + + //Reaction trigger + select(mTreeModel->index(0, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + + //Reaction child condition trigger + select(mTreeModel->index(0, 0, mTreeModel->index(0, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + + //Reaction response + select(mTreeModel->index(1, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + + //Reaction custom code response + select(mTreeModel->index(0, 0, mTreeModel->index(1, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 1); +} + +void TutorialTreeSelectionManagerTest:: + testSelectReactionOrChildrenChangingToAnotherReaction() { + QModelIndex step1Index = mTreeModel->index(5, 0); + QModelIndex reaction1_1Index = mTreeModel->index(3, 0, step1Index); + QModelIndex step2Index = mTreeModel->index(6, 0); + QModelIndex reaction2_1Index = mTreeModel->index(3, 0, step2Index); + + select(reaction1_1Index); + + QCOMPARE(mReactionSelectedSpy->count(), 1); + assertReactionSignal(mReactionSelectedSpy, 0, mReaction1); + + select(reaction2_1Index); + + QCOMPARE(mReactionSelectedSpy->count(), 2); + assertReactionSignal(mReactionSelectedSpy, 1, mReaction2); + + //Reaction trigger + select(mTreeModel->index(0, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 3); + assertReactionSignal(mReactionSelectedSpy, 2, mReaction1); + + select(mTreeModel->index(0, 0, reaction2_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 4); + assertReactionSignal(mReactionSelectedSpy, 3, mReaction2); + + //Reaction nested condition trigger + select(mTreeModel->index(0, 0, mTreeModel->index(0, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 5); + assertReactionSignal(mReactionSelectedSpy, 4, mReaction1); + + select(mTreeModel->index(0, 0, reaction2_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 6); + assertReactionSignal(mReactionSelectedSpy, 5, mReaction2); + + //Reaction response + select(mTreeModel->index(1, 0, reaction1_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 7); + assertReactionSignal(mReactionSelectedSpy, 6, mReaction1); + + select(mTreeModel->index(1, 0, reaction2_1Index)); + + QCOMPARE(mReactionSelectedSpy->count(), 8); + assertReactionSignal(mReactionSelectedSpy, 7, mReaction2); + + //Reaction custom code response + select(mTreeModel->index(0, 0, mTreeModel->index(1, 0, reaction1_1Index))); + + QCOMPARE(mReactionSelectedSpy->count(), 9); + assertReactionSignal(mReactionSelectedSpy, 8, mReaction1); + + select(reaction2_1Index); + + QCOMPARE(mReactionSelectedSpy->count(), 10); + assertReactionSignal(mReactionSelectedSpy, 9, mReaction2); +} + /////////////////////////////////// Helpers //////////////////////////////////// void TutorialTreeSelectionManagerTest::select(const QModelIndex& index) { @@ -331,6 +547,20 @@ QCOMPARE(qvariant_cast<Step*>(argument), step); } +//Reaction* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(Reaction*); + +void TutorialTreeSelectionManagerTest::assertReactionSignal( + const QSignalSpy* spy, + int index, + Reaction* reaction) const { + QCOMPARE(spy->at(index).count(), 1); + + QVariant argument = spy->at(index).at(0); + QCOMPARE(argument.userType(), mReactionStarType); + QCOMPARE(qvariant_cast<Reaction*>(argument), reaction); +} + QTEST_MAIN(TutorialTreeSelectionManagerTest) #include "TutorialTreeSelectionManagerTest.moc" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-16 02:12:09
|
Revision: 160 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=160&view=rev Author: danxuliu Date: 2010-03-16 02:12:03 +0000 (Tue, 16 Mar 2010) Log Message: ----------- Fix crash when a reaction was saved and there was no WaitFor in the reaction or in the data to save. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp 2010-03-16 00:16:31 UTC (rev 159) +++ trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp 2010-03-16 02:12:03 UTC (rev 160) @@ -77,7 +77,8 @@ mReaction->setOptionName(ui->triggerOptionLineEdit->text()); } - if (*mReaction->waitFor() != *mWaitForWidget->waitFor()) { + if (!mReaction->waitFor() || !mWaitForWidget->waitFor() || + *mReaction->waitFor() != *mWaitForWidget->waitFor()) { WaitFor* oldWaitFor = mReaction->waitFor(); mReaction->setWaitFor(mWaitForWidget->waitFor()); delete oldWaitFor; Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp 2010-03-16 00:16:31 UTC (rev 159) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp 2010-03-16 02:12:03 UTC (rev 160) @@ -48,6 +48,7 @@ void testSelectResponseTypeCustomCode(); void testSaveChanges(); + void testSaveChangesWithNoWaitFor(); private: @@ -60,6 +61,7 @@ QRadioButton* responseCodeRadioButton(ReactionWidget* widget) const; KTextEdit* responseCodeTextEdit(ReactionWidget* widget) const; + void addWaitForSignal(ReactionWidget* widget); void addWaitForSignalToRootWaitFor(ReactionWidget* widget); }; @@ -178,6 +180,23 @@ QCOMPARE(reaction.customCode(), QString("The custom code")); } +void ReactionWidgetTest::testSaveChangesWithNoWaitFor() { + Reaction reaction; + reaction.setTriggerType(Reaction::ConditionMet); + + ReactionWidget widget(&reaction); + + widget.saveChanges(); + + QCOMPARE(reaction.waitFor(), (WaitFor*)0); + + addWaitForSignal(&widget); + widget.saveChanges(); + + QVERIFY(reaction.waitFor() != 0); + QVERIFY(qobject_cast<WaitForSignal*>(reaction.waitFor())); +} + /////////////////////////////////// Helpers //////////////////////////////////// QRadioButton* ReactionWidgetTest::triggerOptionRadioButton( @@ -248,11 +267,7 @@ }; -void ReactionWidgetTest::addWaitForSignalToRootWaitFor(ReactionWidget* widget) { - QTreeView* tree = widget->findChild<QTreeView*>("waitForTreeView"); - QModelIndex index = tree->model()->index(0, 0); - tree->selectionModel()->select(index, QItemSelectionModel::SelectCurrent); - +void ReactionWidgetTest::addWaitForSignal(ReactionWidget* widget) { AddWaitForSignalHelper* helper = new AddWaitForSignalHelper(widget, this); //The dialog is modal, so it won't return to the test code until it is @@ -263,6 +278,14 @@ widget->findChild<KPushButton*>("addButton")->click(); } +void ReactionWidgetTest::addWaitForSignalToRootWaitFor(ReactionWidget* widget) { + QTreeView* tree = widget->findChild<QTreeView*>("waitForTreeView"); + QModelIndex index = tree->model()->index(0, 0); + tree->selectionModel()->select(index, QItemSelectionModel::SelectCurrent); + + addWaitForSignal(widget); +} + QTEST_MAIN(ReactionWidgetTest) #include "ReactionWidgetTest.moc" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-16 00:16:39
|
Revision: 159 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=159&view=rev Author: danxuliu Date: 2010-03-16 00:16:31 +0000 (Tue, 16 Mar 2010) Log Message: ----------- -Fix adding and removing the root WaitForTreeItem when the root WaitFor was added or removed. -Fix disabling add button when the root WaitFor was added or when a negated WaitFor was added to a WaitForNot. -Fix cancelling the addWaitFor dialog. -Fix the window title for the addWaitFor dialog. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp 2010-03-15 19:02:05 UTC (rev 158) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp 2010-03-16 00:16:31 UTC (rev 159) @@ -64,14 +64,15 @@ //private: void WaitForWidget::setupTreeView(WaitFor* waitFor) { - TextTreeItem* rootItem = new TextTreeItem(); + mRootItem = new TextTreeItem(); if (waitFor) { - TreeItem* item = WaitForTreeItem::treeItemForWaitFor(waitFor, rootItem); - rootItem->appendChild(item); + TreeItem* item = WaitForTreeItem::treeItemForWaitFor(waitFor, + mRootItem); + mRootItem->appendChild(item); } QTreeView* treeView = ui->waitForTreeView; - TreeModel* model = new TreeModel(rootItem, treeView); + TreeModel* model = new TreeModel(mRootItem, treeView); QAbstractItemModel* oldModel = treeView->model(); treeView->setModel(model); @@ -156,14 +157,26 @@ KDialog* dialog = new KDialog(this); NewWaitForWidget* widget = new NewWaitForWidget(dialog); dialog->setMainWidget(widget); + dialog->setWindowTitle(widget->windowTitle()); dialog->setObjectName("addWaitForDialog"); if (dialog->exec() == QDialog::Accepted) { newWaitFor = widget->waitFor(); } dialog->deleteLater(); + if (!newWaitFor) { + return; + } + if (!mWaitFor) { + ui->addButton->setEnabled(false); + + TreeItem* item = WaitForTreeItem::treeItemForWaitFor(newWaitFor, + mRootItem); + mRootItem->appendChild(item); + mWaitFor = newWaitFor; + return; } @@ -176,6 +189,8 @@ } if (qobject_cast<WaitForNot*>(mCurrentWaitFor)) { + ui->addButton->setEnabled(false); + WaitForNot* waitForNot = static_cast<WaitForNot*>(mCurrentWaitFor); waitForNot->setNegatedWaitFor(newWaitFor); @@ -208,6 +223,10 @@ delete mWaitFor; mWaitFor = 0; + TreeItem* item = static_cast<TreeItem*>(index.internalPointer()); + mRootItem->removeChild(item); + delete item; + return; } Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h 2010-03-15 19:02:05 UTC (rev 158) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h 2010-03-16 00:16:31 UTC (rev 159) @@ -22,6 +22,7 @@ #include <QWidget> class QItemSelection; +class TreeItem; class WaitFor; namespace Ui { @@ -81,6 +82,13 @@ WaitFor* mCurrentWaitFor; /** + * The root tree item in the tree view. + * It provides the header in the tree view, and acts as parent item for the + * tree item that represents mWaitFor. + */ + TreeItem* mRootItem; + + /** * The Ui Designer generated class. */ Ui::WaitForWidget* ui; @@ -113,7 +121,10 @@ /** * Shows a dialog with a NewWaitForWidget and adds the new WaitFor. * The WaitFor is added to the selected WaitFor, or as the root WaitFor if - * there is none. + * there is none (a new WaitForTreeItem is also added in that case). + * + * When a WaitFor is added the selection doesn't change, so some buttons are + * updated as needed. */ void addWaitFor(); @@ -124,6 +135,8 @@ /** * Removes the selected WaitFor. + * If the root WaitFor is removed, its tree item is also removed from the + * root item. */ void removeWaitFor(); Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp 2010-03-15 19:02:05 UTC (rev 158) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp 2010-03-16 00:16:31 UTC (rev 159) @@ -36,6 +36,7 @@ public slots: void addWaitForSignal() const; + void cancelAddWaitForDialog() const; void setSignalData() const; @@ -57,6 +58,7 @@ void testAddWaitForWhenEmpty(); void testAddWaitForToWaitForComposed(); void testAddWaitForToWaitForNot(); + void testAddWaitForCancellingDialog(); void testEditWaitForSignal(); @@ -189,6 +191,9 @@ QVERIFY(mWidget->waitFor()); QVERIFY(qobject_cast<WaitForSignal*>(mWidget->waitFor())); + QVERIFY(getIndex(0).isValid()); + //No item is selected after adding the WaitFor + assertButtonEnabled(false, false, false); delete mWidget->waitFor(); } @@ -235,8 +240,28 @@ QCOMPARE(mWaitFor->waitFors()[2], mWaitFor3); QCOMPARE(mWaitFor->waitFors()[3], mWaitFor4); QVERIFY(qobject_cast<WaitForSignal*>(mWaitFor4->negatedWaitFor())); + //The WaitForNot item is selected after adding the negated WaitFor, so "Add" + //button must be disabled + assertButtonEnabled(false, false, true); } +void WaitForWidgetTest::testAddWaitForCancellingDialog() { + delete mWidget; + mWidget = new WaitForWidget(0); + + //The dialog is modal, so it won't return to the test code until it is + //closed. Thus, the commands to execute on the dialog must be "queued", + //as calling cancelAddWaitForDialog after the button click won't work. + QTimer::singleShot(500, this, SLOT(cancelAddWaitForDialog())); + + button("addButton")->click(); + + QVERIFY(!mWidget->waitFor()); + QVERIFY(!getIndex(0).isValid()); + //Buttons shouldn't change after cancelling the dialog + assertButtonEnabled(true, false, false); +} + void WaitForWidgetTest::testEditWaitForSignal() { selectItem(getIndex(0, getIndex(0))); @@ -260,6 +285,8 @@ button("removeButton")->click(); QVERIFY(!mWidget->waitFor()); + QVERIFY(!getIndex(0).isValid()); + assertButtonEnabled(true, false, false); } void WaitForWidgetTest::testRemoveWaitForFromWaitForComposed() { @@ -296,6 +323,12 @@ dialog->button(KDialog::Ok)->click(); } +void WaitForWidgetTest::cancelAddWaitForDialog() const { + KDialog* dialog = mWidget->findChild<KDialog*>("addWaitForDialog"); + QVERIFY(dialog); + dialog->button(KDialog::Cancel)->click(); +} + void WaitForWidgetTest::setSignalData() const { KLineEdit* emitterNameLineEdit = mWidget->findChild<KLineEdit*>("emitterNameLineEdit"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-15 19:02:12
|
Revision: 158 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=158&view=rev Author: danxuliu Date: 2010-03-15 19:02:05 +0000 (Mon, 15 Mar 2010) Log Message: ----------- Include a list of Reactions in Step, and adapt StepTreeItem to show them. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/Step.cpp trunk/ktutorial/ktutorial-editor/src/Step.h trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h trunk/ktutorial/ktutorial-editor/tests/unit/StepTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/Step.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/Step.cpp 2010-03-15 18:58:22 UTC (rev 157) +++ trunk/ktutorial/ktutorial-editor/src/Step.cpp 2010-03-15 19:02:05 UTC (rev 158) @@ -17,12 +17,17 @@ ***************************************************************************/ #include "Step.h" +#include "Reaction.h" //public: Step::Step(QObject* parent): QObject(parent) { } +Step::~Step() { + qDeleteAll(mReactions); +} + QString Step::id() const { return mId; } @@ -62,3 +67,23 @@ emit dataChanged(this); } + +void Step::addReaction(Reaction* reaction) { + Q_ASSERT(!mReactions.contains(reaction)); + + mReactions.append(reaction); + + emit reactionAdded(reaction); +} + +QList<Reaction*> Step::reactions() const { + return mReactions; +} + +void Step::removeReaction(Reaction* reaction) { + Q_ASSERT(mReactions.contains(reaction)); + + mReactions.removeOne(reaction); + + emit reactionRemoved(reaction); +} Modified: trunk/ktutorial/ktutorial-editor/src/Step.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/Step.h 2010-03-15 18:58:22 UTC (rev 157) +++ trunk/ktutorial/ktutorial-editor/src/Step.h 2010-03-15 19:02:05 UTC (rev 158) @@ -21,13 +21,17 @@ #include <QObject> +class Reaction; + /** * Container for step data. * It stores the data used in KTutorial steps, but it has nothing to do with * them (they don't even know each other). Its purpose is store the data needed to * generate the code to create a true KTutorial::Step. * - * When any attribute is modified, dataChanged(Step*) signal is emitted. + * When any attribute is modified, dataChanged(Step*) signal is emitted. When + * reactions are added or removed, reactionAdded(Reaction*) and + * reactionRemoved(Reaction*) are emitted. */ class Step: public QObject { Q_OBJECT @@ -35,6 +39,11 @@ Step(QObject* parent = 0); + /** + * Destroys this Step and all its reactions. + */ + virtual ~Step(); + QString id() const; void setId(const QString& id); @@ -47,6 +56,24 @@ QString customTearDownCode() const; void setCustomTearDownCode(const QString& code); + /** + * Adds a new reaction to this Step. + * The Step gets ownership of the Reaction, so it is deleted when the + * Step is deleted. + * + * @param reaction The reaction to add. + */ + void addReaction(Reaction* reaction); + QList<Reaction*> reactions() const; + + /** + * Removes a reaction from this Step. + * The Reaction must be deleted explicitly. + * + * @param reaction The reaction to remove. + */ + void removeReaction(Reaction* reaction); + Q_SIGNALS: /** @@ -56,12 +83,27 @@ */ void dataChanged(Step* step); + /** + * Emitted when the reaction is added to this Step. + * + * @param reaction The reaction added. + */ + void reactionAdded(Reaction* reaction); + + /** + * Emitted when the reaction is removed from this Step. + * + * @param reaction The reaction removed. + */ + void reactionRemoved(Reaction* reaction); + private: QString mId; QString mText; QString mCustomSetupCode; QString mCustomTearDownCode; + QList<Reaction*> mReactions; }; Modified: trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-15 18:58:22 UTC (rev 157) +++ trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-15 19:02:05 UTC (rev 158) @@ -20,6 +20,7 @@ #include <KLocalizedString> +#include "ReactionTreeItem.h" #include "TextTreeItem.h" #include "TreeItemUtil.h" #include "../Step.h" @@ -38,6 +39,14 @@ update(step); connect(step, SIGNAL(dataChanged(Step*)), this, SLOT(update(Step*))); + + foreach(Reaction* reaction, step->reactions()) { + addReaction(reaction); + } + connect(step, SIGNAL(reactionAdded(Reaction*)), + this, SLOT(addReaction(Reaction*))); + connect(step, SIGNAL(reactionRemoved(Reaction*)), + this, SLOT(removeReaction(Reaction*))); } QString StepTreeItem::text() const { @@ -52,6 +61,19 @@ return mStep; } +//private: + +ReactionTreeItem* StepTreeItem::reactionTreeItemForReaction( + Reaction* reaction) const { + foreach (ReactionTreeItem* reactionTreeItem, mReactionTreeItems) { + if (reactionTreeItem->reaction() == reaction) { + return reactionTreeItem; + } + } + + return 0; +} + //private slots: void StepTreeItem::update(Step* step) { @@ -96,3 +118,17 @@ childIndex++; } } + +void StepTreeItem::addReaction(Reaction* reaction) { + ReactionTreeItem* reactionTreeItem = new ReactionTreeItem(reaction, this); + appendChild(reactionTreeItem); + mReactionTreeItems.append(reactionTreeItem); +} + +void StepTreeItem::removeReaction(Reaction* reaction) { + ReactionTreeItem* reactionTreeItem = reactionTreeItemForReaction(reaction); + + removeChild(reactionTreeItem); + mReactionTreeItems.removeOne(reactionTreeItem); + delete reactionTreeItem; +} Modified: trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h 2010-03-15 18:58:22 UTC (rev 157) +++ trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h 2010-03-15 19:02:05 UTC (rev 158) @@ -21,6 +21,8 @@ #include "TreeItem.h" +class Reaction; +class ReactionTreeItem; class Step; class TextTreeItem; @@ -32,7 +34,12 @@ * |-Setup: * | -The custom setup code * --Tear down: - * -The custom tear down code + * | -The custom tear down code + * |-Reaction + * | ... + * |-Reaction + * | ... + * ... * * The items only appear if they have some data to show. For example, if only * the text of the Step is set, its representation is: @@ -48,6 +55,8 @@ * Also note that the order of the child elements is always the same. Even if, * for example, the setup code is set first and then the text, the text item * will appear first and then the setup code item. + * + * @see ReactionTreeItem */ class StepTreeItem: public TreeItem { Q_OBJECT @@ -108,6 +117,19 @@ */ TextTreeItem* mTearDownItem; + /** + * The ReactionTreeItems for each Reaction in the Step. + */ + QList<ReactionTreeItem*> mReactionTreeItems; + + /** + * Returns the ReactionTreeItem for the given Reaction. + * + * @param reaction The Reaction to get its ReactionTreeItem. + * @return The ReactionTreeItem. + */ + ReactionTreeItem* reactionTreeItemForReaction(Reaction* reaction) const; + private Q_SLOTS: /** @@ -122,6 +144,20 @@ */ void update(Step* step); + /** + * Adds a new ReactionTreeItem when a Reaction is added in the step. + * + * @param step The Reaction added in the Step. + */ + void addReaction(Reaction* reaction); + + /** + * Removes the ReactionTreeItem for the Reaction removed in the step. + * + * @param reaction The Reaction removed in the Step. + */ + void removeReaction(Reaction* reaction); + }; #endif Modified: trunk/ktutorial/ktutorial-editor/tests/unit/StepTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/StepTest.cpp 2010-03-15 18:58:22 UTC (rev 157) +++ trunk/ktutorial/ktutorial-editor/tests/unit/StepTest.cpp 2010-03-15 19:02:05 UTC (rev 158) @@ -19,12 +19,15 @@ #include <QtTest> #include "Step.h" +#include "Reaction.h" class StepTest: public QObject { Q_OBJECT private slots: + void initTestCase(); + void testConstructor(); void testSetId(); @@ -35,8 +38,22 @@ void testSetCustomTearDownCode(); + void testAddReaction(); + void testRemoveReaction(); + +private: + + int mReactionStarType; + + void assertReactionSignal(const QSignalSpy& spy, int index, + Reaction* reaction) const; }; +void StepTest::initTestCase() { + //Reaction* must be registered in order to be used with QSignalSpy + mReactionStarType = qRegisterMetaType<Reaction*>("Reaction*"); +} + void StepTest::testConstructor() { QObject parent; Step* step = new Step(&parent); @@ -111,6 +128,74 @@ QCOMPARE(qvariant_cast<Step*>(argument), &step); } +void StepTest::testAddReaction() { + Step step; + Reaction* reaction1 = new Reaction(); + Reaction* reaction2 = new Reaction(); + Reaction* reaction3 = new Reaction(); + + QSignalSpy reactionAddedSpy(&step, SIGNAL(reactionAdded(Reaction*))); + + step.addReaction(reaction1); + step.addReaction(reaction2); + step.addReaction(reaction3); + + QCOMPARE(step.reactions().count(), 3); + QCOMPARE(step.reactions()[0], reaction1); + QCOMPARE(step.reactions()[1], reaction2); + QCOMPARE(step.reactions()[2], reaction3); + QCOMPARE(reactionAddedSpy.count(), 3); + assertReactionSignal(reactionAddedSpy, 0, reaction1); + assertReactionSignal(reactionAddedSpy, 1, reaction2); + assertReactionSignal(reactionAddedSpy, 2, reaction3); +} + +void StepTest::testRemoveReaction() { + Step step; + + //They will be removed and not deleted by the Step, so they are created in + //stack + Reaction reaction1; + Reaction reaction2; + Reaction reaction3; + + step.addReaction(&reaction1); + step.addReaction(&reaction2); + step.addReaction(&reaction3); + + QSignalSpy reactionRemovedSpy(&step, SIGNAL(reactionRemoved(Reaction*))); + + step.removeReaction(&reaction2); + + QCOMPARE(step.reactions().count(), 2); + QCOMPARE(step.reactions()[0], &reaction1); + QCOMPARE(step.reactions()[1], &reaction3); + QCOMPARE(reactionRemovedSpy.count(), 1); + assertReactionSignal(reactionRemovedSpy, 0, &reaction2); + + step.removeReaction(&reaction1); + step.removeReaction(&reaction3); + + QCOMPARE(step.reactions().count(), 0); + QCOMPARE(reactionRemovedSpy.count(), 3); + assertReactionSignal(reactionRemovedSpy, 1, &reaction1); + assertReactionSignal(reactionRemovedSpy, 2, &reaction3); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +//Reaction* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(Reaction*); + +void StepTest::assertReactionSignal(const QSignalSpy& spy, int index, + Reaction* reaction) const { + QCOMPARE(spy.at(index).count(), 1); + + QVariant argument = spy.at(index).at(0); + QCOMPARE(argument.userType(), mReactionStarType); + QCOMPARE(qvariant_cast<Reaction*>(argument), reaction); +} + QTEST_MAIN(StepTest) #include "StepTest.moc" Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp 2010-03-15 18:58:22 UTC (rev 157) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp 2010-03-15 19:02:05 UTC (rev 158) @@ -22,7 +22,9 @@ #include <KLocalizedString> +#include "ReactionTreeItem.h" #include "../Step.h" +#include "../Reaction.h" class StepTreeItemTest: public QObject { Q_OBJECT @@ -50,6 +52,10 @@ void testStepSetCustomTearDownCodeChange(); void testStepSetCustomTearDownCodeEmpty(); + void testStepAddReaction(); + + void testStepRemoveReaction(); + void testChildOrderWhenSettingDataInStep(); void testChildOrderWhenUnsettingDataInStep(); @@ -61,6 +67,7 @@ void assertCustomSetupCode(TreeItem* setupItem, const QString& code) const; void assertCustomTearDownCode(TreeItem* tearDownItem, const QString& code) const; + void assertReaction(TreeItem* reactionItem, const Reaction* reaction) const; void assertDataChanged(const QSignalSpy& spy, int index, TreeItem* item) const; @@ -98,16 +105,24 @@ step.setCustomSetupCode("The setup code"); step.setCustomTearDownCode("The tear down code"); + Reaction* reaction1 = new Reaction(); + step.addReaction(reaction1); + + Reaction* reaction2 = new Reaction(); + step.addReaction(reaction2); + StubTreeItem parent; StepTreeItem item(&step, &parent); QCOMPARE(item.parent(), &parent); QCOMPARE(item.text(), i18nc("@item", "Step %1", "The id")); QCOMPARE(item.step(), &step); - QCOMPARE(item.childCount(), 3); + QCOMPARE(item.childCount(), 5); assertText(item.child(0), "The text"); assertCustomSetupCode(item.child(1), "The setup code"); assertCustomTearDownCode(item.child(2), "The tear down code"); + assertReaction(item.child(3), reaction1); + assertReaction(item.child(4), reaction2); } //TreeItem* must be declared as a metatype to be used in qvariant_cast @@ -271,6 +286,30 @@ QCOMPARE(item.childCount(), 0); } +void StepTreeItemTest::testStepAddReaction() { + Step step; + StepTreeItem item(&step); + + Reaction* reaction = new Reaction(); + step.addReaction(reaction); + + QCOMPARE(item.childCount(), 1); + assertReaction(item.child(0), reaction); +} + +void StepTreeItemTest::testStepRemoveReaction() { + Step step; + StepTreeItem item(&step); + + //It will be removed and not deleted by the Step, so it is created in + //stack + Reaction reaction; + step.addReaction(&reaction); + step.removeReaction(&reaction); + + QCOMPARE(item.childCount(), 0); +} + void StepTreeItemTest::testChildOrderWhenSettingDataInStep() { Step step; StepTreeItem item(&step); @@ -288,21 +327,44 @@ assertText(item.child(0), "The text"); assertCustomSetupCode(item.child(1), "The setup code"); - step.setCustomTearDownCode("The tear down code"); + Reaction* reaction1 = new Reaction(); + step.addReaction(reaction1); QCOMPARE(item.text(), i18nc("@item", "Step")); QCOMPARE(item.childCount(), 3); assertText(item.child(0), "The text"); assertCustomSetupCode(item.child(1), "The setup code"); + assertReaction(item.child(2), reaction1); + + step.setCustomTearDownCode("The tear down code"); + + QCOMPARE(item.text(), i18nc("@item", "Step")); + QCOMPARE(item.childCount(), 4); + assertText(item.child(0), "The text"); + assertCustomSetupCode(item.child(1), "The setup code"); assertCustomTearDownCode(item.child(2), "The tear down code"); + assertReaction(item.child(3), reaction1); + Reaction* reaction2 = new Reaction(); + step.addReaction(reaction2); + + QCOMPARE(item.text(), i18nc("@item", "Step")); + QCOMPARE(item.childCount(), 5); + assertText(item.child(0), "The text"); + assertCustomSetupCode(item.child(1), "The setup code"); + assertCustomTearDownCode(item.child(2), "The tear down code"); + assertReaction(item.child(3), reaction1); + assertReaction(item.child(4), reaction2); + step.setId("The id"); QCOMPARE(item.text(), i18nc("@item", "Step %1", "The id")); - QCOMPARE(item.childCount(), 3); + QCOMPARE(item.childCount(), 5); assertText(item.child(0), "The text"); assertCustomSetupCode(item.child(1), "The setup code"); assertCustomTearDownCode(item.child(2), "The tear down code"); + assertReaction(item.child(3), reaction1); + assertReaction(item.child(4), reaction2); } void StepTreeItemTest::testChildOrderWhenUnsettingDataInStep() { @@ -312,30 +374,54 @@ step.setCustomSetupCode("The setup code"); step.setCustomTearDownCode("The tear down code"); + Reaction reaction1; + step.addReaction(&reaction1); + + Reaction reaction2; + step.addReaction(&reaction2); + StepTreeItem item(&step); step.setText(""); QCOMPARE(item.text(), i18nc("@item", "Step %1", "The id")); - QCOMPARE(item.childCount(), 2); + QCOMPARE(item.childCount(), 4); assertCustomSetupCode(item.child(0), "The setup code"); assertCustomTearDownCode(item.child(1), "The tear down code"); + assertReaction(item.child(2), &reaction1); + assertReaction(item.child(3), &reaction2); + step.removeReaction(&reaction1); + + QCOMPARE(item.text(), i18nc("@item", "Step %1", "The id")); + QCOMPARE(item.childCount(), 3); + assertCustomSetupCode(item.child(0), "The setup code"); + assertCustomTearDownCode(item.child(1), "The tear down code"); + assertReaction(item.child(2), &reaction2); + step.setCustomTearDownCode(""); QCOMPARE(item.text(), i18nc("@item", "Step %1", "The id")); - QCOMPARE(item.childCount(), 1); + QCOMPARE(item.childCount(), 2); assertCustomSetupCode(item.child(0), "The setup code"); + assertReaction(item.child(1), &reaction2); step.setId(""); QCOMPARE(item.text(), i18nc("@item", "Step")); - QCOMPARE(item.childCount(), 1); + QCOMPARE(item.childCount(), 2); assertCustomSetupCode(item.child(0), "The setup code"); + assertReaction(item.child(1), &reaction2); step.setCustomSetupCode(""); QCOMPARE(item.text(), i18nc("@item", "Step")); + QCOMPARE(item.childCount(), 1); + assertReaction(item.child(0), &reaction2); + + step.removeReaction(&reaction2); + + QCOMPARE(item.text(), i18nc("@item", "Step")); QCOMPARE(item.childCount(), 0); } @@ -360,6 +446,13 @@ QCOMPARE(tearDownItem->child(0)->text(), i18nc("@item", code.toAscii())); } +void StepTreeItemTest::assertReaction(TreeItem* reactionItem, + const Reaction* reaction) const { + QVERIFY(qobject_cast<ReactionTreeItem*>(reactionItem)); + QCOMPARE(static_cast<ReactionTreeItem*>(reactionItem)->reaction(), + reaction); +} + void StepTreeItemTest::assertDataChanged(const QSignalSpy& spy, int index, TreeItem* item) const { QCOMPARE(spy.at(index).count(), 1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-15 18:58:31
|
Revision: 157 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=157&view=rev Author: danxuliu Date: 2010-03-15 18:58:22 +0000 (Mon, 15 Mar 2010) Log Message: ----------- Remove "Steps" item that contained all the steps in a tutorial in its tree model. Now steps hang directly from the tutorial, as the intermediate item wasn't really useful. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-15 09:06:46 UTC (rev 156) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-15 18:58:22 UTC (rev 157) @@ -135,33 +135,15 @@ } void TutorialTreeItem::addStep(Step* step) { - TreeItem* rootStepItem; - - if (mStepTreeItems.isEmpty()) { - TextTreeItem* textRootStepItem = new TextTreeItem(this); - textRootStepItem->setText(i18nc("@item", "Steps:")); - appendChild(textRootStepItem); - - rootStepItem = textRootStepItem; - } else { - rootStepItem = mStepTreeItems.at(0)->parent(); - } - - StepTreeItem* stepTreeItem = new StepTreeItem(step, rootStepItem); - rootStepItem->appendChild(stepTreeItem); + StepTreeItem* stepTreeItem = new StepTreeItem(step, this); + appendChild(stepTreeItem); mStepTreeItems.append(stepTreeItem); } void TutorialTreeItem::removeStep(Step* step) { StepTreeItem* stepTreeItem = stepTreeItemForStep(step); - TreeItem* rootStepItem = stepTreeItem->parent(); - rootStepItem->removeChild(stepTreeItem); + removeChild(stepTreeItem); mStepTreeItems.removeOne(stepTreeItem); delete stepTreeItem; - - if (mStepTreeItems.isEmpty()) { - removeChild(rootStepItem); - delete rootStepItem; - } } Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h 2010-03-15 09:06:46 UTC (rev 156) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h 2010-03-15 18:58:22 UTC (rev 157) @@ -38,12 +38,11 @@ * | -The custom setup code * |-Tear down: * | -The custom tear down code - * --Steps: - * -Step first step added - * ... - * -Step second step added - * ... - * ... + * |-Step first step added + * | ... + * |-Step second step added + * | ... + * ... * * The items only appear if they have some data to show. For example, if only * the name of the Tutorial is set, its representation is: @@ -150,7 +149,6 @@ /** * Adds a new StepTreeItem when a Step is added in the tutorial. - * If there were no other steps yet, the parent "Steps:" item is also added. * * @param step The Step added in the Tutorial. */ @@ -158,7 +156,6 @@ /** * Removes the StepTreeItem for the Step removed in the tutorial. - * If there are no other steps, the parent "Steps:" item is also removed. * * @param step The Step removed in the Tutorial. */ Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp 2010-03-15 09:06:46 UTC (rev 156) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp 2010-03-15 18:58:22 UTC (rev 157) @@ -75,8 +75,7 @@ void assertCustomSetupCode(TreeItem* setupItem, const QString& code) const; void assertCustomTearDownCode(TreeItem* tearDownItem, const QString& code) const; - void assertStep(TreeItem* rootStepItem, int index, - const QString& stepId) const; + void assertStep(TreeItem* stepItem, const QString& stepId) const; void assertDataChanged(const QSignalSpy& spy, int index, TreeItem* item) const; @@ -127,15 +126,14 @@ QCOMPARE(item.parent(), &parent); QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName")); - QCOMPARE(item.childCount(), 6); + QCOMPARE(item.childCount(), 7); assertName(item.child(0), "The name"); assertDescription(item.child(1), "The description"); assertLicenseText(item.child(2), "The license text"); assertCustomSetupCode(item.child(3), "The setup code"); assertCustomTearDownCode(item.child(4), "The tear down code"); - QCOMPARE(item.child(5)->childCount(), 2); - assertStep(item.child(5), 0, "First step"); - assertStep(item.child(5), 1, "Second step"); + assertStep(item.child(5), "First step"); + assertStep(item.child(6), "Second step"); } //TreeItem* must be declared as a metatype to be used in qvariant_cast @@ -350,7 +348,7 @@ tutorial.addStep(step); QCOMPARE(item.childCount(), 1); - assertStep(item.child(0), 0, "Step id"); + assertStep(item.child(0), "Step id"); } void TutorialTreeItemTest::testTutorialRemoveStep() { @@ -401,8 +399,7 @@ assertDescription(item.child(0), "The description"); assertCustomSetupCode(item.child(1), "The setup code"); assertCustomTearDownCode(item.child(2), "The tear down code"); - QCOMPARE(item.child(3)->childCount(), 1); - assertStep(item.child(3), 0, "First step"); + assertStep(item.child(3), "First step"); tutorial.setName("The name"); @@ -412,35 +409,32 @@ assertDescription(item.child(1), "The description"); assertCustomSetupCode(item.child(2), "The setup code"); assertCustomTearDownCode(item.child(3), "The tear down code"); - QCOMPARE(item.child(4)->childCount(), 1); - assertStep(item.child(4), 0, "First step"); + assertStep(item.child(4), "First step"); Step* step2 = new Step(); step2->setId("Second step"); tutorial.addStep(step2); QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName")); - QCOMPARE(item.childCount(), 5); + QCOMPARE(item.childCount(), 6); assertName(item.child(0), "The name"); assertDescription(item.child(1), "The description"); assertCustomSetupCode(item.child(2), "The setup code"); assertCustomTearDownCode(item.child(3), "The tear down code"); - QCOMPARE(item.child(4)->childCount(), 2); - assertStep(item.child(4), 0, "First step"); - assertStep(item.child(4), 1, "Second step"); + assertStep(item.child(4), "First step"); + assertStep(item.child(5), "Second step"); tutorial.setLicenseText("The license text"); QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName")); - QCOMPARE(item.childCount(), 6); + QCOMPARE(item.childCount(), 7); assertName(item.child(0), "The name"); assertDescription(item.child(1), "The description"); assertLicenseText(item.child(2), "The license text"); assertCustomSetupCode(item.child(3), "The setup code"); assertCustomTearDownCode(item.child(4), "The tear down code"); - QCOMPARE(item.child(5)->childCount(), 2); - assertStep(item.child(5), 0, "First step"); - assertStep(item.child(5), 1, "Second step"); + assertStep(item.child(5), "First step"); + assertStep(item.child(6), "Second step"); } void TutorialTreeItemTest::testChildOrderWhenUnsettingDataInTutorial() { @@ -466,25 +460,23 @@ tutorial.setLicenseText(""); QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName")); - QCOMPARE(item.childCount(), 5); + QCOMPARE(item.childCount(), 6); assertName(item.child(0), "The name"); assertDescription(item.child(1), "The description"); assertCustomSetupCode(item.child(2), "The setup code"); assertCustomTearDownCode(item.child(3), "The tear down code"); - QCOMPARE(item.child(4)->childCount(), 2); - assertStep(item.child(4), 0, "First step"); - assertStep(item.child(4), 1, "Second step"); + assertStep(item.child(4), "First step"); + assertStep(item.child(5), "Second step"); tutorial.setName(""); QCOMPARE(item.text(), i18nc("@item", "Tutorial")); - QCOMPARE(item.childCount(), 4); + QCOMPARE(item.childCount(), 5); assertDescription(item.child(0), "The description"); assertCustomSetupCode(item.child(1), "The setup code"); assertCustomTearDownCode(item.child(2), "The tear down code"); - QCOMPARE(item.child(3)->childCount(), 2); - assertStep(item.child(3), 0, "First step"); - assertStep(item.child(3), 1, "Second step"); + assertStep(item.child(3), "First step"); + assertStep(item.child(4), "Second step"); tutorial.removeStep(&step1); @@ -493,8 +485,7 @@ assertDescription(item.child(0), "The description"); assertCustomSetupCode(item.child(1), "The setup code"); assertCustomTearDownCode(item.child(2), "The tear down code"); - QCOMPARE(item.child(3)->childCount(), 1); - assertStep(item.child(3), 0, "Second step"); + assertStep(item.child(3), "Second step"); tutorial.setCustomTearDownCode(""); @@ -502,23 +493,20 @@ QCOMPARE(item.childCount(), 3); assertDescription(item.child(0), "The description"); assertCustomSetupCode(item.child(1), "The setup code"); - QCOMPARE(item.child(2)->childCount(), 1); - assertStep(item.child(2), 0, "Second step"); + assertStep(item.child(2), "Second step"); tutorial.setDescription(""); QCOMPARE(item.text(), i18nc("@item", "Tutorial")); QCOMPARE(item.childCount(), 2); assertCustomSetupCode(item.child(0), "The setup code"); - QCOMPARE(item.child(1)->childCount(), 1); - assertStep(item.child(1), 0, "Second step"); + assertStep(item.child(1), "Second step"); tutorial.setCustomSetupCode(""); QCOMPARE(item.text(), i18nc("@item", "Tutorial")); QCOMPARE(item.childCount(), 1); - QCOMPARE(item.child(0)->childCount(), 1); - assertStep(item.child(0), 0, "Second step"); + assertStep(item.child(0), "Second step"); tutorial.removeStep(&step2); @@ -561,12 +549,10 @@ QCOMPARE(tearDownItem->child(0)->text(), i18nc("@item", code.toAscii())); } -void TutorialTreeItemTest::assertStep(TreeItem* rootStepItem, int index, +void TutorialTreeItemTest::assertStep(TreeItem* stepItem, const QString& stepId) const { - QCOMPARE(rootStepItem->text(), i18nc("@item", "Steps:")); - QVERIFY(qobject_cast<StepTreeItem*>(rootStepItem->child(index))); - QCOMPARE(rootStepItem->child(index)->text(), - i18nc("@item", "Step %1", stepId)); + QVERIFY(qobject_cast<StepTreeItem*>(stepItem)); + QCOMPARE(stepItem->text(), i18nc("@item", "Step %1", stepId)); } void TutorialTreeItemTest::assertDataChanged(const QSignalSpy& spy, int index, Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp 2010-03-15 09:06:46 UTC (rev 156) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeSelectionManagerTest.cpp 2010-03-15 18:58:22 UTC (rev 157) @@ -131,23 +131,21 @@ //Tear down select(mTreeModel->index(4, 0)); select(mTreeModel->index(0, 0, mTreeModel->index(4, 0))); - //Steps root - select(mTreeModel->index(5, 0)); QCOMPARE(mStepSelectedSpy->count(), 0); } void TutorialTreeSelectionManagerTest:: testSelectStepOrChildrenChangingToOtherItems() { - QModelIndex step1Index = mTreeModel->index(0, 0, mTreeModel->index(5, 0)); + QModelIndex step1Index = mTreeModel->index(5, 0); select(step1Index); QCOMPARE(mStepSelectedSpy->count(), 1); assertStepSignal(mStepSelectedSpy, 0, mStep1); - //Steps root - select(mTreeModel->index(5, 0)); + //Tutorial name + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 2); assertStepSignal(mStepSelectedSpy, 1, 0); @@ -158,7 +156,7 @@ QCOMPARE(mStepSelectedSpy->count(), 3); assertStepSignal(mStepSelectedSpy, 2, mStep1); - select(mTreeModel->index(5, 0)); + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 4); assertStepSignal(mStepSelectedSpy, 3, 0); @@ -169,7 +167,7 @@ QCOMPARE(mStepSelectedSpy->count(), 5); assertStepSignal(mStepSelectedSpy, 4, mStep1); - select(mTreeModel->index(5, 0)); + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 6); assertStepSignal(mStepSelectedSpy, 5, 0); @@ -180,7 +178,7 @@ QCOMPARE(mStepSelectedSpy->count(), 7); assertStepSignal(mStepSelectedSpy, 6, mStep1); - select(mTreeModel->index(5, 0)); + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 8); assertStepSignal(mStepSelectedSpy, 7, 0); @@ -191,7 +189,7 @@ QCOMPARE(mStepSelectedSpy->count(), 9); assertStepSignal(mStepSelectedSpy, 8, mStep1); - select(mTreeModel->index(5, 0)); + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 10); assertStepSignal(mStepSelectedSpy, 9, 0); @@ -202,7 +200,7 @@ QCOMPARE(mStepSelectedSpy->count(), 11); assertStepSignal(mStepSelectedSpy, 10, mStep1); - select(mTreeModel->index(5, 0)); + select(mTreeModel->index(0, 0)); QCOMPARE(mStepSelectedSpy->count(), 12); assertStepSignal(mStepSelectedSpy, 11, 0); @@ -210,7 +208,7 @@ void TutorialTreeSelectionManagerTest:: testSelectStepOrChildrenWithoutChangingStep() { - QModelIndex step1Index = mTreeModel->index(0, 0, mTreeModel->index(5, 0)); + QModelIndex step1Index = mTreeModel->index(5, 0); select(step1Index); @@ -245,8 +243,8 @@ void TutorialTreeSelectionManagerTest:: testSelectStepOrChildrenChangingToAnotherStep() { - QModelIndex step1Index = mTreeModel->index(0, 0, mTreeModel->index(5, 0)); - QModelIndex step2Index = mTreeModel->index(1, 0, mTreeModel->index(5, 0)); + QModelIndex step1Index = mTreeModel->index(5, 0); + QModelIndex step2Index = mTreeModel->index(6, 0); select(step1Index); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-15 09:06:55
|
Revision: 156 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=156&view=rev Author: danxuliu Date: 2010-03-15 09:06:46 +0000 (Mon, 15 Mar 2010) Log Message: ----------- Add ReactionWidget to edit reactions. 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/ReactionWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.h trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.ui trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-15 08:24:21 UTC (rev 155) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-15 09:06:46 UTC (rev 156) @@ -7,6 +7,7 @@ LicenseWidget.cpp NewWaitForWidget.cpp ReactionTreeItem.cpp + ReactionWidget.cpp StepCustomCodeWidget.cpp StepDataWidget.cpp StepTreeItem.cpp @@ -30,6 +31,7 @@ CustomCodeWidget.ui LicenseWidget.ui NewWaitForWidget.ui + ReactionWidget.ui StepDataWidget.ui TutorialInformationWidget.ui WaitForSignalWidget.ui Added: trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp 2010-03-15 09:06:46 UTC (rev 156) @@ -0,0 +1,157 @@ +/*************************************************************************** + * 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 "ReactionWidget.h" + +#include "ui_ReactionWidget.h" +#include "WaitForWidget.h" +#include "../Reaction.h" +#include "../WaitFor.h" + +//public: + +ReactionWidget::ReactionWidget(Reaction* reaction, QWidget* parent): + EditionWidget(parent), + mReaction(reaction), + mWaitForClone(0) { + + ui = new Ui::ReactionWidget(); + ui->setupUi(this); + + if (reaction->waitFor()) { + mWaitForClone = reaction->waitFor()->clone(); + } + + mWaitForWidget = new WaitForWidget(mWaitForClone, this); + mWaitForWidget->setObjectName("triggerConditionWaitForWidget"); + ui->triggerConditionVerticalLayout->addWidget(mWaitForWidget); + + connect(ui->triggerConditionRadioButton, SIGNAL(toggled(bool)), + this, SLOT(selectTriggerCondition(bool))); + connect(ui->triggerOptionRadioButton, SIGNAL(toggled(bool)), + this, SLOT(selectTriggerOption(bool))); + connect(ui->responseCodeRadioButton, SIGNAL(toggled(bool)), + this, SLOT(selectResponseCode(bool))); + connect(ui->responseStepRadioButton, SIGNAL(toggled(bool)), + this, SLOT(selectResponseStep(bool))); + + if (reaction->triggerType() == Reaction::ConditionMet) { + ui->triggerConditionRadioButton->setChecked(true); + } else { + ui->triggerOptionRadioButton->setChecked(true); + } + + if (reaction->responseType() == Reaction::CustomCode) { + ui->responseCodeRadioButton->setChecked(true); + } else { + ui->responseStepRadioButton->setChecked(true); + } + + ui->triggerOptionLineEdit->setText(reaction->optionName()); + ui->responseCodeTextEdit->setText(reaction->customCode()); + ui->responseStepLineEdit->setText(reaction->nextStepId()); +} + +ReactionWidget::~ReactionWidget() { + delete mWaitForClone; + delete ui; +} + +void ReactionWidget::saveChanges() { + if (mReaction->optionName() != ui->triggerOptionLineEdit->text()) { + mReaction->setOptionName(ui->triggerOptionLineEdit->text()); + } + + if (*mReaction->waitFor() != *mWaitForWidget->waitFor()) { + WaitFor* oldWaitFor = mReaction->waitFor(); + mReaction->setWaitFor(mWaitForWidget->waitFor()); + delete oldWaitFor; + + //Don't delete the cloned WaitFor when this ReactionWidget is deleted if + //it was set to the reaction + if (mWaitForClone == mReaction->waitFor()) { + mWaitForClone = 0; + } + } + + if (mReaction->customCode() != ui->responseCodeTextEdit->toPlainText()) { + mReaction->setCustomCode(ui->responseCodeTextEdit->toPlainText()); + } + + if (mReaction->nextStepId() != ui->responseStepLineEdit->text()) { + mReaction->setNextStepId(ui->responseStepLineEdit->text()); + } + + if (mReaction->triggerType() != Reaction::ConditionMet && + ui->triggerConditionRadioButton->isChecked()) { + mReaction->setTriggerType(Reaction::ConditionMet); + } + + if (mReaction->triggerType() != Reaction::OptionSelected && + ui->triggerOptionRadioButton->isChecked()) { + mReaction->setTriggerType(Reaction::OptionSelected); + } + + if (mReaction->responseType() != Reaction::CustomCode && + ui->responseCodeRadioButton->isChecked()) { + mReaction->setResponseType(Reaction::CustomCode); + } + + if (mReaction->responseType() != Reaction::NextStep && + ui->responseStepRadioButton->isChecked()) { + mReaction->setResponseType(Reaction::NextStep); + } +} + +//private slots: + +void ReactionWidget::selectTriggerCondition(bool checked) { + if (!checked) { + return; + } + + ui->triggerOptionLineEdit->setEnabled(false); + mWaitForWidget->setEnabled(true); +} + +void ReactionWidget::selectTriggerOption(bool checked) { + if (!checked) { + return; + } + + mWaitForWidget->setEnabled(false); + ui->triggerOptionLineEdit->setEnabled(true); +} + +void ReactionWidget::selectResponseStep(bool checked) { + if (!checked) { + return; + } + + ui->responseCodeTextEdit->setEnabled(false); + ui->responseStepLineEdit->setEnabled(true); +} + +void ReactionWidget::selectResponseCode(bool checked) { + if (!checked) { + return; + } + + ui->responseStepLineEdit->setEnabled(false); + ui->responseCodeTextEdit->setEnabled(true); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.h 2010-03-15 09:06:46 UTC (rev 156) @@ -0,0 +1,122 @@ +/*************************************************************************** + * 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 REACTIONWIDGET_H +#define REACTIONWIDGET_H + +#include <QPointer> + +#include "EditionWidget.h" + +class Reaction; +class WaitFor; +class WaitForWidget; + +namespace Ui { +class ReactionWidget; +} + +/** + * Edition widget for a Reaction. + */ +class ReactionWidget: public EditionWidget { +Q_OBJECT +public: + + /** + * Creates a new ReactionWidget for the given Reaction. + * + * @param reaction The reaction to edit. + * @param parent The parent QWidget. + */ + explicit ReactionWidget(Reaction* reaction, QWidget* parent = 0); + + /** + * Destroys this widget. + */ + virtual ~ReactionWidget(); + + /** + * Saves the data in the reaction. + */ + virtual void saveChanges(); + +private: + + /** + * The reaction to edit. + */ + Reaction* mReaction; + + /** + * The cloned WaitFor to be edited in the WaitForWidget. + * A cloned WaitFor instead of the one from the Reaction is used because + * working on it would modify it even if saveChanges() wasn't called. + * The pointer is automatically set to 0 if the object is deleted anywhere + * (that is, not by deleting this pointer, but another one pointing to the + * object). + */ + QPointer<WaitFor> mWaitForClone; + + /** + * The widget to edit the WaitFor. + */ + WaitForWidget* mWaitForWidget; + + /** + * The Ui Designer generated class. + */ + Ui::ReactionWidget* ui; + +private Q_SLOTS: + + /** + * When the condition radio button is selected, it enables and disables the + * appropriate widgets. + * + * @param checked Whether the radio button was checked or unchecked. + */ + void selectTriggerCondition(bool checked); + + /** + * When the option radio button is selected, it enables and disables the + * appropriate widgets. + * + * @param checked Whether the radio button was checked or unchecked. + */ + void selectTriggerOption(bool checked); + + /** + * When the custom code radio button is selected, it enables and disables + * the appropriate widgets. + * + * @param checked Whether the radio button was checked or unchecked. + */ + void selectResponseCode(bool checked); + + /** + * When the next step radio button is selected, it enables and disables the + * appropriate widgets. + * + * @param checked Whether the radio button was checked or unchecked. + */ + void selectResponseStep(bool checked); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.ui (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.ui 2010-03-15 09:06:46 UTC (rev 156) @@ -0,0 +1,123 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ReactionWidget</class> + <widget class="QWidget" name="ReactionWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string comment="@title">Edit reaction</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>Edit the response of a step to certain trigger.</para> +<para>When a step is active, the actions of the user can trigger a response in the tutorial. A trigger can be an option in the step selected by the user, or a condition that was met. The response can be changing to another step, or executing some custom code.</para></string> + </property> + <layout class="QVBoxLayout" name="reactionWidgetVerticalLayout"> + <item> + <widget class="QGroupBox" name="triggerGroupBox"> + <property name="title"> + <string comment="@title:group Something that causes a response">Trigger</string> + </property> + <layout class="QVBoxLayout" name="triggerGroupBoxVerticalLayout"> + <item> + <layout class="QHBoxLayout" name="triggerOptionHorizontalLayout"> + <item> + <widget class="QRadioButton" name="triggerOptionRadioButton"> + <property name="text"> + <string comment="@option:radio">Option:</string> + </property> + </widget> + </item> + <item> + <widget class="KLineEdit" name="triggerOptionLineEdit"> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>The name of the option.</para> +<para>An option with this name will be added to the step, so the same name set here will be shown to the user.</para></string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="triggerConditionVerticalLayout"> + <item> + <widget class="QRadioButton" name="triggerConditionRadioButton"> + <property name="text"> + <string comment="@option:radio">Condition met:</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="responseGroupBox"> + <property name="title"> + <string comment="@title:group">Response</string> + </property> + <layout class="QVBoxLayout" name="responseGroupBoxVerticalLayout"> + <item> + <layout class="QHBoxLayout" name="responseStepHorizontalLayout"> + <item> + <widget class="QRadioButton" name="responseStepRadioButton"> + <property name="text"> + <string comment="@option:radio">Change to step:</string> + </property> + </widget> + </item> + <item> + <widget class="KLineEdit" name="responseStepLineEdit"> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>The id of the step to change to.</para></string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="responseCodeVerticalLayout"> + <item> + <widget class="QRadioButton" name="responseCodeRadioButton"> + <property name="text"> + <string comment="@option:radio">Custom response code:</string> + </property> + </widget> + </item> + <item> + <widget class="KTextEdit" name="responseCodeTextEdit"> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>The custom code to execute.</para> +<para>The code will be written as is into a new function called when the response is triggered. This means that the code must be written in the same programming language the tutorial will be exported to.</para> +<para>Also note that you only have to provide the body of the function. The signature is automatically generated.</para></string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>KLineEdit</class> + <extends>QLineEdit</extends> + <header>klineedit.h</header> + </customwidget> + <customwidget> + <class>KTextEdit</class> + <extends>QTextEdit</extends> + <header>ktextedit.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-15 08:24:21 UTC (rev 155) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-15 09:06:46 UTC (rev 156) @@ -22,6 +22,7 @@ LicenseWidget NewWaitForWidget ReactionTreeItem + ReactionWidget StepCustomCodeWidget StepDataWidget StepTreeItem @@ -53,6 +54,7 @@ LicenseWidget NewWaitForWidget ReactionTreeItem + ReactionWidget StepCustomCodeWidget StepDataWidget StepTreeItem Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp 2010-03-15 09:06:46 UTC (rev 156) @@ -0,0 +1,268 @@ +/*************************************************************************** + * 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 "ReactionWidget.h" + +#include <QRadioButton> +#include <QTreeView> + +#include <KComboBox> +#include <KDialog> +#include <KLineEdit> +#include <KPushButton> +#include <KTextEdit> + +#include "WaitForWidget.h" +#include "../WaitForComposed.h" +#include "../WaitForSignal.h" +#include "../Reaction.h" + +class ReactionWidgetTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testSelectTriggerTypeOption(); + void testSelectTriggerTypeCondition(); + + void testSelectResponseTypeStep(); + void testSelectResponseTypeCustomCode(); + + void testSaveChanges(); + +private: + + QRadioButton* triggerOptionRadioButton(ReactionWidget* widget) const; + KLineEdit* triggerOptionLineEdit(ReactionWidget* widget) const; + QRadioButton* triggerConditionRadioButton(ReactionWidget* widget) const; + WaitForWidget* triggerConditionWidget(ReactionWidget* widget) const; + QRadioButton* responseStepRadioButton(ReactionWidget* widget) const; + KLineEdit* responseStepLineEdit(ReactionWidget* widget) const; + QRadioButton* responseCodeRadioButton(ReactionWidget* widget) const; + KTextEdit* responseCodeTextEdit(ReactionWidget* widget) const; + + void addWaitForSignalToRootWaitFor(ReactionWidget* widget); + +}; + +void ReactionWidgetTest::testConstructor() { + WaitFor* waitFor = new WaitForSignal(); + Reaction reaction; + reaction.setTriggerType(Reaction::ConditionMet); + reaction.setWaitFor(waitFor); + reaction.setOptionName("The option name"); + reaction.setResponseType(Reaction::CustomCode); + reaction.setCustomCode("The custom code"); + reaction.setNextStepId("The step id"); + + QWidget parent; + ReactionWidget* widget = new ReactionWidget(&reaction, &parent); + + QCOMPARE(widget->parentWidget(), &parent); + QVERIFY(!triggerOptionRadioButton(widget)->isChecked()); + QVERIFY(!triggerOptionLineEdit(widget)->isEnabled()); + QCOMPARE(triggerOptionLineEdit(widget)->text(), QString("The option name")); + QVERIFY(triggerConditionRadioButton(widget)->isChecked()); + QVERIFY(triggerConditionWidget(widget)->isEnabled()); + QVERIFY(triggerConditionWidget(widget)->waitFor() != waitFor); + QVERIFY(*triggerConditionWidget(widget)->waitFor() == *waitFor); + QVERIFY(!responseStepRadioButton(widget)->isChecked()); + QVERIFY(!responseStepLineEdit(widget)->isEnabled()); + QCOMPARE(responseStepLineEdit(widget)->text(), QString("The step id")); + QVERIFY(responseCodeRadioButton(widget)->isChecked()); + QVERIFY(responseCodeTextEdit(widget)->isEnabled()); + QCOMPARE(responseCodeTextEdit(widget)->toPlainText(), + QString("The custom code")); +} + +void ReactionWidgetTest::testSelectTriggerTypeOption() { + Reaction reaction; + reaction.setTriggerType(Reaction::ConditionMet); + + ReactionWidget widget(&reaction); + + triggerOptionRadioButton(&widget)->setChecked(true); + + QVERIFY(!triggerConditionRadioButton(&widget)->isChecked()); + QVERIFY(!triggerConditionWidget(&widget)->isEnabled()); + QVERIFY(triggerOptionLineEdit(&widget)->isEnabled()); +} + +void ReactionWidgetTest::testSelectTriggerTypeCondition() { + Reaction reaction; + reaction.setTriggerType(Reaction::OptionSelected); + + ReactionWidget widget(&reaction); + + triggerConditionRadioButton(&widget)->setChecked(true); + + QVERIFY(!triggerOptionRadioButton(&widget)->isChecked()); + QVERIFY(!triggerOptionLineEdit(&widget)->isEnabled()); + QVERIFY(triggerConditionWidget(&widget)->isEnabled()); +} + +void ReactionWidgetTest::testSelectResponseTypeStep() { + Reaction reaction; + reaction.setResponseType(Reaction::CustomCode); + + ReactionWidget widget(&reaction); + + responseStepRadioButton(&widget)->setChecked(true); + + QVERIFY(!responseCodeRadioButton(&widget)->isChecked()); + QVERIFY(!responseCodeTextEdit(&widget)->isEnabled()); + QVERIFY(responseStepLineEdit(&widget)->isEnabled()); +} + +void ReactionWidgetTest::testSelectResponseTypeCustomCode() { + Reaction reaction; + reaction.setResponseType(Reaction::NextStep); + + ReactionWidget widget(&reaction); + + responseCodeRadioButton(&widget)->setChecked(true); + + QVERIFY(!responseStepRadioButton(&widget)->isChecked()); + QVERIFY(!responseStepLineEdit(&widget)->isEnabled()); + QVERIFY(responseCodeTextEdit(&widget)->isEnabled()); +} + +void ReactionWidgetTest::testSaveChanges() { + WaitFor* oldWaitFor = new WaitForComposed(); + Reaction reaction; + reaction.setTriggerType(Reaction::ConditionMet); + reaction.setResponseType(Reaction::CustomCode); + reaction.setWaitFor(oldWaitFor); + + ReactionWidget widget(&reaction); + + addWaitForSignalToRootWaitFor(&widget); + triggerOptionRadioButton(&widget)->setChecked(true); + triggerOptionLineEdit(&widget)->setText("The option name"); + + responseCodeTextEdit(&widget)->setText("The custom code"); + responseStepRadioButton(&widget)->setChecked(true); + responseStepLineEdit(&widget)->setText("The step id"); + + widget.saveChanges(); + + QCOMPARE(reaction.triggerType(), Reaction::OptionSelected); + QCOMPARE(reaction.optionName(), QString("The option name")); + QVERIFY(reaction.waitFor() != oldWaitFor); + WaitForComposed* waitFor = + qobject_cast<WaitForComposed*>(reaction.waitFor()); + QVERIFY(waitFor); + QCOMPARE(waitFor->waitFors().count(), 1); + QVERIFY(qobject_cast<WaitForSignal*>(waitFor->waitFors()[0])); + QCOMPARE(reaction.responseType(), Reaction::NextStep); + QCOMPARE(reaction.nextStepId(), QString("The step id")); + QCOMPARE(reaction.customCode(), QString("The custom code")); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +QRadioButton* ReactionWidgetTest::triggerOptionRadioButton( + ReactionWidget* widget) const { + return widget->findChild<QRadioButton*>("triggerOptionRadioButton"); +} + +KLineEdit* ReactionWidgetTest::triggerOptionLineEdit( + ReactionWidget* widget) const { + return widget->findChild<KLineEdit*>("triggerOptionLineEdit"); +} + +QRadioButton* ReactionWidgetTest::triggerConditionRadioButton( + ReactionWidget* widget) const { + return widget->findChild<QRadioButton*>("triggerConditionRadioButton"); +} + +WaitForWidget* ReactionWidgetTest::triggerConditionWidget( + ReactionWidget* widget) const { + return widget->findChild<WaitForWidget*>("triggerConditionWaitForWidget"); +} + +QRadioButton* ReactionWidgetTest::responseStepRadioButton( + ReactionWidget* widget) const { + return widget->findChild<QRadioButton*>("responseStepRadioButton"); +} + +KLineEdit* ReactionWidgetTest::responseStepLineEdit( + ReactionWidget* widget) const { + return widget->findChild<KLineEdit*>("responseStepLineEdit"); +} + +QRadioButton* ReactionWidgetTest::responseCodeRadioButton( + ReactionWidget* widget) const { + return widget->findChild<QRadioButton*>("responseCodeRadioButton"); +} + +KTextEdit* ReactionWidgetTest::responseCodeTextEdit( + ReactionWidget* widget) const { + return widget->findChild<KTextEdit*>("responseCodeTextEdit"); +} + +class AddWaitForSignalHelper: public QObject { +Q_OBJECT +public: + + AddWaitForSignalHelper(QWidget* widget, QObject* parent): + QObject(parent), + mWidget(widget) { + } + +public slots: + + void addWaitForSignal() const { + KComboBox* comboBox = + mWidget->findChild<KComboBox*>("waitForTypeComboBox"); + QVERIFY(comboBox); + comboBox->setCurrentIndex(3); + + KDialog* dialog = mWidget->findChild<KDialog*>("addWaitForDialog"); + QVERIFY(dialog); + dialog->button(KDialog::Ok)->click(); + } + +private: + + QWidget* mWidget; + +}; + +void ReactionWidgetTest::addWaitForSignalToRootWaitFor(ReactionWidget* widget) { + QTreeView* tree = widget->findChild<QTreeView*>("waitForTreeView"); + QModelIndex index = tree->model()->index(0, 0); + tree->selectionModel()->select(index, QItemSelectionModel::SelectCurrent); + + AddWaitForSignalHelper* helper = new AddWaitForSignalHelper(widget, this); + + //The dialog is modal, so it won't return to the test code until it is + //closed. Thus, the commands to execute on the dialog must be "queued", + //as calling addWaitForSignal after the button click won't work. + QTimer::singleShot(500, helper, SLOT(addWaitForSignal())); + + widget->findChild<KPushButton*>("addButton")->click(); +} + +QTEST_MAIN(ReactionWidgetTest) + +#include "ReactionWidgetTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.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-15 08:24:33
|
Revision: 155 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=155&view=rev Author: danxuliu Date: 2010-03-15 08:24:21 +0000 (Mon, 15 Mar 2010) Log Message: ----------- Ooops, these files were missed in commit 154. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/tests/unit/ReactionTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp Modified: trunk/ktutorial/ktutorial-editor/tests/unit/ReactionTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/ReactionTest.cpp 2010-03-15 06:56:15 UTC (rev 154) +++ trunk/ktutorial/ktutorial-editor/tests/unit/ReactionTest.cpp 2010-03-15 08:24:21 UTC (rev 155) @@ -55,6 +55,14 @@ Q_OBJECT public: + WaitFor* clone() const { + return 0; + } + + bool equals(const WaitFor& waitFor) const { + return false; + } + void emitDataChanged() { emit dataChanged(this); } Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp 2010-03-15 06:56:15 UTC (rev 154) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp 2010-03-15 08:24:21 UTC (rev 155) @@ -63,6 +63,15 @@ public: StubWaitFor(QObject* parent = 0): WaitFor(parent) { } + + virtual WaitFor* clone() const { + return 0; + } + + virtual bool equals(const WaitFor& waitFor) const { + Q_UNUSED(waitFor); + return false; + } }; void WaitForTreeItemTest::testConstructor() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-15 06:56:22
|
Revision: 154 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=154&view=rev Author: danxuliu Date: 2010-03-15 06:56:15 +0000 (Mon, 15 Mar 2010) Log Message: ----------- Add clone() and equals(const WaitFor&) methods to WaitFor and subclasses. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp trunk/ktutorial/ktutorial-editor/src/WaitFor.h trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp trunk/ktutorial/ktutorial-editor/src/WaitForNot.h trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp Added Paths: ----------- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp 2010-03-15 06:56:15 UTC (rev 154) @@ -22,3 +22,11 @@ WaitFor::WaitFor(QObject* parent): QObject(parent) { } + +bool WaitFor::operator==(const WaitFor& waitFor) const { + return equals(waitFor); +} + +bool WaitFor::operator!=(const WaitFor& waitFor) const { + return !equals(waitFor); +} Modified: trunk/ktutorial/ktutorial-editor/src/WaitFor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitFor.h 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/src/WaitFor.h 2010-03-15 06:56:15 UTC (rev 154) @@ -22,14 +22,19 @@ #include <QObject> /** - * Base class for conditions to wait for to be met. + * Abstract base class for conditions to wait for to be met. * Its subclasses store the data used in KTutorial wait for subclasses, but they * have nothing to do with them (they don't even know each others). Its purpose * is store the data needed to generate the code to initialize a true * KTutorial::WaitFor subclass object. * - * Subclasses must emit dataChanged(Step*) signal when their data is modified - * (including the data of child conditions). + * Subclass must implement clone() and equals(const WaitFor&) methods, which + * perform a deep copy and a comparison of the WaitFor. Operators == and != are + * provided for convenience in this base class and it isn't needed to define + * them in subclasses. + * + * Subclasses must also emit dataChanged(Step*) signal when their data is + * modified (including the data of child conditions). */ class WaitFor: public QObject { Q_OBJECT @@ -42,6 +47,49 @@ */ WaitFor(QObject* parent = 0); + /** + * Deep copy of this WaitFor. + * If this WaitFor has child WaitFor, they are also cloned in the returned + * WaitFor. + * + * Subclasses must implement this method. + * + * @return A deep copy of this WaitFor. + */ + virtual WaitFor* clone() const = 0; + + /** + * Deep comparison of this WaitFor to the given one. + * Two WaitFor are equal if they contain the same data and, if they contain + * child WaitFor, if their child WaitFor are equal one to one. The child + * WaitFor aren't checked for identity, but for equality (that is, it is + * checked if they are equal, no matter whether they are the same object or + * not). + * + * Subclasses must implement this method. + * + * @param waitFor The WaitFor to compare to. + * @return True if this WaitFor is equal to the given one, false otherwise. + */ + virtual bool equals(const WaitFor& waitFor) const = 0; + + /** + * Equality operator. + * + * @param waitFor The WaitFor to compare to. + * @return True if this WaitFor is equal to the given one, false otherwise. + */ + bool operator==(const WaitFor& waitFor) const; + + /** + * Inequality operator. + * + * @param waitFor The WaitFor to compare to. + * @return True if this WaitFor is not equal to the given one, false + * otherwise. + */ + bool operator!=(const WaitFor& waitFor) const; + Q_SIGNALS: /** Modified: trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp 2010-03-15 06:56:15 UTC (rev 154) @@ -29,6 +29,41 @@ qDeleteAll(mWaitFors); } +WaitFor* WaitForComposed::clone() const { + WaitForComposed* cloned = new WaitForComposed(); + cloned->setCompositionType(mCompositionType); + + foreach (WaitFor* waitFor, mWaitFors) { + cloned->addWaitFor(waitFor->clone()); + } + + return cloned; +} + +bool WaitForComposed::equals(const WaitFor& waitFor) const { + if (!qobject_cast<const WaitForComposed*>(&waitFor)) { + return false; + } + + const WaitForComposed* waitForComposed = + static_cast<const WaitForComposed*>(&waitFor); + if (waitForComposed->compositionType() != mCompositionType) { + return false; + } + + if (waitForComposed->waitFors().count() != mWaitFors.count()) { + return false; + } + + for (int i=0; i<mWaitFors.count(); ++i) { + if (*waitForComposed->waitFors()[i] != *mWaitFors[i]) { + return false; + } + } + + return true; +} + WaitForComposed::CompositionType WaitForComposed::compositionType() const { return mCompositionType; } Modified: trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h 2010-03-15 06:56:15 UTC (rev 154) @@ -49,6 +49,9 @@ WaitForComposed(QObject* parent = 0); virtual ~WaitForComposed(); + virtual WaitFor* clone() const; + virtual bool equals(const WaitFor& waitFor) const; + CompositionType compositionType() const; void setCompositionType(CompositionType compositionType); Modified: trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp 2010-03-15 06:56:15 UTC (rev 154) @@ -29,6 +29,36 @@ delete mNegatedWaitFor; } +WaitFor* WaitForNot::clone() const { + WaitForNot* cloned = new WaitForNot(); + if (mNegatedWaitFor) { + cloned->setNegatedWaitFor(mNegatedWaitFor->clone()); + } + + return cloned; +} + +bool WaitForNot::equals(const WaitFor& waitFor) const { + if (!qobject_cast<const WaitForNot*>(&waitFor)) { + return false; + } + + const WaitForNot* waitForNot = static_cast<const WaitForNot*>(&waitFor); + if (waitForNot->negatedWaitFor() == 0 && mNegatedWaitFor == 0) { + return true; + } + + if (waitForNot->negatedWaitFor() == 0 || mNegatedWaitFor == 0) { + return false; + } + + if (*waitForNot->negatedWaitFor() != *mNegatedWaitFor) { + return false; + } + + return true; +} + WaitFor* WaitForNot::negatedWaitFor() const { return mNegatedWaitFor; } Modified: trunk/ktutorial/ktutorial-editor/src/WaitForNot.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForNot.h 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/src/WaitForNot.h 2010-03-15 06:56:15 UTC (rev 154) @@ -43,6 +43,9 @@ WaitForNot(QObject* parent = 0); virtual ~WaitForNot(); + virtual WaitFor* clone() const; + virtual bool equals(const WaitFor& waitFor) const; + WaitFor* negatedWaitFor() const; /** Modified: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp 2010-03-15 06:56:15 UTC (rev 154) @@ -23,6 +23,32 @@ WaitForSignal::WaitForSignal(QObject* parent): WaitFor(parent) { } +WaitFor* WaitForSignal::clone() const { + WaitForSignal* cloned = new WaitForSignal(); + cloned->setEmitterName(mEmitterName); + cloned->setSignalName(mSignalName); + + return cloned; +} + +bool WaitForSignal::equals(const WaitFor& waitFor) const { + if (!qobject_cast<const WaitForSignal*>(&waitFor)) { + return false; + } + + const WaitForSignal* waitForSignal = + static_cast<const WaitForSignal*>(&waitFor); + if (waitForSignal->emitterName() != mEmitterName) { + return false; + } + + if (waitForSignal->signalName() != mSignalName) { + return false; + } + + return true; +} + QString WaitForSignal::emitterName() const { return mEmitterName; } Modified: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h 2010-03-15 06:56:15 UTC (rev 154) @@ -41,6 +41,9 @@ */ WaitForSignal(QObject* parent = 0); + virtual WaitFor* clone() const; + virtual bool equals(const WaitFor& waitFor) const; + QString emitterName() const; void setEmitterName(const QString& emitterName); Modified: trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-15 06:56:15 UTC (rev 154) @@ -18,6 +18,7 @@ Reaction Step Tutorial + WaitFor WaitForComposed WaitForNot WaitForSignal @@ -33,6 +34,7 @@ Reaction Step Tutorial + WaitFor WaitForComposed WaitForNot WaitForSignal Modified: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp 2010-03-15 06:56:15 UTC (rev 154) @@ -29,6 +29,11 @@ void testConstructor(); + void testClone(); + void testCloneEmpty(); + + void testEquals(); + void testSetCompositionType(); void testAddWaitFor(); @@ -43,6 +48,28 @@ }; +class StubWaitFor: public WaitFor { +Q_OBJECT +public: + + int mValue; + + StubWaitFor(int value = 0): mValue(value) { + } + + virtual WaitFor* clone() const { + return new StubWaitFor(mValue); + } + + virtual bool equals(const WaitFor& waitFor) const { + if (!qobject_cast<const StubWaitFor*>(&waitFor)) { + return false; + } + + return mValue == static_cast<const StubWaitFor*>(&waitFor)->mValue; + } +}; + void WaitForComposedTest::initTestCase() { //WaitFor* must be registered in order to be used with QSignalSpy mWaitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); @@ -56,6 +83,89 @@ QCOMPARE(waitForComposed->compositionType(), WaitForComposed::And); } +void WaitForComposedTest::testClone() { + WaitForComposed waitForComposed; + waitForComposed.setCompositionType(WaitForComposed::Or); + StubWaitFor* waitFor1 = new StubWaitFor(4); + waitForComposed.addWaitFor(waitFor1); + StubWaitFor* waitFor2 = new StubWaitFor(8); + waitForComposed.addWaitFor(waitFor2); + StubWaitFor* waitFor3 = new StubWaitFor(15); + waitForComposed.addWaitFor(waitFor3); + + WaitForComposed* cloned = + static_cast<WaitForComposed*>(waitForComposed.clone()); + + QVERIFY(cloned != &waitForComposed); + QCOMPARE(cloned->compositionType(), WaitForComposed::Or); + QCOMPARE(cloned->waitFors().count(), 3); + QVERIFY(cloned->waitFors()[0] != waitFor1); + QVERIFY(*cloned->waitFors()[0] == *waitFor1); + QVERIFY(cloned->waitFors()[1] != waitFor2); + QVERIFY(*cloned->waitFors()[1] == *waitFor2); + QVERIFY(cloned->waitFors()[2] != waitFor3); + QVERIFY(*cloned->waitFors()[2] == *waitFor3); + delete cloned; +} + +void WaitForComposedTest::testCloneEmpty() { + WaitForComposed waitForComposed; + waitForComposed.setCompositionType(WaitForComposed::Or); + + WaitForComposed* cloned = + static_cast<WaitForComposed*>(waitForComposed.clone()); + + QVERIFY(cloned != &waitForComposed); + QCOMPARE(cloned->compositionType(), WaitForComposed::Or); + QCOMPARE(cloned->waitFors().count(), 0); + delete cloned; +} + +void WaitForComposedTest::testEquals() { + WaitForComposed waitForComposed1; + WaitForComposed waitForComposed2; + + QCOMPARE(waitForComposed1 == waitForComposed2, true); + + waitForComposed1.setCompositionType(WaitForComposed::Or); + + QCOMPARE(waitForComposed1 == waitForComposed2, false); + QCOMPARE(waitForComposed2 == waitForComposed1, false); + + waitForComposed2.setCompositionType(WaitForComposed::Or); + + QCOMPARE(waitForComposed1 == waitForComposed2, true); + + StubWaitFor* waitFor1_1 = new StubWaitFor(4); + waitForComposed1.addWaitFor(waitFor1_1); + StubWaitFor* waitFor1_2 = new StubWaitFor(8); + waitForComposed1.addWaitFor(waitFor1_2); + StubWaitFor* waitFor1_3 = new StubWaitFor(15); + waitForComposed1.addWaitFor(waitFor1_3); + + QCOMPARE(waitForComposed1 == waitForComposed2, false); + QCOMPARE(waitForComposed2 == waitForComposed1, false); + + StubWaitFor* waitFor2_1 = new StubWaitFor(4); + waitForComposed2.addWaitFor(waitFor2_1); + StubWaitFor* waitFor2_2 = new StubWaitFor(8); + waitForComposed2.addWaitFor(waitFor2_2); + StubWaitFor* waitFor2_3 = new StubWaitFor(16); + waitForComposed2.addWaitFor(waitFor2_3); + + QCOMPARE(waitForComposed1 == waitForComposed2, false); + QCOMPARE(waitForComposed2 == waitForComposed1, false); + + waitFor2_3->mValue = 15; + + QCOMPARE(waitForComposed1 == waitForComposed2, true); + QCOMPARE(waitForComposed2 == waitForComposed1, true); + + StubWaitFor stubWaitFor; + + QCOMPARE(waitForComposed1 == stubWaitFor, false); +} + void WaitForComposedTest::testSetCompositionType() { WaitForComposed waitForComposed; @@ -70,9 +180,9 @@ void WaitForComposedTest::testAddWaitFor() { WaitForComposed waitForComposed; - WaitFor* waitFor1 = new WaitFor(); - WaitFor* waitFor2 = new WaitFor(); - WaitFor* waitFor3 = new WaitFor(); + WaitFor* waitFor1 = new StubWaitFor(); + WaitFor* waitFor2 = new StubWaitFor(); + WaitFor* waitFor3 = new StubWaitFor(); QSignalSpy waitForAddedSpy(&waitForComposed, SIGNAL(waitForAdded(WaitFor*))); @@ -96,9 +206,9 @@ //They will be removed and not deleted by the WaitForComposed, so they are //created in stack - WaitFor waitFor1; - WaitFor waitFor2; - WaitFor waitFor3; + StubWaitFor waitFor1; + StubWaitFor waitFor2; + StubWaitFor waitFor3; waitForComposed.addWaitFor(&waitFor1); waitForComposed.addWaitFor(&waitFor2); Modified: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp 2010-03-15 06:56:15 UTC (rev 154) @@ -27,10 +27,37 @@ void testConstructor(); + void testClone(); + void testCloneEmpty(); + + void testEquals(); + void testSetNegatedWaitFor(); }; +class StubWaitFor: public WaitFor { +Q_OBJECT +public: + + int mValue; + + StubWaitFor(int value = 0): mValue(value) { + } + + virtual WaitFor* clone() const { + return new StubWaitFor(mValue); + } + + virtual bool equals(const WaitFor& waitFor) const { + if (!qobject_cast<const StubWaitFor*>(&waitFor)) { + return false; + } + + return mValue == static_cast<const StubWaitFor*>(&waitFor)->mValue; + } +}; + void WaitForNotTest::testConstructor() { QObject parent; WaitForNot* waitForNot = new WaitForNot(&parent); @@ -39,12 +66,63 @@ QCOMPARE(waitForNot->negatedWaitFor(), (WaitFor*)0); } +void WaitForNotTest::testClone() { + WaitForNot waitForNot; + StubWaitFor* negatedWaitFor = new StubWaitFor(16); + waitForNot.setNegatedWaitFor(negatedWaitFor); + + WaitForNot* cloned = static_cast<WaitForNot*>(waitForNot.clone()); + + QVERIFY(cloned != &waitForNot); + QVERIFY(cloned->negatedWaitFor() != negatedWaitFor); + QVERIFY(*cloned->negatedWaitFor() == *negatedWaitFor); + delete cloned; +} + +void WaitForNotTest::testCloneEmpty() { + WaitForNot waitForNot; + + WaitForNot* cloned = static_cast<WaitForNot*>(waitForNot.clone()); + + QVERIFY(cloned != &waitForNot); + QCOMPARE(cloned->negatedWaitFor(), (WaitFor*)0); + delete cloned; +} + +void WaitForNotTest::testEquals() { + WaitForNot waitForNot1; + WaitForNot waitForNot2; + + QCOMPARE(waitForNot1 == waitForNot2, true); + + StubWaitFor* negatedWaitFor1 = new StubWaitFor(4); + waitForNot1.setNegatedWaitFor(negatedWaitFor1); + + QCOMPARE(waitForNot1 == waitForNot2, false); + QCOMPARE(waitForNot2 == waitForNot1, false); + + StubWaitFor* negatedWaitFor2 = new StubWaitFor(); + waitForNot2.setNegatedWaitFor(negatedWaitFor2); + + QCOMPARE(waitForNot1 == waitForNot2, false); + QCOMPARE(waitForNot2 == waitForNot1, false); + + negatedWaitFor2->mValue = 4; + + QCOMPARE(waitForNot1 == waitForNot2, true); + QCOMPARE(waitForNot2 == waitForNot1, true); + + StubWaitFor stubWaitFor; + + QCOMPARE(waitForNot1 == stubWaitFor, false); +} + //WaitFor* must be declared as a metatype to be used in qvariant_cast Q_DECLARE_METATYPE(WaitFor*); void WaitForNotTest::testSetNegatedWaitFor() { WaitForNot waitForNot; - WaitFor* negatedWaitFor = new WaitFor(); + WaitFor* negatedWaitFor = new StubWaitFor(); //WaitFor* must be registered in order to be used with QSignalSpy int waitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); Modified: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp 2010-03-14 17:15:38 UTC (rev 153) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp 2010-03-15 06:56:15 UTC (rev 154) @@ -29,6 +29,10 @@ void testConstructor(); + void testClone(); + + void testEquals(); + void testSetEmitterName(); void testSetSignalName(); @@ -42,6 +46,28 @@ }; +class StubWaitFor: public WaitFor { +Q_OBJECT +public: + + int mValue; + + StubWaitFor(int value = 0): mValue(value) { + } + + virtual WaitFor* clone() const { + return new StubWaitFor(mValue); + } + + virtual bool equals(const WaitFor& waitFor) const { + if (!qobject_cast<const StubWaitFor*>(&waitFor)) { + return false; + } + + return mValue == static_cast<const StubWaitFor*>(&waitFor)->mValue; + } +}; + void WaitForSignalTest::initTestCase() { //WaitFor* must be registered in order to be used with QSignalSpy mWaitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); @@ -54,6 +80,37 @@ QCOMPARE(waitForSignal->parent(), &parent); } +void WaitForSignalTest::testClone() { + WaitForSignal waitForSignal; + + WaitForSignal* cloned = static_cast<WaitForSignal*>(waitForSignal.clone()); + + QVERIFY(cloned != &waitForSignal); + QCOMPARE(cloned->emitterName(), waitForSignal.emitterName()); + QCOMPARE(cloned->signalName(), waitForSignal.signalName()); + delete cloned; +} + +void WaitForSignalTest::testEquals() { + WaitForSignal waitForSignal1; + waitForSignal1.setEmitterName("The emitter name"); + waitForSignal1.setSignalName("The signal name"); + WaitForSignal waitForSignal2; + + QCOMPARE(waitForSignal1 == waitForSignal2, false); + QCOMPARE(waitForSignal2 == waitForSignal1, false); + + waitForSignal2.setEmitterName("The emitter name"); + waitForSignal2.setSignalName("The signal name"); + + QCOMPARE(waitForSignal1 == waitForSignal2, true); + QCOMPARE(waitForSignal2 == waitForSignal1, true); + + StubWaitFor stubWaitFor; + + QCOMPARE(waitForSignal1 == stubWaitFor, false); +} + void WaitForSignalTest::testSetEmitterName() { WaitForSignal waitForSignal; Added: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForTest.cpp 2010-03-15 06:56:15 UTC (rev 154) @@ -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 <QtTest> + +#include "WaitFor.h" + +class WaitForTest: public QObject { +Q_OBJECT + +private slots: + + void testOperatorEqual(); + + void testOperatorNotEqual(); + +}; + +class StubWaitFor: public WaitFor { +public: + + virtual WaitFor* clone() const { + return 0; + } + + virtual bool equals(const WaitFor& waitFor) const { + Q_UNUSED(waitFor); + return false; + } + +}; + +void WaitForTest::testOperatorEqual() { + StubWaitFor waitFor1; + StubWaitFor waitFor2; + + QCOMPARE(waitFor1 == waitFor2, false); +} + +void WaitForTest::testOperatorNotEqual() { + StubWaitFor waitFor1; + StubWaitFor waitFor2; + + QCOMPARE(waitFor1 != waitFor2, true); +} + +QTEST_MAIN(WaitForTest) + +#include "WaitForTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForTest.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-14 18:10:30
|
Revision: 153 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=153&view=rev Author: danxuliu Date: 2010-03-14 17:15:38 +0000 (Sun, 14 Mar 2010) Log Message: ----------- Add ReactionTreeItem to represent a Reaction 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/ReactionTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.h trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionTreeItemTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-14 16:41:56 UTC (rev 152) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-14 17:15:38 UTC (rev 153) @@ -6,6 +6,7 @@ EditionWidget.cpp LicenseWidget.cpp NewWaitForWidget.cpp + ReactionTreeItem.cpp StepCustomCodeWidget.cpp StepDataWidget.cpp StepTreeItem.cpp Added: trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.cpp 2010-03-14 17:15:38 UTC (rev 153) @@ -0,0 +1,163 @@ +/*************************************************************************** + * 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 "ReactionTreeItem.h" + +#include <KLocalizedString> + +#include "TextTreeItem.h" +#include "WaitForTreeItem.h" +#include "../Reaction.h" + +//public: + +ReactionTreeItem::ReactionTreeItem(Reaction* reaction, TreeItem* parent): + TreeItem(parent), + mReaction(reaction) { + Q_ASSERT(reaction); + + mEmptyTriggerConditionItem = 0; + mTriggerConditionItem = 0; + mTriggerOptionItem = 0; + mResponseCustomCodeItem = 0; + mResponseNextStepItem = 0; + + //Add two dummy childs, as update method expects always to child items + appendChild(new TextTreeItem(this)); + appendChild(new TextTreeItem(this)); + update(reaction); + + connect(reaction, SIGNAL(dataChanged(Reaction*)), + this, SLOT(update(Reaction*))); +} + +QString ReactionTreeItem::text() const { + return i18nc("@item", "Reaction"); +} + +Reaction* ReactionTreeItem::reaction() const { + return mReaction; +} + +//private: + +void ReactionTreeItem::replaceItem(TreeItem* oldItem, TreeItem* newItem) { + Q_ASSERT(oldItem); + Q_ASSERT(newItem); + Q_ASSERT(oldItem->parent()); + Q_ASSERT(oldItem->parent() == newItem->parent()); + + int index = oldItem->childIndex(); + TreeItem* parent = oldItem->parent(); + + parent->removeChild(oldItem); + delete oldItem; + + parent->insertChild(newItem, index); +} + +void ReactionTreeItem::updateConditionItem(Reaction* reaction) { + if (!reaction->waitFor() && !mEmptyTriggerConditionItem) { + mEmptyTriggerConditionItem = new TextTreeItem(this); + mEmptyTriggerConditionItem->setText( + i18nc("@item", "(No condition set)")); + + replaceItem(child(0), mEmptyTriggerConditionItem); + } else if (reaction->waitFor()) { + mTriggerConditionItem = + WaitForTreeItem::treeItemForWaitFor(reaction->waitFor(), this); + + replaceItem(child(0), mTriggerConditionItem); + } +} + +void ReactionTreeItem::updateOptionItem(Reaction* reaction) { + if (!mTriggerOptionItem) { + mTriggerOptionItem = new TextTreeItem(this); + + replaceItem(child(0), mTriggerOptionItem); + } + + QString optionName = reaction->optionName(); + if (optionName.isEmpty()) { + optionName = i18nc("@item", "(option name not set)"); + } else { + optionName = '"' + reaction->optionName() + '"'; + } + + mTriggerOptionItem->setText( + i18nc("@item", "When the option %1 is selected", optionName)); +} + +void ReactionTreeItem::updateCustomCodeItem(Reaction* reaction) { + if (!mResponseCustomCodeItem) { + TextTreeItem* parent = new TextTreeItem(this); + parent->setText(i18nc("@item", "Execute the following code:")); + + mResponseCustomCodeItem = new TextTreeItem(parent); + parent->appendChild(mResponseCustomCodeItem); + + replaceItem(child(1), parent); + } + + if (reaction->customCode().isEmpty()) { + mResponseCustomCodeItem->setText("(No code set)"); + } else { + mResponseCustomCodeItem->setText(reaction->customCode()); + } +} + +void ReactionTreeItem::updateNextStepItem(Reaction* reaction) { + if (!mResponseNextStepItem) { + mResponseNextStepItem = new TextTreeItem(this); + + replaceItem(child(1), mResponseNextStepItem); + } + + QString nextStepId = reaction->nextStepId(); + if (nextStepId.isEmpty()) { + nextStepId = i18nc("@item", "(step id not set)"); + } else { + nextStepId = '"' + reaction->nextStepId() + '"'; + } + + mResponseNextStepItem->setText( + i18nc("@item", "Change to step %1", nextStepId)); +} + +//private slots: + +void ReactionTreeItem::update(Reaction* reaction) { + Q_ASSERT(reaction); + + if (reaction->triggerType() == Reaction::ConditionMet) { + updateConditionItem(reaction); + } + + if (reaction->triggerType() == Reaction::OptionSelected) { + updateOptionItem(reaction); + } + + if (reaction->responseType() == Reaction::CustomCode) { + updateCustomCodeItem(reaction); + } + + if (reaction->responseType() == Reaction::NextStep) { + updateNextStepItem(reaction); + } +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.h 2010-03-14 17:15:38 UTC (rev 153) @@ -0,0 +1,191 @@ +/*************************************************************************** + * 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 REACTIONTREEITEM_H +#define REACTIONTREEITEM_H + +#include <QPointer> +#include "TreeItem.h" + +class Reaction; +class TextTreeItem; +class WaitForTreeItem; + +/** + * A TreeItem that represents a Reaction. + * The tree representation of a reaction is: + * Reaction + * |-Trigger + * --Response + * + * Trigger can be either: + * -When the option "optionName" is selected + * or the representation of a WaitFor, depending on the type of trigger. If the + * trigger is an option and there is no option name set, or if the trigger is a + * condition but there is no WaitFor, a placeholder is used instead. Option + * placeholder is "(option name not set)", and condition placeholder is "(No + * condition set)" (without quotes, but with parenthesis). + * + * Response can be either: + * -Change to step "stepId" + * or: + * -Execute the following code: + * -Custom code + * depending on the type of response. If there is no stepId or code set, a + * placeholder is used instead. Step id placeholder is "(step id not set)", and + * code placeholder is "(No code set)" (without quotes, but with parenthesis). + * + * Whenever the reaction data changes, the ReactionTreeItem and its child items + * are updated as needed. + */ +class ReactionTreeItem: public TreeItem { +Q_OBJECT +public: + + /** + * Creates a new ReactionTreeItem for the given Reaction and with the given + * parent. + * + * @param reaction The reaction to represent. + * @param parent The parent TreeItem. + */ + explicit ReactionTreeItem(Reaction* reaction, TreeItem* parent = 0); + + /** + * Returns "Reaction". + * + * @return The text for this TreeItem. + */ + virtual QString text() const; + + /** + * Returns the Reaction. + * + * @return The Reaction. + */ + Reaction* reaction() const; + +private: + + /** + * The Reaction. + */ + Reaction* mReaction; + + /** + * The child item containing the warning text when there is no condition + * but a condition type is used. + * The pointer is automatically set to 0 if the object is deleted anywhere + * (that is, not by deleting this pointer, but another one pointing to the + * object). + */ + QPointer<TextTreeItem> mEmptyTriggerConditionItem; + + /** + * The child item containing the WaitForTreeItem for the condition, when a + * condition type is used. + * The pointer is automatically set to 0 if the object is deleted anywhere + * (that is, not by deleting this pointer, but another one pointing to the + * object). + */ + QPointer<WaitForTreeItem> mTriggerConditionItem; + + /** + * The child item containing the trigger text, when an option type is used. + * The pointer is automatically set to 0 if the object is deleted anywhere + * (that is, not by deleting this pointer, but another one pointing to the + * object). + */ + QPointer<TextTreeItem> mTriggerOptionItem; + + /** + * The child item containing the response text, when the custom code type is + * used. + * This is a nested item. Its parent (and the direct child of this + * ReactionTreeItem) contains the "Execute the following code:" text. + * The pointer is automatically set to 0 if the object is deleted anywhere + * (that is, not by deleting this pointer, but another one pointing to the + * object). + */ + QPointer<TextTreeItem> mResponseCustomCodeItem; + + /** + * The child item containing the response text, when the next step type is + * used. + * The pointer is automatically set to 0 if the object is deleted anywhere + * (that is, not by deleting this pointer, but another one pointing to the + * object). + */ + QPointer<TextTreeItem> mResponseNextStepItem; + + /** + * Replaces the old item with the new item. + * The old item is destroyed. + * + * @param oldItem The item to remove. + * @param newItem The item to insert. + */ + void replaceItem(TreeItem* oldItem, TreeItem* newItem); + + /** + * Sets a new WaitForTreeItem for the WaitFor of the reaction, or a + * TextTreeItem if there is no WaitFor. + * + * @param reaction The reaction to get the WaitFor from. + */ + void updateConditionItem(Reaction* reaction); + + /** + * Sets a new TextTreeItem or modifies the current one with the option name. + * + * @param reaction The reaction to get the option name from. + */ + void updateOptionItem(Reaction* reaction); + + /** + * Sets a new nested TextTreeItem or modifies the current one with the + * custom code. + * + * @param reaction The reaction to get the custom code from. + */ + void updateCustomCodeItem(Reaction* reaction); + + /** + * Sets a new TextTreeItem or modifies the current one with the step id. + * + * @param reaction The reaction to get the step id from. + */ + void updateNextStepItem(Reaction* reaction); + +private Q_SLOTS: + + /** + * Updates this ReactionTreeItem when the data of its reaction changed. + * If a child item is needed to show some data, it is inserted or updated + * (depending on whether it existed previously or not). + * If the child item is no longer needed, it is removed. + * + * Items may be flat or nested, depending on the data to show. + * + * @param reaction The reaction. + */ + void update(Reaction* reaction); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.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-14 16:41:56 UTC (rev 152) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-14 17:15:38 UTC (rev 153) @@ -21,6 +21,7 @@ EditionDialog LicenseWidget NewWaitForWidget + ReactionTreeItem StepCustomCodeWidget StepDataWidget StepTreeItem @@ -51,6 +52,7 @@ EditionDialog LicenseWidget NewWaitForWidget + ReactionTreeItem StepCustomCodeWidget StepDataWidget StepTreeItem Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionTreeItemTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionTreeItemTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionTreeItemTest.cpp 2010-03-14 17:15:38 UTC (rev 153) @@ -0,0 +1,465 @@ +/*************************************************************************** + * 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 "ReactionTreeItem.h" + +#include <KLocalizedString> + +#include "WaitForTreeItem.h" +#include "../Reaction.h" +#include "../WaitForSignal.h" + +class ReactionTreeItemTest: public QObject { +Q_OBJECT + +private slots: + + void initTestCase(); + + void testConstructorConditionCustomCode(); + void testConstructorOptionNextStep(); + void testConstructorConditionCustomCodeFull(); + void testConstructorOptionNextStepFull(); + + void testReactionSetOptionName(); + void testReactionSetOptionNameChange(); + void testReactionSetOptionNameEmpty(); + + void testReactionSetWaitFor(); + void testReactionSetWaitForChange(); + void testReactionSetWaitForNull(); + + void testReactionSetNextStepId(); + void testReactionSetNextStepIdChange(); + void testReactionSetNextStepIdEmpty(); + + void testReactionSetCustomCode(); + void testReactionSetCustomCodeChange(); + void testReactionSetCustomCodeEmpty(); + + void testReactionSetTriggerTypeToOptionSelected(); + void testReactionSetTriggerTypeToConditionMet(); + + void testReactionSetResponseTypeToNextStep(); + void testReactionSetResponseTypeToCustomCode(); + +private: + + int mTreeItemStarType; + + void assertText(TreeItem* textItem, const QString& licenseText) const; + + void assertWaitFor(TreeItem* item, WaitFor* waitFor) const; + + void assertCustomCode(TreeItem* textItem, const QString& code) const; + + void assertDataChanged(const QSignalSpy& spy, int index, + TreeItem* item) const; + +}; + +class StubTreeItem: public TreeItem { +public: + virtual QString text() const { + return ""; + } +}; + +void ReactionTreeItemTest::initTestCase() { + //TreeItem* must be registered in order to be used with QSignalSpy + mTreeItemStarType = qRegisterMetaType<TreeItem*>("TreeItem*"); +} + +void ReactionTreeItemTest::testConstructorConditionCustomCode() { + Reaction reaction; + reaction.setTriggerType(Reaction::ConditionMet); + reaction.setResponseType(Reaction::CustomCode); + + StubTreeItem parent; + ReactionTreeItem item(&reaction, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.text(), i18nc("@item", "Reaction")); + QCOMPARE(item.reaction(), &reaction); + QCOMPARE(item.childCount(), 2); + assertWaitFor(item.child(0), 0); + assertCustomCode(item.child(1), i18nc("@item", "(No code set)")); +} + +void ReactionTreeItemTest::testConstructorOptionNextStep() { + Reaction reaction; + reaction.setTriggerType(Reaction::OptionSelected); + reaction.setResponseType(Reaction::NextStep); + + StubTreeItem parent; + ReactionTreeItem item(&reaction, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.text(), i18nc("@item", "Reaction")); + QCOMPARE(item.reaction(), &reaction); + QCOMPARE(item.childCount(), 2); + assertText(item.child(0), i18nc("@item", "When the option (option name not " + "set) is selected")); + assertText(item.child(1), i18nc("@item", "Change to step (step id not " + "set)")); +} + +void ReactionTreeItemTest::testConstructorConditionCustomCodeFull() { + WaitFor* waitFor = new WaitForSignal(); + Reaction reaction; + reaction.setTriggerType(Reaction::ConditionMet); + reaction.setWaitFor(waitFor); + reaction.setResponseType(Reaction::CustomCode); + reaction.setCustomCode("The custom code"); + + StubTreeItem parent; + ReactionTreeItem item(&reaction, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.text(), i18nc("@item", "Reaction")); + QCOMPARE(item.reaction(), &reaction); + QCOMPARE(item.childCount(), 2); + assertWaitFor(item.child(0), waitFor); + assertCustomCode(item.child(1), "The custom code"); +} + +void ReactionTreeItemTest::testConstructorOptionNextStepFull() { + Reaction reaction; + reaction.setTriggerType(Reaction::OptionSelected); + reaction.setOptionName("The option name"); + reaction.setResponseType(Reaction::NextStep); + reaction.setNextStepId("The step id"); + + StubTreeItem parent; + ReactionTreeItem item(&reaction, &parent); + + QCOMPARE(item.parent(), &parent); + QCOMPARE(item.text(), i18nc("@item", "Reaction")); + QCOMPARE(item.reaction(), &reaction); + QCOMPARE(item.childCount(), 2); + assertText(item.child(0), i18nc("@item", "When the option \"The option " + "name\" is selected")); + assertText(item.child(1), i18nc("@item", "Change to step \"The step id\"")); +} + +void ReactionTreeItemTest::testReactionSetOptionName() { + Reaction reaction; + reaction.setTriggerType(Reaction::OptionSelected); + + ReactionTreeItem item(&reaction); + + QSignalSpy dataChangedSpy(item.child(0), SIGNAL(dataChanged(TreeItem*))); + + reaction.setOptionName("The option name"); + + QCOMPARE(item.childCount(), 2); + assertText(item.child(0), i18nc("@item", "When the option \"The option " + "name\" is selected")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, item.child(0)); +} + +void ReactionTreeItemTest::testReactionSetOptionNameChange() { + Reaction reaction; + reaction.setTriggerType(Reaction::OptionSelected); + + ReactionTreeItem item(&reaction); + + reaction.setOptionName("The option name"); + + QSignalSpy dataChangedSpy(item.child(0), SIGNAL(dataChanged(TreeItem*))); + + reaction.setOptionName("The new option name"); + + QCOMPARE(item.childCount(), 2); + assertText(item.child(0), i18nc("@item", "When the option \"The new option " + "name\" is selected")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, item.child(0)); +} + +void ReactionTreeItemTest::testReactionSetOptionNameEmpty() { + Reaction reaction; + reaction.setTriggerType(Reaction::OptionSelected); + reaction.setOptionName("The option name"); + + ReactionTreeItem item(&reaction); + + QSignalSpy dataChangedSpy(item.child(0), SIGNAL(dataChanged(TreeItem*))); + + reaction.setOptionName(""); + + QCOMPARE(item.childCount(), 2); + assertText(item.child(0), i18nc("@item", "When the option (option name not " + "set) is selected")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, item.child(0)); +} + +void ReactionTreeItemTest::testReactionSetWaitFor() { + WaitForSignal* waitFor = new WaitForSignal(); + Reaction reaction; + reaction.setTriggerType(Reaction::ConditionMet); + + ReactionTreeItem item(&reaction); + + reaction.setWaitFor(waitFor); + + QCOMPARE(item.childCount(), 2); + assertWaitFor(item.child(0), waitFor); +} + +void ReactionTreeItemTest::testReactionSetWaitForChange() { + //It will be removed and not deleted by the Reaction, so it is created in + //stack + WaitForSignal waitFor; + + WaitForSignal* waitFor2 = new WaitForSignal(); + Reaction reaction; + reaction.setTriggerType(Reaction::ConditionMet); + + ReactionTreeItem item(&reaction); + + reaction.setWaitFor(&waitFor); + reaction.setWaitFor(waitFor2); + + QCOMPARE(item.childCount(), 2); + assertWaitFor(item.child(0), waitFor2); +} + +void ReactionTreeItemTest::testReactionSetWaitForNull() { + //It will be removed and not deleted by the Reaction, so it is created in + //stack + WaitForSignal waitFor; + + Reaction reaction; + reaction.setTriggerType(Reaction::ConditionMet); + reaction.setWaitFor(&waitFor); + + ReactionTreeItem item(&reaction); + + reaction.setWaitFor(0); + + QCOMPARE(item.childCount(), 2); + assertWaitFor(item.child(0), 0); +} + +void ReactionTreeItemTest::testReactionSetNextStepId() { + Reaction reaction; + reaction.setResponseType(Reaction::NextStep); + + ReactionTreeItem item(&reaction); + + QSignalSpy dataChangedSpy(item.child(1), SIGNAL(dataChanged(TreeItem*))); + + reaction.setNextStepId("The step id"); + + QCOMPARE(item.childCount(), 2); + assertText(item.child(1), i18nc("@item", "Change to step \"The step id\"")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, item.child(1)); +} + +void ReactionTreeItemTest::testReactionSetNextStepIdChange() { + Reaction reaction; + reaction.setResponseType(Reaction::NextStep); + + ReactionTreeItem item(&reaction); + + reaction.setNextStepId("The step id"); + + QSignalSpy dataChangedSpy(item.child(1), SIGNAL(dataChanged(TreeItem*))); + + reaction.setNextStepId("The new step id"); + + QCOMPARE(item.childCount(), 2); + assertText(item.child(1), i18nc("@item", "Change to step \"The new step " + "id\"")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, item.child(1)); +} + +void ReactionTreeItemTest::testReactionSetNextStepIdEmpty() { + Reaction reaction; + reaction.setResponseType(Reaction::NextStep); + reaction.setNextStepId("The step id"); + + ReactionTreeItem item(&reaction); + + QSignalSpy dataChangedSpy(item.child(1), SIGNAL(dataChanged(TreeItem*))); + + reaction.setNextStepId(""); + + QCOMPARE(item.childCount(), 2); + assertText(item.child(1), i18nc("@item", "Change to step (step id not " + "set)")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, item.child(1)); +} + +void ReactionTreeItemTest::testReactionSetCustomCode() { + Reaction reaction; + reaction.setResponseType(Reaction::CustomCode); + + ReactionTreeItem item(&reaction); + + QSignalSpy dataChangedSpy(item.child(1)->child(0), + SIGNAL(dataChanged(TreeItem*))); + + reaction.setCustomCode("The custom code"); + + QCOMPARE(item.childCount(), 2); + assertCustomCode(item.child(1), "The custom code"); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, item.child(1)->child(0)); +} + +void ReactionTreeItemTest::testReactionSetCustomCodeChange() { + Reaction reaction; + reaction.setResponseType(Reaction::CustomCode); + + ReactionTreeItem item(&reaction); + + reaction.setCustomCode("The custom code"); + + QSignalSpy dataChangedSpy(item.child(1)->child(0), + SIGNAL(dataChanged(TreeItem*))); + + reaction.setCustomCode("The new custom code"); + + QCOMPARE(item.childCount(), 2); + assertCustomCode(item.child(1), "The new custom code"); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, item.child(1)->child(0)); +} + +void ReactionTreeItemTest::testReactionSetCustomCodeEmpty() { + Reaction reaction; + reaction.setResponseType(Reaction::CustomCode); + reaction.setCustomCode("The custom code"); + + ReactionTreeItem item(&reaction); + + QSignalSpy dataChangedSpy(item.child(1)->child(0), + SIGNAL(dataChanged(TreeItem*))); + + reaction.setCustomCode(""); + + QCOMPARE(item.childCount(), 2); + assertCustomCode(item.child(1), i18nc("@item", "(No code set)")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, item.child(1)->child(0)); +} + +void ReactionTreeItemTest::testReactionSetTriggerTypeToOptionSelected() { + Reaction reaction; + reaction.setTriggerType(Reaction::ConditionMet); + reaction.setOptionName("The option name"); + + ReactionTreeItem item(&reaction); + + reaction.setTriggerType(Reaction::OptionSelected); + + QCOMPARE(item.childCount(), 2); + assertText(item.child(0), i18nc("@item", "When the option \"The option " + "name\" is selected")); +} + +void ReactionTreeItemTest::testReactionSetTriggerTypeToConditionMet() { + WaitForSignal* waitFor = new WaitForSignal(); + Reaction reaction; + reaction.setTriggerType(Reaction::OptionSelected); + reaction.setWaitFor(waitFor); + + ReactionTreeItem item(&reaction); + + reaction.setTriggerType(Reaction::ConditionMet); + + QCOMPARE(item.childCount(), 2); + assertWaitFor(item.child(0), waitFor); +} + +void ReactionTreeItemTest::testReactionSetResponseTypeToNextStep() { + Reaction reaction; + reaction.setResponseType(Reaction::CustomCode); + reaction.setNextStepId("The step id"); + + ReactionTreeItem item(&reaction); + + reaction.setResponseType(Reaction::NextStep); + + QCOMPARE(item.childCount(), 2); + assertText(item.child(1), i18nc("@item", "Change to step \"The step id\"")); +} + +void ReactionTreeItemTest::testReactionSetResponseTypeToCustomCode() { + Reaction reaction; + reaction.setResponseType(Reaction::NextStep); + reaction.setCustomCode("The custom code"); + + ReactionTreeItem item(&reaction); + + reaction.setResponseType(Reaction::CustomCode); + + QCOMPARE(item.childCount(), 2); + assertCustomCode(item.child(1), "The custom code"); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +void ReactionTreeItemTest::assertText(TreeItem* textItem, + const QString& name) const { + QCOMPARE(textItem->text(), i18nc("@item", "%1", name)); +} + +void ReactionTreeItemTest::assertWaitFor(TreeItem* item, + WaitFor* waitFor) const { + if (!waitFor) { + QCOMPARE(item->text(), i18nc("@item", "(No condition set)")); + return; + } + + WaitForTreeItem* waitForItem = qobject_cast<WaitForTreeItem*>(item); + QVERIFY(waitForItem); + QCOMPARE(waitForItem->waitFor(), waitFor); +} + +void ReactionTreeItemTest::assertCustomCode(TreeItem* textItem, + const QString& code) const { + QCOMPARE(textItem->text(), i18nc("@item", "Execute the following code:")); + QCOMPARE(textItem->childCount(), 1); + QCOMPARE(textItem->child(0)->text(), i18nc("@item", code.toAscii())); +} + +//TreeItem* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(TreeItem*); + +void ReactionTreeItemTest::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(ReactionTreeItemTest) + +#include "ReactionTreeItemTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionTreeItemTest.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-14 16:42:03
|
Revision: 152 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=152&view=rev Author: danxuliu Date: 2010-03-14 16:41:56 +0000 (Sun, 14 Mar 2010) Log Message: ----------- Ooops, these files were missed in commit 150. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-13 18:54:34 UTC (rev 151) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-14 16:41:56 UTC (rev 152) @@ -5,6 +5,7 @@ EditionDialog.cpp EditionWidget.cpp LicenseWidget.cpp + NewWaitForWidget.cpp StepCustomCodeWidget.cpp StepDataWidget.cpp StepTreeItem.cpp @@ -19,14 +20,19 @@ WaitForComposedTreeItem.cpp WaitForNotTreeItem.cpp WaitForSignalTreeItem.cpp + WaitForSignalWidget.cpp WaitForTreeItem.cpp + WaitForWidget.cpp ) kde4_add_ui_files(ktutorial_editor_view_SRCS CustomCodeWidget.ui LicenseWidget.ui + NewWaitForWidget.ui StepDataWidget.ui TutorialInformationWidget.ui + WaitForSignalWidget.ui + WaitForWidget.ui ) kde4_add_library(ktutorial_editor_view ${ktutorial_editor_view_SRCS}) Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-13 18:54:34 UTC (rev 151) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-14 16:41:56 UTC (rev 152) @@ -20,6 +20,7 @@ ActionListWidget EditionDialog LicenseWidget + NewWaitForWidget StepCustomCodeWidget StepDataWidget StepTreeItem @@ -34,7 +35,9 @@ WaitForComposedTreeItem WaitForNotTreeItem WaitForSignalTreeItem + WaitForSignalWidget WaitForTreeItem + WaitForWidget ) MACRO(MEM_TESTS) @@ -47,6 +50,7 @@ ActionListWidget EditionDialog LicenseWidget + NewWaitForWidget StepCustomCodeWidget StepDataWidget StepTreeItem @@ -61,5 +65,7 @@ WaitForComposedTreeItem WaitForNotTreeItem WaitForSignalTreeItem + WaitForSignalWidget WaitForTreeItem + WaitForWidget ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-13 18:54:41
|
Revision: 151 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=151&view=rev Author: danxuliu Date: 2010-03-13 18:54:34 +0000 (Sat, 13 Mar 2010) Log Message: ----------- Add Reaction class to store the data of reactions (changing to a step or executing some code when an option is selected or a condition is met). Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/Reaction.cpp trunk/ktutorial/ktutorial-editor/src/Reaction.h trunk/ktutorial/ktutorial-editor/tests/unit/ReactionTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-13 18:38:49 UTC (rev 150) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-13 18:54:34 UTC (rev 151) @@ -8,6 +8,7 @@ set(ktutorial_editor_SRCS KTutorialEditor.cpp + Reaction.cpp Step.cpp Tutorial.cpp WaitFor.cpp Added: trunk/ktutorial/ktutorial-editor/src/Reaction.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/Reaction.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/Reaction.cpp 2010-03-13 18:54:34 UTC (rev 151) @@ -0,0 +1,93 @@ +/*************************************************************************** + * 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 "Reaction.h" +#include "WaitFor.h" + +//public: + +Reaction::Reaction(QObject* parent): + QObject(parent), + mWaitFor(0), + mTriggerType(OptionSelected), + mResponseType(NextStep) { +} + +Reaction::~Reaction() { + delete mWaitFor; +} + +Reaction::TriggerType Reaction::triggerType() const { + return mTriggerType; +} + +void Reaction::setTriggerType(TriggerType triggerType) { + mTriggerType = triggerType; + + emit dataChanged(this); +} + +QString Reaction::optionName() const { + return mOptionName; +} + +void Reaction::setOptionName(const QString& optionName) { + mOptionName = optionName; + + emit dataChanged(this); +} + +WaitFor* Reaction::waitFor() const { + return mWaitFor; +} + +void Reaction::setWaitFor(WaitFor* waitFor) { + mWaitFor = waitFor; + + emit dataChanged(this); +} + +Reaction::ResponseType Reaction::responseType() const { + return mResponseType; +} + +void Reaction::setResponseType(ResponseType responseType) { + mResponseType = responseType; + + emit dataChanged(this); +} + +QString Reaction::nextStepId() const { + return mNextStepId; +} + +void Reaction::setNextStepId(const QString& nextStepId) { + mNextStepId = nextStepId; + + emit dataChanged(this); +} + +QString Reaction::customCode() const { + return mCustomCode; +} + +void Reaction::setCustomCode(const QString& customCode) { + mCustomCode = customCode; + + emit dataChanged(this); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/Reaction.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/Reaction.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/Reaction.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/Reaction.h 2010-03-13 18:54:34 UTC (rev 151) @@ -0,0 +1,102 @@ +/*************************************************************************** + * 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 REACTION_H +#define REACTION_H + +#include <QObject> + +class WaitFor; + +/** + * Container for reaction data. + * It stores the data necessary to call addWaitFor and addOption methods in a + * KTutorial::Step. That is, it stores the data that defines how a step reacts. + * + * A reaction is composed by a trigger and a response. The trigger can be the + * user selecting an option of the step, or a condition to wait for that is met. + * The response can be changing to another step, or custom code for complexer + * behavior. + * + * When any attribute is modified, dataChanged(Step*) signal is emitted. + */ +class Reaction: public QObject { +Q_OBJECT +public: + + enum TriggerType { + OptionSelected, + ConditionMet + }; + + enum ResponseType { + NextStep, + CustomCode + }; + + Reaction(QObject* parent = 0); + virtual ~Reaction(); + + TriggerType triggerType() const; + void setTriggerType(TriggerType triggerType); + + QString optionName() const; + void setOptionName(const QString& optionName); + + WaitFor* waitFor() const; + + /** + * Sets the condition to wait for. + * The WaitFor will be destroyed when this Reaction is destroyed. However, + * if a WaitFor is set over a previous one, the previous one must be deleted + * explicitly. + * + * @param waitFor The condition to wait for. + */ + void setWaitFor(WaitFor* waitFor); + + ResponseType responseType() const; + void setResponseType(ResponseType responseType); + + QString nextStepId() const; + void setNextStepId(const QString& nextStepId); + + QString customCode() const; + void setCustomCode(const QString& customCode); + +Q_SIGNALS: + + /** + * Emitted when any data in the reaction changed. + * + * @param reaction This reaction. + */ + void dataChanged(Reaction* reaction); + +private: + + TriggerType mTriggerType; + QString mOptionName; + WaitFor* mWaitFor; + ResponseType mResponseType; + QString mNextStepId; + QString mCustomCode; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/Reaction.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-13 18:38:49 UTC (rev 150) +++ trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-13 18:54:34 UTC (rev 151) @@ -15,6 +15,7 @@ ENDMACRO(UNIT_TESTS) unit_tests( + Reaction Step Tutorial WaitForComposed @@ -29,6 +30,7 @@ ENDMACRO(MEM_TESTS) mem_tests( + Reaction Step Tutorial WaitForComposed Added: trunk/ktutorial/ktutorial-editor/tests/unit/ReactionTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/ReactionTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/ReactionTest.cpp 2010-03-13 18:54:34 UTC (rev 151) @@ -0,0 +1,168 @@ +/*************************************************************************** + * 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 "Reaction.h" +#include "WaitFor.h" + +class ReactionTest: public QObject { +Q_OBJECT + +private slots: + + void initTestCase(); + + void testConstructor(); + + void testSetTriggerType(); + + void testSetOptionName(); + + void testSetWaitFor(); + + void testSetResponseType(); + + void testSetNextStepId(); + + void testSetCustomCode(); + +private: + + int mReactionStarType; + + void assertDataChanged(const QSignalSpy& spy, int index, + Reaction* reaction) const; + +}; + +class MockWaitFor: public WaitFor { +Q_OBJECT +public: + + void emitDataChanged() { + emit dataChanged(this); + } + +}; + +void ReactionTest::initTestCase() { + //Reaction* must be registered in order to be used with QSignalSpy + mReactionStarType = qRegisterMetaType<Reaction*>("Reaction*"); +} + +void ReactionTest::testConstructor() { + QObject parent; + Reaction* reaction = new Reaction(&parent); + + QCOMPARE(reaction->parent(), &parent); + QCOMPARE(reaction->triggerType(), Reaction::OptionSelected); + QCOMPARE(reaction->responseType(), Reaction::NextStep); + QCOMPARE(reaction->waitFor(), (WaitFor*)0); +} + +void ReactionTest::testSetTriggerType() { + Reaction reaction; + + QSignalSpy dataChangedSpy(&reaction, SIGNAL(dataChanged(Reaction*))); + + reaction.setTriggerType(Reaction::ConditionMet); + + QCOMPARE(reaction.triggerType(), Reaction::ConditionMet); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, &reaction); +} + +void ReactionTest::testSetOptionName() { + Reaction reaction; + + QSignalSpy dataChangedSpy(&reaction, SIGNAL(dataChanged(Reaction*))); + + reaction.setOptionName("The option name"); + + QCOMPARE(reaction.optionName(), QString("The option name")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, &reaction); +} + +void ReactionTest::testSetWaitFor() { + Reaction reaction; + + QSignalSpy dataChangedSpy(&reaction, SIGNAL(dataChanged(Reaction*))); + + MockWaitFor* waitFor = new MockWaitFor(); + reaction.setWaitFor(waitFor); + + QCOMPARE(reaction.waitFor(), waitFor); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, &reaction); +} + +void ReactionTest::testSetResponseType() { + Reaction reaction; + + QSignalSpy dataChangedSpy(&reaction, SIGNAL(dataChanged(Reaction*))); + + reaction.setResponseType(Reaction::CustomCode); + + QCOMPARE(reaction.responseType(), Reaction::CustomCode); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, &reaction); +} + +void ReactionTest::testSetNextStepId() { + Reaction reaction; + + QSignalSpy dataChangedSpy(&reaction, SIGNAL(dataChanged(Reaction*))); + + reaction.setNextStepId("The id"); + + QCOMPARE(reaction.nextStepId(), QString("The id")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, &reaction); +} + +void ReactionTest::testSetCustomCode() { + Reaction reaction; + + QSignalSpy dataChangedSpy(&reaction, SIGNAL(dataChanged(Reaction*))); + + reaction.setCustomCode("The custom code"); + + QCOMPARE(reaction.customCode(), QString("The custom code")); + QCOMPARE(dataChangedSpy.count(), 1); + assertDataChanged(dataChangedSpy, 0, &reaction); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +//Reaction* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(Reaction*); + +void ReactionTest::assertDataChanged(const QSignalSpy& spy, int index, + Reaction* reaction) const { + QCOMPARE(spy.at(index).count(), 1); + + QVariant argument = spy.at(index).at(0); + QCOMPARE(argument.userType(), mReactionStarType); + QCOMPARE(qvariant_cast<Reaction*>(argument), reaction); +} + +QTEST_MAIN(ReactionTest) + +#include "ReactionTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/ReactionTest.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-13 18:38:56
|
Revision: 150 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=150&view=rev Author: danxuliu Date: 2010-03-13 18:38:49 +0000 (Sat, 13 Mar 2010) Log Message: ----------- Add widgets to edit WaitFors. Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.h trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.h trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.ui trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.ui trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForSignalWidgetTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp Added: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp 2010-03-13 18:38:49 UTC (rev 150) @@ -0,0 +1,55 @@ +/*************************************************************************** + * 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 "NewWaitForWidget.h" + +#include "ui_NewWaitForWidget.h" +#include "../WaitForComposed.h" +#include "../WaitForNot.h" +#include "../WaitForSignal.h" + +//public: + +NewWaitForWidget::NewWaitForWidget(QWidget* parent): QWidget(parent) { + ui = new Ui::NewWaitForWidget(); + ui->setupUi(this); +} + +NewWaitForWidget::~NewWaitForWidget() { + delete ui; +} + +WaitFor* NewWaitForWidget::waitFor() const { + int index = ui->waitForTypeComboBox->currentIndex(); + + if (index == 0) { + WaitForComposed* waitFor = new WaitForComposed(); + waitFor->setCompositionType(WaitForComposed::And); + return waitFor; + } else if (index == 1) { + WaitForComposed* waitFor = new WaitForComposed(); + waitFor->setCompositionType(WaitForComposed::Or); + return waitFor; + } else if (index == 2) { + return new WaitForNot(); + } else if (index == 3) { + return new WaitForSignal(); + } + + return 0; +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.h 2010-03-13 18:38:49 UTC (rev 150) @@ -0,0 +1,67 @@ +/*************************************************************************** + * 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 NEWWAITFORWIDGET_H +#define NEWWAITFORWIDGET_H + +#include <QWidget> + +class WaitFor; + +namespace Ui { +class NewWaitForWidget; +} + +/** + * Widget to create a new condition. + * Note that this is not an edition widget, as it has no data to edit. It + * creates a new object, which can be got using waitFor() method. + */ +class NewWaitForWidget: public QWidget { +Q_OBJECT +public: + + /** + * Creates a new NewWaitForWidget. + * + * @param parent The parent QWidget. + */ + explicit NewWaitForWidget(QWidget* parent = 0); + + /** + * Destroys this widget. + */ + virtual ~NewWaitForWidget(); + + /** + * Return the new WaitFor. + * + * @return The new WaitFor. + */ + WaitFor* waitFor() const; + +private: + + /** + * The Ui Designer generated class. + */ + Ui::NewWaitForWidget* ui; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui 2010-03-13 18:38:49 UTC (rev 150) @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>NewWaitForWidget</class> + <widget class="QWidget" name="NewWaitForWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string comment="@title">New condition to wait for</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>Selects the type of the new condition.</para></string> + </property> + <layout class="QVBoxLayout" name="NewWaitForWidgetVerticalLayout"> + <item> + <widget class="QGroupBox" name="waitForTypeGroupBox"> + <property name="title"> + <string comment="@title">Condition to wait for type</string> + </property> + <layout class="QHBoxLayout" name="waitForTypeGroupBoxHorizontalLayout"> + <item> + <widget class="QLabel" name="waitForTypeLabel"> + <property name="text"> + <string>Type:</string> + </property> + <property name="buddy"> + <cstring>waitForTypeComboBox</cstring> + </property> + </widget> + </item> + <item> + <widget class="KComboBox" name="waitForTypeComboBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <item> + <property name="text"> + <string comment="@item:inlistbox">All the contained conditions must match</string> + </property> + </item> + <item> + <property name="text"> + <string comment="@item:inlistbox">Any of the contained conditions must match</string> + </property> + </item> + <item> + <property name="text"> + <string comment="@item:inlistbox">The contained condition can't match</string> + </property> + </item> + <item> + <property name="text"> + <string comment="@item:inlistbox">The specified signal is emitted</string> + </property> + </item> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="newWaitForWidgetSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>215</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>KComboBox</class> + <extends>QComboBox</extends> + <header>kcombobox.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.cpp 2010-03-13 18:38:49 UTC (rev 150) @@ -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/>. * + ***************************************************************************/ + +#include "WaitForSignalWidget.h" + +#include "ui_WaitForSignalWidget.h" +#include "../WaitForSignal.h" + +//public: + +WaitForSignalWidget::WaitForSignalWidget(WaitForSignal* waitForSignal, + QWidget* parent): + EditionWidget(parent), + mWaitForSignal(waitForSignal) { + + ui = new Ui::WaitForSignalWidget(); + ui->setupUi(this); + + ui->emitterNameLineEdit->setText(waitForSignal->emitterName()); + ui->signalNameLineEdit->setText(waitForSignal->signalName()); +} + +WaitForSignalWidget::~WaitForSignalWidget() { + delete ui; +} + +void WaitForSignalWidget::saveChanges() { + QString emitterName = ui->emitterNameLineEdit->text(); + if (mWaitForSignal->emitterName() != emitterName) { + mWaitForSignal->setEmitterName(emitterName); + } + + QString signalName = ui->signalNameLineEdit->text(); + if (mWaitForSignal->signalName() != signalName) { + mWaitForSignal->setSignalName(signalName); + } +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.h 2010-03-13 18:38:49 UTC (rev 150) @@ -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/>. * + ***************************************************************************/ + +#ifndef WAITFORSIGNALWIDGET_H +#define WAITFORSIGNALWIDGET_H + +#include "EditionWidget.h" + +class WaitForSignal; + +namespace Ui { +class WaitForSignalWidget; +} + +/** + * Edition widget for the condition to wait for a signal. + */ +class WaitForSignalWidget: public EditionWidget { +Q_OBJECT +public: + + /** + * Creates a new WaitForSignalWidget for the given WaitForSignal. + * + * @param waitForSignal The WaitForSignal to set its data. + * @param parent The parent QWidget. + */ + explicit WaitForSignalWidget(WaitForSignal* waitForSignal, + QWidget* parent = 0); + + /** + * Destroys this widget. + */ + virtual ~WaitForSignalWidget(); + + /** + * Saves the emitter name and the signal name in the WaitForSignal. + */ + virtual void saveChanges(); + +private: + + /** + * The WaitForSignal to edit. + */ + WaitForSignal* mWaitForSignal; + + /** + * The Ui Designer generated class. + */ + Ui::WaitForSignalWidget* ui; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.ui (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.ui 2010-03-13 18:38:49 UTC (rev 150) @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>WaitForSignalWidget</class> + <widget class="QWidget" name="WaitForSignalWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string comment="@title">Edit signal to wait for</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>Set the emitter name and the signal to wait for.</para></string> + </property> + <layout class="QVBoxLayout" name="WaitForSignalVerticalLayout"> + <item> + <widget class="QGroupBox" name="waitForSignalGroupBox"> + <property name="title"> + <string comment="@title:group">Wait for signal</string> + </property> + <layout class="QHBoxLayout" name="waitForSignalGroupBoxHorizontalLayout"> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="emitterNameLabel"> + <property name="text"> + <string>Emitter name:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>emitterNameLineEdit</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="signalNameLabel"> + <property name="text"> + <string>Signal name:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>signalNameLineEdit</cstring> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="KLineEdit" name="emitterNameLineEdit"> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>The name of the QObject that emits the signal.</para> +<para>Note that the name is not the class of the object, but the string returned by its objectName() method.</para></string> + </property> + </widget> + </item> + <item> + <widget class="KLineEdit" name="signalNameLineEdit"> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>The name of the signal.</para> +<para>The name must be written as <em>signalName(TypeOfFirstArgument, TypeOfSecondArgument, TypeOfThirdArgument...)</em>, without including <em>SIGNAL()</em> wrapping text.</para></string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="waitForSignalWidgetSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>182</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>KLineEdit</class> + <extends>QLineEdit</extends> + <header>klineedit.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp 2010-03-13 18:38:49 UTC (rev 150) @@ -0,0 +1,243 @@ +/*************************************************************************** + * 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 "WaitForWidget.h" + +#include "ui_WaitForWidget.h" +#include "EditionDialog.h" +#include "NewWaitForWidget.h" +#include "TextTreeItem.h" +#include "TreeModel.h" +#include "WaitForSignalWidget.h" +#include "WaitForTreeItem.h" +#include "../WaitForComposed.h" +#include "../WaitForNot.h" +#include "../WaitForSignal.h" + +//public: + +WaitForWidget::WaitForWidget(WaitFor* waitFor, QWidget* parent): + QWidget(parent), + mWaitFor(waitFor), + mCurrentWaitFor(0) { + + ui = new Ui::WaitForWidget(); + ui->setupUi(this); + + ui->addButton->setIcon(KIcon("list-add")); + ui->editButton->setIcon(KIcon("document-edit")); + ui->removeButton->setIcon(KIcon("list-remove")); + + setupTreeView(waitFor); + + updateWaitForSelection(0); + + connect(ui->addButton, SIGNAL(clicked(bool)), this, SLOT(addWaitFor())); + connect(ui->editButton, SIGNAL(clicked(bool)), this, SLOT(editWaitFor())); + connect(ui->removeButton, SIGNAL(clicked(bool)), + this, SLOT(removeWaitFor())); +} + +WaitForWidget::~WaitForWidget() { + delete ui; +} + +WaitFor* WaitForWidget::waitFor() const { + return mWaitFor; +} + +//private: + +void WaitForWidget::setupTreeView(WaitFor* waitFor) { + TextTreeItem* rootItem = new TextTreeItem(); + if (waitFor) { + TreeItem* item = WaitForTreeItem::treeItemForWaitFor(waitFor, rootItem); + rootItem->appendChild(item); + } + + QTreeView* treeView = ui->waitForTreeView; + TreeModel* model = new TreeModel(rootItem, treeView); + + QAbstractItemModel* oldModel = treeView->model(); + treeView->setModel(model); + delete oldModel; + + connect(treeView->selectionModel(), + SIGNAL(selectionChanged(QItemSelection, QItemSelection)), + this, + SLOT(handleSelectionChanged(QItemSelection, QItemSelection))); +} + +void WaitForWidget::updateWaitForSelection(WaitFor* selectedWaitFor) { + mCurrentWaitFor = selectedWaitFor; + + if (!selectedWaitFor) { + if (mWaitFor) { + ui->addButton->setEnabled(false); + } else { + ui->addButton->setEnabled(true); + } + ui->editButton->setEnabled(false); + ui->removeButton->setEnabled(false); + + return; + } + + if (qobject_cast<WaitForComposed*>(selectedWaitFor)) { + ui->addButton->setEnabled(true); + ui->editButton->setEnabled(false); + ui->removeButton->setEnabled(true); + + return; + } + + if (qobject_cast<WaitForNot*>(selectedWaitFor)) { + if (static_cast<WaitForNot*>(selectedWaitFor)->negatedWaitFor()) { + ui->addButton->setEnabled(false); + } else { + ui->addButton->setEnabled(true); + } + ui->editButton->setEnabled(false); + ui->removeButton->setEnabled(true); + + return; + } + + if (qobject_cast<WaitForSignal*>(selectedWaitFor)) { + ui->addButton->setEnabled(false); + ui->editButton->setEnabled(true); + ui->removeButton->setEnabled(true); + + return; + } +} + +//private slots: + +void WaitForWidget::handleSelectionChanged(const QItemSelection& selected, + const QItemSelection& deselected) { + //Only single selections are supported + Q_ASSERT(selected.count() <= 1); + Q_ASSERT(deselected.count() <= 1); + + WaitFor* selectedWaitFor = 0; + + if (selected.count() == 1) { + Q_ASSERT(selected.at(0).indexes().count() == 1); + + QModelIndex index = selected.at(0).indexes().at(0); + WaitForTreeItem* item = + static_cast<WaitForTreeItem*>(index.internalPointer()); + + selectedWaitFor = item->waitFor(); + } + + updateWaitForSelection(selectedWaitFor); +} + +void WaitForWidget::addWaitFor() { + WaitFor* newWaitFor = 0; + + KDialog* dialog = new KDialog(this); + NewWaitForWidget* widget = new NewWaitForWidget(dialog); + dialog->setMainWidget(widget); + dialog->setObjectName("addWaitForDialog"); + if (dialog->exec() == QDialog::Accepted) { + newWaitFor = widget->waitFor(); + } + dialog->deleteLater(); + + if (!mWaitFor) { + mWaitFor = newWaitFor; + return; + } + + if (qobject_cast<WaitForComposed*>(mCurrentWaitFor)) { + WaitForComposed* waitForComposed = + static_cast<WaitForComposed*>(mCurrentWaitFor); + + waitForComposed->addWaitFor(newWaitFor); + return; + } + + if (qobject_cast<WaitForNot*>(mCurrentWaitFor)) { + WaitForNot* waitForNot = static_cast<WaitForNot*>(mCurrentWaitFor); + + waitForNot->setNegatedWaitFor(newWaitFor); + return; + } +} + +void WaitForWidget::editWaitFor() { + EditionWidget* editionWidget = 0; + if (qobject_cast<WaitForSignal*>(mCurrentWaitFor)) { + WaitForSignal* waitForSignal = + static_cast<WaitForSignal*>(mCurrentWaitFor); + editionWidget = new WaitForSignalWidget(waitForSignal, this); + } + + Q_ASSERT(editionWidget); + + EditionDialog* dialog = new EditionDialog(editionWidget, this); + dialog->setObjectName("editionDialog"); + dialog->exec(); + dialog->deleteLater(); +} + +void WaitForWidget::removeWaitFor() { + QModelIndex index = + ui->waitForTreeView->selectionModel()->selectedIndexes()[0]; + QModelIndex parent = index.parent(); + + if (!parent.isValid()) { + delete mWaitFor; + mWaitFor = 0; + + return; + } + + WaitFor* parentWaitFor = + static_cast<WaitForTreeItem*>(parent.internalPointer())->waitFor(); + + if (qobject_cast<WaitForComposed*>(parentWaitFor)) { + WaitForComposed* waitForComposed = + static_cast<WaitForComposed*>(parentWaitFor); + + //When the WaitFor is removed, mCurrentWaitFor changes because the + //selected item in the tree view changes. The WaitFor to be removed must + //be stord to properly delete it. + WaitFor* waitForToRemove = mCurrentWaitFor; + waitForComposed->removeWaitFor(waitForToRemove); + delete waitForToRemove; + + return; + } + + if (qobject_cast<WaitForNot*>(parentWaitFor)) { + WaitForNot* waitForNot = static_cast<WaitForNot*>(parentWaitFor); + + //When the WaitFor is removed, mCurrentWaitFor changes because the + //selected item in the tree view changes. The WaitFor to be removed must + //be stord to properly delete it. + WaitFor* waitForToRemove = mCurrentWaitFor; + waitForNot->setNegatedWaitFor(0); + delete waitForToRemove; + + return; + } +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h 2010-03-13 18:38:49 UTC (rev 150) @@ -0,0 +1,132 @@ +/*************************************************************************** + * 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 WAITFORWIDGET_H +#define WAITFORWIDGET_H + +#include <QWidget> + +class QItemSelection; +class WaitFor; + +namespace Ui { +class WaitForWidget; +} + +/** + * Widget to create or edit a WaitFor. + * The following operations can be done: add a WaitFor, edit a WaitFor or remove + * a WaitFor. + * + * A WaitFor can be added only as the first WaitFor (when the list is empty), or + * as a child of a composed WaitFor (selecting the one that will be its parent). + * + * A WaitFor can be edited if it is a plain condition, that is, it is not + * composed from other WaitFors. + * + * Finally, any WaitFor can be removed. + * + * The WaitFor, returned by waitFor() method, must be explicitly deleted. + * However, the WaitFor set in the constructor may have been deleted by the + * widget if the user removed the root WaitFor. + */ +class WaitForWidget: public QWidget { +Q_OBJECT +public: + + /** + * Creates a new WaitForWidget. + * + * @param parent The parent QWidget. + */ + explicit WaitForWidget(WaitFor* waitFor, QWidget* parent = 0); + + /** + * Destroys this widget. + */ + virtual ~WaitForWidget(); + + /** + * Returns the WaitFor. + * + * @return The WaitFor, if any. + */ + WaitFor* waitFor() const; + +private: + + /** + * The WaitFor to edit. + */ + WaitFor* mWaitFor; + + /** + * The WaitFor currently selected. + */ + WaitFor* mCurrentWaitFor; + + /** + * The Ui Designer generated class. + */ + Ui::WaitForWidget* ui; + + /** + * Sets up the tree view for the WaitFor to be edited. + * + * @param waitFor The WaitFor to be edited. + */ + void setupTreeView(WaitFor* waitFor); + + /** + * Sets the current WaitFor and enables or disables the buttons as needed. + * + * @param selectedWaitFor The selected WaitFor. + */ + void updateWaitForSelection(WaitFor* selectedWaitFor); + +private Q_SLOTS: + + /** + * Handles a change in the selection in the tree view. + * + * @param selected The item selection of selected items. + * @param selected The item selection of deselected items. + */ + void handleSelectionChanged(const QItemSelection& selected, + const QItemSelection& deselected); + + /** + * Shows a dialog with a NewWaitForWidget and adds the new WaitFor. + * The WaitFor is added to the selected WaitFor, or as the root WaitFor if + * there is none. + */ + void addWaitFor(); + + /** + * Shows an EditionDialog for the selected WaitFor. + */ + void editWaitFor(); + + /** + * Removes the selected WaitFor. + */ + void removeWaitFor(); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.ui (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.ui 2010-03-13 18:38:49 UTC (rev 150) @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>WaitForWidget</class> + <widget class="QWidget" name="WaitForWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string comment="@title">Edit condition to wait for</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>Edit a condition to wait for until it is met.</para> +<para>A condition can be a plain condition or a composed condition. Plain conditions wait for some specific thing to happen, for example, they wait until a signal is emitted. Composed conditions contain other conditions (plain or also composed) and wait until something happens in its contained conditions, for example, wait until all the contained conditions were met.</para></string> + </property> + <layout class="QVBoxLayout" name="waitForWidgetVerticalLayout"> + <item> + <widget class="QTreeView" name="waitForTreeView"/> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="KPushButton" name="addButton"> + <property name="toolTip"> + <string comment="@info:tooltip">Add a new condition</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>Adds a new condition.</para> +<para>A condition has to be added to composed conditions, that is, conditions that contain other conditions, or as the root condition when there is no other condition.</para></string> + </property> + <property name="text"> + <string comment="@action:button">Add...</string> + </property> + </widget> + </item> + <item> + <widget class="KPushButton" name="editButton"> + <property name="toolTip"> + <string comment="@info:tooltip">Edit the selected condition</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>Edits the selected condition.</para> +<para>Only plain conditions, that is, conditions that aren't composed by other conditions, can be edited.</para></string> + </property> + <property name="text"> + <string comment="@action:button">Edit...</string> + </property> + </widget> + </item> + <item> + <widget class="KPushButton" name="removeButton"> + <property name="toolTip"> + <string comment="@info:tooltip">Remove the selected condition</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis">Removes the selected condition.</string> + </property> + <property name="text"> + <string comment="@action:button">Remove</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>KPushButton</class> + <extends>QPushButton</extends> + <header>kpushbutton.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp 2010-03-13 18:38:49 UTC (rev 150) @@ -0,0 +1,108 @@ +/*************************************************************************** + * 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 "NewWaitForWidget.h" + +#include <KComboBox> + +#include "../WaitForComposed.h" +#include "../WaitForNot.h" +#include "../WaitForSignal.h" + +class NewWaitForWidgetTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testWaitForWhenAndConditionIsSelected(); + void testWaitForWhenOrConditionIsSelected(); + void testWaitForWhenNotConditionIsSelected(); + void testWaitForWhenSignalConditionIsSelected(); + +private: + + void selectOption(NewWaitForWidget* widget, int index) const; + +}; + +void NewWaitForWidgetTest::testConstructor() { + QWidget parent; + NewWaitForWidget* widget = new NewWaitForWidget(&parent); + + QCOMPARE(widget->parentWidget(), &parent); +} + +void NewWaitForWidgetTest::testWaitForWhenAndConditionIsSelected() { + NewWaitForWidget widget; + + selectOption(&widget, 0); + + WaitForComposed* waitFor = qobject_cast<WaitForComposed*>(widget.waitFor()); + QVERIFY(waitFor); + QCOMPARE(waitFor->compositionType(), WaitForComposed::And); + delete waitFor; +} + +void NewWaitForWidgetTest::testWaitForWhenOrConditionIsSelected() { + NewWaitForWidget widget; + + selectOption(&widget, 1); + + WaitForComposed* waitFor = qobject_cast<WaitForComposed*>(widget.waitFor()); + QVERIFY(waitFor); + QCOMPARE(waitFor->compositionType(), WaitForComposed::Or); + delete waitFor; +} + +void NewWaitForWidgetTest::testWaitForWhenNotConditionIsSelected() { + NewWaitForWidget widget; + + selectOption(&widget, 2); + + WaitForNot* waitFor = qobject_cast<WaitForNot*>(widget.waitFor()); + QVERIFY(waitFor); + delete waitFor; +} + +void NewWaitForWidgetTest::testWaitForWhenSignalConditionIsSelected() { + NewWaitForWidget widget; + + selectOption(&widget, 3); + + WaitForSignal* waitFor = qobject_cast<WaitForSignal*>(widget.waitFor()); + QVERIFY(waitFor); + delete waitFor; +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +void NewWaitForWidgetTest::selectOption(NewWaitForWidget* widget, + int index) const { + KComboBox* comboBox = widget->findChild<KComboBox*>("waitForTypeComboBox"); + + QVERIFY(comboBox); + comboBox->setCurrentIndex(index); +} + +QTEST_MAIN(NewWaitForWidgetTest) + +#include "NewWaitForWidgetTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForSignalWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForSignalWidgetTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForSignalWidgetTest.cpp 2010-03-13 18:38:49 UTC (rev 150) @@ -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 <QtTest> + +#include "WaitForSignalWidget.h" + +#include <KLineEdit> + +#include "../WaitForSignal.h" + +class WaitForSignalWidgetTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testSaveChanges(); + +private: + + KLineEdit* emitterNameLineEdit(WaitForSignalWidget* widget) const; + KLineEdit* signalNameLineEdit(WaitForSignalWidget* widget) const; + +}; + +void WaitForSignalWidgetTest::testConstructor() { + WaitForSignal waitFor; + waitFor.setEmitterName("The emitter name"); + waitFor.setSignalName("The signal name"); + + QWidget parent; + WaitForSignalWidget* widget = new WaitForSignalWidget(&waitFor, &parent); + + QCOMPARE(widget->parentWidget(), &parent); + QCOMPARE(emitterNameLineEdit(widget)->text(), QString("The emitter name")); + QCOMPARE(signalNameLineEdit(widget)->text(), QString("The signal name")); +} + +void WaitForSignalWidgetTest::testSaveChanges() { + WaitForSignal waitFor; + waitFor.setEmitterName("The emitter name"); + waitFor.setSignalName("The signal name"); + + WaitForSignalWidget widget(&waitFor); + emitterNameLineEdit(&widget)->setText("The new emitter name"); + signalNameLineEdit(&widget)->setText("The new signal name"); + + widget.saveChanges(); + + QCOMPARE(waitFor.emitterName(), QString("The new emitter name")); + QCOMPARE(waitFor.signalName(), QString("The new signal name")); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +KLineEdit* WaitForSignalWidgetTest::emitterNameLineEdit( + WaitForSignalWidget* widget) const { + return widget->findChild<KLineEdit*>("emitterNameLineEdit"); +} + +KLineEdit* WaitForSignalWidgetTest::signalNameLineEdit( + WaitForSignalWidget* widget) const { + return widget->findChild<KLineEdit*>("signalNameLineEdit"); +} + +QTEST_MAIN(WaitForSignalWidgetTest) + +#include "WaitForSignalWidgetTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForSignalWidgetTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp 2010-03-13 18:38:49 UTC (rev 150) @@ -0,0 +1,359 @@ +/*************************************************************************** + * 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 "WaitForWidget.h" + +#include <QTreeView> + +#include <KComboBox> +#include <KLineEdit> +#include <KPushButton> + +#include "EditionDialog.h" +#include "../WaitForComposed.h" +#include "../WaitForNot.h" +#include "../WaitForSignal.h" + +class WaitForWidgetTest: public QObject { +Q_OBJECT +public slots: + + void addWaitForSignal() const; + + void setSignalData() const; + +private slots: + + void init(); + void cleanup(); + + void testConstructor(); + void testConstructorFull(); + + void testSelectWaitForAnd(); + void testSelectWaitForOr(); + void testSelectWaitForNot(); + void testSelectWaitForNotEmpty(); + void testSelectWaitForSignal(); + void testClearSelection(); + + void testAddWaitForWhenEmpty(); + void testAddWaitForToWaitForComposed(); + void testAddWaitForToWaitForNot(); + + void testEditWaitForSignal(); + + void testRemoveWaitForFromRoot(); + void testRemoveWaitForFromWaitForComposed(); + void testRemoveWaitForFromWaitForNot(); + +private: + + WaitForComposed* mWaitFor; + WaitForSignal* mWaitFor1; + WaitForComposed* mWaitFor2; + WaitForNot* mWaitFor3; + WaitForSignal* mWaitFor3_1; + WaitForNot* mWaitFor4; + + WaitForWidget* mWidget; + + QModelIndex getIndex(int row, + const QModelIndex& parent = QModelIndex()) const; + + void selectItem(const QModelIndex& index) const; + + KPushButton* button(const QString& name, WaitForWidget* widget = 0) const; + + void assertButtonEnabled(bool addButtonEnabled, + bool editButtonEnabled, + bool removeButtonEnabled, + WaitForWidget* widget = 0) const; + +}; + +void WaitForWidgetTest::init() { + mWaitFor = new WaitForComposed(); + mWaitFor->setCompositionType(WaitForComposed::And); + + mWaitFor1 = new WaitForSignal(); + mWaitFor1->setEmitterName("emitter1"); + mWaitFor1->setSignalName("signal1"); + mWaitFor->addWaitFor(mWaitFor1); + + mWaitFor2 = new WaitForComposed(); + mWaitFor2->setCompositionType(WaitForComposed::Or); + mWaitFor->addWaitFor(mWaitFor2); + + mWaitFor3 = new WaitForNot(); + mWaitFor->addWaitFor(mWaitFor3); + + mWaitFor3_1 = new WaitForSignal(); + mWaitFor3_1->setEmitterName("emitter2"); + mWaitFor3_1->setSignalName("signal2"); + mWaitFor3->setNegatedWaitFor(mWaitFor3_1); + + mWaitFor4 = new WaitForNot(); + mWaitFor->addWaitFor(mWaitFor4); + + mWidget = new WaitForWidget(mWaitFor); +} + +void WaitForWidgetTest::cleanup() { + delete mWidget; + delete mWaitFor; +} + +void WaitForWidgetTest::testConstructor() { + QWidget parent; + WaitForWidget* widget = new WaitForWidget(0, &parent); + + QCOMPARE(widget->parentWidget(), &parent); + QCOMPARE(widget->waitFor(), (WaitFor*)0); + assertButtonEnabled(true, false, false, widget); +} + +void WaitForWidgetTest::testConstructorFull() { + QWidget parent; + WaitForWidget* widget = new WaitForWidget(mWaitFor, &parent); + + QCOMPARE(widget->parentWidget(), &parent); + QCOMPARE(widget->waitFor(), (WaitFor*)mWaitFor); + assertButtonEnabled(false, false, false, widget); +} + +void WaitForWidgetTest::testSelectWaitForAnd() { + selectItem(getIndex(0)); + + assertButtonEnabled(true, false, true); +} + +void WaitForWidgetTest::testSelectWaitForOr() { + selectItem(getIndex(1, getIndex(0))); + + assertButtonEnabled(true, false, true); +} + +void WaitForWidgetTest::testSelectWaitForNot() { + selectItem(getIndex(2, getIndex(0))); + + assertButtonEnabled(false, false, true); +} + +void WaitForWidgetTest::testSelectWaitForNotEmpty() { + selectItem(getIndex(3, getIndex(0))); + + assertButtonEnabled(true, false, true); +} + +void WaitForWidgetTest::testSelectWaitForSignal() { + selectItem(getIndex(0, getIndex(0))); + + assertButtonEnabled(false, true, true); +} + +void WaitForWidgetTest::testClearSelection() { + selectItem(getIndex(0)); + selectItem(QModelIndex()); + + assertButtonEnabled(false, false, false); +} + +void WaitForWidgetTest::testAddWaitForWhenEmpty() { + delete mWidget; + mWidget = new WaitForWidget(0); + + //The dialog is modal, so it won't return to the test code until it is + //closed. Thus, the commands to execute on the dialog must be "queued", + //as calling addWaitForSignal after the button click won't work. + QTimer::singleShot(500, this, SLOT(addWaitForSignal())); + + button("addButton")->click(); + + QVERIFY(mWidget->waitFor()); + QVERIFY(qobject_cast<WaitForSignal*>(mWidget->waitFor())); + delete mWidget->waitFor(); +} + +void WaitForWidgetTest::testAddWaitForToWaitForComposed() { + selectItem(getIndex(1, getIndex(0))); + + //The dialog is modal, so it won't return to the test code until it is + //closed. Thus, the commands to execute on the dialog must be "queued", + //as calling addWaitForSignal after the button click won't work. + QTimer::singleShot(500, this, SLOT(addWaitForSignal())); + + button("addButton")->click(); + + selectItem(getIndex(0)); + + QTimer::singleShot(500, this, SLOT(addWaitForSignal())); + + button("addButton")->click(); + + QCOMPARE(mWaitFor->waitFors().count(), 5); + QCOMPARE(mWaitFor->waitFors()[0], mWaitFor1); + QCOMPARE(mWaitFor->waitFors()[1], mWaitFor2); + QCOMPARE(mWaitFor->waitFors()[2], mWaitFor3); + QCOMPARE(mWaitFor->waitFors()[3], mWaitFor4); + QVERIFY(qobject_cast<WaitForSignal*>(mWaitFor->waitFors()[4])); + QCOMPARE(mWaitFor2->waitFors().count(), 1); + QVERIFY(qobject_cast<WaitForSignal*>(mWaitFor2->waitFors()[0])); + QVERIFY(mWaitFor->waitFors()[4] != mWaitFor2->waitFors()[0]); +} + +void WaitForWidgetTest::testAddWaitForToWaitForNot() { + selectItem(getIndex(3, getIndex(0))); + + //The dialog is modal, so it won't return to the test code until it is + //closed. Thus, the commands to execute on the dialog must be "queued", + //as calling addWaitForSignal after the button click won't work. + QTimer::singleShot(500, this, SLOT(addWaitForSignal())); + + button("addButton")->click(); + + QCOMPARE(mWaitFor->waitFors().count(), 4); + QCOMPARE(mWaitFor->waitFors()[0], mWaitFor1); + QCOMPARE(mWaitFor->waitFors()[1], mWaitFor2); + QCOMPARE(mWaitFor->waitFors()[2], mWaitFor3); + QCOMPARE(mWaitFor->waitFors()[3], mWaitFor4); + QVERIFY(qobject_cast<WaitForSignal*>(mWaitFor4->negatedWaitFor())); +} + +void WaitForWidgetTest::testEditWaitForSignal() { + selectItem(getIndex(0, getIndex(0))); + + //The dialog is modal, so it won't return to the test code until it is + //closed. Thus, the commands to execute on the dialog must be "queued", + //as calling setSignalData after the button click won't work. + QTimer::singleShot(500, this, SLOT(setSignalData())); + + button("editButton")->click(); + + QCOMPARE(mWaitFor1->emitterName(), QString("The new emitter name")); + QCOMPARE(mWaitFor1->signalName(), QString("The new signal name")); +} + +void WaitForWidgetTest::testRemoveWaitForFromRoot() { + delete mWidget; + WaitForSignal* waitForSignal = new WaitForSignal(); + mWidget = new WaitForWidget(waitForSignal); + + selectItem(getIndex(0)); + button("removeButton")->click(); + + QVERIFY(!mWidget->waitFor()); +} + +void WaitForWidgetTest::testRemoveWaitForFromWaitForComposed() { + selectItem(getIndex(2, getIndex(0))); + button("removeButton")->click(); + + QCOMPARE(mWaitFor->waitFors().count(), 3); + QCOMPARE(mWaitFor->waitFors()[0], mWaitFor1); + QCOMPARE(mWaitFor->waitFors()[1], mWaitFor2); + QCOMPARE(mWaitFor->waitFors()[2], mWaitFor4); +} + +void WaitForWidgetTest::testRemoveWaitForFromWaitForNot() { + selectItem(getIndex(0, getIndex(2, getIndex(0)))); + button("removeButton")->click(); + + QCOMPARE(mWaitFor->waitFors().count(), 4); + QCOMPARE(mWaitFor->waitFors()[0], mWaitFor1); + QCOMPARE(mWaitFor->waitFors()[1], mWaitFor2); + QCOMPARE(mWaitFor->waitFors()[2], mWaitFor3); + QCOMPARE(mWaitFor->waitFors()[3], mWaitFor4); + QVERIFY(!mWaitFor3->negatedWaitFor()); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +void WaitForWidgetTest::addWaitForSignal() const { + KComboBox* comboBox = mWidget->findChild<KComboBox*>("waitForTypeComboBox"); + QVERIFY(comboBox); + comboBox->setCurrentIndex(3); + + KDialog* dialog = mWidget->findChild<KDialog*>("addWaitForDialog"); + QVERIFY(dialog); + dialog->button(KDialog::Ok)->click(); +} + +void WaitForWidgetTest::setSignalData() const { + KLineEdit* emitterNameLineEdit = + mWidget->findChild<KLineEdit*>("emitterNameLineEdit"); + QVERIFY(emitterNameLineEdit); + emitterNameLineEdit->setText("The new emitter name"); + + KLineEdit* signalNameLineEdit = + mWidget->findChild<KLineEdit*>("signalNameLineEdit"); + QVERIFY(signalNameLineEdit); + signalNameLineEdit->setText("The new signal name"); + + EditionDialog* dialog = mWidget->findChild<EditionDialog*>("editionDialog"); + QVERIFY(dialog); + dialog->button(KDialog::Ok)->click(); +} + +QModelIndex WaitForWidgetTest::getIndex(int row, + const QModelIndex& parent) const { + QTreeView* tree = mWidget->findChild<QTreeView*>("waitForTreeView"); + return tree->model()->index(row, 0, parent); +} + +void WaitForWidgetTest::selectItem(const QModelIndex& index) const { + QTreeView* tree = mWidget->findChild<QTreeView*>("waitForTreeView"); + QItemSelectionModel* model = tree->selectionModel(); + model->select(index, QItemSelectionModel::SelectCurrent); +} + +KPushButton* WaitForWidgetTest::button(const QString& name, + WaitForWidget* widget) const { + if (!widget) { + widget = mWidget; + } + + return widget->findChild<KPushButton*>(name); +} + +void WaitForWidgetTest::assertButtonEnabled(bool addButtonEnabled, + bool editButtonEnabled, + bool removeButtonEnabled, + WaitForWidget* widget) const { + if (!widget) { + widget = mWidget; + } + + KPushButton* addButton = button("addButton", widget); + QVERIFY(addButton); + QCOMPARE(addButton->isEnabled(), addButtonEnabled); + + KPushButton* editButton = button("editButton", widget); + QVERIFY(editButton); + QCOMPARE(editButton->isEnabled(), editButtonEnabled); + + KPushButton* removeButton = button("removeButton", widget); + QVERIFY(removeButton); + QCOMPARE(removeButton->isEnabled(), removeButtonEnabled); +} + +QTEST_MAIN(WaitForWidgetTest) + +#include "WaitForWidgetTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.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-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. |
From: <dan...@us...> - 2010-03-12 17:06:09
|
Revision: 148 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=148&view=rev Author: danxuliu Date: 2010-03-12 17:05:56 +0000 (Fri, 12 Mar 2010) Log Message: ----------- Rename objectName to emitterName to avoid clashing with QObject:objectName(). Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp 2010-03-12 00:08:24 UTC (rev 147) +++ trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp 2010-03-12 17:05:56 UTC (rev 148) @@ -23,12 +23,12 @@ WaitForSignal::WaitForSignal(QObject* parent): WaitFor(parent) { } -QString WaitForSignal::objectName() const { - return mObjectName; +QString WaitForSignal::emitterName() const { + return mEmitterName; } -void WaitForSignal::setObjectName(const QString& objectName) { - mObjectName = objectName; +void WaitForSignal::setEmitterName(const QString& emitterName) { + mEmitterName = emitterName; emit dataChanged(this); } Modified: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h 2010-03-12 00:08:24 UTC (rev 147) +++ trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h 2010-03-12 17:05:56 UTC (rev 148) @@ -41,15 +41,15 @@ */ WaitForSignal(QObject* parent = 0); - QString objectName() const; - void setObjectName(const QString& objectName); + QString emitterName() const; + void setEmitterName(const QString& emitterName); QString signalName() const; void setSignalName(const QString& signalName); private: - QString mObjectName; + QString mEmitterName; QString mSignalName; }; Modified: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp 2010-03-12 00:08:24 UTC (rev 147) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp 2010-03-12 17:05:56 UTC (rev 148) @@ -29,7 +29,7 @@ void testConstructor(); - void testSetObjectName(); + void testSetEmitterName(); void testSetSignalName(); @@ -54,14 +54,14 @@ QCOMPARE(waitForSignal->parent(), &parent); } -void WaitForSignalTest::testSetObjectName() { +void WaitForSignalTest::testSetEmitterName() { WaitForSignal waitForSignal; QSignalSpy dataChangedSpy(&waitForSignal, SIGNAL(dataChanged(WaitFor*))); - waitForSignal.setObjectName("The object name"); + waitForSignal.setEmitterName("The emitter name"); - QCOMPARE(waitForSignal.objectName(), QString("The object name")); + QCOMPARE(waitForSignal.emitterName(), QString("The emitter name")); QCOMPARE(dataChangedSpy.count(), 1); assertWaitForSignal(dataChangedSpy, 0, &waitForSignal); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-12 00:08:31
|
Revision: 147 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=147&view=rev Author: danxuliu Date: 2010-03-12 00:08:24 +0000 (Fri, 12 Mar 2010) Log Message: ----------- Add WaitFor and subclasses to store the data of conditions to wait for to be met. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp trunk/ktutorial/ktutorial-editor/src/WaitFor.h trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp trunk/ktutorial/ktutorial-editor/src/WaitForNot.h trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-11 19:36:17 UTC (rev 146) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-12 00:08:24 UTC (rev 147) @@ -10,6 +10,10 @@ KTutorialEditor.cpp Step.cpp Tutorial.cpp + WaitFor.cpp + WaitForComposed.cpp + WaitForNot.cpp + WaitForSignal.cpp ) # Instead of compiling the executable directly from the sources, the sources are Added: trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,24 @@ +/*************************************************************************** + * 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 "WaitFor.h" + +//public: + +WaitFor::WaitFor(QObject* parent): QObject(parent) { +} Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitFor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitFor.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitFor.h 2010-03-12 00:08:24 UTC (rev 147) @@ -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/>. * + ***************************************************************************/ + +#ifndef WAITFOR_H +#define WAITFOR_H + +#include <QObject> + +/** + * Base class for conditions to wait for to be met. + * Its subclasses store the data used in KTutorial wait for subclasses, but they + * have nothing to do with them (they don't even know each others). Its purpose + * is store the data needed to generate the code to initialize a true + * KTutorial::WaitFor subclass object. + * + * Subclasses must emit dataChanged(Step*) signal when their data is modified + * (including the data of child conditions). + */ +class WaitFor: public QObject { +Q_OBJECT +public: + + /** + * Creates a new WaitFor. + * + * @param parent The parent QObject. + */ + WaitFor(QObject* parent = 0); + +Q_SIGNALS: + + /** + * Emitted when any data in the WaitFor changed. + * Subclasses must emit this signal when needed. + * + * @param waitFor This WaitFor. + */ + void dataChanged(WaitFor* waitFor); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitFor.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -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/>. * + ***************************************************************************/ + +#include "WaitForComposed.h" + +//public: + +WaitForComposed::WaitForComposed(QObject* parent): + WaitFor(parent), + mCompositionType(And) { +} + +WaitForComposed::~WaitForComposed() { + qDeleteAll(mWaitFors); +} + +WaitForComposed::CompositionType WaitForComposed::compositionType() const { + return mCompositionType; +} + +void WaitForComposed::setCompositionType(CompositionType compositionType) { + mCompositionType = compositionType; + + emit dataChanged(this); +} + +void WaitForComposed::addWaitFor(WaitFor* waitFor) { + Q_ASSERT(!mWaitFors.contains(waitFor)); + + mWaitFors.append(waitFor); + + emit waitForAdded(waitFor); +} + +QList<WaitFor*> WaitForComposed::waitFors() const { + return mWaitFors; +} + +void WaitForComposed::removeWaitFor(WaitFor* waitFor) { + Q_ASSERT(mWaitFors.contains(waitFor)); + + mWaitFors.removeOne(waitFor); + + emit waitForRemoved(waitFor); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,96 @@ +/*************************************************************************** + * 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 WAITFORCOMPOSED_H +#define WAITFORCOMPOSED_H + +#include "WaitFor.h" + +/** + * Container for composed conditions to wait for data. + * It stores the data used in KTutorial WaitForAnd and WaitForOr, but it has + * nothing to do with them (they don't even know each other). Its purpose is + * store the data needed to generate the code to initialize a true + * KTutorial::WaitForComposed subclass object. + * + * When the composition type is modified, dataChanged(WaitFor*) signal is + * emitted. When WaitFors are added or removed, waitForAdded(WaitFor*) and + * waitForRemoved(WaitFor*) are emitted. + */ +class WaitForComposed: public WaitFor { +Q_OBJECT +public: + + enum CompositionType { + And, + Or + }; + + /** + * Creates a new WaitForComposed. + * + * @param parent The parent QObject. + */ + WaitForComposed(QObject* parent = 0); + virtual ~WaitForComposed(); + + CompositionType compositionType() const; + void setCompositionType(CompositionType compositionType); + + /** + * Adds a new WaitFor to this WaitForComposed. + * This WaitForComposed gets ownership of the added WaitFor, so it is + * deleted when this WaitForComposed is deleted. + * + * @param waitFor The WaitFor to add. + */ + void addWaitFor(WaitFor* waitFor); + QList<WaitFor*> waitFors() const; + + /** + * Removes a WaitFor from this WaitForComposed. + * The WaitFor must be deleted explicitly. + * + * @param waitFor The WaitFor to remove. + */ + void removeWaitFor(WaitFor* waitFor); + +Q_SIGNALS: + + /** + * Emitted when the WaitFor is added to this WaitForComposed. + * + * @param waitFor The WaitFor added. + */ + void waitForAdded(WaitFor* waitFor); + + /** + * Emitted when the WaitFor is removed from this WaitForComposed. + * + * @param waitFor The WaitFor removed. + */ + void waitForRemoved(WaitFor* waitFor); + +private: + + CompositionType mCompositionType; + QList<WaitFor*> mWaitFors; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,40 @@ +/*************************************************************************** + * 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 "WaitForNot.h" + +//public: + +WaitForNot::WaitForNot(QObject* parent): + WaitFor(parent), + mNegatedWaitFor(0) { +} + +WaitForNot::~WaitForNot() { + delete mNegatedWaitFor; +} + +WaitFor* WaitForNot::negatedWaitFor() const { + return mNegatedWaitFor; +} + +void WaitForNot::setNegatedWaitFor(WaitFor* waitFor) { + mNegatedWaitFor = waitFor; + + emit dataChanged(this); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForNot.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForNot.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForNot.h 2010-03-12 00:08:24 UTC (rev 147) @@ -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/>. * + ***************************************************************************/ + +#ifndef WAITFORNOT_H +#define WAITFORNOT_H + +#include "WaitFor.h" + +/** + * Container for negated wait for data. + * It stores the data used in KTutorial WaitForNot, but it has nothing to do + * with it (they don't even know each other). Its purpose is store the data + * needed to generate the code to initialize a true KTutorial::WaitForNot + * object. + * + * When the negated wait for is modified, dataChanged(WaitFor*) signal is + * emitted. + */ +class WaitForNot: public WaitFor { +Q_OBJECT +public: + + /** + * Creates a new WaitForNot. + * + * @param parent The parent QObject. + */ + WaitForNot(QObject* parent = 0); + virtual ~WaitForNot(); + + WaitFor* negatedWaitFor() const; + + /** + * Sets the negated WaitFor. + * The WaitFor will be destroyed when this WaitForNot is destroyed. However, + * if a WaitFor is set over a previous one, the previous one must be deleted + * explicitly. + * + * @param waitFor The WaitFor to set. + */ + void setNegatedWaitFor(WaitFor* waitFor); + +private: + + WaitFor* mNegatedWaitFor; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForNot.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -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 "WaitForSignal.h" + +//public: + +WaitForSignal::WaitForSignal(QObject* parent): WaitFor(parent) { +} + +QString WaitForSignal::objectName() const { + return mObjectName; +} + +void WaitForSignal::setObjectName(const QString& objectName) { + mObjectName = objectName; + + emit dataChanged(this); +} + +QString WaitForSignal::signalName() const { + return mSignalName; +} + +void WaitForSignal::setSignalName(const QString& signalName) { + mSignalName = signalName; + + emit dataChanged(this); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h 2010-03-12 00:08:24 UTC (rev 147) @@ -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/>. * + ***************************************************************************/ + +#ifndef WAITFORSIGNAL_H +#define WAITFORSIGNAL_H + +#include "WaitFor.h" + +/** + * Container for conditions that wait for a signal to be emitted data. + * It stores the data used in KTutorial WaitForSignal, but it has nothing to do + * with it (they don't even know each other). Its purpose is store the data + * needed to generate the code to initialize a true KTutorial::WaitForSignal + * object. + * + * When any attribute is modified, dataChanged(WaitFor*) signal is emitted. + */ +class WaitForSignal: public WaitFor { +Q_OBJECT +public: + + /** + * Creates a new WaitForSignal. + * + * @param parent The parent QObject. + */ + WaitForSignal(QObject* parent = 0); + + QString objectName() const; + void setObjectName(const QString& objectName); + + QString signalName() const; + void setSignalName(const QString& signalName); + +private: + + QString mObjectName; + QString mSignalName; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-11 19:36:17 UTC (rev 146) +++ trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-12 00:08:24 UTC (rev 147) @@ -17,6 +17,9 @@ unit_tests( Step Tutorial + WaitForComposed + WaitForNot + WaitForSignal ) MACRO(MEM_TESTS) @@ -28,4 +31,7 @@ mem_tests( Step Tutorial + WaitForComposed + WaitForNot + WaitForSignal ) Added: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,143 @@ +/*************************************************************************** + * 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 "WaitForComposed.h" + +class WaitForComposedTest: public QObject { +Q_OBJECT + +private slots: + + void initTestCase(); + + void testConstructor(); + + void testSetCompositionType(); + + void testAddWaitFor(); + void testRemoveWaitFor(); + +private: + + int mWaitForStarType; + + void assertWaitForSignal(const QSignalSpy& spy, int index, + WaitFor* waitFor); + +}; + +void WaitForComposedTest::initTestCase() { + //WaitFor* must be registered in order to be used with QSignalSpy + mWaitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); +} + +void WaitForComposedTest::testConstructor() { + QObject parent; + WaitForComposed* waitForComposed = new WaitForComposed(&parent); + + QCOMPARE(waitForComposed->parent(), &parent); + QCOMPARE(waitForComposed->compositionType(), WaitForComposed::And); +} + +void WaitForComposedTest::testSetCompositionType() { + WaitForComposed waitForComposed; + + QSignalSpy dataChangedSpy(&waitForComposed, SIGNAL(dataChanged(WaitFor*))); + + waitForComposed.setCompositionType(WaitForComposed::Or); + + QCOMPARE(waitForComposed.compositionType(), WaitForComposed::Or); + QCOMPARE(dataChangedSpy.count(), 1); + assertWaitForSignal(dataChangedSpy, 0, &waitForComposed); +} + +void WaitForComposedTest::testAddWaitFor() { + WaitForComposed waitForComposed; + WaitFor* waitFor1 = new WaitFor(); + WaitFor* waitFor2 = new WaitFor(); + WaitFor* waitFor3 = new WaitFor(); + + QSignalSpy waitForAddedSpy(&waitForComposed, + SIGNAL(waitForAdded(WaitFor*))); + + waitForComposed.addWaitFor(waitFor1); + waitForComposed.addWaitFor(waitFor2); + waitForComposed.addWaitFor(waitFor3); + + QCOMPARE(waitForComposed.waitFors().count(), 3); + QCOMPARE(waitForComposed.waitFors()[0], waitFor1); + QCOMPARE(waitForComposed.waitFors()[1], waitFor2); + QCOMPARE(waitForComposed.waitFors()[2], waitFor3); + QCOMPARE(waitForAddedSpy.count(), 3); + assertWaitForSignal(waitForAddedSpy, 0, waitFor1); + assertWaitForSignal(waitForAddedSpy, 1, waitFor2); + assertWaitForSignal(waitForAddedSpy, 2, waitFor3); +} + +void WaitForComposedTest::testRemoveWaitFor() { + WaitForComposed waitForComposed; + + //They will be removed and not deleted by the WaitForComposed, so they are + //created in stack + WaitFor waitFor1; + WaitFor waitFor2; + WaitFor waitFor3; + + waitForComposed.addWaitFor(&waitFor1); + waitForComposed.addWaitFor(&waitFor2); + waitForComposed.addWaitFor(&waitFor3); + + QSignalSpy waitForRemovedSpy(&waitForComposed, + SIGNAL(waitForRemoved(WaitFor*))); + + waitForComposed.removeWaitFor(&waitFor2); + + QCOMPARE(waitForComposed.waitFors().count(), 2); + QCOMPARE(waitForComposed.waitFors()[0], &waitFor1); + QCOMPARE(waitForComposed.waitFors()[1], &waitFor3); + QCOMPARE(waitForRemovedSpy.count(), 1); + assertWaitForSignal(waitForRemovedSpy, 0, &waitFor2); + + waitForComposed.removeWaitFor(&waitFor1); + waitForComposed.removeWaitFor(&waitFor3); + + QCOMPARE(waitForComposed.waitFors().count(), 0); + QCOMPARE(waitForRemovedSpy.count(), 3); + assertWaitForSignal(waitForRemovedSpy, 1, &waitFor1); + assertWaitForSignal(waitForRemovedSpy, 2, &waitFor3); +} + +//WaitFor* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(WaitFor*); + +/////////////////////////////////// Helpers //////////////////////////////////// + +void WaitForComposedTest::assertWaitForSignal(const QSignalSpy& spy, int index, + WaitFor* waitFor) { + QCOMPARE(spy.at(index).count(), 1); + + QVariant argument = spy.at(index).at(0); + QCOMPARE(argument.userType(), mWaitForStarType); + QCOMPARE(qvariant_cast<WaitFor*>(argument), waitFor); +} + +QTEST_MAIN(WaitForComposedTest) + +#include "WaitForComposedTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -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 <QtTest> + +#include "WaitForNot.h" + +class WaitForNotTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testSetNegatedWaitFor(); + +}; + +void WaitForNotTest::testConstructor() { + QObject parent; + WaitForNot* waitForNot = new WaitForNot(&parent); + + QCOMPARE(waitForNot->parent(), &parent); + QCOMPARE(waitForNot->negatedWaitFor(), (WaitFor*)0); +} + +//WaitFor* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(WaitFor*); + +void WaitForNotTest::testSetNegatedWaitFor() { + WaitForNot waitForNot; + WaitFor* negatedWaitFor = new WaitFor(); + + //WaitFor* must be registered in order to be used with QSignalSpy + int waitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); + QSignalSpy dataChangedSpy(&waitForNot, SIGNAL(dataChanged(WaitFor*))); + + waitForNot.setNegatedWaitFor(negatedWaitFor); + + QCOMPARE(waitForNot.negatedWaitFor(), negatedWaitFor); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), waitForStarType); + QCOMPARE(qvariant_cast<WaitFor*>(argument), &waitForNot); +} + +QTEST_MAIN(WaitForNotTest) + +#include "WaitForNotTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,97 @@ +/*************************************************************************** + * 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 "WaitForSignal.h" + +class WaitForSignalTest: public QObject { +Q_OBJECT + +private slots: + + void initTestCase(); + + void testConstructor(); + + void testSetObjectName(); + + void testSetSignalName(); + +private: + + int mWaitForStarType; + + void assertWaitForSignal(const QSignalSpy& spy, int index, + WaitFor* waitFor); + +}; + +void WaitForSignalTest::initTestCase() { + //WaitFor* must be registered in order to be used with QSignalSpy + mWaitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); +} + +void WaitForSignalTest::testConstructor() { + QObject parent; + WaitForSignal* waitForSignal = new WaitForSignal(&parent); + + QCOMPARE(waitForSignal->parent(), &parent); +} + +void WaitForSignalTest::testSetObjectName() { + WaitForSignal waitForSignal; + + QSignalSpy dataChangedSpy(&waitForSignal, SIGNAL(dataChanged(WaitFor*))); + + waitForSignal.setObjectName("The object name"); + + QCOMPARE(waitForSignal.objectName(), QString("The object name")); + QCOMPARE(dataChangedSpy.count(), 1); + assertWaitForSignal(dataChangedSpy, 0, &waitForSignal); +} + +void WaitForSignalTest::testSetSignalName() { + WaitForSignal waitForSignal; + + QSignalSpy dataChangedSpy(&waitForSignal, SIGNAL(dataChanged(WaitFor*))); + + waitForSignal.setSignalName("The signal name"); + + QCOMPARE(waitForSignal.signalName(), QString("The signal name")); + QCOMPARE(dataChangedSpy.count(), 1); + assertWaitForSignal(dataChangedSpy, 0, &waitForSignal); +} + +//WaitFor* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(WaitFor*); + +/////////////////////////////////// Helpers //////////////////////////////////// + +void WaitForSignalTest::assertWaitForSignal(const QSignalSpy& spy, int index, + WaitFor* waitFor) { + QCOMPARE(spy.at(index).count(), 1); + + QVariant argument = spy.at(index).at(0); + QCOMPARE(argument.userType(), mWaitForStarType); + QCOMPARE(qvariant_cast<WaitFor*>(argument), waitFor); +} + +QTEST_MAIN(WaitForSignalTest) + +#include "WaitForSignalTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.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-11 19:36:24
|
Revision: 146 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=146&view=rev Author: danxuliu Date: 2010-03-11 19:36:17 +0000 (Thu, 11 Mar 2010) Log Message: ----------- Fix registering meta type. I don't know why it worked with the wrong type... but if the signals were emitted the test passed, and if they weren't the test didn't pass, so the test was "fine" anyway. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp Modified: trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp 2010-03-10 18:47:21 UTC (rev 145) +++ trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp 2010-03-11 19:36:17 UTC (rev 146) @@ -57,7 +57,7 @@ void TutorialTest::initTestCase() { //Step* must be registered in order to be used with QSignalSpy - mStepStarType = qRegisterMetaType<Tutorial*>("Step*"); + mStepStarType = qRegisterMetaType<Step*>("Step*"); } void TutorialTest::testConstructor() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-10 18:47:28
|
Revision: 145 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=145&view=rev Author: danxuliu Date: 2010-03-10 18:47:21 +0000 (Wed, 10 Mar 2010) Log Message: ----------- -Add localization infrastructure. -Add Spanish localization. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/po/ trunk/ktutorial/ktutorial-editor/po/CMakeLists.txt trunk/ktutorial/ktutorial-editor/po/Messages.sh trunk/ktutorial/ktutorial-editor/po/es.po trunk/ktutorial/ktutorial-editor/po/ktutorial-editor.pot Modified: trunk/ktutorial/ktutorial-editor/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/CMakeLists.txt 2010-03-10 18:35:20 UTC (rev 144) +++ trunk/ktutorial/ktutorial-editor/CMakeLists.txt 2010-03-10 18:47:21 UTC (rev 145) @@ -4,5 +4,6 @@ include(KDE4Defaults) +add_subdirectory(po) add_subdirectory(src) add_subdirectory(tests) Added: trunk/ktutorial/ktutorial-editor/po/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/po/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-editor/po/CMakeLists.txt 2010-03-10 18:47:21 UTC (rev 145) @@ -0,0 +1,25 @@ +find_program(GETTEXT_MSGFMT_EXECUTABLE msgfmt) + +if(NOT GETTEXT_MSGFMT_EXECUTABLE) + message( +"------ + NOTE: msgfmt not found. Translations will *not* be installed +------") +else(NOT GETTEXT_MSGFMT_EXECUTABLE) + + set(catalogname ktutorial-editor) + + add_custom_target(translations ALL) + + file(GLOB PO_FILES *.po) + + foreach(_poFile ${PO_FILES}) + get_filename_component(_lang ${_poFile} NAME_WE) + set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo) + add_custom_command(TARGET translations + COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} --check -o ${_gmoFile} ${_poFile} + DEPENDS ${_poFile}) + install(FILES ${_gmoFile} DESTINATION ${LOCALE_INSTALL_DIR}/${_lang}/LC_MESSAGES/ RENAME ${catalogname}.mo) + endforeach(_poFile ${PO_FILES}) + +endif(NOT GETTEXT_MSGFMT_EXECUTABLE) Property changes on: trunk/ktutorial/ktutorial-editor/po/CMakeLists.txt ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/po/Messages.sh =================================================================== --- trunk/ktutorial/ktutorial-editor/po/Messages.sh (rev 0) +++ trunk/ktutorial/ktutorial-editor/po/Messages.sh 2010-03-10 18:47:21 UTC (rev 145) @@ -0,0 +1,48 @@ +#!/bin/sh + +BASEDIR="../src/" # root of translatable sources +PROJECT="ktutorial-editor" # project name +BUGADDR="http://sourceforge.net/tracker/?group_id=301227&atid=1270278" # MSGID-Bugs +WDIR=`pwd` # working dir + +echo "Preparing rc files" +cd ${BASEDIR} +# we use simple sorting to make sure the lines do not jump around too much from system to system +find . -name '*.rc' -o -name '*.ui' -o -name '*.kcfg' | sort > ${WDIR}/rcfiles.list +xargs --arg-file=${WDIR}/rcfiles.list extractrc > ${WDIR}/rc.cpp +# additional string for KAboutData +echo 'i18nc("NAME OF TRANSLATORS","Your names");' >> ${WDIR}/rc.cpp +echo 'i18nc("EMAIL OF TRANSLATORS","Your emails");' >> ${WDIR}/rc.cpp +cd ${WDIR} +echo "Done preparing rc files" + + +echo "Extracting messages" +cd ${BASEDIR} +# see above on sorting +find . -name '*.cpp' -o -name '*.h' -o -name '*.c' | sort > ${WDIR}/infiles.list +echo "rc.cpp" >> ${WDIR}/infiles.list +cd ${WDIR} +xgettext --from-code=UTF-8 -C -kde -ki18n -ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 -ktr2i18n:1 \ + -kI18N_NOOP:1 -kI18N_NOOP2:1c,2 -kaliasLocale -kki18n:1 -kki18nc:1c,2 -kki18np:1,2 -kki18ncp:1c,2,3 \ + --msgid-bugs-address="${BUGADDR}" \ + --files-from=infiles.list -D ${BASEDIR} -D ${WDIR} -o ${PROJECT}.pot || { echo "error while calling xgettext. aborting."; exit 1; } +echo "Done extracting messages" + + +echo "Merging translations" +catalogs=`find . -name '*.po'` +for cat in $catalogs; do + echo $cat + msgmerge -o $cat.new $cat ${PROJECT}.pot + mv $cat.new $cat +done +echo "Done merging translations" + + +echo "Cleaning up" +cd ${WDIR} +rm rcfiles.list +rm infiles.list +rm rc.cpp +echo "Done" Property changes on: trunk/ktutorial/ktutorial-editor/po/Messages.sh ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/po/es.po =================================================================== --- trunk/ktutorial/ktutorial-editor/po/es.po (rev 0) +++ trunk/ktutorial/ktutorial-editor/po/es.po 2010-03-10 18:47:21 UTC (rev 145) @@ -0,0 +1,423 @@ +# Spanish translations for ktutorial-editor package +# Traducciones al español para el paquete ktutorial-editor. +# Copyright (C) 2010 Daniel Calviño Sánchez +# This file is distributed under the same license as the ktutorial-editor package. +# +# Daniel Calviño Sánchez <dan...@gm...>, 2010. +msgid "" +msgstr "" +"Project-Id-Version: ktutorial-editor\n" +"Report-Msgid-Bugs-To: http://sourceforge." +"net/tracker/?group_id=301227&atid=1270278\n" +"POT-Creation-Date: 2010-03-10 19:41+0100\n" +"PO-Revision-Date: 2010-03-10 19:41-0500\n" +"Last-Translator: Daniel Calviño Sánchez <dan...@gm...>\n" +"Language-Team: Spanish <>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Lokalize 1.0\n" + +#: KTutorialEditor.cpp:77 +msgctxt "@title" +msgid "Edit tutorial" +msgstr "Editar tutorial" + +#: KTutorialEditor.cpp:82 +msgctxt "@title" +msgid "Edit step" +msgstr "Editar paso" + +#: KTutorialEditor.cpp:94 +msgctxt "@action" +msgid "Set information..." +msgstr "Establecer información..." + +#: KTutorialEditor.cpp:95 +msgctxt "@info:status" +msgid "Set the name and description of the tutorial." +msgstr "Establecer el nombre y la descripción del tutorial." + +#: KTutorialEditor.cpp:104 +msgctxt "@action" +msgid "Set license..." +msgstr "Establecer licencia..." + +#: KTutorialEditor.cpp:105 +msgctxt "@info:status" +msgid "Set the license text of the tutorial." +msgstr "Establecer el texto de licencia del tutorial." + +#: KTutorialEditor.cpp:113 KTutorialEditor.cpp:153 +msgctxt "@action" +msgid "Set setup code..." +msgstr "Establecer código de inicialización..." + +#: KTutorialEditor.cpp:114 +msgctxt "@info:status" +msgid "Set the custom code to be executed when the tutorial starts." +msgstr "" +"Establecer el código propio para ser ejecutado cuando comience el tutorial." + +#: KTutorialEditor.cpp:122 KTutorialEditor.cpp:163 +msgctxt "@action" +msgid "Set tear down code..." +msgstr "Establecer el código de finalización..." + +#: KTutorialEditor.cpp:123 +msgctxt "@info:status" +msgid "Set the custom code to be executed when the tutorial finishes." +msgstr "" +"Establecer el código propio para ser ejecutado cuando termine el tutorial." + +#: KTutorialEditor.cpp:134 +msgctxt "@action" +msgid "Add step..." +msgstr "Añadir paso..." + +#: KTutorialEditor.cpp:135 +msgctxt "@info:status" +msgid "Add a new step to the tutorial." +msgstr "Añadir un nuevo paso al tutorial." + +#: KTutorialEditor.cpp:143 +msgctxt "@action" +msgid "Set data..." +msgstr "Establecer datos..." + +#: KTutorialEditor.cpp:144 +msgctxt "@info:status" +msgid "Set the name and text of the currently selected step." +msgstr "Establecer el nombre y el texto del paso seleccionado actualmente." + +#: KTutorialEditor.cpp:154 +msgctxt "@info:status" +msgid "" +"Set the custom code to be executed when the tutorial passes to the currently " +"selected step." +msgstr "" +"Establecer el código propio para ser ejecutado cuando el tutorial cambie al " +"paso seleccionado actualmente." + +#: KTutorialEditor.cpp:164 +msgctxt "@info:status" +msgid "" +"Set the custom code to be executed when the tutorial changes from the " +"currently selected step to another step." +msgstr "" +"Establecer el código propio para ser ejecutado cuando el tutorial cambie del " +"paso seleccionado actualmente a otro paso." + +#: KTutorialEditor.cpp:174 +msgctxt "@action" +msgid "Remove step" +msgstr "Eliminar paso" + +#: KTutorialEditor.cpp:175 +msgctxt "@info:status" +msgid "Removes the currently selected step from the tutorial." +msgstr "Elimina del tutorial el paso seleccionado actualmente." + +#: main.cpp:27 +msgctxt "@title" +msgid "KTutorial editor" +msgstr "Editor para KTutorial" + +#: main.cpp:29 +msgctxt "@title" +msgid "An editor to create tutorials for <application>KTutorial</application>." +msgstr "" +"Un editor para crear tutoriales para <application>KTutorial</application>." + +#: main.cpp:32 +msgctxt "@info:credit" +msgid "Copyright (c) 2010 Daniel Calviño Sánchez" +msgstr "Copyright (c) 2010 Daniel Calviño Sánchez" + +#: main.cpp:33 +msgctxt "@info:credit" +msgid "Daniel Calviño Sánchez" +msgstr "Daniel Calviño Sánchez" + +#: main.cpp:34 +msgctxt "@info:credit" +msgid "Main developer" +msgstr "Desarrollador principal" + +#: view/StepCustomCodeWidget.cpp:39 +msgctxt "@title" +msgid "Step setup code" +msgstr "Código de inicialización del paso" + +#: view/StepCustomCodeWidget.cpp:40 +msgctxt "@title" +msgid "Set the step setup code" +msgstr "Establecer el código de inicialización del paso" + +#: view/StepCustomCodeWidget.cpp:41 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the code to be executed when the tutorials passes to the step.</" +"para><para>The code will be written as is to the setup of the step, after " +"the setup code generated automatically by the editor. This means that the " +"code must be written in the same programming language the tutorial will be " +"exported to.</para>" +msgstr "" +"<para>Establece el código que se ejecutará cuando el tutorial cambie al paso." +"</para><para>El código se escribirá tal cuál en la inicialización del paso, " +"tras el código de inicialización generado automáticamente por el editor. " +"Esto quiere decir que el código debe estar escrito en el mismo lenguaje de " +"programación que en el que se exportará el tutorial.</para>" + +#: view/StepCustomCodeWidget.cpp:50 +msgctxt "@title" +msgid "Step tear down code" +msgstr "Código de finalización del paso" + +#: view/StepCustomCodeWidget.cpp:51 +msgctxt "@title" +msgid "Set the step tear down code" +msgstr "Establecer el código de finalización del paso" + +#: view/StepCustomCodeWidget.cpp:52 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the code to be executed when the tutorial changes from this step " +"to another.</para><para>The code will be written as is to the tear down of " +"the step, before the tear down code generated automatically by the editor. " +"This means that the code must be written in the same programming language " +"the tutorial will be exported to.</para>" +msgstr "" +"<para>Establece el código que se ejecutará cuando el tutorial cambie de este " +"paso a otro.</para><para>El código se escribirá tal cuál en la finalización " +"del paso, tras el código de finalización generado automáticamente por el " +"editor. Esto quiere decir que el código debe estar escrito en el mismo " +"lenguaje de programación que en el que se exportará el tutorial.</para>" + +#: view/StepTreeItem.cpp:45 +msgctxt "@item Noun, a step in a tutorial" +msgid "Step" +msgstr "Paso" + +#: view/StepTreeItem.cpp:48 +msgctxt "@item Noun, a step in a tutorial" +msgid "Step %1" +msgstr "Paso %1" + +#: view/StepTreeItem.cpp:74 +msgctxt "@item" +msgid "Text: %1" +msgstr "Texto: %1" + +#: view/StepTreeItem.cpp:83 view/TutorialTreeItem.cpp:120 +msgctxt "@item" +msgid "Setup:" +msgstr "Inicialización:" + +#: view/StepTreeItem.cpp:93 view/TutorialTreeItem.cpp:130 +msgctxt "@item" +msgid "Tear down:" +msgstr "Finalización:" + +#: view/TutorialCustomCodeWidget.cpp:40 +msgctxt "@title" +msgid "Tutorial setup code" +msgstr "Código de inicialización del tutorial" + +#: view/TutorialCustomCodeWidget.cpp:41 +msgctxt "@title" +msgid "Set the tutorial setup code" +msgstr "Establecer el código de inicialización del tutorial" + +#: view/TutorialCustomCodeWidget.cpp:42 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the code to be executed when the tutorial starts.</para><para>The " +"code will be written as is to the setup of the tutorial, after the setup " +"code generated automatically by the editor. This means that the code must be " +"written in the same programming language the tutorial will be exported to.</" +"para>" +msgstr "" +"<para>Establece el código que se ejecutará cuando el tutorial comience.</" +"para><para>El código se escribirá tal cuál en la inicialización del " +"tutorial, tras el código de inicialización generado automáticamente por el " +"editor. Esto quiere decir que el código debe estar escrito en el mismo " +"lenguaje de programación que en el que se exportará el tutorial.</para>" + +#: view/TutorialCustomCodeWidget.cpp:51 +msgctxt "@title" +msgid "Tutorial tear down code" +msgstr "Código de finalización del tutorial" + +#: view/TutorialCustomCodeWidget.cpp:52 +msgctxt "@title" +msgid "Set the tutorial tear down code" +msgstr "Establecer el código de finalización del tutorial..." + +#: view/TutorialCustomCodeWidget.cpp:53 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the code to be executed when the tutorial finishes.</" +"para><para>The code will be written as is to the tear down of the tutorial, " +"before the tear down code generated automatically by the editor. This means " +"that the code must be written in the same programming language the tutorial " +"will be exported to.</para>" +msgstr "" +"<para>Establece el código que se ejecutará cuando el tutorial termine.</" +"para><para>El código se escribirá tal cuál en la finalización del tutorial, " +"tras el código de finalización generado automáticamente por el editor. Esto " +"quiere decir que el código debe estar escrito en el mismo lenguaje de " +"programación que en el que se exportará el tutorial.</para>" + +#: view/TutorialTreeItem.cpp:55 +msgctxt "@item" +msgid "Tutorial" +msgstr "Tutorial" + +#: view/TutorialTreeItem.cpp:58 +msgctxt "@item" +msgid "Tutorial %1" +msgstr "Tutorial %1" + +#: view/TutorialTreeItem.cpp:88 +msgctxt "@item Noun, the name of a tutorial" +msgid "Name: %1" +msgstr "Nombre: %1" + +#: view/TutorialTreeItem.cpp:100 +msgctxt "@item" +msgid "Description: %1" +msgstr "Descripción: %1" + +#: view/TutorialTreeItem.cpp:110 +msgctxt "@item" +msgid "License:" +msgstr "Licencia:" + +#: view/TutorialTreeItem.cpp:142 +msgctxt "@item" +msgid "Steps:" +msgstr "Pasos:" + +#: rc.cpp:3 +msgctxt "@title:menu" +msgid "Tutorial" +msgstr "Tutorial" + +#: rc.cpp:6 +msgctxt "@title:menu Noun, a step in a tutorial" +msgid "Step" +msgstr "Paso" + +#: rc.cpp:9 +msgctxt "@title:menu" +msgid "Panels" +msgstr "Paneles" + +#: rc.cpp:12 +msgctxt "@title" +msgid "Set tutorial license" +msgstr "Establecer licencia del tutorial" + +#: rc.cpp:15 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the license of the tutorial.</para>\n" +"<para>The license is copied, commented, to the top of the exported tutorial " +"file. That is, you don't have to worry about how comments are written in the " +"programming language the tutorial will be exported to. Just set the pure " +"text of the license, and the editor will take care of adding the necessary " +"characters in each line to mark them as comments instead of source code.</" +"para>" +msgstr "" +"<para>Establece la licencia del tutorial.</para>\n" +"<para>La licencia se copia, comentada, en la parte superior del archivo al " +"que se exporta el tutorial. Es decir, no tienes que preocuparte de cómo se " +"escriben los comentarios en el lenguaje de programación en el que se " +"exportará. Simplemente establece el texto puro de la licencia, y el editor " +"se encargará de añadirle los caracteres necesarios en cada línea para " +"indicar que son comentarios en lugar de código fuente.</para>" + +#: rc.cpp:19 +msgctxt "@title" +msgid "License text" +msgstr "Texto de la licencia" + +#: rc.cpp:22 +msgctxt "@title" +msgid "Set step data" +msgstr "Establecer datos del paso" + +#: rc.cpp:25 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the id and the text of the step</para>\n" +"<para>The text is shown to the user when the tutorial changes to that step.</" +"para>\n" +"<para>On the other hand, the id is only used internally and never shown to " +"the user. It is used to identify the steps in the tutorial when it has to " +"change from one to step to another.</para>" +msgstr "" +"<para>Establecer el identificador y el texto del paso</para>\n" +"<para>El texto se muestra al usuario cuando el tutorial cambia a ese paso.</" +"para>\n" +"<para>En cambio, el identificador sólo se utiliza internamente y nunca se " +"muestra al usuario. Se utiliza para identificar los pasos en el tutorial " +"cuando tiene que cambiar de un paso a otro.</para>" + +#: rc.cpp:30 +msgctxt "@title" +msgid "Step data" +msgstr "Datos del paso" + +#: rc.cpp:33 +msgctxt "@label:textbox" +msgid "Id:" +msgstr "Identificador:" + +#: rc.cpp:36 +msgctxt "@label:textbox" +msgid "Text:" +msgstr "Texto:" + +#: rc.cpp:39 +msgctxt "@title" +msgid "Set tutorial information" +msgstr "Establecer información del tutorial" + +#: rc.cpp:42 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the name and description of the tutorial.</para>\n" +"<para>The name and the description are shown in the dialog where the " +"tutorial to be started is selected.</para>" +msgstr "" +"<para>Establecer el nombre y la descripción del tutorial.</para>\n" +"<para>El nombre y la descripción se muestran en el diálogo en el que se " +"selecciona qué tutorial se empezará.</para>" + +#: rc.cpp:46 +msgctxt "@title" +msgid "Tutorial information" +msgstr "Información del tutorial" + +#: rc.cpp:49 +msgctxt "@label:textbox Noun, the name of a tutorial" +msgid "Name:" +msgstr "Nombre:" + +#: rc.cpp:52 +msgctxt "@label:textbox" +msgid "Description:" +msgstr "Descripción:" + +#: rc.cpp:53 +msgctxt "NAME OF TRANSLATORS" +msgid "Your names" +msgstr "Daniel Calviño Sánchez" + +#: rc.cpp:54 +msgctxt "EMAIL OF TRANSLATORS" +msgid "Your emails" +msgstr "dan...@gm..." Added: trunk/ktutorial/ktutorial-editor/po/ktutorial-editor.pot =================================================================== --- trunk/ktutorial/ktutorial-editor/po/ktutorial-editor.pot (rev 0) +++ trunk/ktutorial/ktutorial-editor/po/ktutorial-editor.pot 2010-03-10 18:47:21 UTC (rev 145) @@ -0,0 +1,378 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: http://sourceforge.net/tracker/?" +"group_id=301227&atid=1270278\n" +"POT-Creation-Date: 2010-03-10 19:41+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" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: KTutorialEditor.cpp:77 +msgctxt "@title" +msgid "Edit tutorial" +msgstr "" + +#: KTutorialEditor.cpp:82 +msgctxt "@title" +msgid "Edit step" +msgstr "" + +#: KTutorialEditor.cpp:94 +msgctxt "@action" +msgid "Set information..." +msgstr "" + +#: KTutorialEditor.cpp:95 +msgctxt "@info:status" +msgid "Set the name and description of the tutorial." +msgstr "" + +#: KTutorialEditor.cpp:104 +msgctxt "@action" +msgid "Set license..." +msgstr "" + +#: KTutorialEditor.cpp:105 +msgctxt "@info:status" +msgid "Set the license text of the tutorial." +msgstr "" + +#: KTutorialEditor.cpp:113 KTutorialEditor.cpp:153 +msgctxt "@action" +msgid "Set setup code..." +msgstr "" + +#: KTutorialEditor.cpp:114 +msgctxt "@info:status" +msgid "Set the custom code to be executed when the tutorial starts." +msgstr "" + +#: KTutorialEditor.cpp:122 KTutorialEditor.cpp:163 +msgctxt "@action" +msgid "Set tear down code..." +msgstr "" + +#: KTutorialEditor.cpp:123 +msgctxt "@info:status" +msgid "Set the custom code to be executed when the tutorial finishes." +msgstr "" + +#: KTutorialEditor.cpp:134 +msgctxt "@action" +msgid "Add step..." +msgstr "" + +#: KTutorialEditor.cpp:135 +msgctxt "@info:status" +msgid "Add a new step to the tutorial." +msgstr "" + +#: KTutorialEditor.cpp:143 +msgctxt "@action" +msgid "Set data..." +msgstr "" + +#: KTutorialEditor.cpp:144 +msgctxt "@info:status" +msgid "Set the name and text of the currently selected step." +msgstr "" + +#: KTutorialEditor.cpp:154 +msgctxt "@info:status" +msgid "" +"Set the custom code to be executed when the tutorial passes to the currently " +"selected step." +msgstr "" + +#: KTutorialEditor.cpp:164 +msgctxt "@info:status" +msgid "" +"Set the custom code to be executed when the tutorial changes from the " +"currently selected step to another step." +msgstr "" + +#: KTutorialEditor.cpp:174 +msgctxt "@action" +msgid "Remove step" +msgstr "" + +#: KTutorialEditor.cpp:175 +msgctxt "@info:status" +msgid "Removes the currently selected step from the tutorial." +msgstr "" + +#: main.cpp:27 +msgctxt "@title" +msgid "KTutorial editor" +msgstr "" + +#: main.cpp:29 +msgctxt "@title" +msgid "An editor to create tutorials for <application>KTutorial</application>." +msgstr "" + +#: main.cpp:32 +msgctxt "@info:credit" +msgid "Copyright (c) 2010 Daniel Calviño Sánchez" +msgstr "" + +#: main.cpp:33 +msgctxt "@info:credit" +msgid "Daniel Calviño Sánchez" +msgstr "" + +#: main.cpp:34 +msgctxt "@info:credit" +msgid "Main developer" +msgstr "" + +#: view/StepCustomCodeWidget.cpp:39 +msgctxt "@title" +msgid "Step setup code" +msgstr "" + +#: view/StepCustomCodeWidget.cpp:40 +msgctxt "@title" +msgid "Set the step setup code" +msgstr "" + +#: view/StepCustomCodeWidget.cpp:41 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the code to be executed when the tutorials passes to the step.</" +"para><para>The code will be written as is to the setup of the step, after " +"the setup code generated automatically by the editor. This means that the " +"code must be written in the same programming language the tutorial will be " +"exported to.</para>" +msgstr "" + +#: view/StepCustomCodeWidget.cpp:50 +msgctxt "@title" +msgid "Step tear down code" +msgstr "" + +#: view/StepCustomCodeWidget.cpp:51 +msgctxt "@title" +msgid "Set the step tear down code" +msgstr "" + +#: view/StepCustomCodeWidget.cpp:52 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the code to be executed when the tutorial changes from this step " +"to another.</para><para>The code will be written as is to the tear down of " +"the step, before the tear down code generated automatically by the editor. " +"This means that the code must be written in the same programming language " +"the tutorial will be exported to.</para>" +msgstr "" + +#: view/StepTreeItem.cpp:45 +msgctxt "@item Noun, a step in a tutorial" +msgid "Step" +msgstr "" + +#: view/StepTreeItem.cpp:48 +msgctxt "@item Noun, a step in a tutorial" +msgid "Step %1" +msgstr "" + +#: view/StepTreeItem.cpp:74 +msgctxt "@item" +msgid "Text: %1" +msgstr "" + +#: view/StepTreeItem.cpp:83 view/TutorialTreeItem.cpp:120 +msgctxt "@item" +msgid "Setup:" +msgstr "" + +#: view/StepTreeItem.cpp:93 view/TutorialTreeItem.cpp:130 +msgctxt "@item" +msgid "Tear down:" +msgstr "" + +#: view/TutorialCustomCodeWidget.cpp:40 +msgctxt "@title" +msgid "Tutorial setup code" +msgstr "" + +#: view/TutorialCustomCodeWidget.cpp:41 +msgctxt "@title" +msgid "Set the tutorial setup code" +msgstr "" + +#: view/TutorialCustomCodeWidget.cpp:42 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the code to be executed when the tutorial starts.</para><para>The " +"code will be written as is to the setup of the tutorial, after the setup " +"code generated automatically by the editor. This means that the code must be " +"written in the same programming language the tutorial will be exported to.</" +"para>" +msgstr "" + +#: view/TutorialCustomCodeWidget.cpp:51 +msgctxt "@title" +msgid "Tutorial tear down code" +msgstr "" + +#: view/TutorialCustomCodeWidget.cpp:52 +msgctxt "@title" +msgid "Set the tutorial tear down code" +msgstr "" + +#: view/TutorialCustomCodeWidget.cpp:53 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the code to be executed when the tutorial finishes.</" +"para><para>The code will be written as is to the tear down of the tutorial, " +"before the tear down code generated automatically by the editor. This means " +"that the code must be written in the same programming language the tutorial " +"will be exported to.</para>" +msgstr "" + +#: view/TutorialTreeItem.cpp:55 +msgctxt "@item" +msgid "Tutorial" +msgstr "" + +#: view/TutorialTreeItem.cpp:58 +msgctxt "@item" +msgid "Tutorial %1" +msgstr "" + +#: view/TutorialTreeItem.cpp:88 +msgctxt "@item Noun, the name of a tutorial" +msgid "Name: %1" +msgstr "" + +#: view/TutorialTreeItem.cpp:100 +msgctxt "@item" +msgid "Description: %1" +msgstr "" + +#: view/TutorialTreeItem.cpp:110 +msgctxt "@item" +msgid "License:" +msgstr "" + +#: view/TutorialTreeItem.cpp:142 +msgctxt "@item" +msgid "Steps:" +msgstr "" + +#: rc.cpp:3 +msgctxt "@title:menu" +msgid "Tutorial" +msgstr "" + +#: rc.cpp:6 +msgctxt "@title:menu Noun, a step in a tutorial" +msgid "Step" +msgstr "" + +#: rc.cpp:9 +msgctxt "@title:menu" +msgid "Panels" +msgstr "" + +#: rc.cpp:12 +msgctxt "@title" +msgid "Set tutorial license" +msgstr "" + +#: rc.cpp:15 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the license of the tutorial.</para>\n" +"<para>The license is copied, commented, to the top of the exported tutorial " +"file. That is, you don't have to worry about how comments are written in the " +"programming language the tutorial will be exported to. Just set the pure " +"text of the license, and the editor will take care of adding the necessary " +"characters in each line to mark them as comments instead of source code.</" +"para>" +msgstr "" + +#: rc.cpp:19 +msgctxt "@title" +msgid "License text" +msgstr "" + +#: rc.cpp:22 +msgctxt "@title" +msgid "Set step data" +msgstr "" + +#: rc.cpp:25 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the id and the text of the step</para>\n" +"<para>The text is shown to the user when the tutorial changes to that step.</" +"para>\n" +"<para>On the other hand, the id is only used internally and never shown to " +"the user. It is used to identify the steps in the tutorial when it has to " +"change from one to step to another.</para>" +msgstr "" + +#: rc.cpp:30 +msgctxt "@title" +msgid "Step data" +msgstr "" + +#: rc.cpp:33 +msgctxt "@label:textbox" +msgid "Id:" +msgstr "" + +#: rc.cpp:36 +msgctxt "@label:textbox" +msgid "Text:" +msgstr "" + +#: rc.cpp:39 +msgctxt "@title" +msgid "Set tutorial information" +msgstr "" + +#: rc.cpp:42 +msgctxt "@info:whatsthis" +msgid "" +"<para>Set the name and description of the tutorial.</para>\n" +"<para>The name and the description are shown in the dialog where the " +"tutorial to be started is selected.</para>" +msgstr "" + +#: rc.cpp:46 +msgctxt "@title" +msgid "Tutorial information" +msgstr "" + +#: rc.cpp:49 +msgctxt "@label:textbox Noun, the name of a tutorial" +msgid "Name:" +msgstr "" + +#: rc.cpp:52 +msgctxt "@label:textbox" +msgid "Description:" +msgstr "" + +#: rc.cpp:53 +msgctxt "NAME OF TRANSLATORS" +msgid "Your names" +msgstr "" + +#: rc.cpp:54 +msgctxt "EMAIL OF TRANSLATORS" +msgid "Your emails" +msgstr "" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-10 18:35:27
|
Revision: 144 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=144&view=rev Author: danxuliu Date: 2010-03-10 18:35:20 +0000 (Wed, 10 Mar 2010) Log Message: ----------- Fix wrong whats this text. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp 2010-03-10 18:11:11 UTC (rev 143) +++ trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp 2010-03-10 18:35:20 UTC (rev 144) @@ -50,7 +50,7 @@ "Step tear down code")); setWindowTitle(i18nc("@title", "Set the step tear down code")); setWhatsThis(i18nc("@info:whatsthis", "<para>Set the code to be " -"executed when the tutorial finishes.</para>" +"executed when the tutorial changes from this step to another.</para>" "<para>The code will be written as is to the tear down of the step, before the " "tear down code generated automatically by the editor. This means that the " "code must be written in the same programming language the tutorial will be " This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-10 18:11:18
|
Revision: 143 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=143&view=rev Author: danxuliu Date: 2010-03-10 18:11:11 +0000 (Wed, 10 Mar 2010) Log Message: ----------- Remove unnecessary window title (widgets using CustomCodeWidget.ui set their own title). Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/CustomCodeWidget.ui Modified: trunk/ktutorial/ktutorial-editor/src/view/CustomCodeWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CustomCodeWidget.ui 2010-03-10 17:58:12 UTC (rev 142) +++ trunk/ktutorial/ktutorial-editor/src/view/CustomCodeWidget.ui 2010-03-10 18:11:11 UTC (rev 143) @@ -10,9 +10,6 @@ <height>300</height> </rect> </property> - <property name="windowTitle"> - <string comment="@title">Set custom code</string> - </property> <layout class="QVBoxLayout" name="CustomCodeWidgetLayout"> <item> <widget class="QGroupBox" name="customCodeGroupBox"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-10 17:58:35
|
Revision: 142 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=142&view=rev Author: danxuliu Date: 2010-03-10 17:58:12 +0000 (Wed, 10 Mar 2010) Log Message: ----------- Set icons for actions. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-10 17:50:56 UTC (rev 141) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-10 17:58:12 UTC (rev 142) @@ -94,6 +94,7 @@ action->setText(i18nc("@action", "Set information...")); action->setStatusTip(i18nc("@info:status", "Set the name and description " "of the tutorial.")); + action->setIcon(KIcon("documentinfo")); actionCollection()->addAction("setTutorialInformation", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialInformation())); @@ -103,6 +104,7 @@ action->setText(i18nc("@action", "Set license...")); action->setStatusTip(i18nc("@info:status", "Set the license text of the " "tutorial.")); + action->setIcon(KIcon("document-edit")); actionCollection()->addAction("setTutorialLicense", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialLicense())); actionListWidget->addAction(action); @@ -111,6 +113,7 @@ action->setText(i18nc("@action", "Set setup code...")); action->setStatusTip(i18nc("@info:status", "Set the custom code to be " "executed when the tutorial starts.")); + action->setIcon(KIcon("code-function")); actionCollection()->addAction("setTutorialSetup", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialSetup())); actionListWidget->addAction(action); @@ -119,6 +122,7 @@ action->setText(i18nc("@action", "Set tear down code...")); action->setStatusTip(i18nc("@info:status", "Set the custom code to be " "executed when the tutorial finishes.")); + action->setIcon(KIcon("code-function")); actionCollection()->addAction("setTutorialTearDown", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialTearDown())); actionListWidget->addAction(action); @@ -130,6 +134,7 @@ action->setText(i18nc("@action", "Add step...")); action->setStatusTip(i18nc("@info:status", "Add a new step to the " "tutorial.")); + action->setIcon(KIcon("list-add")); actionCollection()->addAction("addStep", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(addStep())); actionListWidget->addAction(action); @@ -138,6 +143,7 @@ action->setText(i18nc("@action", "Set data...")); action->setStatusTip(i18nc("@info:status", "Set the name and text of the " "currently selected step.")); + action->setIcon(KIcon("document-edit")); action->setEnabled(false); actionCollection()->addAction("setStepData", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepData())); @@ -147,6 +153,7 @@ action->setText(i18nc("@action", "Set setup code...")); action->setStatusTip(i18nc("@info:status", "Set the custom code to be " "executed when the tutorial passes to the currently selected step.")); + action->setIcon(KIcon("code-function")); action->setEnabled(false); actionCollection()->addAction("setStepSetup", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepSetup())); @@ -157,6 +164,7 @@ action->setStatusTip(i18nc("@info:status", "Set the custom code to be " "executed when the tutorial changes from the currently selected step to " "another step.")); + action->setIcon(KIcon("code-function")); action->setEnabled(false); actionCollection()->addAction("setStepTearDown", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepTearDown())); @@ -166,6 +174,7 @@ action->setText(i18nc("@action", "Remove step")); action->setStatusTip(i18nc("@info:status", "Removes the currently selected " "step from the tutorial.")); + action->setIcon(KIcon("list-remove")); action->setEnabled(false); actionCollection()->addAction("removeStep", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(removeStep())); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-10 17:51:03
|
Revision: 141 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=141&view=rev Author: danxuliu Date: 2010-03-10 17:50:56 +0000 (Wed, 10 Mar 2010) Log Message: ----------- Add docks to show the edition actions. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/view/ActionListWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/ActionListWidget.h trunk/ktutorial/ktutorial-editor/tests/unit/view/ActionListWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-09 21:12:53 UTC (rev 140) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-10 17:50:56 UTC (rev 141) @@ -18,6 +18,7 @@ #include "KTutorialEditor.h" +#include <QDockWidget> #include <QTreeView> #include <KAction> @@ -27,6 +28,7 @@ #include "Step.h" #include "Tutorial.h" +#include "view/ActionListWidget.h" #include "view/EditionDialog.h" #include "view/LicenseWidget.h" #include "view/StepCustomCodeWidget.h" @@ -46,6 +48,8 @@ setupTutorialToBeEdited(); + setupDocks(); + setupActions(); setupGUI(); @@ -69,9 +73,23 @@ this, SLOT(selectStep(Step*))); } +void KTutorialEditor::setupDocks() { + mTutorialActionDock = new QDockWidget(i18nc("@title", "Edit tutorial"), + this); + mTutorialActionDock->setObjectName("editTutorialDock"); + addDockWidget(Qt::RightDockWidgetArea, mTutorialActionDock); + + mStepActionDock = new QDockWidget(i18nc("@title", "Edit step"), this); + mStepActionDock->setObjectName("editStepDock"); + addDockWidget(Qt::RightDockWidgetArea, mStepActionDock); +} + void KTutorialEditor::setupActions() { KStandardAction::quit(kapp, SLOT(quit()), actionCollection()); + ActionListWidget* actionListWidget = + new ActionListWidget(mTutorialActionDock); + KAction* action = new KAction(this); action->setText(i18nc("@action", "Set information...")); action->setStatusTip(i18nc("@info:status", "Set the name and description " @@ -79,6 +97,7 @@ actionCollection()->addAction("setTutorialInformation", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialInformation())); + actionListWidget->addAction(action); action = new KAction(this); action->setText(i18nc("@action", "Set license...")); @@ -86,6 +105,7 @@ "tutorial.")); actionCollection()->addAction("setTutorialLicense", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialLicense())); + actionListWidget->addAction(action); action = new KAction(this); action->setText(i18nc("@action", "Set setup code...")); @@ -93,6 +113,7 @@ "executed when the tutorial starts.")); actionCollection()->addAction("setTutorialSetup", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialSetup())); + actionListWidget->addAction(action); action = new KAction(this); action->setText(i18nc("@action", "Set tear down code...")); @@ -100,13 +121,18 @@ "executed when the tutorial finishes.")); actionCollection()->addAction("setTutorialTearDown", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialTearDown())); + actionListWidget->addAction(action); + mTutorialActionDock->setWidget(actionListWidget); + actionListWidget = new ActionListWidget(mStepActionDock); + action = new KAction(this); action->setText(i18nc("@action", "Add step...")); action->setStatusTip(i18nc("@info:status", "Add a new step to the " "tutorial.")); actionCollection()->addAction("addStep", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(addStep())); + actionListWidget->addAction(action); action = new KAction(this); action->setText(i18nc("@action", "Set data...")); @@ -115,6 +141,7 @@ action->setEnabled(false); actionCollection()->addAction("setStepData", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepData())); + actionListWidget->addAction(action); action = new KAction(this); action->setText(i18nc("@action", "Set setup code...")); @@ -123,6 +150,7 @@ action->setEnabled(false); actionCollection()->addAction("setStepSetup", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepSetup())); + actionListWidget->addAction(action); action = new KAction(this); action->setText(i18nc("@action", "Set tear down code...")); @@ -132,6 +160,7 @@ action->setEnabled(false); actionCollection()->addAction("setStepTearDown", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepTearDown())); + actionListWidget->addAction(action); action = new KAction(this); action->setText(i18nc("@action", "Remove step")); @@ -140,6 +169,14 @@ action->setEnabled(false); actionCollection()->addAction("removeStep", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(removeStep())); + actionListWidget->addAction(action); + + mStepActionDock->setWidget(actionListWidget); + + actionCollection()->addAction("showEditTutorialDock", + mTutorialActionDock->toggleViewAction()); + actionCollection()->addAction("showEditStepDock", + mStepActionDock->toggleViewAction()); } void KTutorialEditor::showEditionDialog(EditionWidget* editionWidget) { Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-09 21:12:53 UTC (rev 140) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-10 17:50:56 UTC (rev 141) @@ -45,8 +45,18 @@ * The main tree view that shows the tutorial. */ QTreeView* mTreeView; - + /** + * Dock with the actions to edit a tutorial. + */ + QDockWidget* mTutorialActionDock; + + /** + * Dock with the actions to edit a step. + */ + QDockWidget* mStepActionDock; + + /** * The tutorial being edited. */ Tutorial* mTutorial; @@ -64,6 +74,11 @@ void setupTutorialToBeEdited(); /** + * Sets up the dock widgets. + */ + void setupDocks(); + + /** * Sets up all the actions used in the application. */ void setupActions(); Modified: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-09 21:12:53 UTC (rev 140) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-10 17:50:56 UTC (rev 141) @@ -19,5 +19,12 @@ <Action name="removeStep"/> </Menu> </Menu> + <Menu name="view"> + <Menu name="panels"> + <Text context="@title:menu">Panels</Text> + <Action name="showEditTutorialDock"/> + <Action name="showEditStepDock"/> + </Menu> + </Menu> </MenuBar> </gui> Added: trunk/ktutorial/ktutorial-editor/src/view/ActionListWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/ActionListWidget.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/ActionListWidget.cpp 2010-03-10 17:50:56 UTC (rev 141) @@ -0,0 +1,127 @@ +/*************************************************************************** + * 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 "ActionListWidget.h" + +#include <QAction> +#include <QActionEvent> +#include <QToolButton> +#include <QVBoxLayout> + +/** + * A button which always leave room for an icon, even if there is none, so that + * all button texts are correctly aligned. + * + * Code got from Gwenview's app/sidebar.cpp file, licensed as GPL 2 or later + * (at the time of KDE SVN revision 968729). + */ +class ForcedIconToolButton: public QToolButton { +protected: + + virtual void paintEvent(QPaintEvent* event) { + forceIcon(); + QToolButton::paintEvent(event); + } + +private: + + void forceIcon() { + if (!icon().isNull()) { + return; + } + + // Assign an empty icon to the button if there is no icon associated + // with the action so that all button texts are correctly aligned. + QSize wantedSize = iconSize(); + if (mEmptyIcon.isNull() || + mEmptyIcon.actualSize(wantedSize) != wantedSize) { + QPixmap pix(wantedSize); + pix.fill(Qt::transparent); + mEmptyIcon.addPixmap(pix); + } + setIcon(mEmptyIcon); + } + + QIcon mEmptyIcon; + +}; + +//public: + +ActionListWidget::ActionListWidget(QWidget* parent): QWidget(parent) { + QVBoxLayout* layout = new QVBoxLayout(this); + layout->addStretch(); + layout->setMargin(0); + layout->setSpacing(0); + + setLayout(layout); +} + +//protected: + +void ActionListWidget::actionEvent(QActionEvent* event) { + if (event->type() == QEvent::ActionAdded) { + addToolButtonForAction(event->action(), + toolButtonForAction(event->before())); + return; + } + + if (event->type() == QEvent::ActionRemoved) { + QToolButton* button = toolButtonForAction(event->action()); + layout()->removeWidget(button); + button->deleteLater(); + return; + } +} + +//private: + +QToolButton* ActionListWidget::toolButtonForAction(QAction* action) { + for (int i=0; i<layout()->count(); i++ ) { + QWidget* widget = layout()->itemAt(i)->widget(); + if (widget) { + QToolButton* button = static_cast<QToolButton*>(widget); + if (button->defaultAction() == action) { + return button; + } + } + } + + return 0; +} + +void ActionListWidget::addToolButtonForAction(QAction* action, + QToolButton* before) { + Q_ASSERT(action); + + QToolButton* button = new ForcedIconToolButton(); + button->setDefaultAction(action); + button->setObjectName(action->objectName() + "ToolButton"); + button->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + button->setAutoRaise(true); + button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + + int index; + if (before == 0) { + index = layout()->count() - 1; + } else { + index = layout()->indexOf(before); + } + + static_cast<QVBoxLayout*>(layout())->insertWidget(index, button); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/ActionListWidget.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/ActionListWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/ActionListWidget.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/ActionListWidget.h 2010-03-10 17:50:56 UTC (rev 141) @@ -0,0 +1,81 @@ +/*************************************************************************** + * 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 ACTIONLISTWIDGET_H +#define ACTIONLISTWIDGET_H + +#include <QWidget> + +class QToolButton; + +/** + * QWidget to show the added actions as QToolButtons. + * Standard widgets show the actions added to them in a menu. This widget shows + * them in a list of QToolButtons. Adding, inserting and removing actions is + * supported. + * + * Each QToolButton is named like its action, followed by "ToolButton". + * + * A special tool button subclass, that ensures that there is always an icon + * even if it is empty, is used. When there is an icon, Oxygen and other styles + * align the text with the icon, instead of centering it like it is done when + * there is no icon and a size policy other than fixed is used. A minimum + * expanding size policiy is used for the tool buttons to fill the whole width + * of this widget, instead of having each one its own width. + */ +class ActionListWidget: public QWidget { +Q_OBJECT +public: + + /** + * Creates a new empty ActionListWidget. + * + * @param parent The parent widget. + */ + explicit ActionListWidget(QWidget* parent = 0); + +protected: + + /** + * Handles adding, changing or deleting an action in this ActionListWidget. + * + * @param event The action event. + */ + virtual void actionEvent(QActionEvent* event); + +private: + + /** + * Returns the QToolButton in this widget that shows the given action. + * + * @param action The action to get its QToolButton. + */ + QToolButton* toolButtonForAction(QAction* action); + + /** + * Adds a new QToolButton for the given action. + * + * @param action The action to add a QToolButton for it. + * @param before Add the action before this tool button, or append it if it + * is 0. + */ + void addToolButtonForAction(QAction* action, QToolButton* before); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/ActionListWidget.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-09 21:12:53 UTC (rev 140) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-10 17:50:56 UTC (rev 141) @@ -1,6 +1,7 @@ include_directories(${KDE4_INCLUDES}) set(ktutorial_editor_view_SRCS + ActionListWidget.cpp EditionDialog.cpp EditionWidget.cpp LicenseWidget.cpp Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/ActionListWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/ActionListWidgetTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/ActionListWidgetTest.cpp 2010-03-10 17:50:56 UTC (rev 141) @@ -0,0 +1,183 @@ +/*************************************************************************** + * 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 "ActionListWidget.h" + +#include <QAction> +#include <QLayout> +#include <QToolButton> + +#include <KIcon> + +class ActionListWidgetTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testAddAction(); + void testAddActionSeveralActions(); + + void testInsertAction(); + void testInsertActionSeveralActions(); + + void testRemoveAction(); + void testRemoveActionSeveralActions(); + +private: + + QToolButton* toolButton(const ActionListWidget* widget, + const QAction* action) const; + + void assertToolButton(const ActionListWidget* widget, int index, + const QAction* action) const; + +}; + +void ActionListWidgetTest::testConstructor() { + QWidget parent; + ActionListWidget* widget = new ActionListWidget(&parent); + + QCOMPARE(widget->parent(), &parent); + QVERIFY(widget->layout()->itemAt(widget->layout()->count()-1)->spacerItem()); +} + +void ActionListWidgetTest::testAddAction() { + ActionListWidget widget; + QAction* action = new QAction(this); + action->setObjectName("action"); + + widget.addAction(action); + + assertToolButton(&widget, 0, action); + QVERIFY(widget.layout()->itemAt(widget.layout()->count()-1)->spacerItem()); +} + +void ActionListWidgetTest::testAddActionSeveralActions() { + ActionListWidget widget; + QAction* action1 = new QAction(this); + action1->setObjectName("action1"); + QAction* action2 = new QAction(this); + action2->setObjectName("action2"); + QAction* action3 = new QAction(this); + action3->setObjectName("action3"); + action3->setIcon(KIcon("kde")); + + widget.addAction(action1); + widget.addAction(action2); + widget.addAction(action3); + + assertToolButton(&widget, 0, action1); + assertToolButton(&widget, 1, action2); + assertToolButton(&widget, 2, action3); + QVERIFY(widget.layout()->itemAt(widget.layout()->count()-1)->spacerItem()); +} + +void ActionListWidgetTest::testInsertAction() { + ActionListWidget widget; + QAction* action = new QAction(this); + action->setObjectName("action"); + + widget.insertAction(0, action); + + assertToolButton(&widget, 0, action); + QVERIFY(widget.layout()->itemAt(widget.layout()->count()-1)->spacerItem()); +} + +void ActionListWidgetTest::testInsertActionSeveralActions() { + ActionListWidget widget; + QAction* action1 = new QAction(this); + action1->setObjectName("action1"); + QAction* action2 = new QAction(this); + action2->setObjectName("action2"); + QAction* action3 = new QAction(this); + action3->setObjectName("action3"); + action3->setIcon(KIcon("kde")); + + widget.insertAction(0, action3); + widget.insertAction(action3, action1); + widget.insertAction(action3, action2); + + assertToolButton(&widget, 0, action1); + assertToolButton(&widget, 1, action2); + assertToolButton(&widget, 2, action3); + QVERIFY(widget.layout()->itemAt(widget.layout()->count()-1)->spacerItem()); +} + +void ActionListWidgetTest::testRemoveAction() { + ActionListWidget widget; + QAction* action = new QAction(this); + action->setObjectName("action"); + + widget.addAction(action); + widget.removeAction(action); + + QCOMPARE(widget.layout()->count(), 1); + QVERIFY(widget.layout()->itemAt(0)->spacerItem()); +} + +void ActionListWidgetTest::testRemoveActionSeveralActions() { + ActionListWidget widget; + QAction* action1 = new QAction(this); + action1->setObjectName("action1"); + QAction* action2 = new QAction(this); + action2->setObjectName("action2"); + QAction* action3 = new QAction(this); + action3->setObjectName("action3"); + action3->setIcon(KIcon("kde")); + + widget.addAction(action1); + widget.addAction(action2); + widget.addAction(action3); + + widget.removeAction(action2); + + assertToolButton(&widget, 0, action1); + assertToolButton(&widget, 1, action3); + + widget.removeAction(action1); + widget.removeAction(action3); + + QCOMPARE(widget.layout()->count(), 1); + QVERIFY(widget.layout()->itemAt(0)->spacerItem()); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +QToolButton* ActionListWidgetTest::toolButton(const ActionListWidget* widget, + const QAction* action) const { + QString buttonName = action->objectName() + "ToolButton"; + return widget->findChild<QToolButton*>(buttonName); +} + +void ActionListWidgetTest::assertToolButton(const ActionListWidget* widget, + int index, const QAction* action) const { + QToolButton* button = toolButton(widget, action); + + QVERIFY(button); + QCOMPARE(button->parent(), widget); + QCOMPARE(button->defaultAction(), action); + QCOMPARE(widget->layout()->indexOf(button), index); +} + +QTEST_MAIN(ActionListWidgetTest) + +#include "ActionListWidgetTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/ActionListWidgetTest.cpp ___________________________________________________________________ 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-09 21:12:53 UTC (rev 140) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-10 17:50:56 UTC (rev 141) @@ -17,6 +17,7 @@ ENDMACRO(UNIT_TESTS) unit_tests( + ActionListWidget EditionDialog LicenseWidget StepCustomCodeWidget @@ -39,6 +40,7 @@ ENDMACRO(MEM_TESTS) mem_tests( + ActionListWidget EditionDialog LicenseWidget StepCustomCodeWidget This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-09 21:12:59
|
Revision: 140 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=140&view=rev Author: danxuliu Date: 2010-03-09 21:12:53 +0000 (Tue, 09 Mar 2010) Log Message: ----------- Change the list of classes to test in CMakeLists.txt from horizontal to vertical. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/view/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/ktutorial-editor/tests/unit/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-09 20:38:48 UTC (rev 139) +++ trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-09 21:12:53 UTC (rev 140) @@ -14,7 +14,10 @@ ENDFOREACH(_className) ENDMACRO(UNIT_TESTS) -unit_tests(Step Tutorial) +unit_tests( + Step + Tutorial +) MACRO(MEM_TESTS) FOREACH(_testname ${ARGN}) @@ -22,4 +25,7 @@ ENDFOREACH(_testname) ENDMACRO(MEM_TESTS) -mem_tests(Step Tutorial) +mem_tests( + Step + Tutorial +) Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-09 20:38:48 UTC (rev 139) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-09 21:12:53 UTC (rev 140) @@ -16,7 +16,21 @@ ENDFOREACH(_className) ENDMACRO(UNIT_TESTS) -unit_tests(EditionDialog LicenseWidget StepCustomCodeWidget StepDataWidget StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialCustomCodeWidget TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager) +unit_tests( + EditionDialog + LicenseWidget + StepCustomCodeWidget + StepDataWidget + StepTreeItem + TextTreeItem + TreeItem + TreeItemUtil + TreeModel + TutorialCustomCodeWidget + TutorialInformationWidget + TutorialTreeItem + TutorialTreeSelectionManager +) MACRO(MEM_TESTS) FOREACH(_testname ${ARGN}) @@ -24,4 +38,18 @@ ENDFOREACH(_testname) ENDMACRO(MEM_TESTS) -mem_tests(EditionDialog LicenseWidget StepCustomCodeWidget StepDataWidget StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialCustomCodeWidget TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager) +mem_tests( + EditionDialog + LicenseWidget + StepCustomCodeWidget + StepDataWidget + StepTreeItem + TextTreeItem + TreeItem + TreeItemUtil + TreeModel + TutorialCustomCodeWidget + TutorialInformationWidget + TutorialTreeItem + TutorialTreeSelectionManager +) Modified: trunk/ktutorial/ktutorial-library/test/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/test/CMakeLists.txt 2010-03-09 20:38:48 UTC (rev 139) +++ trunk/ktutorial/ktutorial-library/test/CMakeLists.txt 2010-03-09 21:12:53 UTC (rev 140) @@ -14,7 +14,20 @@ ENDFOREACH(_className) ENDMACRO(UNIT_TESTS) -unit_tests(Option Step Tutorial TutorialInformation TutorialManager WaitFor WaitForAnd WaitForComposed WaitForEvent 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 +35,17 @@ ENDFOREACH(_testname) ENDMACRO(MEM_TESTS) -mem_tests(Option Step Tutorial TutorialInformation TutorialManager WaitFor WaitForAnd WaitForComposed WaitForEvent WaitForNot WaitForOr WaitForSignal) +mem_tests( + Option + Step + Tutorial + TutorialInformation + TutorialManager + WaitFor + WaitForAnd + WaitForComposed + WaitForEvent + WaitForNot + WaitForOr + WaitForSignal +) Modified: trunk/ktutorial/ktutorial-library/test/scripting/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/test/scripting/CMakeLists.txt 2010-03-09 20:38:48 UTC (rev 139) +++ trunk/ktutorial/ktutorial-library/test/scripting/CMakeLists.txt 2010-03-09 21:12:53 UTC (rev 140) @@ -11,7 +11,13 @@ ENDFOREACH(_className) ENDMACRO(UNIT_TESTS) -unit_tests(ScriptedStep ScriptedTutorial Scripting ScriptingModule ScriptManager) +unit_tests( + ScriptedStep + ScriptedTutorial + Scripting + ScriptingModule + ScriptManager +) MACRO(MEM_TESTS) FOREACH(_testname ${ARGN}) @@ -19,4 +25,10 @@ ENDFOREACH(_testname) ENDMACRO(MEM_TESTS) -mem_tests(ScriptedStep ScriptedTutorial Scripting ScriptingModule ScriptManager) +mem_tests( + ScriptedStep + ScriptedTutorial + Scripting + ScriptingModule + ScriptManager +) Modified: trunk/ktutorial/ktutorial-library/test/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/test/view/CMakeLists.txt 2010-03-09 20:38:48 UTC (rev 139) +++ trunk/ktutorial/ktutorial-library/test/view/CMakeLists.txt 2010-03-09 21:12:53 UTC (rev 140) @@ -16,7 +16,11 @@ ENDFOREACH(_className) ENDMACRO(UNIT_TESTS) -unit_tests(StepWidget TutorialListModel TutorialManagerDialog) +unit_tests( + StepWidget + TutorialListModel + TutorialManagerDialog +) MACRO(MEM_TESTS) FOREACH(_testname ${ARGN}) @@ -24,4 +28,8 @@ ENDFOREACH(_testname) ENDMACRO(MEM_TESTS) -mem_tests(StepWidget TutorialListModel TutorialManagerDialog) +mem_tests( + StepWidget + TutorialListModel + TutorialManagerDialog +) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-09 20:38:54
|
Revision: 139 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=139&view=rev Author: danxuliu Date: 2010-03-09 20:38:48 +0000 (Tue, 09 Mar 2010) Log Message: ----------- Fix Krazy2 i18n argument issues. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc trunk/ktutorial/ktutorial-editor/src/main.cpp trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/TutorialCustomCodeWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp Modified: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-09 20:38:48 UTC (rev 139) @@ -4,14 +4,14 @@ <MenuBar> <Menu name="edit"> <Menu name="editTutorials"> - <Text context="@item:inmenu">Tutorial</Text> + <Text context="@title:menu">Tutorial</Text> <Action name="setTutorialInformation"/> <Action name="setTutorialLicense"/> <Action name="setTutorialSetup"/> <Action name="setTutorialTearDown"/> </Menu> <Menu name="editSteps"> - <Text context="@item:inmenu">Step</Text> + <Text context="@title:menu Noun, a step in a tutorial">Step</Text> <Action name="addStep"/> <Action name="setStepData"/> <Action name="setStepSetup"/> Modified: trunk/ktutorial/ktutorial-editor/src/main.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/main.cpp 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/main.cpp 2010-03-09 20:38:48 UTC (rev 139) @@ -26,8 +26,8 @@ KAboutData aboutData("ktutorial-editor", 0, ki18nc("@title", "KTutorial editor"), "0.1", - ki18nc("@info", "An editor to create tutorials for " - "<application>KTutorial</application>."), + ki18nc("@title", "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"), Modified: trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp 2010-03-09 20:38:48 UTC (rev 139) @@ -36,7 +36,7 @@ if (type == Setup) { ui->customCodeTextEdit->setText(step->customSetupCode()); - ui->customCodeGroupBox->setTitle(i18nc("@ŧitle", "Step setup code")); + ui->customCodeGroupBox->setTitle(i18nc("@title", "Step setup code")); setWindowTitle(i18nc("@title", "Set the step setup code")); setWhatsThis(i18nc("@info:whatsthis", "<para>Set the code to be " "executed when the tutorials passes to the step.</para>" @@ -46,7 +46,7 @@ "exported to.</para>")); } else { ui->customCodeTextEdit->setText(step->customTearDownCode()); - ui->customCodeGroupBox->setTitle(i18nc("@ŧitle", + ui->customCodeGroupBox->setTitle(i18nc("@title", "Step tear down code")); setWindowTitle(i18nc("@title", "Set the step tear down code")); setWhatsThis(i18nc("@info:whatsthis", "<para>Set the code to be " Modified: trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-09 20:38:48 UTC (rev 139) @@ -42,10 +42,10 @@ QString StepTreeItem::text() const { if (mStepId.isEmpty()) { - return i18nc("@item", "Step"); + return i18nc("@item Noun, a step in a tutorial", "Step"); } - return i18nc("@item", "Step %1", mStepId); + return i18nc("@item Noun, a step in a tutorial", "Step %1", mStepId); } Step* StepTreeItem::step() const { Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialCustomCodeWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialCustomCodeWidget.cpp 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialCustomCodeWidget.cpp 2010-03-09 20:38:48 UTC (rev 139) @@ -36,7 +36,7 @@ if (type == Setup) { ui->customCodeTextEdit->setText(tutorial->customSetupCode()); - ui->customCodeGroupBox->setTitle(i18nc("@ŧitle", + ui->customCodeGroupBox->setTitle(i18nc("@title", "Tutorial setup code")); setWindowTitle(i18nc("@title", "Set the tutorial setup code")); setWhatsThis(i18nc("@info:whatsthis", "<para>Set the code to be " @@ -47,7 +47,7 @@ "exported to.</para>")); } else { ui->customCodeTextEdit->setText(tutorial->customTearDownCode()); - ui->customCodeGroupBox->setTitle(i18nc("@ŧitle", + ui->customCodeGroupBox->setTitle(i18nc("@title", "Tutorial tear down code")); setWindowTitle(i18nc("@title", "Set the tutorial tear down code")); setWhatsThis(i18nc("@info:whatsthis", "<para>Set the code to be " Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui 2010-03-09 20:38:48 UTC (rev 139) @@ -29,7 +29,7 @@ <item> <widget class="QLabel" name="nameLabel"> <property name="text"> - <string comment="@label:textbox">Name:</string> + <string comment="@label:textbox Noun, the name of a tutorial">Name:</string> </property> <property name="buddy"> <cstring>nameLineEdit</cstring> Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-09 20:38:48 UTC (rev 139) @@ -84,7 +84,8 @@ } } else { TreeItemUtil::addFlatItemIfNeeded(this, mNameItem, childIndex); - mNameItem->setText(i18nc("@item", "Name: %1", tutorial->name())); + mNameItem->setText(i18nc("@item Noun, the name of a tutorial", + "Name: %1", tutorial->name())); mTutorialId = tutorial->id(); emit dataChanged(this); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-09 20:07:50
|
Revision: 138 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=138&view=rev Author: danxuliu Date: 2010-03-09 20:07:44 +0000 (Tue, 09 Mar 2010) Log Message: ----------- Fix Krazy2 null string assignment issue. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-09 20:04:23 UTC (rev 137) +++ trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-09 20:07:44 UTC (rev 138) @@ -59,7 +59,7 @@ if (step->id().isEmpty()) { if (!mStepId.isEmpty()) { - mStepId = QString(); + mStepId.clear(); emit dataChanged(this); } } else { Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-09 20:04:23 UTC (rev 137) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-09 20:07:44 UTC (rev 138) @@ -79,7 +79,7 @@ TreeItemUtil::removeFlatItemIfNeeded(mNameItem); if (!mTutorialId.isEmpty()) { - mTutorialId = QString(); + mTutorialId.clear(); emit dataChanged(this); } } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |