2 // Copyright 2010 Mikko Keinänen
4 // This file is part of EmuFront.
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.
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.
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/>.
20 #include <QSqlRelationalTableModel>
21 #include "dbfilepath.h"
22 #include "../dataobjects/filepathobject.h"
24 DbFilePath::DbFilePath(QObject *parent) : DatabaseManager(parent)
26 sqlTableModel = getData();
29 QSqlTableModel* DbFilePath::getDataModel()
34 EmuFrontObject* DbFilePath::getDataObjectFromModel(QModelIndex *index)
36 return new FilePathObject;
39 bool DbFilePath::updateDataObjectToModel(const EmuFrontObject *ob)
44 bool DbFilePath::insertDataObjectToModel(const EmuFrontObject *ob)
49 int DbFilePath::countDataObjectRefs(int id) const
54 // WARNING: this will delete also all the databindings to selected media image path
55 bool DbFilePath::deleteDataObjectFromModel(QModelIndex *index)
60 QSqlTableModel* DbFilePath::getData()
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"));