{
}
-/*EmuFrontObject::EmuFrontObject(const EmuFrontObject &ob)
- : id(ob.id), name(ob.name)
+EmuFrontObject::EmuFrontObject(const EmuFrontObject &ob)
+ : QObject(), id(ob.id), name(ob.name)
{
// no need to perform deep copy here, see:
// http://doc.trolltech.com/4.0/shclass.html
-}*/
+}
EmuFrontObject::EmuFrontObject(int id, QString name)
: id(id), name(name)
{}
-/*EmuFrontObject::~EmuFrontObject()
+EmuFrontObject::~EmuFrontObject()
{
}
id = ob.id;
name = ob.name;
return (*this);
-}*/
+}
EmuFrontObject(int id, QString name);
// No need for these as long we use QString (see Implicit Data Sharing)
- //EmuFrontObject(const EmuFrontObject &);
- //virtual ~EmuFrontObject();
- //EmuFrontObject &operator=(const EmuFrontObject &);
+ EmuFrontObject(const EmuFrontObject &);
+ ~EmuFrontObject();
+ EmuFrontObject &operator=(const EmuFrontObject &);
virtual const QString getName() const
{ return name; }
virtual int getId() const
{ return id; }
virtual void setName(QString name)
- { this->name = name; };
+ { this->name = name; }
virtual void setId(int id)
{ this->id = id; }
#include "filepathobject.h"
+#include "setup.h"
-FilePathObject::FilePathObject() : EmuFrontFileObject(), platform(0), mediaType(0)
+FilePathObject::FilePathObject() : EmuFrontFileObject(), setup(0)
{
}
FilePathObject::FilePathObject(int id, QString name, QString filename, int filetype)
- : EmuFrontFileObject(id, name, filename, filetype), platform(0), mediaType(0)
- {}
+ : EmuFrontFileObject(id, name, filename, filetype), setup(0) {}
FilePathObject::FilePathObject(int id, QString name, QString filename,
- int filetype, Platform *plf, MediaType *med)
- : EmuFrontFileObject(id, name, filename, filetype), platform(plf), mediaType(med)
- {}
+ int filetype, Setup *setup)
+ : EmuFrontFileObject(id, name, filename, filetype), setup(setup) {}
FilePathObject::~FilePathObject()
{
- if (platform) delete platform;
- if (mediaType) delete mediaType;
+ if (setup) delete setup;
}
FilePathObject::FilePathObject(const FilePathObject &fpobj)
: EmuFrontFileObject(fpobj.id, fpobj.name, fpobj.filename, fpobj.filetype)
{
- // Note: no need to deep copy members of type QString
- // QString uses Implicit Data Sharing (http://doc.trolltech.com/4.0/shclass.html)
- Platform *p = fpobj.platform;
- platform = new Platform(p->getId(), p->getName(), p->getFilename());
- MediaType *mt = fpobj.mediaType;
- mediaType = new MediaType(mt->getId(), mt->getName(), mt->getFilename());
+ Setup *s = fpobj.setup;
+ setup = new Setup(*s);
}
FilePathObject& FilePathObject::operator =(const FilePathObject &fpobj)
name = fpobj.name;
filename = fpobj.filename;
filetype = fpobj.filetype;
- if (platform) delete platform;
- Platform *p = fpobj.platform;
- platform = new Platform(p->getId(), p->getName(), p->getFilename());
- if (mediaType) delete mediaType;
- MediaType *mt = fpobj.mediaType;
- mediaType = new MediaType(mt->getId(), mt->getName(), mt->getFilename());
+ if (setup) delete setup;
+ Setup *sup = fpobj.setup;
+ setup = new Setup(*sup);
return (*this);
}
+
+Setup* FilePathObject::getSetup() const
+{ return setup; }
+void FilePathObject::setSetup(Setup *sup)
+{ setup = sup; }
#define FILEPATHOBJECT_H
#include "emufrontfileobject.h"
-#include "platform.h"
-#include "mediatype.h"
+
+class Setup;
class FilePathObject : public EmuFrontFileObject
{
FilePathObject();
~FilePathObject();
FilePathObject(int id, QString name, QString filename, int filetype);
- FilePathObject(int id, QString name, QString filename, int filetype, Platform*, MediaType*);
+ FilePathObject(int id, QString name, QString filename, int filetype, Setup*);
FilePathObject(const FilePathObject &);
FilePathObject& operator=(const FilePathObject &);
- Platform* getPlatform() const
- { return platform; }
- MediaType* getMediaType() const
- { return mediaType; }
- void setPlatform(Platform *plf)
- { platform = plf; }
- void setMediaType(MediaType *med)
- { mediaType = med; }
+ Setup* getSetup() const;
+ void setSetup(Setup *);
private:
- Platform *platform;
- MediaType *mediaType;
-
+ Setup *setup;
};
#endif // FILEPATHOBJECT_H
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Foobar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+
+#include "setup.h"
+#include "platform.h"
+#include "mediatype.h"
+
+Setup::Setup() : EmuFrontObject()
+{
+}
+
+Setup::Setup(int id, Platform *plf, MediaType *mt, QStringList fileTypeExtensions)
+ : EmuFrontObject(id,
+ QString("%1%2")
+ .arg(plf ? plf->getName() : "")
+ .arg(mt ? mt->getName() : "")),
+ fileTypeExtensions(fileTypeExtensions)
+{
+}
+
+Setup::~Setup()
+{
+ delete platform;
+ delete mediaType;
+}
+
+Setup::Setup(const Setup &s)
+ : EmuFrontObject(s.getId(), s.getName()),
+ fileTypeExtensions(s.fileTypeExtensions)
+{
+ Platform *p = s.platform;
+ MediaType *m = s.mediaType;
+ platform = new Platform(*p);
+ mediaType = new MediaType(*m);
+}
+
+Setup& Setup::operator =(const Setup &sup)
+{
+ if (this == &sup) return *this;
+ id = sup.id;
+ name = sup.name;
+ if (platform) delete platform;
+ Platform *p = sup.platform;
+ MediaType *m = sup.mediaType;
+ platform = new Platform(*p);
+ if (mediaType) delete mediaType;
+ mediaType = new MediaType(*m);
+ return (*this);
+}
+
+Platform* Setup::getPlatform() const
+{ return platform; }
+void Setup::setPlatform(Platform *plf)
+{ platform = plf; }
+
+MediaType* Setup::getMediaType() const
+{ return mediaType; }
+void Setup::setMediaType(MediaType *mt)
+{ mediaType = mt; }
+
+QStringList Setup::getSupportedFileTypeExtensions() const
+{ return fileTypeExtensions; }
+void Setup::setSupportedFileTypeExtensions(QStringList ftx)
+{ fileTypeExtensions = ftx; }
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Foobar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef SETUP_H
+#define SETUP_H
+#include <QStringList>
+#include "emufrontobject.h"
+
+class Platform;
+class MediaType;
+
+class Setup : public EmuFrontObject
+{
+public:
+ Setup();
+ ~Setup();
+ Setup(int id, Platform *, MediaType *, QStringList fileTypeExtensions);
+ Setup(const Setup &);
+ Setup& operator=(const Setup &);
+ Platform* getPlatform() const;
+ MediaType* getMediaType() const;
+ QStringList getSupportedFileTypeExtensions() const;
+ void setPlatform(Platform *);
+ void setMediaType(MediaType *);
+ void setSupportedFileTypeExtensions(QStringList);
+
+
+private:
+ Platform *platform;
+ MediaType *mediaType;
+ // QStringList is implicitly shared.
+ QStringList fileTypeExtensions;
+};
+
+#endif // SETUP_H
const QString DatabaseManager::DB_TABLE_NAME_MEDIATYPE = QString("mediatype");
const QString DatabaseManager::DB_TABLE_NAME_PLATFORM = QString("platform");
const QString DatabaseManager::DB_TABLE_NAME_FILEPATH = QString("filepath");
+const QString DatabaseManager::DB_TABLE_NAME_SETUP = QString("setup");
DatabaseManager::DatabaseManager(QObject *parent)
: QObject(parent)
// be destroyed when parent is destroyed
}
+QSqlQueryModel* DatabaseManager::getDataModel()
+{
+ return sqlTableModel;
+}
+
bool DatabaseManager::openDB()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
return path;
}
-void DatabaseManager::resetModel() const
+void DatabaseManager::resetModel()
{
if (!sqlTableModel) return;
- sqlTableModel->setFilter("");
- sqlTableModel->select();
+ clearFilters();
}
// sql must return a count(*) value
return numEntries;
}
-EmuFrontObject* DatabaseManager::getDataObject(int id) const
+EmuFrontObject* DatabaseManager::getDataObject(int id)
{
- sqlTableModel->setFilter(QString("id = %1").arg(id));
- sqlTableModel->select();
+ filterById(id);
EmuFrontObject *plf = 0;
if (sqlTableModel->rowCount() == 1)
{
class QSqlError;
class QFile;
-class QSqlTableModel;
+class QSqlQueryModel;
class QModelIndex;
class EmuFrontObject;
DatabaseManager(QObject *parent = 0);
~DatabaseManager();
- virtual QSqlTableModel* getDataModel() = 0;
+ QSqlQueryModel* getDataModel();
EmuFrontObject* getDataObjectFromModel(QModelIndex*);
- EmuFrontObject* getDataObject(int id) const;
+ EmuFrontObject* getDataObject(int id);
virtual bool updateDataObjectToModel(const EmuFrontObject*) = 0;
virtual bool insertDataObjectToModel(const EmuFrontObject*) = 0;
virtual bool deleteDataObjectFromModel(QModelIndex*) = 0;
virtual int countDataObjectRefs(int id) const = 0;
static bool openDB();
- void resetModel() const;
+ void resetModel();
enum {
Filetype_MediaImageContainer = 0,
Filetype_Screenshot = 1,
Filetype_MediaTypeIcon = 3 };
protected:
- QSqlTableModel* sqlTableModel;
- //virtual QSqlTableModel* getDataModel() = 0;
+ QSqlQueryModel* sqlTableModel;
virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ) const = 0;
+ virtual void filterById(int id) = 0;
+ virtual void clearFilters() = 0;
int countRows(QString tableName, QString columnName, int id) const;
static const QString DB_TABLE_NAME_FILEPATH;
static const QString DB_TABLE_NAME_MEDIATYPE;
static const QString DB_TABLE_NAME_PLATFORM;
+ static const QString DB_TABLE_NAME_SETUP;
private:
static const QString DB_FILENAME;
static const QString DATABASE;
- virtual QSqlTableModel* getData() = 0;
+ virtual QSqlQueryModel* getData() = 0;
static QString getDbPath();
};
query.exec("drop table if exists mediaimage");
query.exec("drop table if exists mediaimagecontainer");
query.exec("drop table if exists filepath");
+ query.exec("drop table if exists setup");
query.exec("drop table if exists mediatype");
query.exec("drop table if exists platform");
if (!ret) throw QString("mediatype.");
+ qDebug() << "Creating table setup";
+
+ ret = query.exec("create table if not exists setup "
+ "(id integer primary key, "
+ "platformid integer, "
+ "mediatypeid integer, "
+ "filetypeextensions text, "
+ "foreign key (platformid) references platform(id), "
+ "foreign key (mediatypeid) references mediatype(id))");
+
/*qDebug() << "Creating table filetype";
ret = query.exec("create table filetype if not exists"
"(id integer primary key, "
"(id integer primary key, "
"name text, "
"filetypeid integer, "
- "platformid integer, "
- "mediatypeid integer, "
+ "setupid integer, "
"lastscanned numeric, "
- "foreign key (platformid) references platform(id), "
- "foreign key (mediatypeid) references mediatype(id))");
+ "foreign key (setupid) references setup(id))");
if (!ret) throw QString("filepath");
#include <QSqlRelationalTableModel>
#include <QSqlRecord>
+#include <QSqlQuery>
#include "../dataobjects/filepathobject.h"
#include "dbfilepath.h"
-#include "dbplatform.h"
-#include "dbmediatype.h"
+#include "dbsetup.h"
-DbFilePath::DbFilePath(QObject *parent) : DatabaseManager(parent)
+DbFilePath::DbFilePath(QObject *parent) : DbQueryModelManager(parent)
{
- dbPlatform = new DbPlatform(this);
- dbMediaType = new DbMediaType(this);
+ dbSetup = new DbSetup(this);
sqlTableModel = getData();
}
-QSqlTableModel* DbFilePath::getDataModel()
-{
- return sqlTableModel;
-}
-
EmuFrontObject* DbFilePath::recordToDataObject(const QSqlRecord *rec) const
{
int id = rec->value(FilePath_Id).toInt();
QString fpath = rec->value(FilePath_Name).toString();
- int plfId = rec->value(FilePath_PlatformId).toInt();
- int mtId = rec->value(FilePath_MediaTypeId).toInt();
+ int setupId = rec->value(FilePath_SetupId).toInt();
int fileType = rec->value(FilePath_FileTypeId).toInt();
- Platform *plf = dynamic_cast<Platform*>(dbPlatform->getDataObject(plfId));
- MediaType *mt = dynamic_cast<MediaType*>(dbMediaType->getDataObject(mtId));
+ Setup *sup = dynamic_cast<Setup*>(dbSetup->getDataObject(setupId));
// TODO
//int lastScanned = 0;
- return new FilePathObject(id, fpath, fpath, fileType, plf, mt);
+ return new FilePathObject(id, fpath, fpath, fileType, sup);
}
bool DbFilePath::updateDataObjectToModel(const EmuFrontObject *ob)
{
const FilePathObject *fpo = dynamic_cast<const FilePathObject*>(ob);
bool ret = false;
- sqlTableModel->setFilter(QString("id = %1").arg(fpo->getId()));
+ QSqlQuery query;
+ query.prepare(QString("UPDATE filepath SET "
+ "name=:name, "
+ "filetypeid=:filetypeid, "
+ "setupid=:setupid, "
+ "lastscanned=:lastscanned "
+ "WHERE id=:id"));
+ query.bindValue(":name", fpo->getName());
+ query.bindValue(":filetypeid", fpo->getFiletype());
+ query.bindValue(":lastscanned", 0); // TODO
+ query.bindValue(":id", fpo->getId());
+ ret = query.exec();
+ if (ret) resetModel();
+ /*sqlTableModel->setFilter(QString("id = %1").arg(fpo->getId()));
sqlTableModel->select();
if (sqlTableModel->rowCount() == 1)
{
QSqlRecord rec = sqlTableModel->record(0);
rec.setValue("name", fpo->getName());
- rec.setValue("filetypeid", fpo->getFiletype());
+ rec.setValue("filetypeid", fpo->getFilet.bype());
- Platform *pl = fpo->getPlatform();
- MediaType *mt = fpo->getMediaType();
- if (pl) rec.setValue("platformid", pl->getId());
- if (mt) rec.setValue("mediatypeid", mt->getId());
+ Setup *sup = fpo->getSetup();
+ if (sup) rec.setValue("setupid", sup->getId());
// TODO
//rec.setValue("lastscanned", 0);
- }
+ }*/
return ret;
}
bool DbFilePath::insertDataObjectToModel(const EmuFrontObject *ob)
{
const FilePathObject *fpo = dynamic_cast<const FilePathObject*>(ob);
- int row = 0;
+ QSqlQuery query;
+ query.prepare("INSERT INTO filepath (id, name, filetypeid, setupid, lastscanned) "
+ "VALUES (NULL, :name, :filetypeid, :setupid, :lastscanned) ");
+ query.bindValue(":name", fpo->getName());
+ query.bindValue(":filetypeid", fpo->getFiletype());
+ if (fpo->getSetup())
+ query.bindValue(":setupid", fpo->getSetup()->getId());
+ query.bindValue(":lastscanned", 0); // TODO
+ return query.exec();
+ /*int row = 0;
+
sqlTableModel->insertRows(row, 1);
- Platform *pl = fpo->getPlatform();
- MediaType *mt = fpo->getMediaType();
+
+ Setup *sup = fpo->getSetup();
+ //Platform *pl = fpo->getPlatform();
+ //MediaType *mt = fpo->getMediaType();
//sqlTableModel->setData(sqlTableModel->index(row, FilePath_Id), NULL);
sqlTableModel->setData(sqlTableModel->index(row, FilePath_Name), fpo->getName());
sqlTableModel->setData(sqlTableModel->index(row, FilePath_FileTypeId), fpo->getFiletype());
// not all the file path types have platform and/or media type
- if (pl) sqlTableModel->setData(sqlTableModel->index(row, FilePath_PlatformId), pl->getId());
- if (mt) sqlTableModel->setData(sqlTableModel->index(row, FilePath_MediaTypeId), mt->getId());
+ //if (pl) sqlTableModel->setData(sqlTableModel->index(row, FilePath_PlatformId), pl->getId());
+ //if (mt) sqlTableModel->setData(sqlTableModel->index(row, FilePath_MediaTypeId), mt->getId());
+ if (sup) sqlTableModel->setData(sqlTableModel->index(row, FilePath_SetupId), sup->getId());
// TODO:
sqlTableModel->setData(sqlTableModel->index(row, FilePath_LastScanned), 0);
- return sqlTableModel->submitAll();
+ return sqlTableModel->submitAll();*/
}
int DbFilePath::countDataObjectRefs(int id) const
return false;
}
-QSqlTableModel* DbFilePath::getData()
+QString DbFilePath::constructSelect(QString whereClause) const
+{
+ QString where = whereClause.isEmpty()
+ ? "" : QString("WHERE ").append(whereClause);
+
+ return QString("SELECT filepath.id AS FilePathId, "
+ "filepath.name AS Name, "
+ "filepath.lastscanned AS LastScanned, "
+ "setup.id AS SetupId, "
+ "platform.name || ' ' || mediatype.name AS SetupName "
+ "FROM filepath "
+ "INNER JOIN setup ON filepath.setupid=setup.id "
+ "INNER JOIN platform ON setup.platformid=platform.id "
+ "INNER JOIN mediatype ON setup.mediatypeid=mediatype.id "
+ "%1 "
+ "ORDER BY SetupName").arg(where);
+}
+
+QString DbFilePath::constructSelectById(int id) const
{
- QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this);
- model->setTable(DB_TABLE_NAME_FILEPATH);
- model->setRelation(FilePath_PlatformId,
+ return constructSelect(QString("filepath.id = %1").arg(id));
+}
+
+QSqlQueryModel* DbFilePath::getData()
+{
+ QSqlQueryModel *model = new QSqlQueryModel;
+ model->setQuery(constructSelect());
+ model->setHeaderData(FilePath_Id, Qt::Horizontal, tr("Id"));
+ model->setHeaderData(FilePath_Name, Qt::Horizontal, tr("Name"));
+ model->setHeaderData(FilePath_LastScanned, Qt::Horizontal, tr("Last scanned"));
+ model->setHeaderData(FilePath_SetupId, Qt::Horizontal, tr("Set up id"));
+ model->setHeaderData(FilePath_SetupName, Qt::Horizontal, tr("Set up"));
+ return model;
+
+ //"platform.name, mediatype.name
+ /*QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this);
+ model->setTable(DB_TABLE_NAME_FILEPATH);*/
+ /*model->setRelation(FilePath_PlatformId,
QSqlRelation(DB_TABLE_NAME_PLATFORM, "id", "name"));
model->setRelation(FilePath_MediaTypeId,
- QSqlRelation(DB_TABLE_NAME_MEDIATYPE, "id", "name"));
- model->setSort(FilePath_Name, Qt::AscendingOrder);
- model->setHeaderData(FilePath_MediaTypeId, Qt::Horizontal, tr("Media type"));
- model->setHeaderData(FilePath_PlatformId, Qt::Horizontal, tr("Platform"));
- model->select();
- return model;
+ QSqlRelation(DB_TABLE_NAME_MEDIATYPE, "id", "name"e));*/
+ /*model->setRelation(FilePath_SetupId,
+ QSqlRelation(DB_TABLE_NAME_SETUP, "id", ""));
+ model->setSort(FilePath_Name, Qt::AscendingOrder);*/
+
+ //model->setHeaderData(FilePath_MediaTypeId, Qt::Horizontal, tr("Media type"));
+ //model->setHeaderData(FilePath_PlatformId, Qt::Horizontal, tr("Platform"));
+ /*model->select();
+ return model;*/
}
#ifndef DBFILEPATH_H
#define DBFILEPATH_H
-#include "databasemanager.h"
+#include "dbquerymodelmanager.h"
-class DbPlatform;
-class DbMediaType;
+class DbSetup;
-class DbFilePath : public DatabaseManager
+class DbFilePath : public DbQueryModelManager
{
public:
DbFilePath(QObject *);
- virtual QSqlTableModel* getDataModel();
virtual bool updateDataObjectToModel(const EmuFrontObject*);
bool insertDataObjectToModel(const EmuFrontObject*);
bool deleteDataObjectFromModel(QModelIndex*);
protected:
virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ) const;
+ virtual QString constructSelectById(int id) const;
+ virtual QString constructSelect(QString whereClause = "") const;
private:
- virtual QSqlTableModel* getData();
- DbPlatform *dbPlatform;
- DbMediaType *dbMediaType;
+ virtual QSqlQueryModel* getData();
+ DbSetup *dbSetup;
// TODO: add last scanned column
enum { FilePath_Id = 0,
FilePath_Name,
FilePath_FileTypeId,
- FilePath_PlatformId,
- FilePath_MediaTypeId,
- FilePath_LastScanned };
+ FilePath_LastScanned,
+ FilePath_SetupId,
+ FilePath_SetupName };
};
#endif // DBFILEPATH_H
#include "../dataobjects/mediatype.h"
-DbMediaType::DbMediaType(QObject *parent) : DatabaseManager(parent)
+DbMediaType::DbMediaType(QObject *parent) : DbTableModelManager(parent)
{
sqlTableModel = getData();
}
-QSqlTableModel* DbMediaType::getDataModel()
-{
- return sqlTableModel;
-}
-
EmuFrontObject* DbMediaType::recordToDataObject(const QSqlRecord *record) const
{
int id = record->value(MediaType_Id).toInt();
{
const MediaType *plf = dynamic_cast<const MediaType*>(ob);
bool ret = false;
- sqlTableModel->setFilter(QString("id = %1").arg(plf->getId()));
- sqlTableModel->select();
- if (sqlTableModel->rowCount() == 1)
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ tmodel->setFilter(QString("id = %1").arg(plf->getId()));
+ tmodel->select();
+ if (tmodel->rowCount() == 1)
{
QSqlRecord record = sqlTableModel->record(0);
record.setValue("name", plf->getName());
record.setValue("filename", plf->getFilename());
- sqlTableModel->setRecord(0, record);
- ret = sqlTableModel->submitAll();
+ tmodel->setRecord(0, record);
+ ret = tmodel->submitAll();
}
resetModel();
return ret;
{
const MediaType *plf = dynamic_cast<const MediaType*>(ob);
int row = 0;
- sqlTableModel->insertRows(row, 1);
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ tmodel->insertRows(row, 1);
// the null value for index will be set implicitily
// when we don't assign any value to cell 0 in the sql table model
//sqlTableModel->setData(sqlTableModel->index(row, 0), NULL);
- sqlTableModel->setData(sqlTableModel->index(row, MediaType_Name), plf->getName());
- sqlTableModel->setData(sqlTableModel->index(row, MediaType_Filename), plf->getFilename());
- return sqlTableModel->submitAll();
+ tmodel->setData(sqlTableModel->index(row, MediaType_Name), plf->getName());
+ tmodel->setData(sqlTableModel->index(row, MediaType_Filename), plf->getFilename());
+ return tmodel->submitAll();
}
int DbMediaType::countDataObjectRefs(int id) const
bool DbMediaType::deleteDataObjectFromModel(QModelIndex *index)
{
QSqlDatabase::database().transaction();
- QSqlRecord record = sqlTableModel->record(index->row());
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ QSqlRecord record = tmodel->record(index->row());
int id = record.value(MediaType_Id).toInt();
qDebug() << "Deleting mediatype " << id;
int count = countDataObjectRefs(id);
return false;
}
}
- sqlTableModel->removeRow(index->row());
- sqlTableModel->submitAll();
+ tmodel->removeRow(index->row());
+ tmodel->submitAll();
return QSqlDatabase::database().commit();
}
-QSqlTableModel* DbMediaType::getData()
+QSqlQueryModel* DbMediaType::getData()
{
QSqlTableModel *model = new QSqlTableModel(this);
model->setTable(DB_TABLE_NAME_MEDIATYPE);
model->select();
return model;
}
+
#ifndef DBMEDIATYPE_H
#define DBMEDIATYPE_H
-#include "databasemanager.h"
+#include "dbtablemodelmanager.h"
+#include "../dataobjects/mediatype.h"
-class DbMediaType : public DatabaseManager
+class DbMediaType : public DbTableModelManager
{
public:
DbMediaType(QObject *);
- virtual QSqlTableModel* getDataModel();
virtual bool updateDataObjectToModel(const EmuFrontObject*);
virtual bool insertDataObjectToModel(const EmuFrontObject*);
virtual bool deleteDataObjectFromModel(QModelIndex*);
virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ) const;
private:
- virtual QSqlTableModel* getData();
+ virtual QSqlQueryModel* getData();
};
#include "dbplatform.h"
-DbPlatform::DbPlatform(QObject *parent) : DatabaseManager(parent)
+DbPlatform::DbPlatform(QObject *parent) : DbTableModelManager(parent)
{
sqlTableModel = getData();
}
-QSqlTableModel* DbPlatform::getDataModel()
-{
- return sqlTableModel;
-}
-
EmuFrontObject* DbPlatform::recordToDataObject(const QSqlRecord *record) const
{
int id = record->value(Platform_Id).toInt();
{
const Platform *plf = dynamic_cast<const Platform*>(ob);
bool ret = false;
- sqlTableModel->setFilter(QString("id = %1").arg(plf->getId()));
- sqlTableModel->select();
- if (sqlTableModel->rowCount() == 1)
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ tmodel->setFilter(QString("id = %1").arg(plf->getId()));
+ tmodel->select();
+ if (tmodel->rowCount() == 1)
{
- QSqlRecord record = sqlTableModel->record(0);
+ QSqlRecord record = tmodel->record(0);
record.setValue("name", plf->getName());
record.setValue("filename", plf->getFilename());
- sqlTableModel->setRecord(0, record);
- ret = sqlTableModel->submitAll();
+ tmodel->setRecord(0, record);
+ ret = tmodel->submitAll();
}
resetModel();
return ret;
{
const Platform *plf = dynamic_cast<const Platform*>(ob);
int row = 0;
- sqlTableModel->insertRows(row, 1);
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ tmodel->insertRows(row, 1);
// the null value for index will be set implicitily
// when we don't assign any value to cell 0 in the sql table model
//sqlTableModel->setData(sqlTableModel->index(row, 0), NULL);
- sqlTableModel->setData(sqlTableModel->index(row, 1), plf->getName());
- sqlTableModel->setData(sqlTableModel->index(row, 2), plf->getFilename());
- return sqlTableModel->submitAll();
+ tmodel->setData(sqlTableModel->index(row, 1), plf->getName());
+ tmodel->setData(sqlTableModel->index(row, 2), plf->getFilename());
+ return tmodel->submitAll();
}
int DbPlatform::countDataObjectRefs(int id) const
bool DbPlatform::deleteDataObjectFromModel(QModelIndex *index)
{
QSqlDatabase::database().transaction();
- QSqlRecord record = sqlTableModel->record(index->row());
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ QSqlRecord record = tmodel->record(index->row());
int id = record.value(Platform_Id).toInt();
qDebug() << "Deleting platform " << id;
int count = countDataObjectRefs(id);
return false;
}
}
- sqlTableModel->removeRow(index->row());
- sqlTableModel->submitAll();
+ tmodel->removeRow(index->row());
+ tmodel->submitAll();
return QSqlDatabase::database().commit();
}
-QSqlTableModel* DbPlatform::getData()
+QSqlQueryModel* DbPlatform::getData()
{
QSqlTableModel *model = new QSqlTableModel(this);
model->setTable(DB_TABLE_NAME_PLATFORM);
model->select();
return model;
}
+
+/*void DbPlatform::filterById(int id)
+{
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ tmodel->setFilter(QString("id = %1").arg(id));
+ tmodel->setQuery(constructSelectById(id));
+ tmodel->select();
+}*/
#ifndef DBPLATFORM_H
#define DBPLATFORM_H
-#include "databasemanager.h"
+#include "dbtablemodelmanager.h"
#include "../dataobjects/platform.h"
class QModelIndex;
-class DbPlatform : public DatabaseManager
+class DbPlatform : public DbTableModelManager
{
public:
DbPlatform(QObject *);
- virtual QSqlTableModel* getDataModel();
virtual bool updateDataObjectToModel(const EmuFrontObject*);
bool insertDataObjectToModel(const EmuFrontObject*);
bool deleteDataObjectFromModel(QModelIndex*);
virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ) const;
private:
- virtual QSqlTableModel* getData();
+ virtual QSqlQueryModel* getData();
};
#endif // DBPLATFORM_H
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Foobar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+
+#include <QSqlQueryModel>
+#include "dbquerymodelmanager.h"
+
+
+DbQueryModelManager::DbQueryModelManager(QObject *parent)
+ : DatabaseManager(parent)
+{
+}
+
+void DbQueryModelManager::filterById(int id)
+{
+ sqlTableModel->setQuery(constructSelectById(id));
+}
+
+void DbQueryModelManager::clearFilters()
+{
+ sqlTableModel->setQuery(constructSelect());
+}
+
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Foobar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef DBQUERYMODELMANAGER_H
+#define DBQUERYMODELMANAGER_H
+
+#include "databasemanager.h"
+
+class DbQueryModelManager : public DatabaseManager
+{
+public:
+ DbQueryModelManager(QObject *parent);
+protected:
+ void filterById(int id);
+ void clearFilters();
+ virtual QString constructSelectById(int id) const = 0;
+ virtual QString constructSelect(QString whereClause = "") const = 0;
+};
+
+#endif // DBQUERYMODELMANAGER_H
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Foobar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+
+#include <QStringList>
+#include <QSqlRecord>
+#include <QSqlQuery>
+#include <QSqlRelationalTableModel>
+#include "dbsetup.h"
+#include "dbplatform.h"
+#include "dbmediatype.h"
+
+const QString DbSetup::FILE_TYPE_EXTENSION_SEPARATOR = QString("|");
+
+DbSetup::DbSetup(QObject *parent) : DbQueryModelManager(parent)
+{
+ dbPlatform = new DbPlatform(this);
+ dbMediaType = new DbMediaType(this);
+ sqlTableModel = getData();
+}
+
+EmuFrontObject* DbSetup::recordToDataObject(const QSqlRecord *rec) const
+{
+ int id = rec->value(Setup_Id).toInt();
+ QString extensions = rec->value(Setup_FileTypeExtensions).toString();
+ QStringList list = extensions.split(FILE_TYPE_EXTENSION_SEPARATOR);
+ int plfId = rec->value(Setup_PlatformId).toInt();
+ int mtId = rec->value(Setup_MediaTypeId).toInt();
+ Platform *plf = dynamic_cast<Platform*>(dbPlatform->getDataObject(plfId));
+ MediaType *mt = dynamic_cast<MediaType*>(dbMediaType->getDataObject(mtId));
+ return new Setup(id, plf, mt, list);
+}
+
+bool DbSetup::updateDataObjectToModel(const EmuFrontObject *ob)
+{
+ const Setup *fpo = dynamic_cast<const Setup*>(ob);
+ bool ret = false;
+ QSqlQuery query;
+ query.prepare(QString("UPDATE setup SET "
+ "platformid=:platformid, "
+ "mediatypeid=:mediatypeid, "
+ "filetypeextensions:=filetypeextensions "
+ "WHERE id = :id"));
+ if (fpo->getPlatform())
+ query.bindValue(":platformid", fpo->getPlatform()->getId());
+ if (fpo->getMediaType())
+ query.bindValue(":mediatypeid", fpo->getMediaType()->getId());
+ query.bindValue(":filetypeextensions", fpo->getSupportedFileTypeExtensions().join(FILE_TYPE_EXTENSION_SEPARATOR));
+ query.bindValue(":id", fpo->getId());
+ query.exec();
+
+ /*sqlTableModel->setFilter(QString("id = %1").arg(fpo->getId()));
+ sqlTableModel->select();
+ if (sqlTableModel->rowCount() == 1)
+ {
+ QSqlRecord rec = sqlTableModel->record(0);
+ rec.setValue("filetypeid", fpo->getFiletype());
+
+ Platform *pl = fpo->getPlatform();
+ MediaType *mt = fpo->getMediaType();
+ if (pl) rec.setValue("platformid", pl->getId());
+ if (mt) rec.setValue("mediatypeid", mt->getId());
+
+ QStringList list = fpo->getSupportedFileTypeExtensions();
+ if (list.count() > 0)
+ rec.setValue("filetypeextensions", list.join(FILE_TYPE_EXTENSION_SEPARATOR));
+ }*/
+ return ret;
+}
+
+bool DbSetup::insertDataObjectToModel(const EmuFrontObject *ob)
+{
+ const Setup *fpo = dynamic_cast<const Setup*>(ob);
+ QSqlQuery query;
+ query.prepare("INSERT INTO setup (id, platformid, mediatypeid, fileextensions)"
+ "VALUES (NULL, :platformid, :mediatypeid, :fileextensions)");
+ if (fpo->getPlatform())
+ query.bindValue(":platformid", fpo->getPlatform()->getId());
+ if (fpo->getMediaType())
+ query.bindValue(":mediatypeid", fpo->getMediaType()->getId());
+ query.bindValue(":filetypeextensions", fpo->getSupportedFileTypeExtensions().join(FILE_TYPE_EXTENSION_SEPARATOR));
+ return query.exec();
+
+ /*int row = 0;
+ sqlTableModel->insertRows(row, 1);
+
+ Platform *pl = fpo->getPlatform();
+ MediaType *mt = fpo->getMediaType();
+
+ //sqlTableModel->setData(sqlTableModel->index(row, FilePath_Id), NULL);
+ // not all the file path types have platform and/or media type
+ if (pl) sqlTableModel->setData(sqlTableModel->index(row, Setup_PlatformId), pl->getId());
+ if (mt) sqlTableModel->setData(sqlTableModel->index(row, Setup_MediaTypeId), mt->getId());
+ QStringList list = fpo->getSupportedFileTypeExtensions();
+ if (list.count() > 0)
+ sqlTableModel->setData(sqlTableModel->index(row, Setup_FileTypeExtensions), list.join(FILE_TYPE_EXTENSION_SEPARATOR));
+ return sqlTableModel->submitAll();*/
+}
+
+int DbSetup::countDataObjectRefs(int ) const
+{
+ return 0;
+}
+
+QString DbSetup::constructSelect(QString whereClause) const
+{
+ QString where = whereClause.isEmpty()
+ ? "" : QString("WHERE ").append(whereClause);
+ return QString(
+ "SELECT setup.id AS SetupId, "
+ "setup.platformid AS PlatformId, "
+ "setup.mediatypeid AS MediaTypeId, "
+ "setup.filetypeextensions AS SupportedFileTypeExtensions, "
+ "platform.name || ' ' || mediatype.name AS SetupName, "
+ "FROM setup %1"
+ "INNER JOIN platform ON setup.platformid=platform.id "
+ "INNER JOIN mediatype ON setup.mediatypeid=mediatype.id "
+ "ORDER BY SetupName"
+ ).arg(where);
+}
+
+QString DbSetup::constructSelectById(int id) const
+{
+ return constructSelect(QString("setup.id = %1").arg(id));
+}
+
+// WARNING: this will delete also all the databindings to selected media image path
+bool DbSetup::deleteDataObjectFromModel(QModelIndex */*index*/)
+{
+ return false;
+}
+
+QSqlQueryModel* DbSetup::getData()
+{
+ QSqlQueryModel *model = new QSqlQueryModel;
+ model->setQuery(constructSelect());
+ model->setHeaderData(Setup_Id, Qt::Horizontal, tr("Id"));
+ model->setHeaderData(Setup_PlatformId, Qt::Horizontal, tr("Platform id"));
+ model->setHeaderData(Setup_MediaTypeId, Qt::Horizontal, tr("Media type id"));
+ model->setHeaderData(Setup_FileTypeExtensions, Qt::Horizontal, tr("File types"));
+ model->setHeaderData(Setup_Name, Qt::Horizontal, tr("Name"));
+ return model;
+
+ /*QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this);
+ model->setTable(DB_TABLE_NAME_FILEPATH);
+ model->setRelation(FilePath_PlatformId,
+ QSqlRelation(DB_TABLE_NAME_PLATFORM, "id", "name"));
+ model->setRelation(FilePath_MediaTypeId,
+ QSqlRelation(DB_TABLE_NAME_MEDIATYPE, "id", "name"));
+ model->setSort(FilePath_Name, Qt::AscendingOrder);
+ model->setHeaderData(FilePath_MediaTypeId, Qt::Horizontal, tr("Media type"));
+ model->setHeaderData(FilePath_PlatformId, Qt::Horizontal, tr("Platform"));
+ model->select();
+ return model;*/
+}
+
+/*void DbMediaType::filterById(int id)
+{
+ sqlTableModel->setQuery(constructSelectById(id));
+}*/
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Foobar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef DBSETUP_H
+#define DBSETUP_H
+
+#include "dbquerymodelmanager.h"
+#include "../dataobjects/setup.h"
+
+class DbPlatform;
+class DbMediaType;
+
+class DbSetup : public DbQueryModelManager
+{
+public:
+ DbSetup(QObject *);
+ virtual bool updateDataObjectToModel(const EmuFrontObject*);
+ bool insertDataObjectToModel(const EmuFrontObject*);
+ bool deleteDataObjectFromModel(QModelIndex*);
+ int countDataObjectRefs(int) const;
+ enum { Setup_Id = 0,
+ Setup_PlatformId,
+ Setup_MediaTypeId,
+ Setup_FileTypeExtensions,
+ Setup_Name };
+ static const QString FILE_TYPE_EXTENSION_SEPARATOR;
+
+protected:
+ virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ) const;
+ virtual QString constructSelectById(int id) const;
+ virtual QString constructSelect(QString whereClause = "") const;
+
+private:
+ virtual QSqlQueryModel* getData();
+ DbPlatform *dbPlatform;
+ DbMediaType *dbMediaType;
+};
+#endif // DBSETUP_H
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Foobar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+
+#include <QSqlTableModel>
+#include "dbtablemodelmanager.h"
+
+DbTableModelManager::DbTableModelManager(QObject *parent)
+ : DatabaseManager(parent)
+{
+}
+
+void DbTableModelManager::filterById(int id)
+{
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ tmodel->setFilter(QString("id = %1").arg(id));
+ tmodel->select();
+}
+
+void DbTableModelManager::clearFilters()
+{
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ tmodel->setFilter("");
+ tmodel->select();
+}
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Foobar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef DBTABLEMODELMANAGER_H
+#define DBTABLEMODELMANAGER_H
+
+#include "databasemanager.h"
+
+class DbTableModelManager : public DatabaseManager
+{
+public:
+ DbTableModelManager(QObject *parent);
+protected:
+ void filterById(int id);
+ void clearFilters();
+};
+
+#endif // DBTABLEMODELMANAGER_H
void DbObjectDialog::updateList() const
{
if (!dbManager) return;
+ qDebug() << "Going to reset the data model";
dbManager->resetModel();
}
#include <QSqlRecord>
#include "../db/dbplatform.h"
#include "../db/dbmediatype.h"
+#include "../db/dbsetup.h"
#include "mediaimagepathdialog.h"
-#include "../dataobjects/platform.h"
-#include "../dataobjects/mediatype.h"
+//#include "../dataobjects/platform.h"
+//#include "../dataobjects/mediatype.h"
#include "../dataobjects/filepathobject.h"
MediaImagePathDialog::MediaImagePathDialog(QWidget *parent, EmuFrontObject *efObject)
{
qDebug() << "Creating MediaImagePathDialog";
initWidgets();
- populateMediaTypeComBox();
- populatePlatformComBox();
+ //populateMediaTypeComBox();
+ //populatePlatformComBox();
+ dbPlatform = 0;
+ dbMediaType = 0;
connectSignals();
layout();
}
// these widgets will be automatically parented using layout components
filePathLabel = new QLabel;
filePathButton = new QPushButton(tr("&Browse filepath"));
- mediaTypeComBox = new QComboBox;
- platformComBox = new QComboBox;
+ /*mediaTypeComBox = new QComboBox;
+ platformComBox = new QComboBox;*/
+ setupComBox = new QComboBox;
}
-void MediaImagePathDialog::populateMediaTypeComBox()
+void MediaImagePathDialog::populateSetupComBox()
+{
+ qDebug() << "MediaImagePathDialog populating media types combo box";
+ dbSetup = new DbSetup(this);
+ setupComBox->setModel(dbSetup->getDataModel());
+ setupComBox->setModelColumn(DbSetup::Setup_Name);
+}
+
+/*void MediaImagePathDialog::populateMediaTypeComBox()
{
qDebug() << "MediaImagePathDialog populating media types combo box";
dbMediaType = new DbMediaType(this);
dbPlatform = new DbPlatform(this);
platformComBox->setModel(dbPlatform->getDataModel());
platformComBox->setModelColumn(DbPlatform::Platform_Name);
-}
+}*/
void MediaImagePathDialog::layout()
{
qDebug() << "MediaImagePathDialog setting layout";
- QLabel *platformLabel = new QLabel(tr("&Platform"));
+ /*QLabel *platformLabel = new QLabel(tr("&Platform"));
platformLabel->setBuddy(platformComBox);
QLabel *mediaTypeLabel = new QLabel(tr("Media&Type"));
- mediaTypeLabel->setBuddy(mediaTypeComBox);
+ mediaTypeLabel->setBuddy(mediaTypeComBox);*/
+ QLabel *setupLabel = new QLabel(tr("&Set up"));
+ setupLabel->setBuddy(setupComBox);
QGridLayout *gridLayout = new QGridLayout;
- gridLayout->addWidget(platformLabel, 0, 0);
+ /*gridLayout->addWidget(platformLabel, 0, 0);
gridLayout->addWidget(platformComBox, 0, 1);
gridLayout->addWidget(mediaTypeLabel, 1, 0);
- gridLayout->addWidget(mediaTypeComBox, 1, 1);
- gridLayout->addWidget(filePathButton, 2, 0);
- gridLayout->addWidget(filePathLabel, 2, 1);
+ gridLayout->addWidget(mediaTypeComBox, 1, 1);*/
+ gridLayout->addWidget(setupLabel, 0, 0);
+ gridLayout->addWidget(setupComBox, 0, 1);
+ gridLayout->addWidget(filePathButton, 1, 0);
+ gridLayout->addWidget(filePathLabel, 1, 1);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(gridLayout);
mainLayout->addWidget(buttonBox);
FilePathObject *fpo = dynamic_cast<FilePathObject*>(ob);
QString fpath = fpo->getName();
filePathLabel->setText(fpath);
- if (fpo->getPlatform()) setSelectedPlatform(fpo->getPlatform());
- if (fpo->getMediaType()) setSelectedMediaType(fpo->getMediaType());
+ if (fpo->getSetup()) setSelectedSetup(fpo->getSetup());
+ /*if (fpo->getPlatform()) setSelectedPlatform(fpo->getPlatform());
+ if (fpo->getMediaType()) setSelectedMediaType(fpo->getMediaType());*/
+}
+
+void MediaImagePathDialog::setSelectedSetup(const Setup *sup)
+{
+ setSelected(setupComBox, sup, DbSetup::Setup_Id);
}
-void MediaImagePathDialog::setSelectedPlatform(const Platform *plf)
+/*void MediaImagePathDialog::setSelectedPlatform(const Platform *plf)
{
setSelected(platformComBox, plf, DbPlatform::Platform_Id);
}
void MediaImagePathDialog::setSelectedMediaType(const MediaType *plf)
{
setSelected(mediaTypeComBox, plf, DbMediaType::MediaType_Id);
-}
+}*/
// TODO: this might be useful to lever to upper classes
void MediaImagePathDialog::setSelected(QComboBox *cbox, const EmuFrontObject *ob, int idIndex)
}
}
-Platform* MediaImagePathDialog::getSelectedPlatform() const
+Setup* MediaImagePathDialog::getSelectedSetup()
+{
+ if (!dbPlatform) dbPlatform = new DbPlatform(this);
+ if (!dbMediaType) dbMediaType = new DbMediaType(this);
+ qDebug() << "MediaImagePathDialog Selecting setup";
+ Setup *sup = 0;
+ int index = setupComBox->currentIndex();
+ qDebug() << "Current index " << index;
+ if (index < 0) return sup;
+ QSqlQueryModel *model
+ = dynamic_cast<QSqlQueryModel*>(setupComBox->model());
+ if (!model)
+ {
+ qDebug() << "Data model missing";
+ return sup;
+ }
+ QSqlRecord rec = model->record(index);
+ if (!rec.isEmpty())
+ {
+ qDebug() << "We have a record";
+ EmuFrontObject *efPlf = dbPlatform->getDataObject(rec.value(DbSetup::Setup_PlatformId).toInt());
+ EmuFrontObject *efMt = dbMediaType->getDataObject(rec.value(DbSetup::Setup_MediaTypeId).toInt());
+
+ Platform *plf = dynamic_cast<Platform*>(efPlf);
+ MediaType *mt = dynamic_cast<MediaType*>(efMt);
+ QString exts = rec.value(DbSetup::Setup_FileTypeExtensions).toString();
+
+ sup = new Setup(rec.value(DbSetup::Setup_Id).toInt(), plf, mt,
+ exts.split(DbSetup::FILE_TYPE_EXTENSION_SEPARATOR));
+ }
+ else qDebug() << "Record missing";
+ return sup;
+}
+/*Platform* MediaImagePathDialog::getSelectedPlatform() const
{
qDebug() << "MediaImagePathDialog Selecting platform";
Platform *plf = 0;
rec.value(DbMediaType::MediaType_Name).toString(),
rec.value(DbMediaType::MediaType_Filename).toString());
return mt;
-}
+}*/
void MediaImagePathDialog::acceptChanges()
{
qDebug() << "Changes accepted";
FilePathObject *fpo = dynamic_cast<FilePathObject*>(efObject);
- Platform *plf = getSelectedPlatform();
+ Setup *sup = getSelectedSetup();
+ if (!sup)
+ {
+ QMessageBox::information(this, tr("Set up"), tr("Set up not selected"), QMessageBox::Ok);
+ return;
+ }
+ qDebug() << "Setup selected " << sup->getName();
+ /*Platform *plf = getSelectedPlatform();
if (!plf)
{
QMessageBox::information(this, tr("Platform"), tr("Platform not selected"), QMessageBox::Ok);
QMessageBox::information(this, tr("Media type"), tr("Media type was not selected"), QMessageBox::Ok);
return;
}
- qDebug() << "Media type selected " << mt->getName();
+ qDebug() << "Media type selected " << mt->getName();*/
QString filePath = filePathLabel->text();
if (filePath.isEmpty())
{
return;
}
qDebug() << "File path selected " << filePath;
- Platform *ptmp = fpo->getPlatform();
+ Setup *tmp = fpo->getSetup();
+ if (sup != tmp)
+ {
+ delete tmp;
+ fpo->setSetup(sup);
+ }
+ /*Platform *ptmp = fpo->getPlatform();
if (plf != ptmp)
{
delete ptmp;
{
delete mtmp;
fpo->setMediaType(mt);
- }
+ }*/
fpo->setName(filePath);
emit dataObjectUpdated();
efObject = 0;
class QLabel;
class QPushButton;
class QSqlTableModel;
+class DbSetup;
+class Setup;
class DbMediaType;
class DbPlatform;
-class MediaType;
-class Platform;
+/* class MediaType;
+class Platform;*/
class MediaImagePathDialog : public DataObjectEditDialog
{
void browseFilePath();
private:
- QComboBox *mediaTypeComBox;
- QComboBox *platformComBox;
+ //QComboBox *mediaTypeComBox;
+ //QComboBox *platformComBox;
+ QComboBox *setupComBox;
QLabel *filePathLabel;
QPushButton *filePathButton;
+ DbSetup *dbSetup;
DbMediaType *dbMediaType;
DbPlatform *dbPlatform;
void initWidgets();
void layout();
void connectSignals();
- void populateMediaTypeComBox();
- void populatePlatformComBox();
- void setSelectedMediaType(const MediaType *);
- void setSelectedPlatform(const Platform *);
+ void populateSetupComBox();
+ //void populateMediaTypeComBox();
+ //void populatePlatformComBox();
+ void setSelectedSetup(const Setup *);
+ //void setSelectedMediaType(const MediaType *);
+ //void setSelectedPlatform(const Platform *);
void setSelected(QComboBox*, const EmuFrontObject*, int idIndex);
- Platform* getSelectedPlatform() const;
- MediaType* getSelectedMediaType() const;
+ Setup* getSelectedSetup();
+ //Platform* getSelectedPlatform() const;
+ //MediaType* getSelectedMediaType() const;
};
db/dbfilepath.h \
utils/ziputil.h \
utils/fileutil.h \
- utils/OSDaB-Zip/unzip.h
+ utils/OSDaB-Zip/unzip.h \
+ dataobjects/setup.h \
+ db/dbsetup.h \
+ db/dbtablemodelmanager.h \
+ db/dbquerymodelmanager.h
SOURCES += main.cpp \
mainwindow.cpp \
db/databasemanager.cpp \
db/dbfilepath.cpp \
utils/ziputil.cpp \
utils/fileutil.cpp \
- utils/OSDaB-Zip/unzip.cpp
+ utils/OSDaB-Zip/unzip.cpp \
+ dataobjects/setup.cpp \
+ db/dbsetup.cpp \
+ db/dbtablemodelmanager.cpp \
+ db/dbquerymodelmanager.cpp
+
+OTHER_FILES +=