Git commit 4b804a4efeecfc9aa51851b3b228819d439932b9 by Shaun Reich. Committed on 03/05/2012 at 16:01. Pushed by sreich into branch 'master'. rm runnermodel. it lives in kde-runtime/declarativeimports/ now. M +0 -1 components/CMakeLists.txt D +0 -20 components/runnermodel/CMakeLists.txt D +0 -2 components/runnermodel/qmldir D +0 -185 components/runnermodel/runnermodel.cpp D +0 -112 components/runnermodel/runnermodel.h D +0 -37 components/runnermodel/runnermodelplugin.cpp D +0 -36 components/runnermodel/runnermodelplugin.h D +0 -12 components/runnermodel/test/CMakeLists.txt D +0 -336 components/runnermodel/test/dynamictreemodel.cpp D +0 -197 components/runnermodel/test/dynamictreemodel.h D +0 -35 components/runnermodel/test/main.cpp D +0 -566 components/runnermodel/test/modeltest.cpp D +0 -94 components/runnermodel/test/modeltest.h http://commits.kde.org/plasma-mobile/4b804a4efeecfc9aa51851b3b228819d439932= b9 diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 2e103fd..77493f1 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -1,5 +1,4 @@ add_subdirectory(metadatamodel) add_subdirectory(mobilecomponents) -add_subdirectory(runnermodel) add_subdirectory(dirmodel) add_subdirectory(settings) diff --git a/components/runnermodel/CMakeLists.txt b/components/runnermodel= /CMakeLists.txt deleted file mode 100644 index 95ac027..0000000 --- a/components/runnermodel/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -project(runnermodel) - -set(runnermodel_SRCS - runnermodel.cpp - runnermodelplugin.cpp - ) - -qt4_automoc(${runnermodel_SRCS}) - -kde4_add_library(runnermodelplugin SHARED ${runnermodel_SRCS}) -target_link_libraries(runnermodelplugin - ${QT_QTCORE_LIBRARY} - ${QT_QTDECLARATIVE_LIBRARY} - ${KDE4_PLASMA_LIBS} - ) - -install(TARGETS runnermodelplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/k= de/runnermodel) -install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/runnermode= l) - -#add_subdirectory(test) diff --git a/components/runnermodel/qmldir b/components/runnermodel/qmldir deleted file mode 100644 index a6a966e..0000000 --- a/components/runnermodel/qmldir +++ /dev/null @@ -1,2 +0,0 @@ -plugin runnermodelplugin - diff --git a/components/runnermodel/runnermodel.cpp b/components/runnermode= l/runnermodel.cpp deleted file mode 100644 index b2dff3d..0000000 --- a/components/runnermodel/runnermodel.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - Copyright 2011 Aaron Seigo - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public Lice= nse - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "runnermodel.h" - -#include -#include -#include - -#include - -#include - -RunnerModel::RunnerModel(QObject *parent) - : QAbstractListModel(parent), - m_manager(0), - m_startQueryTimer(new QTimer(this)) -{ - QHash roles; - roles.insert(Qt::DisplayRole, "label"); - roles.insert(Qt::DecorationRole, "icon"); - roles.insert(Type, "type"); - roles.insert(Relevance, "relevance"); - roles.insert(Data, "data"); - roles.insert(Id, "id"); - roles.insert(SubText, "description"); - roles.insert(Enabled, "enabled"); - roles.insert(RunnerId, "runnerid"); - roles.insert(RunnerName, "runnerName"); - roles.insert(Actions, "actions"); - setRoleNames(roles); - - m_startQueryTimer->setSingleShot(true); - m_startQueryTimer->setInterval(10); - connect(m_startQueryTimer, SIGNAL(timeout()), this, SLOT(startQuery())= ); -} - -int RunnerModel::rowCount(const QModelIndex& index) const -{ - return index.isValid() ? 0 : m_matches.count(); -} - -int RunnerModel::count() const -{ - return m_matches.count(); -} - -QStringList RunnerModel::runners() const -{ - return m_manager ? m_manager->allowedRunners() : QStringList(); -} - -void RunnerModel::setRunners(const QStringList &allowedRunners) -{ - if (m_manager) { - m_manager->setAllowedRunners(allowedRunners); - - //automagically enter single runner mode if there's only 1 allowed= runner - m_manager->setSingleMode(allowedRunners.count() =3D=3D 1); - emit runnersChanged(); - } else { - m_pendingRunnersList =3D allowedRunners; - } -} - -void RunnerModel::run(int index) -{ - if (index >=3D 0 && index < m_matches.count()) { - m_manager->run(m_matches.at(index)); - } -} - -QVariant RunnerModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid() || index.parent().isValid() || - index.column() > 0 || index.row() < 0 || index.row() >=3D m_matche= s.count()) { - // index requested must be valid, but we have no child items! - //kDebug() << "invalid index requested"; - return QVariant(); - } - - if (role =3D=3D Qt::DisplayRole) { - return m_matches.at(index.row()).text(); - } else if (role =3D=3D Qt::DecorationRole) { - return m_matches.at(index.row()).icon(); - } else if (role =3D=3D Type) { - return m_matches.at(index.row()).type(); - } else if (role =3D=3D Relevance) { - return m_matches.at(index.row()).relevance(); - } else if (role =3D=3D Data) { - return m_matches.at(index.row()).data(); - } else if (role =3D=3D Id) { - return m_matches.at(index.row()).id(); - } else if (role =3D=3D SubText) { - return m_matches.at(index.row()).subtext(); - } else if (role =3D=3D Enabled) { - return m_matches.at(index.row()).isEnabled(); - } else if (role =3D=3D RunnerId) { - return m_matches.at(index.row()).runner()->id(); - } else if (role =3D=3D RunnerName) { - return m_matches.at(index.row()).runner()->name(); - } else if (role =3D=3D Actions) { - QVariantList actions; - Plasma::QueryMatch amatch =3D m_matches.at(index.row()); - QList theactions =3D m_manager->actionsForMatch(amatch); - foreach(QAction* action, theactions) { - actions +=3D qVariantFromValue(action); - } - return actions; - } - - return QVariant(); -} - -QString RunnerModel::currentQuery() const -{ - return m_manager ? m_manager->query() : QString(); -} - -void RunnerModel::scheduleQuery(const QString &query) -{ - m_pendingQuery =3D query; - m_startQueryTimer->start(); -} - -void RunnerModel::startQuery() -{ - if (!m_manager && m_pendingQuery.isEmpty()) { - // avoid creating a manager just so we can run nothing - return; - } - - //kDebug() << "booooooo yah!!!!!!!!!!!!!" << query; - createManager(); - -// if (m_pendingQuery !=3D m_manager->query()) { - //kDebug() << "running query" << query; - m_manager->launchQuery(m_pendingQuery); - emit queryChanged(); - // } -} - -void RunnerModel::createManager() -{ - if (!m_manager) { - m_manager =3D new Plasma::RunnerManager(this); - connect(m_manager, SIGNAL(matchesChanged(QList= )), - this, SLOT(matchesChanged(QList))); - - if (!m_pendingRunnersList.isEmpty()) { - m_manager->setAllowedRunners(m_pendingRunnersList); - m_manager->setSingleMode(m_pendingRunnersList.count() =3D=3D 1= ); - m_pendingRunnersList.clear(); - } - //connect(m_manager, SIGNAL(queryFinished()), this, SLOT(queryFini= shed())); - } -} - -void RunnerModel::matchesChanged(const QList &matches) -{ - //kDebug() << "got matches:" << matches.count(); - beginResetModel(); - m_matches =3D matches; - endResetModel(); - emit countChanged(); -} - -#include "runnermodel.moc" - diff --git a/components/runnermodel/runnermodel.h b/components/runnermodel/= runnermodel.h deleted file mode 100644 index 6258b37..0000000 --- a/components/runnermodel/runnermodel.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - Copyright 2011 Aaron Seigo - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public Lice= nse - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef RUNNERMODEL_H -#define RUNNERMODEL_H - -#include -#include - -namespace Plasma -{ - class RunnerManager; - class QueryMatch; -} // namespace Plasma - -class QTimer; - -/** - * This model provides bindings to use KRunner from QML - * - * @author Aaron Seigo - */ -class RunnerModel : public QAbstractListModel -{ - Q_OBJECT - - /** - * @property string set the KRunner query - */ - Q_PROPERTY(QString query WRITE scheduleQuery READ currentQuery NOTIFY = queryChanged) - - /** - * @property Array The list of all allowed runner plugins that will be= executed - */ - Q_PROPERTY(QStringList runners WRITE setRunners READ runners NOTIFY ru= nnersChanged) - - /** - * @property int The number of rows of the model - */ - Q_PROPERTY(int count READ count NOTIFY countChanged) - -public: - /** - * @enum Roles of the model, they will be accessible from delegates - */ - enum Roles { - Type =3D Qt::UserRole + 1, - Relevance, - Data, - Id, - SubText, - Enabled, - RunnerId, - RunnerName, - Actions - }; - - RunnerModel(QObject *parent =3D 0); - - QString currentQuery() const; - - QStringList runners() const; - void setRunners(const QStringList &allowedRunners); - - Q_SCRIPTABLE void run(int row); - - int rowCount(const QModelIndex&) const; - int count() const; - QVariant data(const QModelIndex&, int) const; - -public Q_SLOTS: - void scheduleQuery(const QString &query); - -Q_SIGNALS: - void queryChanged(); - void countChanged(); - void runnersChanged(); - -private Q_SLOTS: - void startQuery(); - -private: - void createManager(); - -private Q_SLOTS: - void matchesChanged(const QList &matches); - -private: - Plasma::RunnerManager *m_manager; - QList m_matches; - QStringList m_pendingRunnersList; - QString m_pendingQuery; - QTimer *m_startQueryTimer; -}; - -#endif diff --git a/components/runnermodel/runnermodelplugin.cpp b/components/runn= ermodel/runnermodelplugin.cpp deleted file mode 100644 index 834e7db..0000000 --- a/components/runnermodel/runnermodelplugin.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2011 by Marco Martin - - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "runnermodelplugin.h" - -#include - -#include - -#include "runnermodel.h" - -void RunnerModelPlugin::registerTypes(const char *uri) -{ - Q_ASSERT(uri =3D=3D QLatin1String("org.kde.runnermodel")); - qmlRegisterType(uri, 0, 1, "RunnerModel"); - qmlRegisterInterface("QueryMatch"); - qRegisterMetaType("QueryMatch"); -} - -#include "runnermodelplugin.moc" - diff --git a/components/runnermodel/runnermodelplugin.h b/components/runner= model/runnermodelplugin.h deleted file mode 100644 index b15bf40..0000000 --- a/components/runnermodel/runnermodelplugin.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2011 by Marco Martin - * Copyright 2011 by Aaron Seigo - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef RUNNERMODELPLUGIN_H -#define RUNNERMODELPLUGIN_H - -#include - - -class RunnerModelPlugin : public QDeclarativeExtensionPlugin -{ - Q_OBJECT - -public: - void registerTypes(const char *uri); -}; - -Q_EXPORT_PLUGIN2(datamodelsplugin, RunnerModelPlugin) - -#endif diff --git a/components/runnermodel/test/CMakeLists.txt b/components/runner= model/test/CMakeLists.txt deleted file mode 100644 index fa89a86..0000000 --- a/components/runnermodel/test/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -set(runnermodeltest_SRCS - main.cpp - dynamictreemodel.cpp - modeltest.cpp - ../runnermodel.cpp - ) - -qt4_automoc(${runnermodeltest_SRCS}) -#kde4_add_library(datamodelsplugin SHARED ${datamodels_SRCS}) -kde4_add_executable(runnermodeltest ${runnermodeltest_SRCS}) -target_link_libraries(runnermodeltest ${QT_QTTEST_LIBRARY} ${KDE4_PLASMA_L= IBS}) - diff --git a/components/runnermodel/test/dynamictreemodel.cpp b/components/= runnermodel/test/dynamictreemodel.cpp deleted file mode 100644 index fa634b6..0000000 --- a/components/runnermodel/test/dynamictreemodel.cpp +++ /dev/null @@ -1,336 +0,0 @@ -/*************************************************************************= *** -** -** Copyright (C) 2009 Stephen Kelly -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -**************************************************************************= **/ - -#include "dynamictreemodel.h" - -#include -#include -#include - - -DynamicTreeModel::DynamicTreeModel(QObject *parent) - : QAbstractItemModel(parent), - nextId(1) -{ -} - -QModelIndex DynamicTreeModel::index(int row, int column, const QModelIndex= &parent) const -{ -// if (column !=3D 0) -// return QModelIndex(); - - - if ( column < 0 || row < 0 ) - return QModelIndex(); - - QList > childIdColumns =3D m_childItems.value(parent.inter= nalId()); - - const qint64 grandParent =3D findParentId(parent.internalId()); - if (grandParent >=3D 0) { - QList > parentTable =3D m_childItems.value(grandParent); - Q_ASSERT(parent.column() < parentTable.size()); - QList parentSiblings =3D parentTable.at(parent.column()); - Q_ASSERT(parent.row() < parentSiblings.size()); - } - - if (childIdColumns.size() =3D=3D 0) - return QModelIndex(); - - if (column >=3D childIdColumns.size()) - return QModelIndex(); - - QList rowIds =3D childIdColumns.at(column); - - if ( row >=3D rowIds.size()) - return QModelIndex(); - - qint64 id =3D rowIds.at(row); - - return createIndex(row, column, reinterpret_cast(id)); - -} - -qint64 DynamicTreeModel::findParentId(qint64 searchId) const -{ - if (searchId <=3D 0) - return -1; - - QHashIterator > > i(m_childItems); - while (i.hasNext()) - { - i.next(); - QListIterator > j(i.value()); - while (j.hasNext()) - { - QList l =3D j.next(); - if (l.contains(searchId)) - { - return i.key(); - } - } - } - return -1; -} - -QModelIndex DynamicTreeModel::parent(const QModelIndex &index) const -{ - if (!index.isValid()) - return QModelIndex(); - - qint64 searchId =3D index.internalId(); - qint64 parentId =3D findParentId(searchId); - // Will never happen for valid index, but what the hey... - if (parentId <=3D 0) - return QModelIndex(); - - qint64 grandParentId =3D findParentId(parentId); - if (grandParentId < 0) - grandParentId =3D 0; - - int column =3D 0; - QList childList =3D m_childItems.value(grandParentId).at(column); - - int row =3D childList.indexOf(parentId); - - return createIndex(row, column, reinterpret_cast(parentId)); - -} - -int DynamicTreeModel::rowCount(const QModelIndex &index ) const -{ - QList > cols =3D m_childItems.value(index.internalId()); - - if (cols.size() =3D=3D 0 ) - return 0; - - if (index.column() > 0) - return 0; - - return cols.at(0).size(); -} - -int DynamicTreeModel::columnCount(const QModelIndex &index ) const -{ -// Q_UNUSED(index); - return m_childItems.value(index.internalId()).size(); -} - -QVariant DynamicTreeModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (Qt::DisplayRole =3D=3D role) - { - return m_items.value(index.internalId()); - } - return QVariant(); -} - -void DynamicTreeModel::clear() -{ - beginResetModel(); - m_items.clear(); - m_childItems.clear(); - nextId =3D 1; - endResetModel(); -} - - -ModelChangeCommand::ModelChangeCommand( DynamicTreeModel *model, QObject *= parent ) - : QObject(parent), m_model(model), m_numCols(1), m_startRow(-1), m_end= Row(-1) -{ - -} - -QModelIndex ModelChangeCommand::findIndex(QList rows) -{ - const int col =3D 0; - QModelIndex parent =3D QModelIndex(); - QListIterator i(rows); - while (i.hasNext()) - { - parent =3D m_model->index(i.next(), col, parent); - Q_ASSERT(parent.isValid()); - } - return parent; -} - -ModelInsertCommand::ModelInsertCommand(DynamicTreeModel *model, QObject *p= arent ) - : ModelChangeCommand(model, parent) -{ - -} - -void ModelInsertCommand::doCommand() -{ - QModelIndex parent =3D findIndex(m_rowNumbers); - m_model->beginInsertRows(parent, m_startRow, m_endRow); - qint64 parentId =3D parent.internalId(); - for (int row =3D m_startRow; row <=3D m_endRow; row++) - { - for(int col =3D 0; col < m_numCols; col++ ) - { - if (m_model->m_childItems[parentId].size() <=3D col) - { - m_model->m_childItems[parentId].append(QList()); - } -// QString name =3D QUuid::createUuid().toString(); - qint64 id =3D m_model->newId(); - QString name =3D QString::number(id); - - m_model->m_items.insert(id, name); - m_model->m_childItems[parentId][col].insert(row, id); - - } - } - m_model->endInsertRows(); -} - - -ModelMoveCommand::ModelMoveCommand(DynamicTreeModel *model, QObject *paren= t) - : ModelChangeCommand(model, parent) -{ - -} -bool ModelMoveCommand::emitPreSignal(const QModelIndex &srcParent, int src= Start, int srcEnd, const QModelIndex &destParent, int destRow) -{ - return m_model->beginMoveRows(srcParent, srcStart, srcEnd, destParent, d= estRow); -} - -void ModelMoveCommand::doCommand() -{ - QModelIndex srcParent =3D findIndex(m_rowNumbers); - QModelIndex destParent =3D findIndex(m_destRowNumbers); - - if (!emitPreSignal(srcParent, m_startRow, m_endRow, destParent, m_dest= Row)) - { - return; - } - - for (int column =3D 0; column < m_numCols; ++column) - { - QList l =3D m_model->m_childItems.value(srcParent.internal= Id())[column].mid(m_startRow, m_endRow - m_startRow + 1 ); - - for (int i =3D m_startRow; i <=3D m_endRow ; i++) - { - m_model->m_childItems[srcParent.internalId()][column].removeAt= (m_startRow); - } - int d; - if (m_destRow < m_startRow) - d =3D m_destRow; - else - { - if (srcParent =3D=3D destParent) - d =3D m_destRow - (m_endRow - m_startRow + 1); - else - d =3D m_destRow - (m_endRow - m_startRow) + 1; - } - - foreach(const qint64 id, l) - { - m_model->m_childItems[destParent.internalId()][column].insert(= d++, id); - } - } - - emitPostSignal(); -} - -void ModelMoveCommand::emitPostSignal() -{ - m_model->endMoveRows(); -} - -ModelResetCommand::ModelResetCommand(DynamicTreeModel* model, QObject* par= ent) - : ModelMoveCommand(model, parent) -{ - -} - -ModelResetCommand::~ModelResetCommand() -{ - -} - -bool ModelResetCommand::emitPreSignal(const QModelIndex &srcParent, int sr= cStart, int srcEnd, const QModelIndex &destParent, int destRow) -{ - Q_UNUSED(srcParent); - Q_UNUSED(srcStart); - Q_UNUSED(srcEnd); - Q_UNUSED(destParent); - Q_UNUSED(destRow); - - return true; -} - -void ModelResetCommand::emitPostSignal() -{ - m_model->reset(); -} - -ModelResetCommandFixed::ModelResetCommandFixed(DynamicTreeModel* model, QO= bject* parent) - : ModelMoveCommand(model, parent) -{ - -} - -ModelResetCommandFixed::~ModelResetCommandFixed() -{ - -} - -bool ModelResetCommandFixed::emitPreSignal(const QModelIndex &srcParent, i= nt srcStart, int srcEnd, const QModelIndex &destParent, int destRow) -{ - Q_UNUSED(srcParent); - Q_UNUSED(srcStart); - Q_UNUSED(srcEnd); - Q_UNUSED(destParent); - Q_UNUSED(destRow); - - m_model->beginResetModel(); - return true; -} - -void ModelResetCommandFixed::emitPostSignal() -{ - m_model->endResetModel(); -} - diff --git a/components/runnermodel/test/dynamictreemodel.h b/components/ru= nnermodel/test/dynamictreemodel.h deleted file mode 100644 index 809b76a..0000000 --- a/components/runnermodel/test/dynamictreemodel.h +++ /dev/null @@ -1,197 +0,0 @@ -/*************************************************************************= *** -** -** Copyright (C) 2009 Stephen Kelly -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -**************************************************************************= **/ - -#ifndef DYNAMICTREEMODEL_H -#define DYNAMICTREEMODEL_H - -#include - -#include -#include - - -class DynamicTreeModel : public QAbstractItemModel -{ - Q_OBJECT - -public: - DynamicTreeModel(QObject *parent =3D 0); - - QModelIndex index(int row, int column, const QModelIndex &parent =3D QMo= delIndex()) const; - QModelIndex parent(const QModelIndex &index) const; - int rowCount(const QModelIndex &index =3D QModelIndex()) const; - int columnCount(const QModelIndex &index =3D QModelIndex()) const; - - QVariant data(const QModelIndex &index, int role =3D Qt::DisplayRole) co= nst; - - void clear(); - -protected slots: - - /** - Finds the parent id of the string with id @p searchId. - - Returns -1 if not found. - */ - qint64 findParentId(qint64 searchId) const; - -private: - QHash m_items; - QHash > > m_childItems; - qint64 nextId; - qint64 newId() { return nextId++; }; - - QModelIndex m_nextParentIndex; - int m_nextRow; - - int m_depth; - int maxDepth; - - friend class ModelInsertCommand; - friend class ModelMoveCommand; - friend class ModelResetCommand; - friend class ModelResetCommandFixed; - -}; - - -class ModelChangeCommand : public QObject -{ - Q_OBJECT -public: - - explicit ModelChangeCommand( DynamicTreeModel *model, QObject *parent = =3D 0 ); - - virtual ~ModelChangeCommand() {} - - void setAncestorRowNumbers(QList rowNumbers) { m_rowNumbers =3D row= Numbers; } - - QModelIndex findIndex(QList rows); - - void setStartRow(int row) { m_startRow =3D row; } - - void setEndRow(int row) { m_endRow =3D row; } - - void setNumCols(int cols) { m_numCols =3D cols; } - - virtual void doCommand() =3D 0; - -protected: - DynamicTreeModel* m_model; - QList m_rowNumbers; - int m_numCols; - int m_startRow; - int m_endRow; - -}; - -typedef QList ModelChangeCommandList; - -class ModelInsertCommand : public ModelChangeCommand -{ - Q_OBJECT - -public: - - explicit ModelInsertCommand(DynamicTreeModel *model, QObject *parent =3D= 0 ); - virtual ~ModelInsertCommand() {} - - virtual void doCommand(); -}; - - -class ModelMoveCommand : public ModelChangeCommand -{ - Q_OBJECT -public: - ModelMoveCommand(DynamicTreeModel *model, QObject *parent); - - virtual ~ModelMoveCommand() {} - - virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, i= nt srcEnd, const QModelIndex &destParent, int destRow); - - virtual void doCommand(); - - virtual void emitPostSignal(); - - void setDestAncestors( QList rows ) { m_destRowNumbers =3D rows; } - - void setDestRow(int row) { m_destRow =3D row; } - -protected: - QList m_destRowNumbers; - int m_destRow; -}; - -/** - A command which does a move and emits a reset signal. -*/ -class ModelResetCommand : public ModelMoveCommand -{ - Q_OBJECT -public: - explicit ModelResetCommand(DynamicTreeModel* model, QObject* parent =3D = 0); - - virtual ~ModelResetCommand(); - - virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, i= nt srcEnd, const QModelIndex &destParent, int destRow); - virtual void emitPostSignal(); - -}; - -/** - A command which does a move and emits a beginResetModel and endResetMode= l signals. -*/ -class ModelResetCommandFixed : public ModelMoveCommand -{ - Q_OBJECT -public: - explicit ModelResetCommandFixed(DynamicTreeModel* model, QObject* parent= =3D 0); - - virtual ~ModelResetCommandFixed(); - - virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, i= nt srcEnd, const QModelIndex &destParent, int destRow); - virtual void emitPostSignal(); - -}; - - -#endif diff --git a/components/runnermodel/test/main.cpp b/components/runnermodel/= test/main.cpp deleted file mode 100644 index 1feee19..0000000 --- a/components/runnermodel/test/main.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "../runnermodel.h" -#include "modeltest.h" - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - QWidget *widget =3D new QWidget; - QVBoxLayout *layout =3D new QVBoxLayout(widget); - - RunnerModel *runnerModel =3D new RunnerModel(widget); - new ModelTest(runnerModel, widget); - - QLineEdit *input =3D new QLineEdit(widget); - QObject::connect(input, SIGNAL(textChanged(QString)), runnerModel, SLO= T(startQuery(QString))); - layout->addWidget(input); - - QTreeView *view =3D new QTreeView(widget); - view->setModel(runnerModel); - layout->addWidget(view); - - QAction *quit =3D new QAction(widget); - quit->setShortcut(Qt::CTRL + Qt::Key_Q); - QObject::connect(quit, SIGNAL(triggered()), &app, SLOT(quit())); - - widget->addAction(quit); - widget->show(); - return app.exec(); -} diff --git a/components/runnermodel/test/modeltest.cpp b/components/runnerm= odel/test/modeltest.cpp deleted file mode 100644 index 88677cc..0000000 --- a/components/runnermodel/test/modeltest.cpp +++ /dev/null @@ -1,566 +0,0 @@ -/*************************************************************************= *** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -**************************************************************************= **/ - - -#include - -#include "modeltest.h" - -#include -//#undef Q_ASSERT -//#define Q_ASSERT QVERIFY - -Q_DECLARE_METATYPE ( QModelIndex ) - -/*! - Connect to all of the models signals. Whenever anything happens reche= ck everything. -*/ -ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) : QOb= ject ( parent ), model ( _model ), fetchingMore ( false ) -{ - Q_ASSERT ( model ); - - connect ( model, SIGNAL (columnsAboutToBeInserted(QModelIndex,int,int)= ), - this, SLOT (runAllTests()) ); - connect ( model, SIGNAL (columnsAboutToBeRemoved(QModelIndex,int,int)), - this, SLOT (runAllTests()) ); - connect ( model, SIGNAL (columnsInserted(QModelIndex,int,int)), - this, SLOT (runAllTests()) ); - connect ( model, SIGNAL (columnsRemoved(QModelIndex,int,int)), - this, SLOT (runAllTests()) ); - connect ( model, SIGNAL (dataChanged(QModelIndex,QModelIndex)), - this, SLOT (runAllTests()) ); - connect ( model, SIGNAL (headerDataChanged(Qt::Orientation,int,int)), - this, SLOT (runAllTests()) ); - connect ( model, SIGNAL (layoutAboutToBeChanged()), this, SLOT (runAll= Tests()) ); - connect ( model, SIGNAL (layoutChanged()), this, SLOT (runAllTests()) = ); - connect ( model, SIGNAL (modelReset()), this, SLOT (runAllTests()) ); - connect ( model, SIGNAL (rowsAboutToBeInserted(QModelIndex,int,int)), - this, SLOT (runAllTests()) ); - connect ( model, SIGNAL (rowsAboutToBeRemoved(QModelIndex,int,int)), - this, SLOT (runAllTests()) ); - connect ( model, SIGNAL (rowsInserted(QModelIndex,int,int)), - this, SLOT (runAllTests()) ); - connect ( model, SIGNAL (rowsRemoved(QModelIndex,int,int)), - this, SLOT (runAllTests()) ); - - // Special checks for inserting/removing - connect ( model, SIGNAL (layoutAboutToBeChanged()), - this, SLOT (layoutAboutToBeChanged()) ); - connect ( model, SIGNAL (layoutChanged()), - this, SLOT (layoutChanged()) ); - - connect ( model, SIGNAL (rowsAboutToBeInserted(QModelIndex,int,int)), - this, SLOT (rowsAboutToBeInserted(QModelIndex,int,int)) ); - connect ( model, SIGNAL (rowsAboutToBeRemoved(QModelIndex,int,int)), - this, SLOT (rowsAboutToBeRemoved(QModelIndex,int,int)) ); - connect ( model, SIGNAL (rowsInserted(QModelIndex,int,int)), - this, SLOT (rowsInserted(QModelIndex,int,int)) ); - connect ( model, SIGNAL (rowsRemoved(QModelIndex,int,int)), - this, SLOT (rowsRemoved(QModelIndex,int,int)) ); - - runAllTests(); -} - -void ModelTest::runAllTests() -{ - if ( fetchingMore ) - return; - nonDestructiveBasicTest(); - rowCount(); - columnCount(); - hasIndex(); - index(); - parent(); - data(); -} - -/*! - nonDestructiveBasicTest tries to call a number of the basic functions = (not all) - to make sure the model doesn't outright segfault, testing the function= s that makes sense. -*/ -void ModelTest::nonDestructiveBasicTest() -{ - Q_ASSERT ( model->buddy ( QModelIndex() ) =3D=3D QModelIndex() ); - model->canFetchMore ( QModelIndex() ); - Q_ASSERT ( model->columnCount ( QModelIndex() ) >=3D 0 ); - Q_ASSERT ( model->data ( QModelIndex() ) =3D=3D QVariant() ); - fetchingMore =3D true; - model->fetchMore ( QModelIndex() ); - fetchingMore =3D false; - Qt::ItemFlags flags =3D model->flags ( QModelIndex() ); - Q_ASSERT ( flags =3D=3D Qt::ItemIsDropEnabled || flags =3D=3D 0 ); - model->hasChildren ( QModelIndex() ); - model->hasIndex ( 0, 0 ); - model->headerData ( 0, Qt::Horizontal ); - model->index ( 0, 0 ); - model->itemData ( QModelIndex() ); - QVariant cache; - model->match ( QModelIndex(), -1, cache ); - model->mimeTypes(); - Q_ASSERT ( model->parent ( QModelIndex() ) =3D=3D QModelIndex() ); - Q_ASSERT ( model->rowCount() >=3D 0 ); - QVariant variant; - model->setData ( QModelIndex(), variant, -1 ); - model->setHeaderData ( -1, Qt::Horizontal, QVariant() ); - model->setHeaderData ( 999999, Qt::Horizontal, QVariant() ); - QMap roles; - model->sibling ( 0, 0, QModelIndex() ); - model->span ( QModelIndex() ); - model->supportedDropActions(); -} - -/*! - Tests model's implementation of QAbstractItemModel::rowCount() and has= Children() - - Models that are dynamically populated are not as fully tested here. - */ -void ModelTest::rowCount() -{ -// qDebug() << "rc"; - // check top row - QModelIndex topIndex =3D model->index ( 0, 0, QModelIndex() ); - int rows =3D model->rowCount ( topIndex ); - Q_ASSERT ( rows >=3D 0 ); - if ( rows > 0 ) - Q_ASSERT ( model->hasChildren ( topIndex ) =3D=3D true ); - - QModelIndex secondLevelIndex =3D model->index ( 0, 0, topIndex ); - if ( secondLevelIndex.isValid() ) { // not the top level - // check a row count where parent is valid - rows =3D model->rowCount ( secondLevelIndex ); - Q_ASSERT ( rows >=3D 0 ); - if ( rows > 0 ) - Q_ASSERT ( model->hasChildren ( secondLevelIndex ) =3D=3D true= ); - } - - // The models rowCount() is tested more extensively in checkChildren(), - // but this catches the big mistakes -} - -/*! - Tests model's implementation of QAbstractItemModel::columnCount() and = hasChildren() - */ -void ModelTest::columnCount() -{ - // check top row - QModelIndex topIndex =3D model->index ( 0, 0, QModelIndex() ); - Q_ASSERT ( model->columnCount ( topIndex ) >=3D 0 ); - - // check a column count where parent is valid - QModelIndex childIndex =3D model->index ( 0, 0, topIndex ); - if ( childIndex.isValid() ) - Q_ASSERT ( model->columnCount ( childIndex ) >=3D 0 ); - - // columnCount() is tested more extensively in checkChildren(), - // but this catches the big mistakes -} - -/*! - Tests model's implementation of QAbstractItemModel::hasIndex() - */ -void ModelTest::hasIndex() -{ -// qDebug() << "hi"; - // Make sure that invalid values returns an invalid index - Q_ASSERT ( model->hasIndex ( -2, -2 ) =3D=3D false ); - Q_ASSERT ( model->hasIndex ( -2, 0 ) =3D=3D false ); - Q_ASSERT ( model->hasIndex ( 0, -2 ) =3D=3D false ); - - int rows =3D model->rowCount(); - int columns =3D model->columnCount(); - - // check out of bounds - Q_ASSERT ( model->hasIndex ( rows, columns ) =3D=3D false ); - Q_ASSERT ( model->hasIndex ( rows + 1, columns + 1 ) =3D=3D false ); - - if ( rows > 0 ) - Q_ASSERT ( model->hasIndex ( 0, 0 ) =3D=3D true ); - - // hasIndex() is tested more extensively in checkChildren(), - // but this catches the big mistakes -} - -/*! - Tests model's implementation of QAbstractItemModel::index() - */ -void ModelTest::index() -{ -// qDebug() << "i"; - // Make sure that invalid values returns an invalid index - Q_ASSERT ( model->index ( -2, -2 ) =3D=3D QModelIndex() ); - Q_ASSERT ( model->index ( -2, 0 ) =3D=3D QModelIndex() ); - Q_ASSERT ( model->index ( 0, -2 ) =3D=3D QModelIndex() ); - - int rows =3D model->rowCount(); - int columns =3D model->columnCount(); - - if ( rows =3D=3D 0 ) - return; - - // Catch off by one errors - Q_ASSERT ( model->index ( rows, columns ) =3D=3D QModelIndex() ); - Q_ASSERT ( model->index ( 0, 0 ).isValid() =3D=3D true ); - - // Make sure that the same index is *always* returned - QModelIndex a =3D model->index ( 0, 0 ); - QModelIndex b =3D model->index ( 0, 0 ); - Q_ASSERT ( a =3D=3D b ); - - // index() is tested more extensively in checkChildren(), - // but this catches the big mistakes -} - -/*! - Tests model's implementation of QAbstractItemModel::parent() - */ -void ModelTest::parent() -{ -// qDebug() << "p"; - // Make sure the model wont crash and will return an invalid QModelInd= ex - // when asked for the parent of an invalid index. - Q_ASSERT ( model->parent ( QModelIndex() ) =3D=3D QModelIndex() ); - - if ( model->rowCount() =3D=3D 0 ) - return; - - // Column 0 | Column 1 | - // QModelIndex() | | - // \- topIndex | topIndex1 | - // \- childIndex | childIndex1 | - - // Common error test #1, make sure that a top level index has a parent - // that is a invalid QModelIndex. - QModelIndex topIndex =3D model->index ( 0, 0, QModelIndex() ); - Q_ASSERT ( model->parent ( topIndex ) =3D=3D QModelIndex() ); - - // Common error test #2, make sure that a second level index has a par= ent - // that is the first level index. - if ( model->rowCount ( topIndex ) > 0 ) { - QModelIndex childIndex =3D model->index ( 0, 0, topIndex ); - Q_ASSERT ( model->parent ( childIndex ) =3D=3D topIndex ); - } - - // Common error test #3, the second column should NOT have the same ch= ildren - // as the first column in a row. - // Usually the second column shouldn't have children. - QModelIndex topIndex1 =3D model->index ( 0, 1, QModelIndex() ); - if ( model->rowCount ( topIndex1 ) > 0 ) { - QModelIndex childIndex =3D model->index ( 0, 0, topIndex ); - QModelIndex childIndex1 =3D model->index ( 0, 0, topIndex1 ); - Q_ASSERT ( childIndex !=3D childIndex1 ); - } - - // Full test, walk n levels deep through the model making sure that all - // parent's children correctly specify their parent. - checkChildren ( QModelIndex() ); -} - -/*! - Called from the parent() test. - - A model that returns an index of parent X should also return X when as= king - for the parent of the index. - - This recursive function does pretty extensive testing on the whole mod= el in an - effort to catch edge cases. - - This function assumes that rowCount(), columnCount() and index() alrea= dy work. - If they have a bug it will point it out, but the above tests should ha= ve already - found the basic bugs because it is easier to figure out the problem in - those tests then this one. - */ -void ModelTest::checkChildren ( const QModelIndex &parent, int currentDept= h ) -{ - // First just try walking back up the tree. - QModelIndex p =3D parent; - while ( p.isValid() ) - p =3D p.parent(); - - // For models that are dynamically populated - if ( model->canFetchMore ( parent ) ) { - fetchingMore =3D true; - model->fetchMore ( parent ); - fetchingMore =3D false; - } - - int rows =3D model->rowCount ( parent ); - int columns =3D model->columnCount ( parent ); - - if ( rows > 0 ) - Q_ASSERT ( model->hasChildren ( parent ) ); - - // Some further testing against rows(), columns(), and hasChildren() - Q_ASSERT ( rows >=3D 0 ); - Q_ASSERT ( columns >=3D 0 ); - if ( rows > 0 ) - Q_ASSERT ( model->hasChildren ( parent ) =3D=3D true ); - - //qDebug() << "parent:" << model->data(parent).toString() << "rows:" <= < rows - // << "columns:" << columns << "parent column:" << parent.colu= mn(); - - Q_ASSERT ( model->hasIndex ( rows + 1, 0, parent ) =3D=3D false ); - for ( int r =3D 0; r < rows; ++r ) { - if ( model->canFetchMore ( parent ) ) { - fetchingMore =3D true; - model->fetchMore ( parent ); - fetchingMore =3D false; - } - Q_ASSERT ( model->hasIndex ( r, columns + 1, parent ) =3D=3D false= ); - for ( int c =3D 0; c < columns; ++c ) { - Q_ASSERT ( model->hasIndex ( r, c, parent ) =3D=3D true ); - QModelIndex index =3D model->index ( r, c, parent ); - // rowCount() and columnCount() said that it existed... - Q_ASSERT ( index.isValid() =3D=3D true ); - - // index() should always return the same index when called twi= ce in a row - QModelIndex modifiedIndex =3D model->index ( r, c, parent ); - Q_ASSERT ( index =3D=3D modifiedIndex ); - - // Make sure we get the same index if we request it twice in a= row - QModelIndex a =3D model->index ( r, c, parent ); - QModelIndex b =3D model->index ( r, c, parent ); - Q_ASSERT ( a =3D=3D b ); - - // Some basic checking on the index that is returned - Q_ASSERT ( index.model() =3D=3D model ); - Q_ASSERT ( index.row() =3D=3D r ); - Q_ASSERT ( index.column() =3D=3D c ); - // While you can technically return a QVariant usually this is= a sign - // of an bug in data() Disable if this really is ok in your m= odel. -// Q_ASSERT ( model->data ( index, Qt::DisplayRole ).isValid() = =3D=3D true ); - - // If the next test fails here is some somewhat useful debug y= ou play with. - - if (model->parent(index) !=3D parent) { - qDebug() << r << c << currentDepth << model->data(index).t= oString() - << model->data(parent).toString(); - qDebug() << index << parent << model->parent(index); -// And a view that you can even use to show the model. -// QTreeView view; -// view.setModel(model); -// view.show(); - } - - // Check that we can get back our real parent. -// qDebug() << model->parent ( index ) << parent ; - Q_ASSERT ( model->parent ( index ) =3D=3D parent ); - - // recursively go down the children - if ( model->hasChildren ( index ) && currentDepth < 10 ) { - //qDebug() << r << c << "has children" << model->rowCount(= index); - checkChildren ( index, ++currentDepth ); - }/* else { if (currentDepth >=3D 10) qDebug() << "checked 10 d= eep"; };*/ - - // make sure that after testing the children that the index do= esn't change. - QModelIndex newerIndex =3D model->index ( r, c, parent ); - Q_ASSERT ( index =3D=3D newerIndex ); - } - } -} - -/*! - Tests model's implementation of QAbstractItemModel::data() - */ -void ModelTest::data() -{ - // Invalid index should return an invalid qvariant - Q_ASSERT ( !model->data ( QModelIndex() ).isValid() ); - - if ( model->rowCount() =3D=3D 0 ) - return; - - // A valid index should have a valid QVariant data - Q_ASSERT ( model->index ( 0, 0 ).isValid() ); - - // shouldn't be able to set data on an invalid index - Q_ASSERT ( model->setData ( QModelIndex(), QLatin1String ( "foo" ), Qt= ::DisplayRole ) =3D=3D false ); - - // General Purpose roles that should return a QString - QVariant variant =3D model->data ( model->index ( 0, 0 ), Qt::ToolTipR= ole ); - if ( variant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( variant ) ); - } - variant =3D model->data ( model->index ( 0, 0 ), Qt::StatusTipRole ); - if ( variant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( variant ) ); - } - variant =3D model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole ); - if ( variant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( variant ) ); - } - - // General Purpose roles that should return a QSize - variant =3D model->data ( model->index ( 0, 0 ), Qt::SizeHintRole ); - if ( variant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( variant ) ); - } - - // General Purpose roles that should return a QFont - QVariant fontVariant =3D model->data ( model->index ( 0, 0 ), Qt::Font= Role ); - if ( fontVariant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( fontVariant ) ); - } - - // Check that the alignment is one we know about - QVariant textAlignmentVariant =3D model->data ( model->index ( 0, 0 ),= Qt::TextAlignmentRole ); - if ( textAlignmentVariant.isValid() ) { - int alignment =3D textAlignmentVariant.toInt(); - Q_ASSERT ( alignment =3D=3D ( alignment & ( Qt::AlignHorizontal_Ma= sk | Qt::AlignVertical_Mask ) ) ); - } - - // General Purpose roles that should return a QColor - QVariant colorVariant =3D model->data ( model->index ( 0, 0 ), Qt::Bac= kgroundColorRole ); - if ( colorVariant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( colorVariant ) ); - } - - colorVariant =3D model->data ( model->index ( 0, 0 ), Qt::TextColorRol= e ); - if ( colorVariant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( colorVariant ) ); - } - - // Check that the "check state" is one we know about. - QVariant checkStateVariant =3D model->data ( model->index ( 0, 0 ), Qt= ::CheckStateRole ); - if ( checkStateVariant.isValid() ) { - int state =3D checkStateVariant.toInt(); - Q_ASSERT ( state =3D=3D Qt::Unchecked || - state =3D=3D Qt::PartiallyChecked || - state =3D=3D Qt::Checked ); - } -} - -/*! - Store what is about to be inserted to make sure it actually happens - - \sa rowsInserted() - */ -void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int sta= rt, int end ) -{ -// Q_UNUSED(end); -// qDebug() << "rowsAboutToBeInserted" << "start=3D" << start << "end= =3D" << end << "parent=3D" << model->data ( parent ).toString() -// << "current count of parent=3D" << model->rowCount ( parent ); // <<= "display of last=3D" << model->data( model->index(start-1, 0, parent) ); -// qDebug() << model->index(start-1, 0, parent) << model->data( model-= >index(start-1, 0, parent) ); - Changing c; - c.parent =3D parent; - c.oldSize =3D model->rowCount ( parent ); - c.last =3D model->data ( model->index ( start - 1, 0, parent ) ); - c.next =3D model->data ( model->index ( start, 0, parent ) ); - insert.push ( c ); -} - -/*! - Confirm that what was said was going to happen actually did - - \sa rowsAboutToBeInserted() - */ -void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int = end ) -{ - Changing c =3D insert.pop(); - Q_ASSERT ( c.parent =3D=3D parent ); -// qDebug() << "rowsInserted" << "start=3D" << start << "end=3D" << en= d << "oldsize=3D" << c.oldSize -// << "parent=3D" << model->data ( parent ).toString() << "current rowc= ount of parent=3D" << model->rowCount ( parent ); - -// for (int ii=3Dstart; ii <=3D end; ii++) -// { -// qDebug() << "itemWasInserted:" << ii << model->data ( model->index= ( ii, 0, parent )); -// } -// qDebug(); - - Q_ASSERT ( c.oldSize + ( end - start + 1 ) =3D=3D model->rowCount ( pa= rent ) ); - Q_ASSERT ( c.last =3D=3D model->data ( model->index ( start - 1, 0, c.= parent ) ) ); - - if (c.next !=3D model->data(model->index(end + 1, 0, c.parent))) { - qDebug() << start << end; - for (int i=3D0; i < model->rowCount(); ++i) - qDebug() << model->index(i, 0).data().toString(); - qDebug() << c.next << model->data(model->index(end + 1, 0, c.paren= t)); - } - - Q_ASSERT ( c.next =3D=3D model->data ( model->index ( end + 1, 0, c.pa= rent ) ) ); -} - -void ModelTest::layoutAboutToBeChanged() -{ - for ( int i =3D 0; i < qBound ( 0, model->rowCount(), 100 ); ++i ) - changing.append ( QPersistentModelIndex ( model->index ( i, 0 ) ) = ); -} - -void ModelTest::layoutChanged() -{ - for ( int i =3D 0; i < changing.count(); ++i ) { - QPersistentModelIndex p =3D changing[i]; - Q_ASSERT ( p =3D=3D model->index ( p.row(), p.column(), p.parent()= ) ); - } - changing.clear(); -} - -/*! - Store what is about to be inserted to make sure it actually happens - - \sa rowsRemoved() - */ -void ModelTest::rowsAboutToBeRemoved ( const QModelIndex &parent, int star= t, int end ) -{ -qDebug() << "ratbr" << parent << start << end; - Changing c; - c.parent =3D parent; - c.oldSize =3D model->rowCount ( parent ); - c.last =3D model->data ( model->index ( start - 1, 0, parent ) ); - c.next =3D model->data ( model->index ( end + 1, 0, parent ) ); - remove.push ( c ); -} - -/*! - Confirm that what was said was going to happen actually did - - \sa rowsAboutToBeRemoved() - */ -void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int e= nd ) -{ - qDebug() << "rr" << parent << start << end; - Changing c =3D remove.pop(); - Q_ASSERT ( c.parent =3D=3D parent ); - Q_ASSERT ( c.oldSize - ( end - start + 1 ) =3D=3D model->rowCount ( pa= rent ) ); - Q_ASSERT ( c.last =3D=3D model->data ( model->index ( start - 1, 0, c.= parent ) ) ); - Q_ASSERT ( c.next =3D=3D model->data ( model->index ( start, 0, c.pare= nt ) ) ); -} - - diff --git a/components/runnermodel/test/modeltest.h b/components/runnermod= el/test/modeltest.h deleted file mode 100644 index f042ed2..0000000 --- a/components/runnermodel/test/modeltest.h +++ /dev/null @@ -1,94 +0,0 @@ -/*************************************************************************= *** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -**************************************************************************= **/ - - -#ifndef MODELTEST_H -#define MODELTEST_H - -#include -#include -#include - -class ModelTest : public QObject -{ - Q_OBJECT - -public: - explicit ModelTest( QAbstractItemModel *model, QObject *parent =3D 0 ); - -private Q_SLOTS: - void nonDestructiveBasicTest(); - void rowCount(); - void columnCount(); - void hasIndex(); - void index(); - void parent(); - void data(); - -protected Q_SLOTS: - void runAllTests(); - void layoutAboutToBeChanged(); - void layoutChanged(); - void rowsAboutToBeInserted( const QModelIndex &parent, int start, int en= d ); - void rowsInserted( const QModelIndex & parent, int start, int end ); - void rowsAboutToBeRemoved( const QModelIndex &parent, int start, int end= ); - void rowsRemoved( const QModelIndex & parent, int start, int end ); - -private: - void checkChildren( const QModelIndex &parent, int currentDepth =3D 0 ); - - QAbstractItemModel *model; - - struct Changing { - QModelIndex parent; - int oldSize; - QVariant last; - QVariant next; - }; - QStack insert; - QStack remove; - - bool fetchingMore; - - QList changing; -}; - -#endif