[Ktutorial-commits] SF.net SVN: ktutorial:[258] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-09-26 17:50:03
|
Revision: 258
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=258&view=rev
Author: danxuliu
Date: 2010-09-26 17:49:55 +0000 (Sun, 26 Sep 2010)
Log Message:
-----------
Add support for WaitForWindow to wait for a specific window to be shown.
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/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/WaitForWindow.cpp
trunk/ktutorial/ktutorial-editor/src/data/WaitForWindow.h
trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowTreeItem.cpp
trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowTreeItem.h
trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.cpp
trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.h
trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.ui
trunk/ktutorial/ktutorial-editor/tests/unit/data/WaitForWindowTest.cpp
trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWindowTreeItemTest.cpp
trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWindowWidgetTest.cpp
Modified: trunk/ktutorial/ktutorial-editor/src/data/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/data/CMakeLists.txt 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/data/CMakeLists.txt 2010-09-26 17:49:55 UTC (rev 258)
@@ -7,6 +7,7 @@
WaitForEvent.cpp
WaitForNot.cpp
WaitForSignal.cpp
+ WaitForWindow.cpp
)
kde4_add_library(ktutorial_editor_data ${ktutorial_editor_data_SRCS})
Added: trunk/ktutorial/ktutorial-editor/src/data/WaitForWindow.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/data/WaitForWindow.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/data/WaitForWindow.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -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 "WaitForWindow.h"
+
+//public:
+
+WaitForWindow::WaitForWindow(QObject* parent): WaitFor(parent) {
+}
+
+WaitFor* WaitForWindow::clone() const {
+ WaitForWindow* cloned = new WaitForWindow();
+ cloned->setWindowObjectName(mWindowObjectName);
+
+ return cloned;
+}
+
+bool WaitForWindow::equals(const WaitFor& waitFor) const {
+ if (!qobject_cast<const WaitForWindow*>(&waitFor)) {
+ return false;
+ }
+
+ const WaitForWindow* waitForWindow =
+ static_cast<const WaitForWindow*>(&waitFor);
+ if (waitForWindow->windowObjectName() != mWindowObjectName) {
+ return false;
+ }
+
+ return true;
+}
+
+QString WaitForWindow::windowObjectName() const {
+ return mWindowObjectName;
+}
+
+void WaitForWindow::setWindowObjectName(const QString& windowObjectName) {
+ mWindowObjectName = windowObjectName;
+
+ emit dataChanged(this);
+}
Property changes on: trunk/ktutorial/ktutorial-editor/src/data/WaitForWindow.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/ktutorial/ktutorial-editor/src/data/WaitForWindow.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/data/WaitForWindow.h (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/data/WaitForWindow.h 2010-09-26 17:49:55 UTC (rev 258)
@@ -0,0 +1,56 @@
+/***************************************************************************
+ * 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 WAITFORWINDOW_H
+#define WAITFORWINDOW_H
+
+#include "WaitFor.h"
+
+/**
+ * Container for conditions that wait for a window to be shown data.
+ * It stores the data used in KTutorial WaitForWindow, 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::WaitForWindow
+ * object.
+ *
+ * When any attribute is modified, dataChanged(WaitFor*) signal is emitted.
+ */
+class WaitForWindow: public WaitFor {
+Q_OBJECT
+public:
+
+ /**
+ * Creates a new WaitForWindow.
+ *
+ * @param parent The parent QObject.
+ */
+ WaitForWindow(QObject* parent = 0);
+
+ virtual WaitFor* clone() const;
+ virtual bool equals(const WaitFor& waitFor) const;
+
+ QString windowObjectName() const;
+ void setWindowObjectName(const QString& windowObjectName);
+
+private:
+
+ QString mWindowObjectName;
+
+};
+
+#endif
Property changes on: trunk/ktutorial/ktutorial-editor/src/data/WaitForWindow.h
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.cpp 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -28,6 +28,7 @@
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
//public:
@@ -266,6 +267,9 @@
if (qobject_cast<const WaitForSignal*>(waitFor)) {
return writeWaitFor(static_cast<const WaitForSignal*>(waitFor));
}
+ if (qobject_cast<const WaitForWindow*>(waitFor)) {
+ return writeWaitFor(static_cast<const WaitForWindow*>(waitFor));
+ }
return "";
}
@@ -362,6 +366,24 @@
return variable;
}
+QString JavascriptExporter::writeWaitFor(const WaitForWindow* waitForWindow) {
+ if (waitForWindow->windowObjectName().isEmpty()) {
+ out() << "//Error: WaitForWindow without window object name!\n";
+ return "";
+ }
+
+ QString variable = "waitFor" +
+ toUpperCamelCase(waitForWindow->windowObjectName()) +
+ "ToBeShown";
+ variable = addVariable(variable);
+
+ out() << variable << " = ktutorial.newWaitFor(\"WaitForWindow\");\n";
+ out() << variable << ".setWindowObjectName(\""
+ << escape(waitForWindow->windowObjectName()) << "\");\n";
+
+ return variable;
+}
+
QTextStream& JavascriptExporter::out() {
mOut << indentation();
return mOut;
Modified: trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.h 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.h 2010-09-26 17:49:55 UTC (rev 258)
@@ -31,6 +31,7 @@
class WaitForEvent;
class WaitForNot;
class WaitForSignal;
+class WaitForWindow;
/**
* Exporter of tutorials to Javascript code.
@@ -214,6 +215,16 @@
QString writeWaitFor(const WaitForSignal* waitForSignal);
/**
+ * Writes the code to create and set a WaitForWindow.
+ * If the window object name isn't set, an error message is written instead,
+ * and an empty string returned.
+ *
+ * @param waitForWindow The WaitForWindow.
+ * @return The name of the variable that holds the WaitFor.
+ */
+ QString writeWaitFor(const WaitForWindow* waitForWindow);
+
+ /**
* Returns the output stream after adding the identation text.
* It is used as a shortcut to "mOut << indentation()". Use it to output any
* line that has no previous indentation.
Modified: trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.cpp 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -29,6 +29,7 @@
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
//public:
@@ -167,6 +168,9 @@
if (element.tagName() == "waitForSignal") {
return readWaitForSignal(element);
}
+ if (element.tagName() == "waitForWindow") {
+ return readWaitForWindow(element);
+ }
Q_ASSERT(false);
return 0;
@@ -238,11 +242,23 @@
return waitForSignal;
}
+WaitFor* TutorialReader::readWaitForWindow(const QDomElement& element) {
+ WaitForWindow* waitForWindow = new WaitForWindow();
+
+ if (element.hasAttribute("windowObjectName")) {
+ waitForWindow->setWindowObjectName(
+ element.attribute("windowObjectName"));
+ }
+
+ return waitForWindow;
+}
+
bool TutorialReader::isWaitForElement(const QDomElement& element) {
if (element.tagName() != "waitForComposed" &&
element.tagName() != "waitForEvent" &&
element.tagName() != "waitForNot" &&
- element.tagName() != "waitForSignal") {
+ 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 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.h 2010-09-26 17:49:55 UTC (rev 258)
@@ -32,6 +32,7 @@
class WaitForEvent;
class WaitForNot;
class WaitForSignal;
+class WaitForWindow;
/**
* Deserializer for tutorials stored in XML.
@@ -135,6 +136,14 @@
WaitFor* readWaitForSignal(const QDomElement& element);
/**
+ * Reads a new WaitForWindow from the "waitForWindow" XML element.
+ *
+ * @param element The element to read the WaitForWindow from.
+ * @return The new WaitForWindow.
+ */
+ WaitFor* readWaitForWindow(const QDomElement& element);
+
+ /**
* Returns whether the given element is one of the WaitFor elements or not.
*
* @param element The element to check.
Modified: trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.cpp 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -25,6 +25,7 @@
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
//public:
@@ -152,6 +153,10 @@
write(static_cast<const WaitForSignal*>(waitFor));
return;
}
+ if (qobject_cast<const WaitForWindow*>(waitFor)) {
+ write(static_cast<const WaitForWindow*>(waitFor));
+ return;
+ }
}
void TutorialWriter::write(const WaitForComposed* waitForComposed) {
@@ -204,3 +209,12 @@
mXmlWriter->writeAttribute("signalName", waitForSignal->signalName());
}
}
+
+void TutorialWriter::write(const WaitForWindow* waitForWindow) {
+ mXmlWriter->writeEmptyElement("waitForWindow");
+
+ if (!waitForWindow->windowObjectName().isEmpty()) {
+ mXmlWriter->writeAttribute("windowObjectName",
+ waitForWindow->windowObjectName());
+ }
+}
Modified: trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.h 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/serialization/TutorialWriter.h 2010-09-26 17:49:55 UTC (rev 258)
@@ -29,6 +29,7 @@
class WaitForEvent;
class WaitForNot;
class WaitForSignal;
+class WaitForWindow;
/**
* Serializes a Tutorial in XML.
@@ -121,6 +122,13 @@
*/
void write(const WaitForSignal* waitForSignal);
+ /**
+ * Writes the XML serialization of the given WaitForWindow.
+ *
+ * @param waitForWindow The WaitForWindow to get its XML serialization.
+ */
+ void write(const WaitForWindow* waitForWindow);
+
};
#endif
Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-09-26 17:49:55 UTC (rev 258)
@@ -28,6 +28,8 @@
WaitForSignalWidget.cpp
WaitForTreeItem.cpp
WaitForWidget.cpp
+ WaitForWindowTreeItem.cpp
+ WaitForWindowWidget.cpp
)
if (QT_QTDBUS_FOUND)
@@ -54,6 +56,7 @@
WaitForEventWidget.ui
WaitForSignalWidget.ui
WaitForWidget.ui
+ WaitForWindowWidget.ui
)
if (QT_QTDBUS_FOUND)
Modified: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -23,6 +23,7 @@
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
//public:
@@ -52,6 +53,8 @@
return new WaitForSignal();
} else if (index == 4) {
return new WaitForEvent();
+ } else if (index == 5) {
+ return new WaitForWindow();
}
return 0;
Modified: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui 2010-09-26 17:49:55 UTC (rev 258)
@@ -66,6 +66,11 @@
<string comment="@item:inlistbox">The specified event is received</string>
</property>
</item>
+ <item>
+ <property name="text">
+ <string comment="@item:inlistbox">The specified window is shown</string>
+ </property>
+ </item>
</widget>
</item>
</layout>
Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/view/WaitForTreeItem.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -21,10 +21,12 @@
#include "WaitForEventTreeItem.h"
#include "WaitForNotTreeItem.h"
#include "WaitForSignalTreeItem.h"
+#include "WaitForWindowTreeItem.h"
#include "../data/WaitForComposed.h"
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
//public:
@@ -50,6 +52,11 @@
parent);
}
+ if (qobject_cast<WaitForWindow*>(waitFor)) {
+ return new WaitForWindowTreeItem(static_cast<WaitForWindow*>(waitFor),
+ parent);
+ }
+
Q_ASSERT(false);
return 0;
}
Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -26,11 +26,13 @@
#include "TreeModel.h"
#include "WaitForEventWidget.h"
#include "WaitForSignalWidget.h"
+#include "WaitForWindowWidget.h"
#include "WaitForTreeItem.h"
#include "../data/WaitForComposed.h"
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
//public:
@@ -137,6 +139,14 @@
return;
}
+
+ if (qobject_cast<WaitForWindow*>(selectedWaitFor)) {
+ ui->addButton->setEnabled(false);
+ ui->editButton->setEnabled(true);
+ ui->removeButton->setEnabled(true);
+
+ return;
+ }
}
//private slots:
@@ -222,6 +232,12 @@
editionWidget = new WaitForSignalWidget(waitForSignal, this);
}
+ if (qobject_cast<WaitForWindow*>(mCurrentWaitFor)) {
+ WaitForWindow* waitForWindow =
+ static_cast<WaitForWindow*>(mCurrentWaitFor);
+ editionWidget = new WaitForWindowWidget(waitForWindow, this);
+ }
+
Q_ASSERT(editionWidget);
EditionDialog* dialog = new EditionDialog(editionWidget, this);
Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowTreeItem.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowTreeItem.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowTreeItem.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -0,0 +1,54 @@
+/***************************************************************************
+ * 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 "WaitForWindowTreeItem.h"
+
+#include <KLocalizedString>
+
+#include "../data/WaitForWindow.h"
+
+//public:
+
+WaitForWindowTreeItem::WaitForWindowTreeItem(WaitForWindow* waitForWindow,
+ TreeItem* parent):
+ WaitForTreeItem(waitForWindow, parent) {
+ mWindowObjectName = waitForWindow->windowObjectName();
+
+ connect(waitForWindow, SIGNAL(dataChanged(WaitFor*)),
+ this, SLOT(update(WaitFor*)));
+}
+
+QString WaitForWindowTreeItem::text() const {
+ QString windowObjectName;
+ if (mWindowObjectName.isEmpty()) {
+ windowObjectName = i18nc("@item", "(object name not set)");
+ } else {
+ windowObjectName = "\"" + mWindowObjectName + "\"";
+ }
+
+ return i18nc("@item", "When the window %1 is shown", windowObjectName);
+}
+
+//private:
+
+void WaitForWindowTreeItem::update(WaitFor* waitFor) {
+ WaitForWindow* waitForWindow = static_cast<WaitForWindow*>(waitFor);
+ mWindowObjectName = waitForWindow->windowObjectName();
+
+ emit dataChanged(this);
+}
Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowTreeItem.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowTreeItem.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowTreeItem.h (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowTreeItem.h 2010-09-26 17:49:55 UTC (rev 258)
@@ -0,0 +1,78 @@
+/***************************************************************************
+ * 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 WAITFORWINDOWTREEITEM_H
+#define WAITFORWINDOWTREEITEM_H
+
+#include "WaitForTreeItem.h"
+
+class WaitForWindow;
+
+/**
+ * A TreeItem that represents a WaitForWindow.
+ * The tree representation of a WaitForWindow is a plain text:
+ * When the window "object name" is shown
+ *
+ * If the window object name isn't set yet, a placeholder is put instead. The
+ * object name placeholder is "(object name not set)" (without quotes, but with
+ * parenthesis).
+ *
+ * Whenever the WaitForWindow data changes, the WaitForWindowTreeItem text is
+ * updated as needed.
+ */
+class WaitForWindowTreeItem: public WaitForTreeItem {
+Q_OBJECT
+public:
+
+ /**
+ * Creates a new WaitForWindowTreeItem for the given WaitForWindow and with
+ * the given parent.
+ *
+ * @param waitForWindow The WaitForWindow to represent.
+ * @param parent The parent TreeItem.
+ */
+ explicit WaitForWindowTreeItem(WaitForWindow* waitForWindow,
+ TreeItem* parent = 0);
+
+ /**
+ * Returns the description of the WaitForWindow.
+ *
+ * @return The text for this TreeItem.
+ */
+ virtual QString text() const;
+
+private:
+
+ /**
+ * The window object name of the WaitForWindow.
+ */
+ QString mWindowObjectName;
+
+private Q_SLOTS:
+
+ /**
+ * Updates this WaitForWindowTreeItem when the data of its WaitForWindow
+ * changed.
+ *
+ * @param waitFor The WaitForWindow.
+ */
+ void update(WaitFor* waitFor);
+
+};
+
+#endif
Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowTreeItem.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -0,0 +1,65 @@
+/***************************************************************************
+ * 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 "WaitForWindowWidget.h"
+
+#include "ui_WaitForWindowWidget.h"
+#include "../data/WaitForWindow.h"
+
+#ifdef QT_QTDBUS_FOUND
+#include "RemoteObjectNameWidget.h"
+#endif
+
+//public:
+
+WaitForWindowWidget::WaitForWindowWidget(WaitForWindow* waitForWindow,
+ QWidget* parent):
+ EditionWidget(parent),
+ mWaitForWindow(waitForWindow) {
+
+ ui = new Ui::WaitForWindowWidget();
+ ui->setupUi(this);
+
+#ifdef QT_QTDBUS_FOUND
+ //Replace ui->windowObjectNameLineEdit with mRemoteObjectNameWidget
+ ui->valueVerticalLayout->removeWidget(ui->windowObjectNameLineEdit);
+ delete ui->windowObjectNameLineEdit;
+
+ mRemoteObjectNameWidget = new RemoteObjectNameWidget(this);
+ ui->valueVerticalLayout->insertWidget(0, mRemoteObjectNameWidget);
+
+ mRemoteObjectNameWidget->setName(waitForWindow->windowObjectName());
+#else
+ ui->windowObjectNameLineEdit->setText(waitForWindow->windowObjectName());
+#endif
+}
+
+WaitForWindowWidget::~WaitForWindowWidget() {
+ delete ui;
+}
+
+void WaitForWindowWidget::saveChanges() {
+#ifdef QT_QTDBUS_FOUND
+ QString windowObjectName = mRemoteObjectNameWidget->name();
+#else
+ QString windowObjectName = ui->windowObjectNameLineEdit->text();
+#endif
+ if (mWaitForWindow->windowObjectName() != windowObjectName) {
+ mWaitForWindow->setWindowObjectName(windowObjectName);
+ }
+}
Property changes on: trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.h (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.h 2010-09-26 17:49:55 UTC (rev 258)
@@ -0,0 +1,81 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Daniel Calviño Sánchez *
+ * dan...@gm... *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
+#ifndef WAITFORWINDOWWIDGET_H
+#define WAITFORWINDOWWIDGET_H
+
+#include "EditionWidget.h"
+
+#ifdef QT_QTDBUS_FOUND
+class RemoteObjectNameWidget;
+#endif
+
+class WaitForWindow;
+
+namespace Ui {
+class WaitForWindowWidget;
+}
+
+/**
+ * Edition widget for the condition to wait for a window to be shown.
+ */
+class WaitForWindowWidget: public EditionWidget {
+Q_OBJECT
+public:
+
+ /**
+ * Creates a new WaitForWindowWidget for the given WaitForWindow.
+ *
+ * @param waitForWindow The WaitForWindow to set its data.
+ * @param parent The parent QWidget.
+ */
+ explicit WaitForWindowWidget(WaitForWindow* waitForWindow,
+ QWidget* parent = 0);
+
+ /**
+ * Destroys this widget.
+ */
+ virtual ~WaitForWindowWidget();
+
+ /**
+ * Saves the window object name in the WaitForWindow.
+ */
+ virtual void saveChanges();
+
+private:
+
+ /**
+ * The WaitForWindow to edit.
+ */
+ WaitForWindow* mWaitForWindow;
+
+ /**
+ * The Ui Designer generated class.
+ */
+ Ui::WaitForWindowWidget* 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/WaitForWindowWidget.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.ui
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.ui (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWindowWidget.ui 2010-09-26 17:49:55 UTC (rev 258)
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>WaitForWindowWidget</class>
+ <widget class="QWidget" name="WaitForWindowWidget">
+ <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 window to wait for</string>
+ </property>
+ <property name="whatsThis">
+ <string comment="@info:whatsthis"><para>Set the object name of the window to wait for.</para></string>
+ </property>
+ <layout class="QVBoxLayout" name="WaitForWindowVerticalLayout">
+ <item>
+ <widget class="QGroupBox" name="waitForWindowGroupBox">
+ <property name="title">
+ <string comment="@title:group">Wait for window</string>
+ </property>
+ <layout class="QHBoxLayout" name="waitForWindowGroupBoxHorizontalLayout">
+ <item>
+ <layout class="QVBoxLayout" name="labelVerticalLayout">
+ <item>
+ <widget class="QLabel" name="windowObjectNameLabel">
+ <property name="text">
+ <string comment="@label:textbox">Window name:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="valueVerticalLayout">
+ <item>
+ <widget class="KLineEdit" name="windowObjectNameLineEdit">
+ <property name="whatsThis">
+ <string comment="@info:whatsthis"><para>The name of the window to be shown.</para>
+<para>Note that the name is not the title of the window or its class name, but the string returned by its objectName() method.</para>
+<para>Also note that it can wait either for windows or for dialogs, not just for windows.</para></string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <spacer name="waitForWindowWidgetSpacer">
+ <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/tests/unit/data/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/data/CMakeLists.txt 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/data/CMakeLists.txt 2010-09-26 17:49:55 UTC (rev 258)
@@ -20,6 +20,7 @@
WaitForEvent
WaitForNot
WaitForSignal
+ WaitForWindow
)
MACRO(MEM_TESTS)
@@ -37,4 +38,5 @@
WaitForEvent
WaitForNot
WaitForSignal
+ WaitForWindow
)
Added: trunk/ktutorial/ktutorial-editor/tests/unit/data/WaitForWindowTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/data/WaitForWindowTest.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/data/WaitForWindowTest.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -0,0 +1,139 @@
+/***************************************************************************
+ * 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 "WaitForWindow.h"
+
+class WaitForWindowTest: public QObject {
+Q_OBJECT
+
+private slots:
+
+ void initTestCase();
+
+ void testConstructor();
+
+ void testClone();
+
+ void testEquals();
+
+ void testSetWindowObjectName();
+
+private:
+
+ int mWaitForStarType;
+
+ void assertWaitForWindow(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 WaitForWindowTest::initTestCase() {
+ //WaitFor* must be registered in order to be used with QSignalSpy
+ mWaitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*");
+}
+
+void WaitForWindowTest::testConstructor() {
+ QObject parent;
+ WaitForWindow* waitForWindow = new WaitForWindow(&parent);
+
+ QCOMPARE(waitForWindow->parent(), &parent);
+}
+
+void WaitForWindowTest::testClone() {
+ WaitForWindow waitForWindow;
+ waitForWindow.setWindowObjectName("The window object name");
+
+ WaitForWindow* cloned = static_cast<WaitForWindow*>(waitForWindow.clone());
+
+ QVERIFY(cloned != &waitForWindow);
+ QCOMPARE(cloned->windowObjectName(), waitForWindow.windowObjectName());
+ delete cloned;
+}
+
+void WaitForWindowTest::testEquals() {
+ WaitForWindow waitForWindow1;
+ waitForWindow1.setWindowObjectName("The window object name");
+ WaitForWindow waitForWindow2;
+
+ QCOMPARE(waitForWindow1 == waitForWindow2, false);
+ QCOMPARE(waitForWindow2 == waitForWindow1, false);
+
+ waitForWindow2.setWindowObjectName("The window object name");
+
+ QCOMPARE(waitForWindow1 == waitForWindow2, true);
+ QCOMPARE(waitForWindow2 == waitForWindow1, true);
+
+ StubWaitFor stubWaitFor;
+
+ QCOMPARE(waitForWindow1 == stubWaitFor, false);
+}
+
+void WaitForWindowTest::testSetWindowObjectName() {
+ WaitForWindow waitForWindow;
+
+ QSignalSpy dataChangedSpy(&waitForWindow, SIGNAL(dataChanged(WaitFor*)));
+
+ waitForWindow.setWindowObjectName("The window object name");
+
+ QCOMPARE(waitForWindow.windowObjectName(),
+ QString("The window object name"));
+ QCOMPARE(dataChangedSpy.count(), 1);
+ assertWaitForWindow(dataChangedSpy, 0, &waitForWindow);
+}
+
+//WaitFor* must be declared as a metatype to be used in qvariant_cast
+Q_DECLARE_METATYPE(WaitFor*);
+
+/////////////////////////////////// Helpers ////////////////////////////////////
+
+void WaitForWindowTest::assertWaitForWindow(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(WaitForWindowTest)
+
+#include "WaitForWindowTest.moc"
Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/data/WaitForWindowTest.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 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/serialization/JavascriptExporterTest.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -27,6 +27,7 @@
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
#define TUTORIAL_EMPTY_INFORMATION_CODE \
"t = Kross.module(\"kdetranslation\");\n"\
@@ -89,6 +90,9 @@
void testWaitForSignal();
void testWaitForSignalWithEscapeSequences();
void testWaitForSignalWithoutEmitterNameOrSignalName();
+ void testWaitForWindow();
+ void testWaitForWindowWithEscapeSequences();
+ void testWaitForWindowWithoutWindowObjectName();
void testWaitForComposed();
void testWaitForComposedWithInvalidChildWaitFor();
void testWaitForNot();
@@ -1217,6 +1221,106 @@
QCOMPARE(exportedTutorial, expected);
}
+void JavascriptExporterTest::testWaitForWindow() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ step->setId("The id");
+ tutorial.addStep(step);
+
+ WaitForWindow* waitForWindow = new WaitForWindow();
+ waitForWindow->setWindowObjectName("The window object name");
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForWindow);
+ 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"
+" waitForTheWindowObjectNameToBeShown = \
+ktutorial.newWaitFor(\"WaitForWindow\");\n"
+" waitForTheWindowObjectNameToBeShown.setWindowObjectName(\
+\"The window object name\");\n"
+" step.addWaitFor(waitForTheWindowObjectNameToBeShown, \"Another step\");\n"
+"}\n"
+CONNECT_STEP_SETUP
+STEP_WITH_ID_THE_ID_AND_EMPTY_TEXT_END_CODE;
+
+ QCOMPARE(exportedTutorial, expected);
+}
+
+void JavascriptExporterTest::testWaitForWindowWithEscapeSequences() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ step->setId("The id");
+ tutorial.addStep(step);
+
+ WaitForWindow* waitForWindow = new WaitForWindow();
+ waitForWindow->setWindowObjectName("The \"window\" object name");
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForWindow);
+ 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"
+" waitForTheWindowObjectNameToBeShown = \
+ktutorial.newWaitFor(\"WaitForWindow\");\n"
+" waitForTheWindowObjectNameToBeShown.setWindowObjectName(\
+\"The \\\"window\\\" object name\");\n"
+" step.addWaitFor(waitForTheWindowObjectNameToBeShown, \"Another step\");\n"
+"}\n"
+CONNECT_STEP_SETUP
+STEP_WITH_ID_THE_ID_AND_EMPTY_TEXT_END_CODE;
+
+ QCOMPARE(exportedTutorial, expected);
+}
+
+void JavascriptExporterTest::testWaitForWindowWithoutWindowObjectName() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ step->setId("The id");
+ tutorial.addStep(step);
+
+ WaitForWindow* waitForWindow = new WaitForWindow();
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForWindow);
+ 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"
+" //Error: WaitForWindow without window object name!\n"
+"}\n"
+CONNECT_STEP_SETUP
+STEP_WITH_ID_THE_ID_AND_EMPTY_TEXT_END_CODE;
+
+ QCOMPARE(exportedTutorial, expected);
+}
+
void JavascriptExporterTest::testWaitForComposed() {
Tutorial tutorial;
Step* step = new Step();
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialReaderTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialReaderTest.cpp 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialReaderTest.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -29,6 +29,7 @@
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
#define HEADER_XML \
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
@@ -88,6 +89,8 @@
void testWaitForEventEmpty();
void testWaitForSignal();
void testWaitForSignalEmpty();
+ void testWaitForWindow();
+ void testWaitForWindowEmpty();
void testWaitForComposed();
void testWaitForComposedEmpty();
void testWaitForNot();
@@ -399,6 +402,38 @@
assertWaitForSignal(waitFor, "", "");
}
+void TutorialReaderTest::testWaitForWindow() {
+ QString data =
+WAITFOR_PARENT_START
+" <waitForWindow windowObjectName=\"The "window" object \
+name\"/>\n"
+WAITFOR_PARENT_END;
+
+ TutorialReader reader;
+ QScopedPointer<Tutorial> tutorial(reader.readTutorial(data));
+ WaitFor* waitFor = tutorial->steps()[0]->reactions()[0]->waitFor();
+
+ WaitForWindow* waitForWindow = qobject_cast<WaitForWindow*>(waitFor);
+ QVERIFY(waitForWindow);
+ QCOMPARE(waitForWindow->windowObjectName(),
+ QString("The \"window\" object name"));
+}
+
+void TutorialReaderTest::testWaitForWindowEmpty() {
+ QString data =
+WAITFOR_PARENT_START
+" <waitForWindow/>\n"
+WAITFOR_PARENT_END;
+
+ TutorialReader reader;
+ QScopedPointer<Tutorial> tutorial(reader.readTutorial(data));
+ WaitFor* waitFor = tutorial->steps()[0]->reactions()[0]->waitFor();
+
+ WaitForWindow* waitForWindow = qobject_cast<WaitForWindow*>(waitFor);
+ QVERIFY(waitForWindow);
+ QCOMPARE(waitForWindow->windowObjectName(), QString(""));
+}
+
void TutorialReaderTest::testWaitForComposed() {
QString data =
WAITFOR_PARENT_START
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialWriterTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialWriterTest.cpp 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialWriterTest.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -27,6 +27,7 @@
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
#define HEADER_XML \
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
@@ -86,6 +87,8 @@
void testWaitForEventEmpty();
void testWaitForSignal();
void testWaitForSignalEmpty();
+ void testWaitForWindow();
+ void testWaitForWindowEmpty();
void testWaitForComposed();
void testWaitForComposedEmpty();
void testWaitForNot();
@@ -440,6 +443,56 @@
QCOMPARE(savedTutorial, expected);
}
+void TutorialWriterTest::testWaitForWindow() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForWindow* waitForWindow = new WaitForWindow();
+ waitForWindow->setWindowObjectName("The \"window\" object name");
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForWindow);
+ reaction->setResponseType(Reaction::NextStep);
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+WAITFOR_PARENT_START
+" <waitForWindow windowObjectName=\"The "window" object \
+name\"/>\n"
+WAITFOR_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testWaitForWindowEmpty() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForWindow* waitForWindow = new WaitForWindow();
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForWindow);
+ reaction->setResponseType(Reaction::NextStep);
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+WAITFOR_PARENT_START
+" <waitForWindow/>\n"
+WAITFOR_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
void TutorialWriterTest::testWaitForComposed() {
Tutorial tutorial;
Step* step = new Step();
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-09-26 17:49:55 UTC (rev 258)
@@ -45,6 +45,8 @@
WaitForSignalWidget
WaitForTreeItem
WaitForWidget
+ WaitForWindowTreeItem
+ WaitForWindowWidget
)
if (QT_QTDBUS_FOUND)
@@ -94,6 +96,8 @@
WaitForSignalWidget
WaitForTreeItem
WaitForWidget
+ WaitForWindowTreeItem
+ WaitForWindowWidget
)
if (QT_QTDBUS_FOUND)
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/NewWaitForWidgetTest.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -26,6 +26,7 @@
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
class NewWaitForWidgetTest: public QObject {
Q_OBJECT
@@ -39,6 +40,7 @@
void testWaitForWhenNotConditionIsSelected();
void testWaitForWhenSignalConditionIsSelected();
void testWaitForWhenEventConditionIsSelected();
+ void testWaitForWhenWindowConditionIsSelected();
private:
@@ -105,6 +107,16 @@
delete waitFor;
}
+void NewWaitForWidgetTest::testWaitForWhenWindowConditionIsSelected() {
+ NewWaitForWidget widget;
+
+ selectOption(&widget, 5);
+
+ WaitForWindow* waitFor = qobject_cast<WaitForWindow*>(widget.waitFor());
+ QVERIFY(waitFor);
+ delete waitFor;
+}
+
/////////////////////////////////// Helpers ////////////////////////////////////
void NewWaitForWidgetTest::selectOption(NewWaitForWidget* widget,
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForTreeItemTest.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -24,11 +24,13 @@
#include "WaitForEventTreeItem.h"
#include "WaitForNotTreeItem.h"
#include "WaitForSignalTreeItem.h"
+#include "WaitForWindowTreeItem.h"
#include "../data/WaitFor.h"
#include "../data/WaitForComposed.h"
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
class WaitForTreeItemTest: public QObject {
Q_OBJECT
@@ -41,6 +43,7 @@
void testTreeItemForWaitForEvent();
void testTreeItemForWaitForNot();
void testTreeItemForWaitForSignal();
+ void testTreeItemForWaitForWindow();
};
@@ -144,6 +147,20 @@
delete item;
}
+void WaitForTreeItemTest::testTreeItemForWaitForWindow() {
+ WaitForWindow waitFor;
+ StubTreeItem parent;
+
+ WaitForTreeItem* item = WaitForTreeItem::treeItemForWaitFor(&waitFor,
+ &parent);
+
+ QVERIFY(qobject_cast<WaitForWindowTreeItem*>(item));
+ QCOMPARE(item->parent(), &parent);
+ QCOMPARE(item->waitFor(), &waitFor);
+
+ delete item;
+}
+
QTEST_MAIN(WaitForTreeItemTest)
#include "WaitForTreeItemTest.moc"
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp 2010-09-25 20:16:03 UTC (rev 257)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -31,6 +31,7 @@
#include "../data/WaitForEvent.h"
#include "../data/WaitForNot.h"
#include "../data/WaitForSignal.h"
+#include "../data/WaitForWindow.h"
class WaitForWidgetTest: public QObject {
Q_OBJECT
@@ -41,6 +42,7 @@
void setEventData() const;
void setSignalData() const;
+ void setWindowData() const;
private slots:
@@ -56,6 +58,7 @@
void testSelectWaitForNotEmpty();
void testSelectWaitForEvent();
void testSelectWaitForSignal();
+ void testSelectWaitForWindow();
void testClearSelection();
void testAddWaitForWhenEmpty();
@@ -65,6 +68,7 @@
void testEditWaitForEvent();
void testEditWaitForSignal();
+ void testEditWaitForWindow();
void testRemoveWaitForFromRoot();
void testRemoveWaitForFromWaitForComposed();
@@ -76,6 +80,7 @@
WaitForSignal* mWaitFor1;
WaitForComposed* mWaitFor2;
WaitForEvent* mWaitFor2_1;
+ WaitForWindow* mWaitFor2_2;
WaitForNot* mWaitFor3;
WaitForSignal* mWaitFor3_1;
WaitForNot* mWaitFor4;
@@ -114,6 +119,10 @@
mWaitFor2_1->setEventName("event");
mWaitFor2->addWaitFor(mWaitFor2_1);
+ mWaitFor2_2 = new WaitForWindow();
+ mWaitFor2_2->setWindowObjectName("windowObject");
+ mWaitFor2->addWaitFor(mWaitFor2_2);
+
mWaitFor3 = new WaitForNot();
mWaitFor->addWaitFor(mWaitFor3);
@@ -187,6 +196,12 @@
assertButtonEnabled(false, true, true);
}
+void WaitForWidgetTest::testSelectWaitForWindow() {
+ selectItem(getIndex(1, getIndex(1, getIndex(0))));
+
+ assertButtonEnabled(false, true, true);
+}
+
void WaitForWidgetTest::testClearSelection() {
selectItem(getIndex(0));
selectItem(QModelIndex());
@@ -235,10 +250,11 @@
QCOMPARE(mWaitFor->waitFors()[2], mWaitFor3);
QCOMPARE(mWaitFor->waitFors()[3], mWaitFor4);
QVERIFY(qobject_cast<WaitForSignal*>(mWaitFor->waitFors()[4]));
- QCOMPARE(mWaitFor2->waitFors().count(), 2);
+ QCOMPARE(mWaitFor2->waitFors().count(), 3);
QCOMPARE(mWaitFor2->waitFors()[0], mWaitFor2_1);
- QVERIFY(qobject_cast<WaitForSignal*>(mWaitFor2->waitFors()[1]));
- QVERIFY(mWaitFor->waitFors()[4] != mWaitFor2->waitFors()[1]);
+ QCOMPARE(mWaitFor2->waitFors()[1], mWaitFor2_2);
+ QVERIFY(qobject_cast<WaitForSignal*>(mWaitFor2->waitFors()[2]));
+ QVERIFY(mWaitFor->waitFors()[4] != mWaitFor2->waitFors()[2]);
}
void WaitForWidgetTest::testAddWaitForToWaitForNot() {
@@ -307,6 +323,20 @@
QCOMPARE(mWaitFor1->signalName(), QString("The new signal name"));
}
+void WaitForWidgetTest::testEditWaitForWindow() {
+ selectItem(getIndex(1, 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 setWindowData after the button click won't work.
+ QTimer::singleShot(500, this, SLOT(setWindowData()));
+
+ button("editButton")->click();
+
+ QCOMPARE(mWaitFor2_2->windowObjectName(),
+ QString("The new window object name"));
+}
+
void WaitForWidgetTest::testRemoveWaitForFromRoot() {
delete mWidget;
WaitForSignal* waitForSignal = new WaitForSignal();
@@ -400,6 +430,21 @@
dialog->button(KDialog::Ok)->click();
}
+void WaitForWidgetTest::setWindowData() const {
+ KLineEdit* windowObjectNameLineEdit =
+#ifdef QT_QTDBUS_FOUND
+ mWidget->findChild<KLineEdit*>("objectNameLineEdit");
+#else
+ mWidget->findChild<KLineEdit*>("windowObjectNameLineEdit");
+#endif
+ QVERIFY(windowObjectNameLineEdit);
+ windowObjectNameLineEdit->setText("The new window object 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");
Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWindowTreeItemTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWindowTreeItemTest.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWindowTreeItemTest.cpp 2010-09-26 17:49:55 UTC (rev 258)
@@ -0,0 +1,130 @@
+/***************************************************************************
+ * 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...
[truncated message content] |