// be destroyed when parent is destroyed
}
-QSqlQueryModel* DatabaseManager::getDataModel()
+QSqlQueryModel* DatabaseManager::getDataModel(bool update)
{
- if (!sqlTableModel) sqlTableModel = getData();
+ if (!sqlTableModel || (sqlTableModel && !update)) sqlTableModel = getData();
return sqlTableModel;
}
DatabaseManager(QObject *parent = 0);
~DatabaseManager();
- QSqlQueryModel* getDataModel();
+ QSqlQueryModel* getDataModel(bool update = false);
EmuFrontObject* getDataObjectFromModel(QModelIndex*);
EmuFrontObject* getDataObject(int id);
EmuFrontObject* getDataObject(QString filter);
connect(buttonBox, SIGNAL(rejected()), this, SLOT(rejectChanges()));
}
+// TODO: remove this after implementing in EFComboBox
void DataObjectEditDialog::setSelected(QComboBox *cbox, const EmuFrontObject *ob, int idIndex)
{
if (!ob) return;
emit updateRejected();
close();
}
+
+void DataObjectEditDialog::updateData()
+{
+}
public:
DataObjectEditDialog(QWidget *parent, EmuFrontObject *ob, Qt::Orientation orientation = Qt::Horizontal);
virtual void setDataObject(EmuFrontObject *) = 0;
+ virtual void updateData();
protected:
virtual void connectSignals();
if (!nameDialog) return;
nameDialog->show();
nameDialog->raise();
+ nameDialog->updateData();
nameDialog->activateWindow();
}
qDebug() << "Setting name to " << efObject->getName();
nameEdit->setText(efObject->getName());
}
+
#include <QSqlRecord>
#include "setupeditdialog.h"
#include "../widgets/stringlistwidget.h"
+#include "../widgets/effileobjectcombobox.h"
#include "../db/dbmediatype.h"
#include "../db/dbplatform.h"
#include "../db/dbsetup.h"
: DataObjectEditDialog(parent, obj)
{
dbSetup = 0; //new DbSetup(this);
- dbPlatform = 0; //new DbPlatform(this);
- dbMediaType = 0; //new DbMediaType(this);
+ dbPlatform = new DbPlatform(this);
+ dbMediaType = new DbMediaType(this);
initWidgets();
qDebug() << "Connecting signals";
connectSignals();
void SetupEditDialog::initWidgets()
{
- mediaTypeComBox = new QComboBox;
- platformComBox = new QComboBox;
+ mediaTypeComBox = new EFFileObjectComboBox(dbMediaType, this); //new QComboBox;
+ platformComBox = new EFFileObjectComboBox(dbPlatform, this); //new QComboBox;
supportedFileTypesList = new StringListWidget;
- populateMediaTypeComBox();
- populatePlatformComBox();
+ //populateMediaTypeComBox();
+ //populatePlatformComBox();
}
-void SetupEditDialog::populateMediaTypeComBox()
+/*void SetupEditDialog::populateMediaTypeComBox()
{
qDebug() << "populating media types combo box";
if (!dbMediaType) dbMediaType = new DbMediaType(this);
platformComBox->setModel(model);
platformComBox->setModelColumn(DbPlatform::EmuFrontFileObject_Name);
qDebug() << "platform combo box populated";
-}
+}*/
void SetupEditDialog::layout()
{
void SetupEditDialog::setSelectedPlatform(const Platform *plf)
{
- setSelected(platformComBox, plf, DbPlatform::EmuFrontFileObject_Id);
+ //setSelected(platformComBox, plf, DbPlatform::EmuFrontFileObject_Id);
+ platformComBox->setSelected(plf);
}
void SetupEditDialog::setSelectedMediaType(const MediaType *plf)
{
- setSelected(mediaTypeComBox, plf, DbMediaType::EmuFrontFileObject_Id);
+ //setSelected(mediaTypeComBox, plf, DbMediaType::EmuFrontFileObject_Id);
+ mediaTypeComBox->setSelected(plf);
}
Platform* SetupEditDialog::getSelectedPlatform() const
{
- Platform *plf = 0;
+ /*Platform *plf = 0;
int index = platformComBox->currentIndex();
qDebug() << "Platform from index " << index << " selected";
if (index < 0)
EmuFrontObject *o
= dbPlatform->getDataObject(rec.value(DbPlatform::EmuFrontFileObject_Id).toInt());
plf = dynamic_cast<Platform*>(o);
- }
+ }*/
+
+ EmuFrontObject *o = platformComBox->getSelected();
+ if (!o) return 0;
+ Platform *plf = dynamic_cast<Platform*>(o);
return plf;
}
MediaType* SetupEditDialog::getSelectedMediaType() const
{
- MediaType *mt = 0;
+ /*MediaType *mt = 0;
int index = mediaTypeComBox->currentIndex();
if (index < 0) return mt;
QSqlQueryModel* mediaTypeModel = dynamic_cast<QSqlQueryModel*>(mediaTypeComBox->model());
EmuFrontObject *o = dbMediaType->getDataObject(rec.value(DbMediaType::EmuFrontFileObject_Id).toInt());
mt = dynamic_cast<MediaType*>(o);
}
+ return mt;*/
+ EmuFrontObject *o = mediaTypeComBox->getSelected();
+ if (!o) return 0;
+ MediaType *mt = dynamic_cast<MediaType*>(o);
return mt;
}
+
+void SetupEditDialog::updateData()
+{
+ qDebug() << "Updating combobox data";
+ platformComBox->updateDataModel();
+ mediaTypeComBox->updateDataModel();
+}
#include "dataobjecteditdialog.h"
-class QComboBox;
+//class QComboBox;
+class EFFileObjectComboBox;
class DbSetup;
class DbMediaType;
class DbPlatform;
SetupEditDialog(QWidget *parent, EmuFrontObject*);
//~SetupEditDialog();
virtual void setDataObject(EmuFrontObject *);
+ virtual void updateData();
protected slots:
virtual void acceptChanges();
private:
- QComboBox *mediaTypeComBox;
- QComboBox *platformComBox;
+ //QComboBox *mediaTypeComBox;
+ EFFileObjectComboBox *mediaTypeComBox;
+ //QComboBox *platformComBox;
+ EFFileObjectComboBox *platformComBox;
DbSetup *dbSetup;
DbPlatform *dbPlatform;
DbMediaType *dbMediaType;
db/dbmediaimage.h \
utils/OSDaB-Zip/zipentry_p.h \
utils/OSDaB-Zip/unzip_p.h \
- emulauncher.h
+ emulauncher.h \
+ widgets/efcombobox.h \
+ widgets/effileobjectcombobox.h
SOURCES += main.cpp \
mainwindow.cpp \
db/databasemanager.cpp \
db/dbemufrontfileobject.cpp \
db/dbmediaimagecontainer.cpp \
db/dbmediaimage.cpp \
- emulauncher.cpp
+ emulauncher.cpp \
+ widgets/efcombobox.cpp \
+ widgets/effileobjectcombobox.cpp
OTHER_FILES +=
--- /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.
+//
+// EmuFront 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+
+#include "efcombobox.h"
+#include "../exceptions/emufrontexception.h"
+#include "../dataobjects/emufrontobject.h"
+#include <QSqlQueryModel>
+#include <QSqlRecord>
+#include <QDebug>
+
+EFComboBox::EFComboBox(DatabaseManager *dbMan, QWidget *parent)
+ : QComboBox(parent), dbManager(dbMan)
+{
+ if (!dbManager)
+ throw new EmuFrontException("Database manager is not available!");
+ updateDataModel();
+}
+
+EFComboBox::~EFComboBox()
+{
+}
+
+void EFComboBox::updateDataModel()
+{
+ QSqlQueryModel *model = dbManager->getDataModel();
+ if (model)
+ setModel(model);
+}
+
+EmuFrontObject* EFComboBox::getSelected() const
+{
+ EmuFrontObject *efo = 0;
+ int index = currentIndex();
+ qDebug() << "Selected index " << index << ".";
+ if (index < 0)
+ return 0;
+ QSqlQueryModel *qmodel
+ = dynamic_cast<QSqlQueryModel*>(model());
+ if (!qmodel) {
+ qDebug() << "No data model available!";
+ return 0;
+ }
+ QSqlRecord rec = qmodel->record(index);
+ if (rec.isEmpty()) {
+ qDebug() << "No record available!";
+ return efo;
+ }
+ qDebug() << "Fetching a data object with id "
+ << rec.value(dataModelIndex_id).toInt();
+ EmuFrontObject *o
+ = dbManager->getDataObject(rec.value(dataModelIndex_id).toInt());
+ return o;
+}
+
+void EFComboBox::setSelected(const EmuFrontObject *efo)
+{
+ if (!efo)
+ return;
+ QSqlQueryModel *qmodel
+ = dynamic_cast<QSqlQueryModel*>(model());
+ for (int i = 0; i < qmodel->rowCount(); i++){
+ QSqlRecord rec = qmodel->record(i);
+ if (rec.value(dataModelIndex_id) == efo->getId()){
+ setCurrentIndex(i);
+ break;
+ }
+ }
+
+}
--- /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.
+//
+// EmuFront 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef EFCOMBOBOX_H
+#define EFCOMBOBOX_H
+
+#include <QComboBox>
+#include "../db/databasemanager.h"
+
+class EFComboBox : public QComboBox
+{
+public:
+ EFComboBox(DatabaseManager *dbMan, QWidget *parent = 0);
+ ~EFComboBox();
+ EmuFrontObject* getSelected() const;
+ // This will replace DataObjectEditDialog::setSelected!
+ void setSelected(const EmuFrontObject*);
+ void updateDataModel();
+protected:
+ DatabaseManager *dbManager;
+ int dataModelIndex_id;
+ int dataModelIndex_name;
+};
+
+#endif // EFCOMBOBOX_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.
+//
+// EmuFront 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+
+#include "effileobjectcombobox.h"
+#include "../db/dbemufrontfileobject.h"
+
+EFFileObjectComboBox::EFFileObjectComboBox(DatabaseManager *dbMan, QWidget *parent)
+ : EFComboBox(dbMan, parent)
+{
+ dataModelIndex_id
+ = DbEmuFrontFileObject::EmuFrontFileObject_Id;
+ dataModelIndex_name
+ = DbEmuFrontFileObject::EmuFrontFileObject_Name;
+ setModelColumn(dataModelIndex_name);
+}
--- /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.
+//
+// EmuFront 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef EFFILEOBJECTCOMBOBOX_H
+#define EFFILEOBJECTCOMBOBOX_H
+
+#include "efcombobox.h"
+
+class EFFileObjectComboBox : public EFComboBox
+{
+public:
+ EFFileObjectComboBox(DatabaseManager *dbMan, QWidget *parent = 0);
+};
+
+#endif // EFFILEOBJECTCOMBOBOX_H