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 version 2 as published by
9 // the Free Software Foundation and appearing in the file gpl.txt included in the
10 // packaging of this file.
12 // EmuFront 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
21 #include "platformmodel.h"
23 PlatformModel::PlatformModel(QObject *parent) :
24 EmuFrontQueryModel(parent)
26 tableName = "platform";
30 Qt::ItemFlags PlatformModel::flags(const QModelIndex &index) const
32 Qt::ItemFlags flags = QSqlQueryModel::flags(index);
33 if (index.column() == EmuFrontFileObject_Name) {
34 flags |= Qt::ItemIsEditable;
39 bool PlatformModel::setData(const QModelIndex &index, const QVariant &value, int /*role*/)
41 if(index.column() != EmuFrontFileObject_Name)
44 QModelIndex primaryKeyIndex
45 = QSqlQueryModel::index(index.row(), EmuFrontFileObject_Id);
47 int id = data(primaryKeyIndex).toInt();
51 if (index.column() == EmuFrontFileObject_Name) {
52 ok = setName(id, value.toString());
59 void PlatformModel::refresh()
61 setQuery(constructSelect());
62 setHeaderData(EmuFrontFileObject_Id, Qt::Horizontal, tr("ID"));
63 setHeaderData(EmuFrontFileObject_Name, Qt::Horizontal, tr("Name"));
64 setHeaderData(EmuFrontFileObject_FileId, Qt::Horizontal, tr("FileID"));
65 setHeaderData(EmuFrontFileObject_FileName, Qt::Horizontal, tr("File Name"));
66 setHeaderData(EmuFrontFileObject_FileCheckSum, Qt::Horizontal, tr("File Checksum"));
67 setHeaderData(EmuFrontFileObject_FileSize, Qt::Horizontal, tr("File Size"));
68 setHeaderData(EmuFrontFileObject_FileType, Qt::Horizontal, tr("File Type"));
69 setHeaderData(EmuFrontFileObject_FileUpdateTime, Qt::Horizontal, tr("File Updated"));
72 QString PlatformModel::constructSelect(QString where) const
74 return QString("SELECT maintbl.id AS FileObjectId, "
75 "maintbl.name AS Name, "
77 "file.name AS FileName, "
78 "file.type AS FileType, "
79 "file.checksum AS FileChecksum, "
80 "file.size AS FileSize, "
81 "file.updatetime AS FileUpdateTime "
83 "LEFT OUTER JOIN file ON maintbl.fileid=file.id "
85 "ORDER BY Name").arg(tableName).arg(where);
88 bool PlatformModel::setName(int id, const QString &name)
91 query.prepare("update platform set name = :name where id = :id");
92 query.bindValue(":name", name);
93 query.bindValue(":id", id);