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/>.
20 #include "setupmodel.h"
23 SetupModel::SetupModel(QObject *parent) :
24 EmuFrontQueryModel(parent)
29 void SetupModel::refresh()
31 setQuery(constructSelect());
32 setHeaderData(Setup_Id, Qt::Horizontal, tr("Id"));
33 setHeaderData(Setup_PlatformId, Qt::Horizontal, tr("Platform id"));
34 setHeaderData(Setup_MediaTypeId, Qt::Horizontal, tr("Media type id"));
35 setHeaderData(Setup_FileTypeExtensions, Qt::Horizontal, tr("File types"));
36 setHeaderData(Setup_Name, Qt::Horizontal, tr("Name"));
39 QString SetupModel::constructSelect(QString where) const
42 "SELECT setup.id AS SetupId, "
43 "setup.platformid AS PlatformId, "
44 "setup.mediatypeid AS MediaTypeId, "
45 "setup.filetypeextensions AS SupportedFileTypeExtensions, "
46 "platform.name || ' ' || mediatype.name AS SetupName "
48 "INNER JOIN platform ON setup.platformid=platform.id "
49 "INNER JOIN mediatype ON setup.mediatypeid=mediatype.id %1 "
54 Qt::ItemFlags SetupModel::flags(const QModelIndex &index) const
56 Qt::ItemFlags flags = QSqlQueryModel::flags(index);
57 if (index.column() == Setup_PlatformId) {
58 flags |= Qt::ItemIsEditable;
63 bool SetupModel::setData(const QModelIndex &index, const QVariant &value, int /*role*/)
65 if(index.column() != Setup_PlatformId)
68 QModelIndex primaryKeyIndex
69 = QSqlQueryModel::index(index.row(), Setup_Id);
71 int id = data(primaryKeyIndex).toInt();
75 if (index.column() == Setup_PlatformId) {
76 ok = setPlatform(id, value.toInt());
83 bool SetupModel::setPlatform(int id, int platformId)
85 qDebug() << "updating setup " << id << " to platform " << platformId;
87 query.prepare(QString("update setup set platformid = :platformid where id = :id"));
88 query.bindValue(":platformid", platformId);
89 query.bindValue(":id", id);
90 qDebug() << query.lastQuery();
91 qDebug() << query.lastError();