Commit 7213eb6a authored by Volker Krause's avatar Volker Krause
Browse files

Add proxy model to map roles

This useful with QtCharts using hardcoded roles.
parent a0c8fb41
......@@ -21,6 +21,7 @@ set(analyzer_lib_srcs
model/numericaggregationmodel.cpp
model/productmodel.cpp
model/ratiosetaggregationmodel.cpp
model/rolemappingproxymodel.cpp
model/schemamodel.cpp
model/singlerowfilterproxymodel.cpp
model/surveymodel.cpp
......
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
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 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 Library 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 "rolemappingproxymodel.h"
using namespace UserFeedback::Analyzer;
RoleMappingProxyModel::RoleMappingProxyModel(QObject* parent) :
QIdentityProxyModel(parent)
{
}
RoleMappingProxyModel::~RoleMappingProxyModel() = default;
void RoleMappingProxyModel::addRoleMapping(int fromRole, int toRole)
{
m_roleMapping.insert(fromRole, toRole);
}
QVariant RoleMappingProxyModel::data(const QModelIndex& index, int role) const
{
const auto it = m_roleMapping.find(role);
if (it != m_roleMapping.end())
return QIdentityProxyModel::data(index, it.value());
return QIdentityProxyModel::data(index, role);
}
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
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 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 Library 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 USERFEEDBACK_ANALYZER_ROLEMAPPINGPROXYMODEL_H
#define USERFEEDBACK_ANALYZER_ROLEMAPPINGPROXYMODEL_H
#include <QIdentityProxyModel>
#include <QHash>
namespace UserFeedback {
namespace Analyzer {
/**
* @todo write docs
*/
class RoleMappingProxyModel : public QIdentityProxyModel
{
Q_OBJECT
public:
explicit RoleMappingProxyModel(QObject *parent = nullptr);
~RoleMappingProxyModel();
void addRoleMapping(int fromRole, int toRole);
QVariant data(const QModelIndex & index, int role) const override;
private:
QHash<int, int> m_roleMapping;
};
}}
#endif // USERFEEDBACK_ANALYZER_ROLEMAPPINGPROXYMODEL_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment