From 4aa007e5cf59288e7d548ea3f613a10ac0a6057e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 1 Feb 2016 14:51:02 +0100 Subject: Removed ListModelResult --- common/listmodelresult.cpp | 21 -------- common/listmodelresult.h | 125 --------------------------------------------- 2 files changed, 146 deletions(-) delete mode 100644 common/listmodelresult.cpp delete mode 100644 common/listmodelresult.h (limited to 'common') diff --git a/common/listmodelresult.cpp b/common/listmodelresult.cpp deleted file mode 100644 index 6ef1c5f..0000000 --- a/common/listmodelresult.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2014 Christian Mollekopf - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#include "listmodelresult.h" diff --git a/common/listmodelresult.h b/common/listmodelresult.h deleted file mode 100644 index 71a0d09..0000000 --- a/common/listmodelresult.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2014 Christian Mollekopf - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#pragma once -#include -#include - -#include "resultprovider.h" - -enum Roles { - DomainObjectRole = Qt::UserRole + 1 -}; - -template -class ListModelResult : public QAbstractListModel -{ -public: - - ListModelResult(const QList &propertyColumns) - :QAbstractListModel(), - mPropertyColumns(propertyColumns) - { - } - - ListModelResult(const QSharedPointer > &emitter, const QList &propertyColumns) - :QAbstractListModel(), - mPropertyColumns(propertyColumns) - { - setEmitter(emitter); - } - - void setEmitter(const QSharedPointer > &emitter) - { - beginResetModel(); - mEntities.clear(); - mEmitter = emitter; - emitter->onAdded([this](const T &value) { - const auto keys = mEntities.keys(); - int index = 0; - for (; index < keys.size(); index++) { - if (value->identifier() < keys.at(index)) { - break; - } - } - beginInsertRows(QModelIndex(), index, index); - mEntities.insert(value->identifier(), value); - endInsertRows(); - }); - emitter->onModified([this](const T &value) { - auto i = mEntities.keys().indexOf(value->identifier()); - mEntities.remove(value->identifier()); - mEntities.insert(value->identifier(), value); - auto idx = index(i, 0, QModelIndex()); - emit dataChanged(idx, idx); - }); - emitter->onRemoved([this](const T &value) { - auto index = mEntities.keys().indexOf(value->identifier()); - beginRemoveRows(QModelIndex(), index, index); - mEntities.remove(value->identifier()); - endRemoveRows(); - }); - emitter->onInitialResultSetComplete([this]() { - }); - emitter->onComplete([this]() { - mEmitter.clear(); - }); - emitter->onClear([this]() { - beginResetModel(); - mEntities.clear(); - endResetModel(); - }); - endResetModel(); - } - - int rowCount(const QModelIndex &parent = QModelIndex()) const - { - return mEntities.size(); - } - - int columnCount(const QModelIndex &parent = QModelIndex()) const - { - return mPropertyColumns.size(); - } - - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const - { - if (index.row() >= mEntities.size()) { - qWarning() << "Out of bounds access"; - return QVariant(); - } - if (role == Qt::DisplayRole) { - if (index.column() < mPropertyColumns.size()) { - auto entity = mEntities.value(mEntities.keys().at(index.row())); - return entity->getProperty(mPropertyColumns.at(index.column())).toString(); - } - } - if (role == DomainObjectRole) { - return QVariant::fromValue(mEntities.value(mEntities.keys().at(index.row()))); - } - return QVariant(); - } - -private: - QSharedPointer > mEmitter; - QMap mEntities; - QList mPropertyColumns; -}; - -- cgit v1.2.3