From 11162794d9158c038375c0fdbcefc2a8290b2a8f Mon Sep 17 00:00:00 2001 From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> Date: Wed, 30 Sep 2015 13:32:53 -0400 Subject: [PATCH] roles: add a global LRC item data role Many LRC models expose the same types of data, but do so using their own item data roles. For example, Call::Role::Object exposes the item's object pointer in some models, but in the PersonModel it is Person::Role::Object. Since their enum values are not guaranteed to be the same, and indeed they are not usually the same, this often requires additional logic in the clients of LRC to determine which model is being used. This patch adds a Ring::Roles enum to be used by LRC models when exposing the same types of data as other models. Issue: #81198 Change-Id: I506c716c12f5b1bb0707e37c6dfa709b4fe03864 --- CMakeLists.txt | 1 + src/itemdataroles.h | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/itemdataroles.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a9fa1aef..c5a23060 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -403,6 +403,7 @@ SET( libringclient_LIB_HDRS src/profilepersisterdefault.h src/shortcutcreatordefault.h src/dbuserrorhandlerdefault.h + src/itemdataroles.h ) SET(libringclient_video_LIB_HDRS diff --git a/src/itemdataroles.h b/src/itemdataroles.h new file mode 100644 index 00000000..0737bea5 --- /dev/null +++ b/src/itemdataroles.h @@ -0,0 +1,48 @@ +/**************************************************************************** + * Copyright (C) 2015 by Savoir-faire Linux * + * Author : Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>* + * * + * 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) 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 * + * Lesser 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/>. * + ***************************************************************************/ +#pragma once + +namespace Ring { + +/** + * The purpose of this enum class is to mimic/extend the Qt::ItemDataRole in LRC so that the same + * value is used when using a common role in the ::data() method of any model in LRC, + * eg: the value of the Object role should not be different for the PersonModel and the CallModel. + * + * This is so that clients of LRC do need additional logic when trying to extract the same type of + * data from multiple types of LRC models. + * + * Thus any data role which is common to multiple models in LRC should be defined here. Data roles + * which are specific to the model can be defined within that model only and their value should + * start with UserRole + 1 + */ + +enum class Role +{ + DisplayRole = Qt::DisplayRole , + Object = Qt::UserRole + 1, + Name , + Number , + LastUsed , + FormattedLastUsed , + State , + FormattedState , + DropState , + UserRole = Qt::UserRole + 100 // this should always be the last role in the list +}; +} // namespace Ring -- GitLab