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