[Ktutorial-commits] SF.net SVN: ktutorial:[294] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2011-03-27 16:07:29
|
Revision: 294 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=294&view=rev Author: danxuliu Date: 2011-03-27 16:07:21 +0000 (Sun, 27 Mar 2011) Log Message: ----------- -Add filters for named objects and widgets in the RemoteObjectChooser dialog. -Update RemoteObject and RemoteObjectNameWidget tests due to changes in RemoteClassStubs. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.cpp trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.h trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.ui trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.cpp trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.h trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectChooserTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectNameWidgetTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectTreeSelectionManagerTest.cpp Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooserFilterModel.cpp trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooserFilterModel.h trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectChooserFilterModelTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2011-03-27 16:07:21 UTC (rev 294) @@ -37,6 +37,7 @@ set(ktutorial_editor_view_SRCS ${ktutorial_editor_view_SRCS} RemoteObjectChooser.cpp + RemoteObjectChooserFilterModel.cpp RemoteObjectNameWidget.cpp RemoteObjectTreeItem.cpp RemoteObjectTreeItemUpdater.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.cpp 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.cpp 2011-03-27 16:07:21 UTC (rev 294) @@ -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,6 +25,7 @@ #include <KDialogButtonBox> #include <KMessageBox> +#include "RemoteObjectChooserFilterModel.h" #include "RemoteObjectTreeItem.h" #include "RemoteObjectTreeItemUpdater.h" #include "RemoteObjectTreeSelectionManager.h" @@ -165,8 +166,17 @@ RemoteObject* mainWindow = remoteEditorSupport->mainWindow(); RemoteObjectTreeItem* rootItem = new RemoteObjectTreeItem(mainWindow); TreeModel* treeModel = new TreeModel(rootItem, this); - ui->remoteObjectsTreeView->setModel(treeModel); + RemoteObjectChooserFilterModel* filterModel = + new RemoteObjectChooserFilterModel(this); + filterModel->setSourceModel(treeModel); + ui->remoteObjectsTreeView->setModel(filterModel); + + connect(ui->showOnlyNamedObjectsCheckBox, SIGNAL(toggled(bool)), + filterModel, SLOT(setNamedObjectFilterEnabled(bool))); + connect(ui->showOnlyWidgetsCheckBox, SIGNAL(toggled(bool)), + filterModel, SLOT(setWidgetFilterEnabled(bool))); + RemoteObjectTreeItemUpdater* updater = new RemoteObjectTreeItemUpdater(this); rootItem->setUpdater(updater); Modified: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.h 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.h 2011-03-27 16:07:21 UTC (rev 294) @@ -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 * @@ -45,6 +45,11 @@ * When the user selects a remote object in the list and that object represents * a widget, the widget is highlighted in the target application. * + * The list shows all the available remote objects in the target application. + * Some of them may not be useful at all (for example, those without name), so + * the user can select some filters to narrow the remote objects shown in the + * list hiding those that do not pass the filters. + * * The window contains an "Ok" and a "Cancel" button, like the ones found in * dialogs. A window is used instead of a dialog to be shown in the task bar (as * after hidding the rest of KTutorial editor windows no entry would be shown if Modified: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.ui 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.ui 2011-03-27 16:07:21 UTC (rev 294) @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>400</width> - <height>300</height> + <height>400</height> </rect> </property> <property name="windowTitle"> @@ -20,6 +20,34 @@ </property> <layout class="QVBoxLayout" name="remoteObjectChooserVerticalLayout"> <item> + <widget class="QGroupBox" name="filtersGroupBox"> + <property name="whatsThis"> + <string comment="@info:whatsthis"><p>Filters the objects shown in the list.</p> + +<p>Note, however, that if an object has to be shown in the list its parent object is also shown even if it should have been filtered.</p></string> + </property> + <property name="title"> + <string comment="@title:group">Filters</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QCheckBox" name="showOnlyNamedObjectsCheckBox"> + <property name="text"> + <string comment="@option:check">Show only named objects</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="showOnlyWidgetsCheckBox"> + <property name="text"> + <string comment="@option:check">Show only widgets</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> <widget class="AutoExpandableTreeView" name="remoteObjectsTreeView"/> </item> <item> Added: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooserFilterModel.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooserFilterModel.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooserFilterModel.cpp 2011-03-27 16:07:21 UTC (rev 294) @@ -0,0 +1,120 @@ +/*************************************************************************** + * 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 "RemoteObjectChooserFilterModel.h" + +#include <QQueue> + +#include "RemoteObjectTreeItem.h" +#include "../targetapplication/RemoteClass.h" +#include "../targetapplication/RemoteObject.h" + +//public: + +RemoteObjectChooserFilterModel::RemoteObjectChooserFilterModel( + QObject* parent /* = 0*/): + QSortFilterProxyModel(parent), + mNamedObjectFilterEnabled(false), + mWidgetFilterEnabled(false) { +} + +//public slots: + +void RemoteObjectChooserFilterModel::setNamedObjectFilterEnabled( + bool namedObjectFilterEnabled) { + mNamedObjectFilterEnabled = namedObjectFilterEnabled; + invalidateFilter(); +} + +void RemoteObjectChooserFilterModel::setWidgetFilterEnabled( + bool widgetFilterEnabled) { + mWidgetFilterEnabled = widgetFilterEnabled; + invalidateFilter(); +} + +//protected: + +bool RemoteObjectChooserFilterModel::filterAcceptsRow(int sourceRow, + const QModelIndex &sourceParent) const { + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + RemoteObjectTreeItem* item = static_cast<RemoteObjectTreeItem*>( + index.internalPointer()); + RemoteObject* remoteObject = item->remoteObject(); + Q_ASSERT(remoteObject); + + //Breadth-first traversal. No "scientific" reason to use it instead of + //depth-first, just the "feeling" that it will find widgets and named + //objects sooner than a depth-first approach. + QQueue<RemoteObject*> objects; + objects.append(remoteObject); + + while (!objects.isEmpty()) { + remoteObject = objects.dequeue(); + + try { + if (filterNamedObject(remoteObject) && filterWidget(remoteObject)) { + return true; + } + + objects.append(remoteObject->children()); + } catch (DBusException) { + return true; + } + } + + return false; +} + +//private: + +bool RemoteObjectChooserFilterModel::filterNamedObject( + RemoteObject* remoteObject) const +throw (DBusException) { + if (!mNamedObjectFilterEnabled || !remoteObject->name().isEmpty()) { + return true; + } + + return false; +} + +bool RemoteObjectChooserFilterModel::filterWidget( + RemoteObject* remoteObject) const +throw (DBusException) { + if (!mWidgetFilterEnabled || isWidget(remoteObject->remoteClass())) { + return true; + } + + return false; +} + +bool RemoteObjectChooserFilterModel::isWidget(RemoteClass* remoteClass) const +throw (DBusException) { + if (!remoteClass) { + return false; + } + + if (remoteClass->className() == "QWidget") { + return true; + } + + if (isWidget(remoteClass->superClass())) { + return true; + } + + return false; +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooserFilterModel.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooserFilterModel.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooserFilterModel.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooserFilterModel.h 2011-03-27 16:07:21 UTC (rev 294) @@ -0,0 +1,141 @@ +/*************************************************************************** + * 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 REMOTEOBJECTCHOOSERFILTERMODEL_H +#define REMOTEOBJECTCHOOSERFILTERMODEL_H + +#include <QSortFilterProxyModel> + +#include "../targetapplication/DBusException.h" + +class RemoteClass; +class RemoteObject; + +/** + * Proxy model to filter RemoteObjecTreeItem tree models. + * When applied on a TreeModel composed by RemoteObjectTreeItems it hides those + * items that do not pass the enabled filters. Note that the TreeModel must + * contain only RemoteObjectTreeItems; no other TreeItem types can appear in the + * source model. + * + * There are two available filters: named objects and widgets. Both filters + * check the RemoteObjects referenced by the RemoteObjectTreeItems. The first + * checks if it has a name, and the second checks if it is a widget. + * + * The filters can be enabled and disabled using + * setNamedObjectFilterEnabled(bool) and setWidgetFilterEnabled(bool). When both + * filters are disabled every item in the model is shown. + * + * When there are filters enabled, an item may be shown even if it does not pass + * them if any of its descendants does. + */ +class RemoteObjectChooserFilterModel: public QSortFilterProxyModel { +Q_OBJECT +public: + + /** + * Creates a new RemoteObjectChooserFilterModel. + * + * @param parent The parent object. + */ + RemoteObjectChooserFilterModel(QObject* parent = 0); + +public Q_SLOTS: + + /** + * Enables or disables the named object filter. + * + * @param namedObjectFilterEnabled If the filter has to be enabled or + * disabled. + */ + void setNamedObjectFilterEnabled(bool namedObjectFilterEnabled); + + /** + * Enables or disables the widget filter. + * + * @param widgetFilterEnabled If the filter has to be enabled or disabled. + */ + void setWidgetFilterEnabled(bool widgetFilterEnabled); + +protected: + + /** + * Returns true if the item indicated by the given sourceRow and + * sourceParent should be included in the model, false otherwise. + * An item is included if the item, or any of its children, passes the + * enabled filters. If no filter is enabled, every item is included in the + * model. + * Also, if there was a problem querying the remote objects the item is also + * included in the model. + * + * @param sourceRow The row of the index in the source model. + * @param sourceParent The parent of the index in the source model. + * @return True if the item passes the filter, false otherwise. + */ + virtual bool filterAcceptsRow(int sourceRow, + const QModelIndex &sourceParent) const; + +private: + + /** + * Whether the named object filter is enabled or not. + */ + bool mNamedObjectFilterEnabled; + + /** + * Whether the widget filter is enabled or not. + */ + bool mWidgetFilterEnabled; + + /** + * Checks if the given remote object passes the name object filter. + * The remote object passes the filter if the filter is not enabled, or if + * the filter is enabled and the remote object has a name. + * + * @param remoteObject The remote object to check. + * @return True if the remote object passes the named object filter, false + * otherwise. + * @throws DBusException If a DBus error happens. + */ + bool filterNamedObject(RemoteObject* remoteObject) const + throw (DBusException); + + /** + * Checks if the given remote object passes the widget filter. + * The remote object passes the filter if the filter is not enabled, or if + * the filter is enabled and the remote object is a widget. + * + * @param remoteObject The remote object to check. + * @return True if the remote object passes the widget filter, false + * otherwise. + * @throws DBusException If a DBus error happens. + */ + bool filterWidget(RemoteObject* remoteObject) const throw (DBusException); + + /** + * Returns true if the remote class is a widget, false otherwise. + * + * @param remoteClass The remote class to check. + * @return True if the remote class is a widget, false otherwise. + * @throws DBusException If a DBus error happens. + */ + bool isWidget(RemoteClass* remoteClass) const throw (DBusException); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooserFilterModel.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.cpp 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.cpp 2011-03-27 16:07:21 UTC (rev 294) @@ -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 * @@ -18,6 +18,8 @@ #include "RemoteObjectTreeSelectionManager.h" +#include <QAbstractProxyModel> + #include "RemoteObjectTreeItem.h" //public: @@ -65,6 +67,17 @@ return getRemoteObjectForTreeItem(item->parent()); } +QModelIndex RemoteObjectTreeSelectionManager::getTreeModelIndex( + const QModelIndex& index) const { + const QAbstractProxyModel* proxyModel = + qobject_cast<const QAbstractProxyModel*>(index.model()); + if (proxyModel) { + return proxyModel->mapToSource(index); + } + + return index; +} + //private slots: void RemoteObjectTreeSelectionManager::handleSelectionChanged( @@ -81,6 +94,7 @@ Q_ASSERT(selected.at(0).indexes().count() == 1); QModelIndex index = selected.at(0).indexes().at(0); + index = getTreeModelIndex(index); selectedItem = static_cast<TreeItem*>(index.internalPointer()); } @@ -88,6 +102,7 @@ Q_ASSERT(deselected.at(0).indexes().count() == 1); QModelIndex index = deselected.at(0).indexes().at(0); + index = getTreeModelIndex(index); deselectedItem = static_cast<TreeItem*>(index.internalPointer()); } Modified: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.h 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.h 2011-03-27 16:07:21 UTC (rev 294) @@ -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,9 +26,9 @@ class TreeItem; /** - * Watches the QItemSelectionModel of a TreeModel composed by - * RemoteObjectTreeItems for changes in the selection. - * When an item is selected in the TreeModel, + * Watches the QItemSelectionModel of a TreeModel (or a proxy to a TreeModel) + * composed by RemoteObjectTreeItems for changes in the selection. + * When an item is selected in the TreeModel (or its proxy), * remoteObjectSelected(RemoteObject*) signal is emitted with the RemoteObject * represented by the selected item. * @@ -82,6 +82,16 @@ */ RemoteObject* getRemoteObjectForTreeItem(TreeItem* item); + /** + * Ensures that the index comes from a tree model and not from a proxy + * model. + * + * @param index The index to "clean". + * @return The index mapped to the given one in the source model, or the + * given index if it already comes from a source model. + */ + QModelIndex getTreeModelIndex(const QModelIndex& index) const; + private Q_SLOTS: /** Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h 2011-03-27 16:07:21 UTC (rev 294) @@ -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 * @@ -69,6 +69,47 @@ } }; +/** + * ... + * |-42: "The object name 42" + * |-420: "The object name 420" + * |-421: "The object name 421" + * |-422: "The object name 422" + * |-423: "The object name 423" + * |-5: "Duplicated grandparent" + * | |-50: "The object name 50" + * | | |-500: "Duplicated object" + * | | |... + * | |... + * |-6: "Duplicated grandparent" + * | |-60: "Duplicated parent" + * | | |-600: "Duplicated object" + * | | |... + * | |... + * |-7: "The object name 7" + * | |-70: "Duplicated parent" + * | | |-700: "Duplicated object" + * | | |... + * | |... + * |-8: "The object name 8" + * |-80: "" (The class name 80) + * | |-800: "Duplicated object" + * | |-801: "The object name 801" + * | |-802: "" + * | |... + * |-81: "" (QWidgetChildChild) + * | |-810: "" + * | |-811: "" + * | |-812: "" + * | |-813: "" + * |... + * |-82: "The object name 82" (ChildChildQWidget) + * | |-820: "The object name 820" + * | |... + * |-83: "The object name 83" (The class name 83) + * |-830: "The object name 830" (ChildQWidget) + * |... + */ class StubObjectRegisterAdaptor: public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.ktutorial.ObjectRegister") @@ -79,8 +120,26 @@ public slots: + QString objectName(int objectId) { + if (objectId == 500 || objectId == 600 || objectId == 700 || + objectId == 800) { + return "Duplicated object"; + } - QString objectName(int objectId) { + if (objectId == 60 || objectId == 70) { + return "Duplicated parent"; + } + + if (objectId == 5 || objectId == 6) { + return "Duplicated grandparent"; + } + + if (objectId == 80 || objectId == 81 || objectId == 802 || + objectId == 810 || objectId == 811 || objectId == 812 || + objectId == 813) { + return ""; + } + if (objectId > 1000) { return ""; } @@ -89,6 +148,14 @@ } QString className(int objectId) { + if (objectId == 81 || objectId == 82) { + return "ChildChildQWidget"; + } + + if (objectId == 830) { + return "ChildQWidget"; + } + if (objectId > 1000) { return ""; } @@ -97,7 +164,7 @@ } QList<int> childObjectIds(int objectId) { - if (objectId > 42) { + if (objectId > 99) { return QList<int>(); } @@ -105,6 +172,14 @@ for (int i=0; i<4; i++) { ids.append(objectId * 10 + i); } + + if (objectId == 42) { + ids.append(5); + ids.append(6); + ids.append(7); + ids.append(8); + } + return ids; } }; Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectTest.cpp 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectTest.cpp 2011-03-27 16:07:21 UTC (rev 294) @@ -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 * @@ -122,11 +122,15 @@ RemoteObject remoteObject(mService, mMapper, 42); QList<RemoteObject*> children = remoteObject.children(); - QCOMPARE(children.count(), 4); + QCOMPARE(children.count(), 8); QCOMPARE(children[0]->objectId(), 420); QCOMPARE(children[1]->objectId(), 421); QCOMPARE(children[2]->objectId(), 422); QCOMPARE(children[3]->objectId(), 423); + QCOMPARE(children[4]->objectId(), 5); + QCOMPARE(children[5]->objectId(), 6); + QCOMPARE(children[6]->objectId(), 7); + QCOMPARE(children[7]->objectId(), 8); } void RemoteObjectTest::testChildrenWhenRemoteObjectIsNotAvailable() { Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2011-03-27 16:07:21 UTC (rev 294) @@ -54,6 +54,7 @@ unit_tests( RemoteObjectChooser + RemoteObjectChooserFilterModel RemoteObjectNameWidget RemoteObjectTreeItem RemoteObjectTreeItemUpdater @@ -103,6 +104,7 @@ if (QT_QTDBUS_FOUND) mem_tests( RemoteObjectChooser + RemoteObjectChooserFilterModel RemoteObjectTreeItem RemoteObjectTreeItemUpdater RemoteObjectTreeSelectionManager Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectChooserFilterModelTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectChooserFilterModelTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectChooserFilterModelTest.cpp 2011-03-27 16:07:21 UTC (rev 294) @@ -0,0 +1,338 @@ +/*************************************************************************** + * 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 "RemoteObjectChooserFilterModel.h" + +#include "RemoteObjectTreeItem.h" +#include "TreeModel.h" +#include "../targetapplication/RemoteClassStubs.h" +#include "../targetapplication/RemoteObject.h" +#include "../targetapplication/RemoteObjectMapper.h" + +class RemoteObjectChooserFilterModelTest: public QObject { +Q_OBJECT + +private slots: + + void init(); + void cleanup(); + + void testNamedObjectFilter(); + void testNamedObjectFilterWhenRemoteObjectsAreNotAvailable(); + + void testWidgetFilter(); + void testWidgetFilterWhenRemoteObjectsAreNotAvailable(); + + void testNamedObjectAndWidgetFilters(); + +private: + + StubObjectRegister* mObjectRegister; + RemoteObjectMapper* mMapper; + + TreeModel* mTreeModel; + + RemoteObjectChooserFilterModel* mFilterModel; + + QModelIndex mappedFromSource(int row, int column, const QModelIndex& parent) const; + +}; + +void RemoteObjectChooserFilterModelTest::init() { + QVERIFY(QDBusConnection::sessionBus().isConnected()); + + mObjectRegister = new StubObjectRegister(); + QDBusConnection::sessionBus().registerObject("/ktutorial/ObjectRegister", + mObjectRegister, QDBusConnection::ExportAdaptors); + + QString service = QDBusConnection::sessionBus().baseService(); + mMapper = new RemoteObjectMapper(service); + + RemoteObject* mainWindow = mMapper->remoteObject(42); + RemoteObjectTreeItem* rootItem = new RemoteObjectTreeItem(mainWindow); + mTreeModel = new TreeModel(rootItem, this); + + mFilterModel = new RemoteObjectChooserFilterModel(this); + mFilterModel->setSourceModel(mTreeModel); +} + +void RemoteObjectChooserFilterModelTest::cleanup() { + delete mFilterModel; + + delete mTreeModel; + + delete mMapper; + + QDBusConnection::sessionBus().unregisterObject("/ktutorial/ObjectRegister"); + delete mObjectRegister; +} + +void RemoteObjectChooserFilterModelTest::testNamedObjectFilter() { + mFilterModel->setNamedObjectFilterEnabled(true); + + QModelIndex baseIndex = mFilterModel->index(7, 0); + QModelIndex sourceBaseIndex = mTreeModel->index(7, 0); + + QCOMPARE(mFilterModel->rowCount(baseIndex), 3); + QCOMPARE(mappedFromSource(0, 0, sourceBaseIndex), + mFilterModel->index(0, 0, baseIndex)); + QCOMPARE(mappedFromSource(1, 0, sourceBaseIndex), + QModelIndex()); + QCOMPARE(mappedFromSource(2, 0, sourceBaseIndex), + mFilterModel->index(1, 0, baseIndex)); + QCOMPARE(mappedFromSource(3, 0, sourceBaseIndex), + mFilterModel->index(2, 0, baseIndex)); + + QModelIndex childBaseIndex = mFilterModel->index(0, 0, baseIndex); + QModelIndex childSourceBaseIndex = mTreeModel->index(0, 0, sourceBaseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 3); + QCOMPARE(mappedFromSource(0, 0, childSourceBaseIndex), + mFilterModel->index(0, 0, childBaseIndex)); + QCOMPARE(mappedFromSource(1, 0, childSourceBaseIndex), + mFilterModel->index(1, 0, childBaseIndex)); + QCOMPARE(mappedFromSource(2, 0, childSourceBaseIndex), + QModelIndex()); + QCOMPARE(mappedFromSource(3, 0, childSourceBaseIndex), + mFilterModel->index(2, 0, childBaseIndex)); + + childBaseIndex = mFilterModel->index(1, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + + childBaseIndex = mFilterModel->index(2, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + + mFilterModel->setNamedObjectFilterEnabled(false); + + baseIndex = mFilterModel->index(7, 0); + sourceBaseIndex = mTreeModel->index(7, 0); + + QCOMPARE(mFilterModel->rowCount(baseIndex), 4); + QCOMPARE(mappedFromSource(0, 0, sourceBaseIndex), + mFilterModel->index(0, 0, baseIndex)); + QCOMPARE(mappedFromSource(1, 0, sourceBaseIndex), + mFilterModel->index(1, 0, baseIndex)); + QCOMPARE(mappedFromSource(2, 0, sourceBaseIndex), + mFilterModel->index(2, 0, baseIndex)); + QCOMPARE(mappedFromSource(3, 0, sourceBaseIndex), + mFilterModel->index(3, 0, baseIndex)); + + childBaseIndex = mFilterModel->index(0, 0, baseIndex); + childSourceBaseIndex = mTreeModel->index(0, 0, sourceBaseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + QCOMPARE(mappedFromSource(0, 0, childSourceBaseIndex), + mFilterModel->index(0, 0, childBaseIndex)); + QCOMPARE(mappedFromSource(1, 0, childSourceBaseIndex), + mFilterModel->index(1, 0, childBaseIndex)); + QCOMPARE(mappedFromSource(2, 0, childSourceBaseIndex), + mFilterModel->index(2, 0, childBaseIndex)); + QCOMPARE(mappedFromSource(3, 0, childSourceBaseIndex), + mFilterModel->index(3, 0, childBaseIndex)); + + childBaseIndex = mFilterModel->index(1, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + + childBaseIndex = mFilterModel->index(2, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + + childBaseIndex = mFilterModel->index(3, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); +} + +void RemoteObjectChooserFilterModelTest:: + testNamedObjectFilterWhenRemoteObjectsAreNotAvailable() { + QDBusConnection::sessionBus().unregisterObject("/ktutorial/ObjectRegister"); + + mFilterModel->setNamedObjectFilterEnabled(true); + + QModelIndex baseIndex = mFilterModel->index(7, 0); + + QCOMPARE(mFilterModel->rowCount(baseIndex), 4); + + mFilterModel->setNamedObjectFilterEnabled(false); + + QCOMPARE(mFilterModel->rowCount(baseIndex), 4); +} + +void RemoteObjectChooserFilterModelTest::testWidgetFilter() { + mFilterModel->setWidgetFilterEnabled(true); + + QModelIndex baseIndex = mFilterModel->index(0, 0); + QModelIndex sourceBaseIndex = mTreeModel->index(7, 0); + + QCOMPARE(mFilterModel->rowCount(baseIndex), 3); + QCOMPARE(mappedFromSource(0, 0, sourceBaseIndex), + QModelIndex()); + QCOMPARE(mappedFromSource(1, 0, sourceBaseIndex), + mFilterModel->index(0, 0, baseIndex)); + QCOMPARE(mappedFromSource(2, 0, sourceBaseIndex), + mFilterModel->index(1, 0, baseIndex)); + QCOMPARE(mappedFromSource(3, 0, sourceBaseIndex), + mFilterModel->index(2, 0, baseIndex)); + + QModelIndex childBaseIndex = mFilterModel->index(0, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 0); + + childBaseIndex = mFilterModel->index(1, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 0); + + childBaseIndex = mFilterModel->index(2, 0, baseIndex); + QModelIndex childSourceBaseIndex = mTreeModel->index(3, 0, sourceBaseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 1); + QCOMPARE(mappedFromSource(0, 0, childSourceBaseIndex), + mFilterModel->index(0, 0, childBaseIndex)); + + mFilterModel->setWidgetFilterEnabled(false); + + baseIndex = mFilterModel->index(7, 0); + sourceBaseIndex = mTreeModel->index(7, 0); + + QCOMPARE(mFilterModel->rowCount(baseIndex), 4); + QCOMPARE(mappedFromSource(0, 0, sourceBaseIndex), + mFilterModel->index(0, 0, baseIndex)); + QCOMPARE(mappedFromSource(1, 0, sourceBaseIndex), + mFilterModel->index(1, 0, baseIndex)); + QCOMPARE(mappedFromSource(2, 0, sourceBaseIndex), + mFilterModel->index(2, 0, baseIndex)); + QCOMPARE(mappedFromSource(3, 0, sourceBaseIndex), + mFilterModel->index(3, 0, baseIndex)); + + childBaseIndex = mFilterModel->index(0, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + + childBaseIndex = mFilterModel->index(1, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + + childBaseIndex = mFilterModel->index(2, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + + childBaseIndex = mFilterModel->index(3, 0, baseIndex); + childSourceBaseIndex = mTreeModel->index(3, 0, sourceBaseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + QCOMPARE(mappedFromSource(0, 0, childSourceBaseIndex), + mFilterModel->index(0, 0, childBaseIndex)); + QCOMPARE(mappedFromSource(1, 0, childSourceBaseIndex), + mFilterModel->index(1, 0, childBaseIndex)); + QCOMPARE(mappedFromSource(2, 0, childSourceBaseIndex), + mFilterModel->index(2, 0, childBaseIndex)); + QCOMPARE(mappedFromSource(3, 0, childSourceBaseIndex), + mFilterModel->index(3, 0, childBaseIndex)); +} + +void RemoteObjectChooserFilterModelTest:: + testWidgetFilterWhenRemoteObjectsAreNotAvailable() { + QDBusConnection::sessionBus().unregisterObject("/ktutorial/ObjectRegister"); + + mFilterModel->setWidgetFilterEnabled(true); + + QModelIndex baseIndex = mFilterModel->index(7, 0); + + QCOMPARE(mFilterModel->rowCount(baseIndex), 4); + + mFilterModel->setWidgetFilterEnabled(false); + + QCOMPARE(mFilterModel->rowCount(baseIndex), 4); +} + +void RemoteObjectChooserFilterModelTest::testNamedObjectAndWidgetFilters() { + mFilterModel->setNamedObjectFilterEnabled(true); + mFilterModel->setWidgetFilterEnabled(true); + + QModelIndex baseIndex = mFilterModel->index(0, 0); + QModelIndex sourceBaseIndex = mTreeModel->index(7, 0); + + QCOMPARE(mFilterModel->rowCount(baseIndex), 2); + QCOMPARE(mappedFromSource(0, 0, sourceBaseIndex), + QModelIndex()); + QCOMPARE(mappedFromSource(1, 0, sourceBaseIndex), + QModelIndex()); + QCOMPARE(mappedFromSource(2, 0, sourceBaseIndex), + mFilterModel->index(0, 0, baseIndex)); + QCOMPARE(mappedFromSource(3, 0, sourceBaseIndex), + mFilterModel->index(1, 0, baseIndex)); + + QModelIndex childBaseIndex = mFilterModel->index(0, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 0); + + childBaseIndex = mFilterModel->index(1, 0, baseIndex); + QModelIndex childSourceBaseIndex = mTreeModel->index(3, 0, sourceBaseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 1); + QCOMPARE(mappedFromSource(0, 0, childSourceBaseIndex), + mFilterModel->index(0, 0, childBaseIndex)); + + mFilterModel->setNamedObjectFilterEnabled(false); + mFilterModel->setWidgetFilterEnabled(false); + + baseIndex = mFilterModel->index(7, 0); + sourceBaseIndex = mTreeModel->index(7, 0); + + QCOMPARE(mFilterModel->rowCount(baseIndex), 4); + QCOMPARE(mappedFromSource(0, 0, sourceBaseIndex), + mFilterModel->index(0, 0, baseIndex)); + QCOMPARE(mappedFromSource(1, 0, sourceBaseIndex), + mFilterModel->index(1, 0, baseIndex)); + QCOMPARE(mappedFromSource(2, 0, sourceBaseIndex), + mFilterModel->index(2, 0, baseIndex)); + QCOMPARE(mappedFromSource(3, 0, sourceBaseIndex), + mFilterModel->index(3, 0, baseIndex)); + + childBaseIndex = mFilterModel->index(0, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + + childBaseIndex = mFilterModel->index(1, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + + childBaseIndex = mFilterModel->index(2, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); + + childBaseIndex = mFilterModel->index(3, 0, baseIndex); + + QCOMPARE(mFilterModel->rowCount(childBaseIndex), 4); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +QModelIndex RemoteObjectChooserFilterModelTest::mappedFromSource(int row, + int column, const QModelIndex& parent) const { + return mFilterModel->mapFromSource(mTreeModel->index(row, column, parent)); +} + +QTEST_MAIN(RemoteObjectChooserFilterModelTest) + +#include "../targetapplication/moc_RemoteClassStubs.cxx" +#include "RemoteObjectChooserFilterModelTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectChooserFilterModelTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectChooserTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectChooserTest.cpp 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectChooserTest.cpp 2011-03-27 16:07:21 UTC (rev 294) @@ -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 * @@ -64,6 +64,10 @@ //Closing with ALT+F4 can't be tested, as it depends on the window manager //rather than the widget + void testShowOnlyNamedObjects(); + void testShowOnlyWidgets(); + void testShowOnlyNamedWidgets(); + void testSelectRemoteObject(); void testOkButton(); @@ -78,6 +82,9 @@ void killTargetApplication(int timeToWait); + QCheckBox* showOnlyNamedObjectsCheckBox(RemoteObjectChooser* widget) const; + QCheckBox* showOnlyWidgetsCheckBox(RemoteObjectChooser* widget) const; + QTreeView* remoteObjectsTreeView(RemoteObjectChooser* widget) const; QPushButton* okButton(RemoteObjectChooser* widget) const; @@ -315,6 +322,98 @@ QVERIFY(dialog->isVisible()); } +void RemoteObjectChooserTest::testShowOnlyNamedObjects() { + TargetApplication::self()->setTargetApplicationFilePath(mPath); + + QWidget window(0, Qt::Window); + //Queue closing the information message box + closeInformationMessageBox(1000); + RemoteObjectChooser* chooser = new RemoteObjectChooser(&window); + chooser->show(); + + //Give the target application time to start + QTest::qWait(1000); + + QVERIFY(remoteObjectsTreeView(chooser)->model()); + + QModelIndex index = remoteObjectsTreeView(chooser)->model()->index(7, 0); + QCOMPARE(remoteObjectsTreeView(chooser)->model()->rowCount(index), 4); + + showOnlyNamedObjectsCheckBox(chooser)->click(); + + QCOMPARE(remoteObjectsTreeView(chooser)->model()->rowCount(index), 3); + + showOnlyNamedObjectsCheckBox(chooser)->click(); + + QCOMPARE(remoteObjectsTreeView(chooser)->model()->rowCount(index), 4); +} + +void RemoteObjectChooserTest::testShowOnlyWidgets() { + TargetApplication::self()->setTargetApplicationFilePath(mPath); + + QWidget window(0, Qt::Window); + //Queue closing the information message box + closeInformationMessageBox(1000); + RemoteObjectChooser* chooser = new RemoteObjectChooser(&window); + chooser->show(); + + //Give the target application time to start + QTest::qWait(1000); + + QVERIFY(remoteObjectsTreeView(chooser)->model()); + + QModelIndex index = remoteObjectsTreeView(chooser)->model()->index(7, 0); + QCOMPARE(remoteObjectsTreeView(chooser)->model()->rowCount(index), 4); + + showOnlyWidgetsCheckBox(chooser)->click(); + + //The index changes because the other base items were hidden + index = remoteObjectsTreeView(chooser)->model()->index(0, 0); + QCOMPARE(remoteObjectsTreeView(chooser)->model()->rowCount(index), 3); + + showOnlyWidgetsCheckBox(chooser)->click(); + + index = remoteObjectsTreeView(chooser)->model()->index(7, 0); + QCOMPARE(remoteObjectsTreeView(chooser)->model()->rowCount(index), 4); +} + +void RemoteObjectChooserTest::testShowOnlyNamedWidgets() { + TargetApplication::self()->setTargetApplicationFilePath(mPath); + + QWidget window(0, Qt::Window); + //Queue closing the information message box + closeInformationMessageBox(1000); + RemoteObjectChooser* chooser = new RemoteObjectChooser(&window); + chooser->show(); + + //Give the target application time to start + QTest::qWait(1000); + + QVERIFY(remoteObjectsTreeView(chooser)->model()); + + QModelIndex index = remoteObjectsTreeView(chooser)->model()->index(7, 0); + QCOMPARE(remoteObjectsTreeView(chooser)->model()->rowCount(index), 4); + + showOnlyWidgetsCheckBox(chooser)->click(); + + //The index changes because the other base items were hidden + index = remoteObjectsTreeView(chooser)->model()->index(0, 0); + QCOMPARE(remoteObjectsTreeView(chooser)->model()->rowCount(index), 3); + + showOnlyNamedObjectsCheckBox(chooser)->click(); + + QCOMPARE(remoteObjectsTreeView(chooser)->model()->rowCount(index), 2); + + showOnlyWidgetsCheckBox(chooser)->click(); + + index = remoteObjectsTreeView(chooser)->model()->index(7, 0); + QCOMPARE(remoteObjectsTreeView(chooser)->model()->rowCount(index), 3); + + showOnlyNamedObjectsCheckBox(chooser)->click(); + + QCOMPARE(remoteObjectsTreeView(chooser)->model()->rowCount(index), 4); +} + void RemoteObjectChooserTest::testSelectRemoteObject() { TargetApplication::self()->setTargetApplicationFilePath(mPath); @@ -516,6 +615,16 @@ QTimer::singleShot(timeToWait, helper, SLOT(killTargetApplication())); } +QCheckBox* RemoteObjectChooserTest::showOnlyNamedObjectsCheckBox( + RemoteObjectChooser* widget) const { + return widget->findChild<QCheckBox*>("showOnlyNamedObjectsCheckBox"); +} + +QCheckBox* RemoteObjectChooserTest::showOnlyWidgetsCheckBox( + RemoteObjectChooser* widget) const { + return widget->findChild<QCheckBox*>("showOnlyWidgetsCheckBox"); +} + QTreeView* RemoteObjectChooserTest::remoteObjectsTreeView( RemoteObjectChooser* widget) const { return widget->findChild<QTreeView*>("remoteObjectsTreeView"); Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectNameWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectNameWidgetTest.cpp 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectNameWidgetTest.cpp 2011-03-27 16:07:21 UTC (rev 294) @@ -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 * @@ -67,6 +67,8 @@ void assertRemoteObjectSignal(const QSignalSpy& spy, int index, const RemoteObject* remoteObject) const; + void assertCompletionItems(const QStringList& items) const; + }; void RemoteObjectNameWidgetTest::initTestCase() { @@ -102,12 +104,7 @@ QCOMPARE(widget->parentWidget(), &parent); QCOMPARE(widget->name(), QString("")); QStringList items = objectNameLineEdit(widget)->completionObject()->items(); - QCOMPARE(items.count(), 5); - QVERIFY(items.contains("The object name 42")); - QVERIFY(items.contains("The object name 420")); - QVERIFY(items.contains("The object name 421")); - QVERIFY(items.contains("The object name 422")); - QVERIFY(items.contains("The object name 423")); + assertCompletionItems(items); } void RemoteObjectNameWidgetTest::testSetName() { @@ -172,12 +169,7 @@ QTest::qWait(1000); items = objectNameLineEdit(&widget)->completionObject()->items(); - QCOMPARE(items.count(), 5); - QVERIFY(items.contains("The object name 42")); - QVERIFY(items.contains("The object name 420")); - QVERIFY(items.contains("The object name 421")); - QVERIFY(items.contains("The object name 422")); - QVERIFY(items.contains("The object name 423")); + assertCompletionItems(items); widget.setName("The object name 423"); @@ -240,6 +232,22 @@ QCOMPARE(qvariant_cast<RemoteObject*>(argument), remoteObject); } +void RemoteObjectNameWidgetTest::assertCompletionItems( + const QStringList& items) const { + QCOMPARE(items.count(), 77); + QVERIFY(items.contains("The object name 42")); + QVERIFY(items.contains("The object name 420")); + QVERIFY(items.contains("The object name 421")); + QVERIFY(items.contains("The object name 422")); + QVERIFY(items.contains("The object name 423")); + QVERIFY(items.contains("The object name 7")); + QVERIFY(items.contains("The object name 62")); + QVERIFY(items.contains("The object name 833")); + QVERIFY(items.contains("Duplicated object")); + QVERIFY(items.contains("Duplicated parent")); + QVERIFY(items.contains("Duplicated grandparent")); +} + QTEST_MAIN(RemoteObjectNameWidgetTest) #include "RemoteObjectNameWidgetTest.moc" Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectTreeSelectionManagerTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectTreeSelectionManagerTest.cpp 2011-03-09 16:38:59 UTC (rev 293) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectTreeSelectionManagerTest.cpp 2011-03-27 16:07:21 UTC (rev 294) @@ -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,6 +20,8 @@ #include "RemoteObjectTreeSelectionManager.h" +#include <QSortFilterProxyModel> + #include "RemoteObjectTreeItem.h" #include "TreeModel.h" #include "../targetapplication/RemoteObject.h" @@ -40,6 +42,8 @@ void testSelectRemoteObjectClearingTheSelection(); void testSelectRemoteObjectChangingBetweenRemoteObjects(); + void testSelectInProxyModel(); + private: int mRemoteObjectStarType; @@ -215,6 +219,32 @@ assertRemoteObjectSignal(mRemoteObjectSelectedSpy, 2, mRemoteObject3); } +void RemoteObjectTreeSelectionManagerTest::testSelectInProxyModel() { + QSortFilterProxyModel proxyModel; + proxyModel.setSourceModel(mTreeModel); + + QItemSelectionModel selectionModel(&proxyModel); + RemoteObjectTreeSelectionManager selectionManager(&selectionModel); + + QSignalSpy remoteObjectSelectedSpy(&selectionManager, + SIGNAL(remoteObjectSelected(RemoteObject*))); + + QModelIndex remoteObject1Index = proxyModel.index(0, 0); + selectionModel.select(remoteObject1Index, + QItemSelectionModel::SelectCurrent); + + QCOMPARE(remoteObjectSelectedSpy.count(), 1); + assertRemoteObjectSignal(&remoteObjectSelectedSpy, 0, mRemoteObject1); + + QModelIndex remoteObject1_2Index = + proxyModel.index(1, 0, remoteObject1Index); + selectionModel.select(remoteObject1_2Index, + QItemSelectionModel::SelectCurrent); + + QCOMPARE(remoteObjectSelectedSpy.count(), 2); + assertRemoteObjectSignal(&remoteObjectSelectedSpy, 1, mRemoteObject1_2); +} + /////////////////////////////////// Helpers //////////////////////////////////// void RemoteObjectTreeSelectionManagerTest::select(const QModelIndex& index) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |