Initial MediaImagePathDialog implementation
[emufront] / src / db / dbfilepath.cpp
1 // EmuFront
2 // Copyright 2010 Mikko Keinänen
3 //
4 // This file is part of EmuFront.
5 //
6 //
7 // EmuFront is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Foobar is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
19
20 #include <QSqlRelationalTableModel>
21 #include "dbfilepath.h"
22 #include "../dataobjects/filepathobject.h"
23
24 DbFilePath::DbFilePath(QObject *parent) : DatabaseManager(parent)
25 {
26     sqlTableModel = getData();
27 }
28
29 QSqlTableModel* DbFilePath::getDataModel()
30 {
31     return sqlTableModel;
32 }
33
34 EmuFrontObject* DbFilePath::getDataObjectFromModel(QModelIndex *index)
35 {
36     return new FilePathObject;
37 }
38
39 bool DbFilePath::updateDataObjectToModel(const EmuFrontObject *ob)
40 {
41     return false;
42 }
43
44 bool DbFilePath::insertDataObjectToModel(const EmuFrontObject *ob)
45 {
46     return false;
47 }
48
49 int DbFilePath::countDataObjectRefs(int id) const
50 {
51     return 0;
52 }
53
54 // WARNING: this will delete also all the databindings to selected media image path
55 bool DbFilePath::deleteDataObjectFromModel(QModelIndex *index)
56 {
57     return false;
58 }
59
60 QSqlTableModel* DbFilePath::getData()
61 {
62    QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this);
63    model->setTable(DB_TABLE_NAME_FILEPATH);
64    model->setRelation(FilePath_PlatformId,
65        QSqlRelation(DB_TABLE_NAME_PLATFORM, "id", "name"));
66    model->setRelation(FilePath_MediaTypeId,
67        QSqlRelation(DB_TABLE_NAME_MEDIATYPE, "id", "name"));
68    model->setSort(FilePath_Name, Qt::AscendingOrder);
69    model->setHeaderData(FilePath_MediaTypeId, Qt::Horizontal, tr("Media type"));
70    model->setHeaderData(FilePath_PlatformId, Qt::Horizontal, tr("Platform"));
71    model->select();
72    return model;
73 }