[Ktutorial-commits] SF.net SVN: ktutorial:[156] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
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. |