-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrichsqlmodel.cpp
47 lines (41 loc) · 1.41 KB
/
richsqlmodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Copyright (C) 30-8-2016 Abdullateef Qallaa
*
* This file is part of Furqan project,
* hosted on GitHub: https://github.com/laateef/furqan,
* licensed under GPLv3.
*
* GNU General Public License Usage
* This file may be used under the terms of the GNU
* General Public License version 3.0 as published by the Free Software
* Foundation and appearing in the file LICENSE.md included in the
* packaging of this file. Please review the following information to
* ensure the GNU General Public License version 3.0 requirements will be
* met: http://www.gnu.org/copyleft/gpl.html.
*/
#include "richsqlmodel.h"
#include "abstractrelation.h"
RichSqlModel::RichSqlModel(QObject *parent, QSqlDatabase db) :
QSqlTableModel(parent, db)
{}
void RichSqlModel::setRelation(int column, AbstractRelation *relation)
{
m_relationMap.insert(column, relation);
}
AbstractRelation *RichSqlModel::relation(int column) const
{
return m_relationMap.value(column, NULL);
}
QVariant RichSqlModel::data(const QModelIndex &idx, int role) const
{
if (role == Qt::DisplayRole) {
if (m_relationMap.find(idx.column()) == m_relationMap.end()) {
return QSqlTableModel::data(idx, role);
} else {
return m_relationMap.value(idx.column())->forwardLookup(QSqlTableModel::data(idx).toLongLong());
}
} else {
return QSqlTableModel::data(idx, role);
}
return QVariant();
}