[Ktutorial-commits] SF.net SVN: ktutorial:[306] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2011-05-16 16:47:00
|
Revision: 306 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=306&view=rev Author: danxuliu Date: 2011-05-16 16:46:51 +0000 (Mon, 16 May 2011) Log Message: ----------- Add support for WaitForProperty to wait for a property to change its value to the expected one. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/data/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.cpp trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.h trunk/ktutorial/ktutorial-editor/src/serialization/Tutorial.xsd trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.cpp trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.h trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.cpp trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.h 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/data/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/serialization/JavascriptExporterTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialReaderTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialWriterTest.cpp 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/data/WaitForProperty.cpp trunk/ktutorial/ktutorial-editor/src/data/WaitForProperty.h trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyTreeItem.h trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.h trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.ui trunk/ktutorial/ktutorial-editor/tests/unit/data/WaitForPropertyTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForPropertyTreeItemTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForPropertyWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/data/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/data/CMakeLists.txt 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/data/CMakeLists.txt 2011-05-16 16:46:51 UTC (rev 306) @@ -6,6 +6,7 @@ WaitForComposed.cpp WaitForEvent.cpp WaitForNot.cpp + WaitForProperty.cpp WaitForSignal.cpp WaitForWindow.cpp ) Added: trunk/ktutorial/ktutorial-editor/src/data/WaitForProperty.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/data/WaitForProperty.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/data/WaitForProperty.cpp 2011-05-16 16:46:51 UTC (rev 306) @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (C) 2011 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 "WaitForProperty.h" + +//public: + +WaitForProperty::WaitForProperty(QObject* parent): WaitFor(parent) { +} + +WaitFor* WaitForProperty::clone() const { + WaitForProperty* cloned = new WaitForProperty(); + cloned->setObjectName(mObjectName); + cloned->setPropertyName(mPropertyName); + cloned->setValue(mValue); + + return cloned; +} + +bool WaitForProperty::equals(const WaitFor& waitFor) const { + if (!qobject_cast<const WaitForProperty*>(&waitFor)) { + return false; + } + + const WaitForProperty* waitForProperty = + static_cast<const WaitForProperty*>(&waitFor); + if (waitForProperty->objectName() != mObjectName) { + return false; + } + + if (waitForProperty->propertyName() != mPropertyName) { + return false; + } + + if (waitForProperty->value() != mValue) { + return false; + } + + return true; +} + +QString WaitForProperty::objectName() const { + return mObjectName; +} + +void WaitForProperty::setObjectName(const QString& objectName) { + mObjectName = objectName; + + emit dataChanged(this); +} + +QString WaitForProperty::propertyName() const { + return mPropertyName; +} + +void WaitForProperty::setPropertyName(const QString& propertyName) { + mPropertyName = propertyName; + + emit dataChanged(this); +} + +QString WaitForProperty::value() const { + return mValue; +} + +void WaitForProperty::setValue(const QString& value) { + mValue = value; + + emit dataChanged(this); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/data/WaitForProperty.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/data/WaitForProperty.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/data/WaitForProperty.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/data/WaitForProperty.h 2011-05-16 16:46:51 UTC (rev 306) @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2011 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 WAITFORPROPERTY_H +#define WAITFORPROPERTY_H + +#include "WaitFor.h" + +/** + * Container for conditions that wait for a property to have some value data. + * It stores the data used in KTutorial WaitForProperty, 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::WaitForProperty + * object. + * + * When any attribute is modified, dataChanged(WaitFor*) signal is emitted. + */ +class WaitForProperty: public WaitFor { +Q_OBJECT +public: + + /** + * Creates a new WaitForProperty. + * + * @param parent The parent QObject. + */ + WaitForProperty(QObject* parent = 0); + + virtual WaitFor* clone() const; + virtual bool equals(const WaitFor& waitFor) const; + + QString objectName() const; + void setObjectName(const QString& objectName); + + QString propertyName() const; + void setPropertyName(const QString& propertyName); + + QString value() const; + void setValue(const QString& value); + +private: + + QString mObjectName; + QString mPropertyName; + QString mValue; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/data/WaitForProperty.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.cpp 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.cpp 2011-05-16 16:46:51 UTC (rev 306) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -29,6 +29,7 @@ #include "../data/WaitForComposed.h" #include "../data/WaitForEvent.h" #include "../data/WaitForNot.h" +#include "../data/WaitForProperty.h" #include "../data/WaitForSignal.h" #include "../data/WaitForWindow.h" @@ -270,6 +271,9 @@ if (qobject_cast<const WaitForNot*>(waitFor)) { return writeWaitFor(static_cast<const WaitForNot*>(waitFor)); } + if (qobject_cast<const WaitForProperty*>(waitFor)) { + return writeWaitFor(static_cast<const WaitForProperty*>(waitFor)); + } if (qobject_cast<const WaitForSignal*>(waitFor)) { return writeWaitFor(static_cast<const WaitForSignal*>(waitFor)); } @@ -347,6 +351,38 @@ return variable; } +QString JavascriptExporter::writeWaitFor( + const WaitForProperty* waitForProperty) { + if (waitForProperty->objectName().isEmpty()) { + out() << "//Error: WaitForProperty without object name!\n"; + return ""; + } + + if (waitForProperty->propertyName().isEmpty()) { + out() << "//Error: WaitForProperty without property name!\n"; + return ""; + } + + if (waitForProperty->value().isEmpty()) { + out() << "//Error: WaitForProperty without value!\n"; + return ""; + } + + QString propertyName = waitForProperty->propertyName(); + propertyName.remove(QRegExp("\\(.*")); + QString variable = "waitFor" + toUpperCamelCase(propertyName) + + "In" + toUpperCamelCase(waitForProperty->objectName()); + variable = addVariable(variable); + + out() << variable << " = ktutorial.newWaitFor(\"WaitForProperty\");\n"; + out() << variable << ".setProperty(ktutorial.findObject(\"" + << escape(waitForProperty->objectName()) << "\"), \"" + << escape(waitForProperty->propertyName()) << "\", " + << waitForProperty->value() << ");\n"; + + return variable; +} + QString JavascriptExporter::writeWaitFor(const WaitForSignal* waitForSignal) { if (waitForSignal->emitterName().isEmpty()) { out() << "//Error: WaitForSignal without emitter name!\n"; Modified: trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.h 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.h 2011-05-16 16:46:51 UTC (rev 306) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -30,6 +30,7 @@ class WaitForComposed; class WaitForEvent; class WaitForNot; +class WaitForProperty; class WaitForSignal; class WaitForWindow; @@ -207,6 +208,18 @@ QString writeWaitFor(const WaitForNot* waitForNot); /** + * Writes the code to create and set a WaitForProperty. + * If the object name, the property name or the value aren't set, an error + * message is written instead, and an empty string returned. + * + * The value is written as is. It is neither escaped nor wrapped in quotes. + * + * @param waitForProperty The WaitForProperty. + * @return The name of the variable that holds the WaitFor. + */ + QString writeWaitFor(const WaitForProperty* waitForProperty); + + /** * Writes the code to create and set a WaitForSignal. * If the emitter name or the signal name aren't set, an error message is * written instead, and an empty string returned. Modified: trunk/ktutorial/ktutorial-editor/src/serialization/Tutorial.xsd =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/Tutorial.xsd 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/serialization/Tutorial.xsd 2011-05-16 16:46:51 UTC (rev 306) @@ -44,6 +44,7 @@ <xsd:element name="waitForComposed" type="WaitForComposedType"/> <xsd:element name="waitForEvent" type="WaitForEventType"/> <xsd:element name="waitForNot" type="WaitForNotType"/> + <xsd:element name="waitForProperty" type="WaitForPropertyType"/> <xsd:element name="waitForSignal" type="WaitForSignalType"/> <xsd:element name="waitForWindow" type="WaitForWindowType"/> </xsd:choice> @@ -92,6 +93,12 @@ </xsd:sequence> </xsd:complexType> + <xsd:complexType name="WaitForPropertyType"> + <xsd:attribute name="objectName" type="xsd:string" use="optional"/> + <xsd:attribute name="propertyName" type="xsd:string" use="optional"/> + <xsd:attribute name="value" type="xsd:string" use="optional"/> + </xsd:complexType> + <xsd:complexType name="WaitForSignalType"> <xsd:attribute name="emitterName" type="xsd:string" use="optional"/> <xsd:attribute name="signalName" type="xsd:string" use="optional"/> Modified: trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.cpp 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.cpp 2011-05-16 16:46:51 UTC (rev 306) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -28,6 +28,7 @@ #include "../data/WaitForComposed.h" #include "../data/WaitForEvent.h" #include "../data/WaitForNot.h" +#include "../data/WaitForProperty.h" #include "../data/WaitForSignal.h" #include "../data/WaitForWindow.h" @@ -165,6 +166,9 @@ if (element.tagName() == "waitForNot") { return readWaitForNot(element); } + if (element.tagName() == "waitForProperty") { + return readWaitForProperty(element); + } if (element.tagName() == "waitForSignal") { return readWaitForSignal(element); } @@ -229,6 +233,22 @@ return waitForNot; } +WaitFor* TutorialReader::readWaitForProperty(const QDomElement& element) { + WaitForProperty* waitForProperty = new WaitForProperty(); + + if (element.hasAttribute("objectName")) { + waitForProperty->setObjectName(element.attribute("objectName")); + } + if (element.hasAttribute("propertyName")) { + waitForProperty->setPropertyName(element.attribute("propertyName")); + } + if (element.hasAttribute("value")) { + waitForProperty->setValue(element.attribute("value")); + } + + return waitForProperty; +} + WaitFor* TutorialReader::readWaitForSignal(const QDomElement& element) { WaitForSignal* waitForSignal = new WaitForSignal(); @@ -257,6 +277,7 @@ if (element.tagName() != "waitForComposed" && element.tagName() != "waitForEvent" && element.tagName() != "waitForNot" && + element.tagName() != "waitForProperty" && element.tagName() != "waitForSignal" && element.tagName() != "waitForWindow") { return false; Modified: trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.h 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.h 2011-05-16 16:46:51 UTC (rev 306) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -31,6 +31,7 @@ class WaitForComposed; class WaitForEvent; class WaitForNot; +class WaitForProperty; class WaitForSignal; class WaitForWindow; @@ -128,6 +129,14 @@ WaitFor* readWaitForNot(const QDomElement& element); /** + * Reads a new WaitForProperty from the "waitForProperty" XML element. + * + * @param element The element to read the WaitForProperty from. + * @return The new WaitForProperty. + */ + WaitFor* readWaitForProperty(const QDomElement& element); + + /** * Reads a new WaitForSignal from the "waitForSignal" XML element. * * @param element The element to read the WaitForSignal from. Modified: trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.cpp 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.cpp 2011-05-16 16:46:51 UTC (rev 306) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -24,6 +24,7 @@ #include "../data/WaitForComposed.h" #include "../data/WaitForEvent.h" #include "../data/WaitForNot.h" +#include "../data/WaitForProperty.h" #include "../data/WaitForSignal.h" #include "../data/WaitForWindow.h" @@ -149,6 +150,10 @@ write(static_cast<const WaitForNot*>(waitFor)); return; } + if (qobject_cast<const WaitForProperty*>(waitFor)) { + write(static_cast<const WaitForProperty*>(waitFor)); + return; + } if (qobject_cast<const WaitForSignal*>(waitFor)) { write(static_cast<const WaitForSignal*>(waitFor)); return; @@ -199,6 +204,21 @@ mXmlWriter->writeEndElement(); } +void TutorialWriter::write(const WaitForProperty* waitForProperty) { + mXmlWriter->writeEmptyElement("waitForProperty"); + + if (!waitForProperty->objectName().isEmpty()) { + mXmlWriter->writeAttribute("objectName", waitForProperty->objectName()); + } + if (!waitForProperty->propertyName().isEmpty()) { + mXmlWriter->writeAttribute("propertyName", + waitForProperty->propertyName()); + } + if (!waitForProperty->value().isEmpty()) { + mXmlWriter->writeAttribute("value", waitForProperty->value()); + } +} + void TutorialWriter::write(const WaitForSignal* waitForSignal) { mXmlWriter->writeEmptyElement("waitForSignal"); Modified: trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.h 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.h 2011-05-16 16:46:51 UTC (rev 306) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -28,6 +28,7 @@ class WaitForComposed; class WaitForEvent; class WaitForNot; +class WaitForProperty; class WaitForSignal; class WaitForWindow; @@ -116,6 +117,13 @@ void write(const WaitForNot* waitForNot); /** + * Writes the XML serialization of the given WaitForProperty. + * + * @param waitForProperty The WaitForProperty to get its XML serialization. + */ + void write(const WaitForProperty* waitForProperty); + + /** * Writes the XML serialization of the given WaitForSignal. * * @param waitForSignal The WaitForSignal to get its XML serialization. Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2011-05-16 16:46:51 UTC (rev 306) @@ -27,6 +27,8 @@ WaitForEventTreeItem.cpp WaitForEventWidget.cpp WaitForNotTreeItem.cpp + WaitForPropertyTreeItem.cpp + WaitForPropertyWidget.cpp WaitForSignalTreeItem.cpp WaitForSignalWidget.cpp WaitForTreeItem.cpp @@ -60,6 +62,7 @@ StepDataWidget.ui TutorialInformationWidget.ui WaitForEventWidget.ui + WaitForPropertyWidget.ui WaitForSignalWidget.ui WaitForWidget.ui WaitForWindowWidget.ui Modified: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp 2011-05-16 16:46:51 UTC (rev 306) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -22,6 +22,7 @@ #include "../data/WaitForComposed.h" #include "../data/WaitForEvent.h" #include "../data/WaitForNot.h" +#include "../data/WaitForProperty.h" #include "../data/WaitForSignal.h" #include "../data/WaitForWindow.h" @@ -55,6 +56,8 @@ return new WaitForEvent(); } else if (index == 5) { return new WaitForWindow(); + } else if (index == 6) { + return new WaitForProperty(); } return 0; Modified: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui 2011-05-16 16:46:51 UTC (rev 306) @@ -71,6 +71,11 @@ <string comment="@item:inlistbox">The specified window is shown</string> </property> </item> + <item> + <property name="text"> + <string comment="@item:inlistbox">The specified property has certain value</string> + </property> + </item> </widget> </item> </layout> Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyTreeItem.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyTreeItem.cpp 2011-05-16 16:46:51 UTC (rev 306) @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (C) 2011 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 "WaitForPropertyTreeItem.h" + +#include <KLocalizedString> + +#include "../data/WaitForProperty.h" + +//public: + +WaitForPropertyTreeItem::WaitForPropertyTreeItem( + WaitForProperty* waitForProperty, + TreeItem* parent): + WaitForTreeItem(waitForProperty, parent) { + mObjectName = waitForProperty->objectName(); + mPropertyName = waitForProperty->propertyName(); + mValue = waitForProperty->value(); + + connect(waitForProperty, SIGNAL(dataChanged(WaitFor*)), + this, SLOT(update(WaitFor*))); +} + +QString WaitForPropertyTreeItem::text() const { + QString objectName; + if (mObjectName.isEmpty()) { + objectName = i18nc("@item", "(object name not set)"); + } else { + objectName = "\"" + mObjectName + "\""; + } + + QString propertyName; + if (mPropertyName.isEmpty()) { + propertyName = i18nc("@item", "(property not set)"); + } else { + propertyName = "\"" + mPropertyName + "\""; + } + + QString value; + if (mValue.isEmpty()) { + value = i18nc("@item", "(value not set)"); + } else { + value = mValue; + } + + return i18nc("@item", "When the property %1 in the object %2 changes to " + "the value %3", propertyName, objectName, value); +} + +//private: + +void WaitForPropertyTreeItem::update(WaitFor* waitFor) { + WaitForProperty* waitForProperty = static_cast<WaitForProperty*>(waitFor); + mObjectName = waitForProperty->objectName(); + mPropertyName = waitForProperty->propertyName(); + mValue = waitForProperty->value(); + + emit dataChanged(this); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyTreeItem.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyTreeItem.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyTreeItem.h 2011-05-16 16:46:51 UTC (rev 306) @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (C) 2011 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 WAITFORPROPERTYTREEITEM_H +#define WAITFORPROPERTYTREEITEM_H + +#include "WaitForTreeItem.h" + +class WaitForProperty; + +/** + * A TreeItem that represents a WaitForProperty. + * The tree representation of a WaitForProperty is a plain text: + * When the property "property name" in the object "object name" changes to the + * value value + * + * If the property, the object name or the value aren't set yet, a placeholder + * is put instead. Property placeholder is "(property not set)", the object name + * placeholder is "(object name not set)" , and the value placeholder is "(value + * not set)" (without quotes, but with parenthesis). + * + * Whenever the WaitForProperty data changes, the WaitForPropertyTreeItem text + * is updated as needed. + */ +class WaitForPropertyTreeItem: public WaitForTreeItem { +Q_OBJECT +public: + + /** + * Creates a new WaitForPropertyTreeItem for the given WaitForProperty and + * with the given parent. + * + * @param waitForProperty The WaitForProperty to represent. + * @param parent The parent TreeItem. + */ + explicit WaitForPropertyTreeItem(WaitForProperty* waitForProperty, + TreeItem* parent = 0); + + /** + * Returns the description of the WaitForProperty. + * + * @return The text for this TreeItem. + */ + virtual QString text() const; + +private: + + /** + * The object name of the WaitForProperty. + */ + QString mObjectName; + + /** + * The property name of the WaitForProperty. + */ + QString mPropertyName; + + /** + * The value of the WaitForProperty. + */ + QString mValue; + +private Q_SLOTS: + + /** + * Updates this WaitForPropertyTreeItem when the data of its WaitForProperty + * changed. + * + * @param waitFor The WaitForProperty. + */ + void update(WaitFor* waitFor); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyTreeItem.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.cpp 2011-05-16 16:46:51 UTC (rev 306) @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (C) 2011 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 "WaitForPropertyWidget.h" + +#include "ui_WaitForPropertyWidget.h" +#include "../data/WaitForProperty.h" + +#ifdef QT_QTDBUS_FOUND +#include "RemoteObjectNameWidget.h" +#endif + +//public: + +WaitForPropertyWidget::WaitForPropertyWidget(WaitForProperty* waitForProperty, + QWidget* parent): + EditionWidget(parent), + mWaitForProperty(waitForProperty) { + + ui = new Ui::WaitForPropertyWidget(); +#ifdef QT_QTDBUS_FOUND + //Hack: RemoteObjectNameWidget is created before the other widgets to be + //the first widget in the tab order. I feel dumb, but I tried using + //setTabOrder and got nothing... + mRemoteObjectNameWidget = new RemoteObjectNameWidget(this); +#endif + ui->setupUi(this); + +#ifdef QT_QTDBUS_FOUND + //Replace ui->objectNameLineEdit with mRemoteObjectNameWidget + ui->valueVerticalLayout->removeWidget(ui->objectNameLineEdit); + delete ui->objectNameLineEdit; + + ui->valueVerticalLayout->insertWidget(0, mRemoteObjectNameWidget); + + mRemoteObjectNameWidget->setName(waitForProperty->objectName()); +#else + ui->objectNameLineEdit->setText(waitForProperty->objectName()); +#endif + + ui->propertyNameLineEdit->setText(waitForProperty->propertyName()); + + ui->valueLineEdit->setText(waitForProperty->value()); +} + +WaitForPropertyWidget::~WaitForPropertyWidget() { + delete ui; +} + +void WaitForPropertyWidget::saveChanges() { +#ifdef QT_QTDBUS_FOUND + QString objectName = mRemoteObjectNameWidget->name(); +#else + QString objectName = ui->objectNameLineEdit->text(); +#endif + if (mWaitForProperty->objectName() != objectName) { + mWaitForProperty->setObjectName(objectName); + } + + QString propertyName = ui->propertyNameLineEdit->text(); + if (mWaitForProperty->propertyName() != propertyName) { + mWaitForProperty->setPropertyName(propertyName); + } + + QString value = ui->valueLineEdit->text(); + if (mWaitForProperty->value() != value) { + mWaitForProperty->setValue(value); + } +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.h 2011-05-16 16:46:51 UTC (rev 306) @@ -0,0 +1,82 @@ +/*************************************************************************** + * Copyright (C) 2011 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 WAITFORPROPERTYWIDGET_H +#define WAITFORPROPERTYWIDGET_H + +#include "EditionWidget.h" + +#ifdef QT_QTDBUS_FOUND +class RemoteObjectNameWidget; +#endif + +class WaitForProperty; + +namespace Ui { +class WaitForPropertyWidget; +} + +/** + * Edition widget for the condition to wait for a property. + */ +class WaitForPropertyWidget: public EditionWidget { +Q_OBJECT +public: + + /** + * Creates a new WaitForPropertyWidget for the given WaitForProperty. + * + * @param waitForProperty The WaitForProperty to set its data. + * @param parent The parent QWidget. + */ + explicit WaitForPropertyWidget(WaitForProperty* waitForProperty, + QWidget* parent = 0); + + /** + * Destroys this widget. + */ + virtual ~WaitForPropertyWidget(); + + /** + * Saves the object name, the property name and the value in the + * WaitForProperty. + */ + virtual void saveChanges(); + +private: + + /** + * The WaitForProperty to edit. + */ + WaitForProperty* mWaitForProperty; + + /** + * The Ui Designer generated class. + */ + Ui::WaitForPropertyWidget* ui; + +#ifdef QT_QTDBUS_FOUND + /** + * The widget to get the name of a remote object. + */ + RemoteObjectNameWidget* mRemoteObjectNameWidget; +#endif + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.ui (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.ui 2011-05-16 16:46:51 UTC (rev 306) @@ -0,0 +1,123 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>WaitForPropertyWidget</class> + <widget class="QWidget" name="WaitForPropertyWidget"> + <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 property to wait for</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>Set the object name, the property name and the value to wait for.</para></string> + </property> + <layout class="QVBoxLayout" name="WaitForPropertyVerticalLayout"> + <item> + <widget class="QGroupBox" name="waitForPropertyGroupBox"> + <property name="title"> + <string comment="@title:group">Wait for property</string> + </property> + <layout class="QHBoxLayout" name="waitForPropertyGroupBoxHorizontalLayout"> + <item> + <layout class="QVBoxLayout" name="labelVerticalLayout"> + <item> + <widget class="QLabel" name="objectNameLabel"> + <property name="text"> + <string comment="@label:textbox">Object name:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="propertyNameLabel"> + <property name="text"> + <string comment="@label:textbox">Property name:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>propertyNameLineEdit</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="valueLabel"> + <property name="text"> + <string comment="@label:textbox">Value:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>valueLineEdit</cstring> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="valueVerticalLayout"> + <item> + <widget class="KLineEdit" name="objectNameLineEdit"> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>The name of the QObject that contains the property.</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="propertyNameLineEdit"> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>The name of the property.</para> +<para>Not every property can be used to wait until its value changes to the expected one. Only properties that have a notify signal can be used with that purpose.</para> +<para>Properties that do not have a notify signal can still be used to enrich other conditions (for example, waiting for a signal to be emitted but only changing to the next step if, in addition, some property has some value), but they can not be used alone as single conditions in a reaction.</para></string> + </property> + </widget> + </item> + <item> + <widget class="KLineEdit" name="valueLineEdit"> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>The expected value of the property.</para> +<para>The value is copied as is to the script. That means that it has to be written with the syntax of the script language that the tutorial is going to be exported to. For example, if the tutorial is going to be exported to Javascript and the value to wait for is a text, the value has to be written as <em>"The expected text"</em> (wrapped in quotes).</para> +<para>The value can even contain a programming expression in the script language. For example, something like <em>t.i18nc("@item:inlistbox", "Certain item text")</em> would be used to wait for the localized text of an item in a combo box.</para></string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="waitForPropertyWidgetSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>20</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 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp 2011-05-16 16:46:51 UTC (rev 306) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -20,11 +20,13 @@ #include "WaitForComposedTreeItem.h" #include "WaitForEventTreeItem.h" #include "WaitForNotTreeItem.h" +#include "WaitForPropertyTreeItem.h" #include "WaitForSignalTreeItem.h" #include "WaitForWindowTreeItem.h" #include "../data/WaitForComposed.h" #include "../data/WaitForEvent.h" #include "../data/WaitForNot.h" +#include "../data/WaitForProperty.h" #include "../data/WaitForSignal.h" #include "../data/WaitForWindow.h" @@ -47,6 +49,11 @@ parent); } + if (qobject_cast<WaitForProperty*>(waitFor)) { + return new WaitForPropertyTreeItem( + static_cast<WaitForProperty*>(waitFor), parent); + } + if (qobject_cast<WaitForSignal*>(waitFor)) { return new WaitForSignalTreeItem(static_cast<WaitForSignal*>(waitFor), parent); Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp 2011-05-16 16:46:51 UTC (rev 306) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -25,12 +25,14 @@ #include "TextTreeItem.h" #include "TreeModel.h" #include "WaitForEventWidget.h" +#include "WaitForPropertyWidget.h" #include "WaitForSignalWidget.h" #include "WaitForWindowWidget.h" #include "WaitForTreeItem.h" #include "../data/WaitForComposed.h" #include "../data/WaitForEvent.h" #include "../data/WaitForNot.h" +#include "../data/WaitForProperty.h" #include "../data/WaitForSignal.h" #include "../data/WaitForWindow.h" @@ -132,6 +134,14 @@ return; } + if (qobject_cast<WaitForProperty*>(selectedWaitFor)) { + ui->addButton->setEnabled(false); + ui->editButton->setEnabled(true); + ui->removeButton->setEnabled(true); + + return; + } + if (qobject_cast<WaitForSignal*>(selectedWaitFor)) { ui->addButton->setEnabled(false); ui->editButton->setEnabled(true); @@ -228,6 +238,12 @@ editionWidget = new WaitForEventWidget(waitForEvent, this); } + if (qobject_cast<WaitForProperty*>(mCurrentWaitFor)) { + WaitForProperty* waitForProperty = + static_cast<WaitForProperty*>(mCurrentWaitFor); + editionWidget = new WaitForPropertyWidget(waitForProperty, this); + } + if (qobject_cast<WaitForSignal*>(mCurrentWaitFor)) { WaitForSignal* waitForSignal = static_cast<WaitForSignal*>(mCurrentWaitFor); Modified: trunk/ktutorial/ktutorial-editor/tests/unit/data/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/data/CMakeLists.txt 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/tests/unit/data/CMakeLists.txt 2011-05-16 16:46:51 UTC (rev 306) @@ -19,6 +19,7 @@ WaitForComposed WaitForEvent WaitForNot + WaitForProperty WaitForSignal WaitForWindow ) @@ -37,6 +38,7 @@ WaitForComposed WaitForEvent WaitForNot + WaitForProperty WaitForSignal WaitForWindow ) Added: trunk/ktutorial/ktutorial-editor/tests/unit/data/WaitForPropertyTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/data/WaitForPropertyTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/data/WaitForPropertyTest.cpp 2011-05-16 16:46:51 UTC (rev 306) @@ -0,0 +1,175 @@ +/*************************************************************************** + * Copyright (C) 2011 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 "WaitForProperty.h" + +class WaitForPropertyTest: public QObject { +Q_OBJECT + +private slots: + + void initTestCase(); + + void testConstructor(); + + void testClone(); + + void testEquals(); + + void testSetObjectName(); + + void testSetPropertyName(); + + void testSetValue(); + +private: + + int mWaitForStarType; + + void assertWaitForProperty(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 WaitForPropertyTest::initTestCase() { + //WaitFor* must be registered in order to be used with QSignalSpy + mWaitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); +} + +void WaitForPropertyTest::testConstructor() { + QObject parent; + WaitForProperty* waitForProperty = new WaitForProperty(&parent); + + QCOMPARE(waitForProperty->parent(), &parent); +} + +void WaitForPropertyTest::testClone() { + WaitForProperty waitForProperty; + waitForProperty.setObjectName("The object name"); + waitForProperty.setPropertyName("The property name"); + waitForProperty.setValue("The value"); + + WaitForProperty* cloned = + static_cast<WaitForProperty*>(waitForProperty.clone()); + + QVERIFY(cloned != &waitForProperty); + QCOMPARE(cloned->objectName(), waitForProperty.objectName()); + QCOMPARE(cloned->propertyName(), waitForProperty.propertyName()); + QCOMPARE(cloned->value(), waitForProperty.value()); + delete cloned; +} + +void WaitForPropertyTest::testEquals() { + WaitForProperty waitForProperty1; + waitForProperty1.setObjectName("The object name"); + waitForProperty1.setPropertyName("The property name"); + waitForProperty1.setValue("The value"); + WaitForProperty waitForProperty2; + + QCOMPARE(waitForProperty1 == waitForProperty2, false); + QCOMPARE(waitForProperty2 == waitForProperty1, false); + + waitForProperty2.setObjectName("The object name"); + waitForProperty2.setPropertyName("The property name"); + waitForProperty2.setValue("The value"); + + QCOMPARE(waitForProperty1 == waitForProperty2, true); + QCOMPARE(waitForProperty2 == waitForProperty1, true); + + StubWaitFor stubWaitFor; + + QCOMPARE(waitForProperty1 == stubWaitFor, false); +} + +void WaitForPropertyTest::testSetObjectName() { + WaitForProperty waitForProperty; + + QSignalSpy dataChangedSpy(&waitForProperty, SIGNAL(dataChanged(WaitFor*))); + + waitForProperty.setObjectName("The object name"); + + QCOMPARE(waitForProperty.objectName(), QString("The object name")); + QCOMPARE(dataChangedSpy.count(), 1); + assertWaitForProperty(dataChangedSpy, 0, &waitForProperty); +} + +void WaitForPropertyTest::testSetPropertyName() { + WaitForProperty waitForProperty; + + QSignalSpy dataChangedSpy(&waitForProperty, SIGNAL(dataChanged(WaitFor*))); + + waitForProperty.setPropertyName("The property name"); + + QCOMPARE(waitForProperty.propertyName(), QString("The property name")); + QCOMPARE(dataChangedSpy.count(), 1); + assertWaitForProperty(dataChangedSpy, 0, &waitForProperty); +} + +void WaitForPropertyTest::testSetValue() { + WaitForProperty waitForProperty; + + QSignalSpy dataChangedSpy(&waitForProperty, SIGNAL(dataChanged(WaitFor*))); + + waitForProperty.setValue("The value"); + + QCOMPARE(waitForProperty.value(), QString("The value")); + QCOMPARE(dataChangedSpy.count(), 1); + assertWaitForProperty(dataChangedSpy, 0, &waitForProperty); +} + +//WaitFor* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(WaitFor*); + +/////////////////////////////////// Helpers //////////////////////////////////// + +void WaitForPropertyTest::assertWaitForProperty(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(WaitForPropertyTest) + +#include "WaitForPropertyTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/data/WaitForPropertyTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/tests/unit/serialization/JavascriptExporterTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/serialization/JavascriptExporterTest.cpp 2011-05-16 16:39:27 UTC (rev 305) +++ trunk/ktutorial/ktutorial-editor/tests/unit/serialization/JavascriptExporterTest.cpp 2011-05-16 16:46:51 UTC (rev 306) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -26,6 +26,7 @@ #include "../data/WaitForComposed.h" #include "../data/WaitForEvent.h" #include "../data/WaitForNot.h" +#include "../data/WaitForProperty.h" #include "../data/WaitForSignal.h" #include "../data/WaitForWindow.h" @@ -89,6 +90,9 @@ void testWaitForEvent(); void testWaitForEventWithEscapeSequences(); void testWaitForEventWithoutReceiverNameOrEventName(); + void testWaitForProperty(); + void testWaitForPropertyWithEscapeSequences(); + void testWaitForPropertyWithoutObjectNameOrPropertyNameOrValue(); void testWaitForSignal(); void testWaitForSignalWithEscapeSequences(); void testWaitForSignalWithoutEmitterNameOrSignalName(); @@ -1148,6 +1152,144 @@ QCOMPARE(exportedTutorial, expected); } +void JavascriptExporterTest::testWaitForProperty() { + Tutorial tutorial; + Step* step = new Step(); + step->setId("The id"); + tutorial.addStep(step); + + WaitForProperty* waitForProperty = new WaitForProperty(); + waitForProperty->setObjectName("The object name"); + waitForProperty->setPropertyName("thePropertyName"); + waitForProperty->setValue("TheValue"); + + Reaction* reaction = new Reaction(); + reaction->setTriggerType(Reaction::ConditionMet); + reaction->setWaitFor(waitForProperty); + reaction->setResponseType(Reaction::NextStep); + reaction->setNextStepId("Another step"); + step->addReaction(reaction); + + JavascriptExporter exporter; + QString exportedTutorial = exporter.exportTutorial(&tutorial); + + QString expected = +TUTORIAL_EMPTY_INFORMATION_CODE +STEP_WITH_ID_THE_ID_AND_EMPTY_TEXT_START_CODE +"function theIdStepSetup(step) {\n" +" waitForThePropertyNameInTheObjectName = \ +ktutorial.newWaitFor(\"WaitForProperty\");\n" +" waitForThePropertyNameInTheObjectName.setProperty(\ +ktutorial.findObject(\"The object name\"), \"thePropertyName\", TheValue);\n" +" step.addWaitFor(waitForThePropertyNameInTheObjectName, \ +\"Another step\");\n" +"}\n" +CONNECT_STEP_SETUP +STEP_WITH_ID_THE_ID_AND_EMPTY_TEXT_END_CODE; + + QCOMPARE(exportedTutorial, expected); +} + +void JavascriptExporterTest::testWaitForPropertyWithEscapeSequences() { + Tutorial tutorial; + Step* step = new Step(); + step->setId("The id"); + tutorial.addStep(step); + + WaitForProperty* waitForProper... [truncated message content] |