X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fdb%2Fplatformmodel.cpp;h=66a2815b796cabc24b69d3d78a9553de07d24c09;hb=fc4f578420b02ccb6532815ce651d37186cf2710;hp=328755b3ebf59c91209d96c866c36b20506d17b1;hpb=1790a3d91c15cbbef6958a26eb14c737349f9450;p=emufront diff --git a/src/db/platformmodel.cpp b/src/db/platformmodel.cpp index 328755b..66a2815 100644 --- a/src/db/platformmodel.cpp +++ b/src/db/platformmodel.cpp @@ -17,80 +17,11 @@ // You should have received a copy of the GNU General Public License // along with EmuFront. If not, see . -#include #include "platformmodel.h" PlatformModel::PlatformModel(QObject *parent) : - EmuFrontQueryModel(parent) + EmuFrontFileObjectModel(parent) { tableName = "platform"; refresh(); } - -Qt::ItemFlags PlatformModel::flags(const QModelIndex &index) const -{ - Qt::ItemFlags flags = QSqlQueryModel::flags(index); - if (index.column() == EmuFrontFileObject_Name) { - flags |= Qt::ItemIsEditable; - } - return flags; -} - -bool PlatformModel::setData(const QModelIndex &index, const QVariant &value, int /*role*/) -{ - if(index.column() != EmuFrontFileObject_Name) - return false; - - QModelIndex primaryKeyIndex - = QSqlQueryModel::index(index.row(), EmuFrontFileObject_Id); - - int id = data(primaryKeyIndex).toInt(); - clear(); - - bool ok; - if (index.column() == EmuFrontFileObject_Name) { - ok = setName(id, value.toString()); - } - - refresh(); - return ok; -} - -void PlatformModel::refresh() - { - setQuery(constructSelect()); - setHeaderData(EmuFrontFileObject_Id, Qt::Horizontal, tr("ID")); - setHeaderData(EmuFrontFileObject_Name, Qt::Horizontal, tr("Name")); - setHeaderData(EmuFrontFileObject_FileId, Qt::Horizontal, tr("FileID")); - setHeaderData(EmuFrontFileObject_FileName, Qt::Horizontal, tr("File Name")); - setHeaderData(EmuFrontFileObject_FileCheckSum, Qt::Horizontal, tr("File Checksum")); - setHeaderData(EmuFrontFileObject_FileSize, Qt::Horizontal, tr("File Size")); - setHeaderData(EmuFrontFileObject_FileType, Qt::Horizontal, tr("File Type")); - setHeaderData(EmuFrontFileObject_FileUpdateTime, Qt::Horizontal, tr("File Updated")); - } - -QString PlatformModel::constructSelect(QString where) const -{ - return QString("SELECT maintbl.id AS FileObjectId, " - "maintbl.name AS Name, " - "file.id AS FileId, " - "file.name AS FileName, " - "file.type AS FileType, " - "file.checksum AS FileChecksum, " - "file.size AS FileSize, " - "file.updatetime AS FileUpdateTime " - "FROM %1 AS maintbl " - "LEFT OUTER JOIN file ON maintbl.fileid=file.id " - "%2 " - "ORDER BY Name").arg(tableName).arg(where); -} - -bool PlatformModel::setName(int id, const QString &name) -{ - QSqlQuery query; - query.prepare("update platform set name = :name where id = :id"); - query.bindValue(":name", name); - query.bindValue(":id", id); - return query.exec(); -} -