[Ktutorial-commits] SF.net SVN: ktutorial:[308] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2011-05-16 22:44:42
|
Revision: 308 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=308&view=rev Author: danxuliu Date: 2011-05-16 22:44:36 +0000 (Mon, 16 May 2011) Log Message: ----------- Provide completion in the property line edit in WaitForPropertyWidget with the properties of the chosen RemoteObject. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.cpp trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.h trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.h trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForPropertyWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.cpp 2011-05-16 22:42:33 UTC (rev 307) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.cpp 2011-05-16 22:44:36 UTC (rev 308) @@ -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 * @@ -50,6 +50,15 @@ return mMapper->remoteClass(reply.value()); } +QStringList RemoteClass::propertyList() throw (DBusException) { + QDBusReply<QStringList> reply = call("propertyList", mClassName); + if (!reply.isValid()) { + throw DBusException(reply.error().message()); + } + + return reply.value(); +} + QStringList RemoteClass::signalList() throw (DBusException) { QDBusReply<QStringList> reply = call("signalList", mClassName); if (!reply.isValid()) { Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.h 2011-05-16 22:42:33 UTC (rev 307) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.h 2011-05-16 22:44:36 UTC (rev 308) @@ -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 * @@ -73,6 +73,16 @@ RemoteClass* superClass() throw (DBusException); /** + * Returns a list with the properties defined in the remote class. + * The list only includes the properties from the class itself, but not its + * super classes. + * + * @return The properties. + * @throws DBusException If a DBus error happens. + */ + QStringList propertyList() throw (DBusException); + + /** * Returns a list with the signals defined in the remote class. * The list only includes the signals from the class itself, but not its * super classes. Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.cpp 2011-05-16 22:42:33 UTC (rev 307) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.cpp 2011-05-16 22:44:36 UTC (rev 308) @@ -22,7 +22,11 @@ #include "../data/WaitForProperty.h" #ifdef QT_QTDBUS_FOUND +#include <KDebug> + #include "RemoteObjectNameWidget.h" +#include "../targetapplication/RemoteClass.h" +#include "../targetapplication/RemoteObject.h" #endif //public: @@ -48,6 +52,9 @@ ui->valueVerticalLayout->insertWidget(0, mRemoteObjectNameWidget); + connect(mRemoteObjectNameWidget, SIGNAL(remoteObjectChosen(RemoteObject*)), + this, SLOT(setChosenRemoteObject(RemoteObject*))); + mRemoteObjectNameWidget->setName(waitForProperty->objectName()); #else ui->objectNameLineEdit->setText(waitForProperty->objectName()); @@ -82,3 +89,41 @@ mWaitForProperty->setValue(value); } } + +//private: + +#ifdef QT_QTDBUS_FOUND +void WaitForPropertyWidget::setPropertyCompletion(RemoteClass* remoteClass) +throw (DBusException) { + KCompletion* completion = ui->propertyNameLineEdit->completionObject(); + completion->clear(); + completion->setOrder(KCompletion::Sorted); + + while (remoteClass) { + foreach (const QString& property, remoteClass->propertyList()) { + completion->addItem(property); + } + + remoteClass = remoteClass->superClass(); + } +} +#endif + +//private slots: + +#ifdef QT_QTDBUS_FOUND +void WaitForPropertyWidget::setChosenRemoteObject(RemoteObject* remoteObject) { + if (!remoteObject) { + setPropertyCompletion(0); + return; + } + + try { + setPropertyCompletion(remoteObject->remoteClass()); + } catch (DBusException e) { + kWarning() << "The property completion could not be set, there was a " + << "problem getting the class of the remote object (" + << e.message() << ")."; + } +} +#endif Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.h 2011-05-16 22:42:33 UTC (rev 307) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForPropertyWidget.h 2011-05-16 22:44:36 UTC (rev 308) @@ -22,6 +22,10 @@ #include "EditionWidget.h" #ifdef QT_QTDBUS_FOUND +#include "../targetapplication/DBusException.h" + +class RemoteClass; +class RemoteObject; class RemoteObjectNameWidget; #endif @@ -75,8 +79,28 @@ * The widget to get the name of a remote object. */ RemoteObjectNameWidget* mRemoteObjectNameWidget; + + /** + * Sets the completion of the property line edit to the properties contained + * in the given remote class and its super classes. + * + * @param remoteClass The class to get its property list. + */ + void setPropertyCompletion(RemoteClass* remoteClass) throw (DBusException); #endif +private slots: + +#ifdef QT_QTDBUS_FOUND + /** + * Sets the completion for the property names based in the chosen remote + * object. + * + * @param remoteObject The chosen RemoteObject. + */ + void setChosenRemoteObject(RemoteObject* remoteObject); +#endif + }; #endif Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h 2011-05-16 22:42:33 UTC (rev 307) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h 2011-05-16 22:44:36 UTC (rev 308) @@ -59,6 +59,15 @@ return ""; } + QStringList propertyList(const QString& className) { + QStringList propertyList; + for (int i=0; i<3; ++i) { + propertyList.append(className + "Property" + QString::number(i)); + } + + return propertyList; + } + QStringList signalList(const QString& className) { QStringList signalList; for (int i=0; i<3; ++i) { Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassTest.cpp 2011-05-16 22:42:33 UTC (rev 307) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassTest.cpp 2011-05-16 22:44:36 UTC (rev 308) @@ -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 * @@ -49,6 +49,9 @@ void testSuperClass(); void testSuperClassWhenRemoteClassIsNotAvailable(); + void testPropertyList(); + void testPropertyListWhenRemoteClassIsNotAvailable(); + void testSignalList(); void testSignalListWhenRemoteClassIsNotAvailable(); @@ -100,6 +103,24 @@ EXPECT_EXCEPTION(remoteClass.superClass(), DBusException); } +void RemoteClassTest::testPropertyList() { + RemoteClass remoteClass(mService, mMapper, "Class"); + + QStringList propertyList = remoteClass.propertyList(); + QCOMPARE(propertyList.count(), 3); + QCOMPARE(propertyList[0], QString("ClassProperty0")); + QCOMPARE(propertyList[1], QString("ClassProperty1")); + QCOMPARE(propertyList[2], QString("ClassProperty2")); +} + +void RemoteClassTest::testPropertyListWhenRemoteClassIsNotAvailable() { + RemoteClass remoteClass(mService, mMapper, "Class"); + + QDBusConnection::sessionBus().unregisterObject("/ktutorial/ObjectRegister"); + + EXPECT_EXCEPTION(remoteClass.propertyList(), DBusException); +} + void RemoteClassTest::testSignalList() { RemoteClass remoteClass(mService, mMapper, "Class"); Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForPropertyWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForPropertyWidgetTest.cpp 2011-05-16 22:42:33 UTC (rev 307) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForPropertyWidgetTest.cpp 2011-05-16 22:44:36 UTC (rev 308) @@ -24,23 +24,57 @@ #include "../data/WaitForProperty.h" +#ifdef QT_QTDBUS_FOUND +#define protected public +#define private public +#include "../targetapplication/TargetApplication.h" +#undef private +#undef protected +#endif + class WaitForPropertyWidgetTest: public QObject { Q_OBJECT private slots: + void init(); + void cleanup(); + void testConstructor(); void testSaveChanges(); + void testPropertyNameCompletion(); + private: + QString mTargetApplicationStubPath; + KLineEdit* objectNameLineEdit(WaitForPropertyWidget* widget) const; KLineEdit* propertyNameLineEdit(WaitForPropertyWidget* widget) const; KLineEdit* valueLineEdit(WaitForPropertyWidget* widget) const; }; +void WaitForPropertyWidgetTest::init() { +#ifdef QT_QTDBUS_FOUND + mTargetApplicationStubPath = QApplication::applicationDirPath() + + "/../targetapplication/TargetApplicationStub"; + + //Avoid signals from previous tests to be delivered to the next ones + //setting a new TargetApplication + delete TargetApplication::sSelf; + TargetApplication::sSelf = new TargetApplication(); +#endif +} + +void WaitForPropertyWidgetTest::cleanup() { +#ifdef QT_QTDBUS_FOUND + delete TargetApplication::sSelf; + TargetApplication::sSelf = 0; +#endif +} + void WaitForPropertyWidgetTest::testConstructor() { WaitForProperty waitFor; waitFor.setObjectName("The object name"); @@ -76,6 +110,35 @@ QCOMPARE(waitFor.value(), QString("The new value")); } +void WaitForPropertyWidgetTest::testPropertyNameCompletion() { +#ifdef QT_QTDBUS_FOUND + TargetApplication::self()->setTargetApplicationFilePath( + mTargetApplicationStubPath); + TargetApplication::self()->start(); + + //Give the target application time to start + QTest::qWait(1000); + + WaitForProperty waitFor; + WaitForPropertyWidget widget(&waitFor); + + objectNameLineEdit(&widget)->setText("The object name 830"); + + KCompletion* completion = propertyNameLineEdit(&widget)->completionObject(); + QStringList items = completion->items(); + QCOMPARE(items.count(), 6); + QCOMPARE(items[0], QString("ChildQWidgetProperty0")); + QCOMPARE(items[1], QString("ChildQWidgetProperty1")); + QCOMPARE(items[2], QString("ChildQWidgetProperty2")); + QCOMPARE(items[3], QString("QWidgetProperty0")); + QCOMPARE(items[4], QString("QWidgetProperty1")); + QCOMPARE(items[5], QString("QWidgetProperty2")); +#else + QSKIP("Property name completion is only available when KTutorial editor is " + "compiled with DBus support", SkipAll); +#endif +} + /////////////////////////////////// Helpers //////////////////////////////////// KLineEdit* WaitForPropertyWidgetTest::objectNameLineEdit( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |