3 ** Copyright 2010 Mikko Keinänen
5 ** This file is part of EmuFront.
8 ** EmuFront is free software: you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License version 2 as published by
10 ** the Free Software Foundation and appearing in the file gpl.txt included in the
11 ** packaging of this file.
13 ** EmuFront is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
18 ** You should have received a copy of the GNU General Public License
19 ** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
22 #include "externalexecutablemodel.h"
24 ExternalExecutableModel::ExternalExecutableModel(QObject *parent) :
25 EmuFrontQueryModel(parent)
27 editableColumns << Executable_Name;
28 editableColumns << Executable_Options;
29 editableColumns << Executable_Executable;
30 editableColumns << Executable_SetupId;
34 void ExternalExecutableModel::refresh()
36 setQuery(constructSelect());
37 setHeaderData(Executable_Id, Qt::Horizontal, tr("Id"));
38 setHeaderData(Executable_Name, Qt::Horizontal, tr("Name"));
39 setHeaderData(Executable_Executable, Qt::Horizontal, tr("Executable"));
40 setHeaderData(Executable_Options, Qt::Horizontal, tr("Options"));
41 setHeaderData(Executable_TypeId, Qt::Horizontal, tr("Type"));
42 setHeaderData(Executable_SetupId, Qt::Horizontal, tr("Setup id"));
43 setHeaderData(Executable_SetupName, Qt::Horizontal, tr("Setup"));
46 QString ExternalExecutableModel::constructSelect(QString where) const
48 return QString("SELECT "
49 "executable.id AS ExecutableId, "
50 "executable.name AS ExecutableName, "
51 "executable.executable AS Executable, "
52 "executable.options AS ExecutableOptions, "
53 "executable.type AS ExecutableType, "
54 "setup.id As ExecutableSetupId, "
55 "platform.name || ' ' || mediatype.name AS SetupName "
57 "INNER JOIN setup ON executable.setupid = setup.id "
58 "INNER JOIN platform ON setup.platformid=platform.id "
59 "INNER JOIN mediatype ON setup.mediatypeid=mediatype.id "
61 "ORDER BY executable.name").arg(where);
64 Qt::ItemFlags ExternalExecutableModel::flags(const QModelIndex &index) const
66 Qt::ItemFlags flags = QSqlQueryModel::flags(index);
67 int col = index.column();
68 if (editableColumns.contains(index.column())) {
69 flags |= Qt::ItemIsEditable;
74 bool ExternalExecutableModel::setData(const QModelIndex &index, const QVariant &value, int role)
76 if (!editableColumns.contains(index.column()))
79 QModelIndex primaryKeyIndex = QSqlQueryModel::index(index.row(), Executable_Id);
80 int id = data(primaryKeyIndex).toInt();
83 switch(index.column())
86 ok = setExecutableName(id, value.toString());
88 case Executable_Executable:
89 ok = setExecutable(id, value.toString());
91 case Executable_Options:
92 ok = setOptions(id, value.toString());
94 case Executable_SetupId:
95 ok = setSetup(id, value.toInt());
104 bool ExternalExecutableModel::insertRows(int row, int count, const QModelIndex &parent)
110 bool ExternalExecutableModel::removeRows(int row, int count, const QModelIndex &parent)
116 bool ExternalExecutableModel::setSetup(int isd, int setupId)
122 bool ExternalExecutableModel::setExecutable(int id, QString name)
128 bool ExternalExecutableModel::setOptions(int id, QString options)
134 bool ExternalExecutableModel::setExecutableName(int id, QString name)