[Ktutorial-commits] SF.net SVN: ktutorial:[236] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-04-26 07:08:06
|
Revision: 236 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=236&view=rev Author: danxuliu Date: 2010-04-26 05:24:17 +0000 (Mon, 26 Apr 2010) Log Message: ----------- Add completion for event names in WaitForEventWidget. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.h trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.cpp 2010-04-25 23:15:13 UTC (rev 235) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.cpp 2010-04-26 05:24:17 UTC (rev 236) @@ -18,6 +18,8 @@ #include "WaitForEventWidget.h" +#include <QMetaEnum> + #include "ui_WaitForEventWidget.h" #include "../data/WaitForEvent.h" @@ -47,6 +49,8 @@ ui->receiverNameLineEdit->setText(waitForEvent->receiverName()); ui->eventNameLineEdit->setText(waitForEvent->eventName()); + + addItemsToEventNameCompletion(); } WaitForEventWidget::~WaitForEventWidget() { @@ -65,6 +69,18 @@ } } +//private: + +void WaitForEventWidget::addItemsToEventNameCompletion() { + int index = QEvent::staticMetaObject.indexOfEnumerator("Type"); + QMetaEnum eventTypeEnumerator = QEvent::staticMetaObject.enumerator(index); + + KCompletion* completion = ui->eventNameLineEdit->completionObject(); + for (int i=0; i<eventTypeEnumerator.keyCount(); ++i) { + completion->addItem(eventTypeEnumerator.key(i)); + } +} + //private slots: #ifdef QT_QTDBUS_FOUND Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.h 2010-04-25 23:15:13 UTC (rev 235) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.h 2010-04-26 05:24:17 UTC (rev 236) @@ -66,6 +66,12 @@ */ Ui::WaitForEventWidget* ui; + /** + * Adds all the event names to the completion object of the event name line + * edit. + */ + void addItemsToEventNameCompletion(); + private Q_SLOTS: #ifdef QT_QTDBUS_FOUND Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventWidgetTest.cpp 2010-04-25 23:15:13 UTC (rev 235) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForEventWidgetTest.cpp 2010-04-26 05:24:17 UTC (rev 236) @@ -33,6 +33,8 @@ void testSaveChanges(); + void testEventNameCompletion(); + private: KLineEdit* receiverNameLineEdit(WaitForEventWidget* widget) const; @@ -69,6 +71,16 @@ QCOMPARE(waitFor.eventName(), QString("The new event name")); } +void WaitForEventWidgetTest::testEventNameCompletion() { + WaitForEvent waitFor; + + WaitForEventWidget widget(&waitFor); + + KCompletion* completion = eventNameLineEdit(&widget)->completionObject(); + QCOMPARE(completion->allMatches("Dest").count(), 1); + QCOMPARE(completion->allMatches("Dest")[0], QString("Destroy")); +} + /////////////////////////////////// Helpers //////////////////////////////////// KLineEdit* WaitForEventWidgetTest::receiverNameLineEdit( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |