Started implementing better MVC support: thanks Petro for the idea! ;)
authorMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 30 Nov 2010 22:42:30 +0000 (00:42 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 30 Nov 2010 22:42:30 +0000 (00:42 +0200)
12 files changed:
src/db/emufrontquerymodel.cpp [new file with mode: 0644]
src/db/emufrontquerymodel.h [new file with mode: 0644]
src/db/platformmodel.cpp [new file with mode: 0644]
src/db/platformmodel.h [new file with mode: 0644]
src/dialogs/dbobjectdialog.cpp
src/dialogs/emufrontdatadialog.cpp [new file with mode: 0644]
src/dialogs/emufrontdatadialog.h [new file with mode: 0644]
src/dialogs/platformmaindialog.cpp [new file with mode: 0644]
src/dialogs/platformmaindialog.h [new file with mode: 0644]
src/emufront.pro
src/mainwindow.cpp
src/mainwindow.h

diff --git a/src/db/emufrontquerymodel.cpp b/src/db/emufrontquerymodel.cpp
new file mode 100644 (file)
index 0000000..9d99e46
--- /dev/null
@@ -0,0 +1,25 @@
+// 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 version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// 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 "emufrontquerymodel.h"
+
+EmuFrontQueryModel::EmuFrontQueryModel(QObject *parent) :
+    QSqlQueryModel(parent)
+{
+}
diff --git a/src/db/emufrontquerymodel.h b/src/db/emufrontquerymodel.h
new file mode 100644 (file)
index 0000000..5e56c18
--- /dev/null
@@ -0,0 +1,39 @@
+// 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 version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// 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 EMUFRONTQUERYMODEL_H
+#define EMUFRONTQUERYMODEL_H
+
+#include <QSqlQueryModel>
+
+class EmuFrontQueryModel : public QSqlQueryModel
+{
+    Q_OBJECT
+public:
+    EmuFrontQueryModel(QObject *parent = 0);
+
+signals:
+
+public slots:
+
+protected:
+    QString tableName;
+};
+
+#endif // EMUFRONTQUERYMODEL_H
diff --git a/src/db/platformmodel.cpp b/src/db/platformmodel.cpp
new file mode 100644 (file)
index 0000000..328755b
--- /dev/null
@@ -0,0 +1,96 @@
+// 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 version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// 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 <QtSql>
+#include "platformmodel.h"
+
+PlatformModel::PlatformModel(QObject *parent) :
+    EmuFrontQueryModel(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();
+}
+
diff --git a/src/db/platformmodel.h b/src/db/platformmodel.h
new file mode 100644 (file)
index 0000000..f7703e4
--- /dev/null
@@ -0,0 +1,55 @@
+// 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 version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// 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 PLATFORMMODEL_H
+#define PLATFORMMODEL_H
+
+#include "emufrontquerymodel.h"
+
+class PlatformModel : public EmuFrontQueryModel
+{
+    Q_OBJECT
+public:
+    PlatformModel(QObject *parent = 0);
+    Qt::ItemFlags flags(const QModelIndex &index) const;
+    bool setData(const QModelIndex &index, const QVariant &value, int role);
+    enum {
+        EmuFrontFileObject_Id,
+        EmuFrontFileObject_Name,
+        EmuFrontFileObject_FileId,
+        EmuFrontFileObject_FileName,
+        EmuFrontFileObject_FileType,
+        EmuFrontFileObject_FileCheckSum,
+        EmuFrontFileObject_FileSize,
+        EmuFrontFileObject_FileUpdateTime
+    };
+
+signals:
+
+public slots:
+
+private:
+
+    void refresh();
+    QString constructSelect(QString where = "") const;
+    bool setName(int id, const QString &name);
+
+};
+
+#endif // PLATFORMMODEL_H
index 46e0ca1..aa57aa1 100644 (file)
@@ -56,7 +56,7 @@ DbObjectDialog::~DbObjectDialog()
 
 void DbObjectDialog::connectSignals()
 {
-    connect(buttonBox, SIGNAL(accepted()), this, SLOT(close()));
+    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
     connect(objectList, SIGNAL(clicked(const QModelIndex &)),
         this, SLOT(listObjectClicked(const QModelIndex &)));
     connect(editButton, SIGNAL(clicked()), this, SLOT(editButtonClicked()));
diff --git a/src/dialogs/emufrontdatadialog.cpp b/src/dialogs/emufrontdatadialog.cpp
new file mode 100644 (file)
index 0000000..2529c1a
--- /dev/null
@@ -0,0 +1,85 @@
+// 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 version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// 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 <QtGui>
+#include "emufrontdatadialog.h"
+
+EmuFrontDataDialog::EmuFrontDataDialog(QWidget *parent) :
+    EmuFrontDialog(parent)
+{
+    editButton = new QPushButton(tr("&Edit"));
+    editButton->setEnabled(false);
+    addButton = new QPushButton(tr("&Add"));
+    deleteButton = new QPushButton(tr("&Delete"));
+    deleteButton->setEnabled(false);
+    objectList = new QTableView(this);
+    buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Vertical);
+    buttonBox->addButton(editButton, QDialogButtonBox::ActionRole);
+    buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
+    buttonBox->addButton(deleteButton, QDialogButtonBox::ActionRole);
+    // this be called from the implementing classes:
+    //connectSignals();
+    layout();
+}
+
+void EmuFrontDataDialog::postInit()
+{
+    connectSignals();
+    setHiddenColumns();
+    hideColumns();
+}
+
+void EmuFrontDataDialog::layout()
+{
+    QHBoxLayout *mainLayout = new QHBoxLayout;
+    mainLayout->addWidget(objectList);
+    mainLayout->addWidget(buttonBox);
+    setLayout(mainLayout);
+}
+
+void EmuFrontDataDialog::hideColumns()
+{
+    foreach(int c, hiddenColumns)
+        objectList->hideColumn(c);
+}
+
+void EmuFrontDataDialog::connectSignals()
+{
+    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+    /*connect(objectList, SIGNAL(clicked(const QModelIndex &)),
+        this, SLOT(listObjectClicked(const QModelIndex &)));*/
+    connect(editButton, SIGNAL(clicked()), this, SLOT(editButtonClicked()));
+    connect(addButton, SIGNAL(clicked()), this, SLOT(addButtonClicked()));
+    connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteButtonClicked()));
+}
+
+void EmuFrontDataDialog::editButtonClicked()
+{
+    qDebug() << "Edit button clicked";
+}
+
+void EmuFrontDataDialog::deleteButtonClicked()
+{
+    qDebug() << "Delete button clicked";
+}
+
+void EmuFrontDataDialog::addButtonClicked()
+{
+    qDebug() << "Delete button clicked";
+}
diff --git a/src/dialogs/emufrontdatadialog.h b/src/dialogs/emufrontdatadialog.h
new file mode 100644 (file)
index 0000000..ede863a
--- /dev/null
@@ -0,0 +1,58 @@
+// 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 version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// 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 EMUFRONTDATADIALOG_H
+#define EMUFRONTDATADIALOG_H
+
+#include "emufrontdialog.h"
+#include "db/emufrontquerymodel.h"
+
+class QDialogButtonBox;
+class QTableView;
+
+class EmuFrontDataDialog : public EmuFrontDialog
+{
+    Q_OBJECT
+public:
+    EmuFrontDataDialog(QWidget *parent = 0);
+
+private slots:
+    void editButtonClicked();
+    void addButtonClicked();
+    void deleteButtonClicked();
+
+protected:
+    EmuFrontQueryModel *model;
+    QList<int> hiddenColumns;
+    QDialogButtonBox *buttonBox;
+    QTableView *objectList;
+    void postInit();
+
+private:
+    QPushButton *editButton;
+    QPushButton *addButton;
+    QPushButton *deleteButton;
+    void layout();
+    virtual void setHiddenColumns() = 0;
+    void hideColumns();
+    virtual void connectSignals();
+
+};
+
+#endif // EMUFRONTDATADIALOG_H
diff --git a/src/dialogs/platformmaindialog.cpp b/src/dialogs/platformmaindialog.cpp
new file mode 100644 (file)
index 0000000..e4951bc
--- /dev/null
@@ -0,0 +1,38 @@
+// 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 version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// 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 <QtGui>
+#include "platformmaindialog.h"
+#include "db/platformmodel.h"
+
+PlatformMainDialog::PlatformMainDialog(QWidget *parent) :
+    EmuFrontDataDialog(parent)
+{
+    model = new PlatformModel(this);
+    objectList->setModel(model);
+    postInit();
+}
+
+void PlatformMainDialog::setHiddenColumns()
+{
+    hiddenColumns << PlatformModel::EmuFrontFileObject_Id;
+    hiddenColumns << PlatformModel::EmuFrontFileObject_FileId;
+    hiddenColumns << PlatformModel::EmuFrontFileObject_FileType;
+    hiddenColumns << PlatformModel::EmuFrontFileObject_FileCheckSum;
+}
diff --git a/src/dialogs/platformmaindialog.h b/src/dialogs/platformmaindialog.h
new file mode 100644 (file)
index 0000000..61eef7d
--- /dev/null
@@ -0,0 +1,36 @@
+// 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 version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// 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 PLATFORMMAINDIALOG_H
+#define PLATFORMMAINDIALOG_H
+
+#include "emufrontdatadialog.h"
+
+
+class PlatformMainDialog : public EmuFrontDataDialog
+{
+    Q_OBJECT
+public:
+    PlatformMainDialog(QWidget *parent = 0);
+private:
+    virtual void setHiddenColumns();
+
+  };
+
+#endif // PLATFORMMAINDIALOG_H
index 25b0c13..5f3365f 100644 (file)
@@ -70,7 +70,11 @@ HEADERS += mainwindow.h \
     dialogs/browsefilepathdialog.h \
     db/dbconfig.h \
     utils/datfileutil.h \
-    widgets/fileextensionwidget.h
+    widgets/fileextensionwidget.h \
+    db/platformmodel.h \
+    dialogs/platformmaindialog.h \
+    dialogs/emufrontdatadialog.h \
+    db/emufrontquerymodel.h
 SOURCES += main.cpp \
     mainwindow.cpp \
     db/databasemanager.cpp \
@@ -128,7 +132,11 @@ SOURCES += main.cpp \
     dialogs/browsefilepathdialog.cpp \
     db/dbconfig.cpp \
     utils/datfileutil.cpp \
-    widgets/fileextensionwidget.cpp
+    widgets/fileextensionwidget.cpp \
+    db/platformmodel.cpp \
+    dialogs/platformmaindialog.cpp \
+    dialogs/emufrontdatadialog.cpp \
+    db/emufrontquerymodel.cpp
 OTHER_FILES +=  
 
 CONFIG += mobility
index 928ea76..eecab39 100644 (file)
@@ -21,6 +21,7 @@
 #include "mainwindow.h"
 #include "emulauncher.h"
 #include "dialogs/platformdialog.h"
+#include "dialogs/platformmaindialog.h"
 #include "dialogs/mediatypedialog.h"
 #include "dialogs/mediaimagepathmaindialog.h"
 #include "dialogs/setupmaindialog.h"
@@ -72,7 +73,12 @@ void MainWindow::createActions()
     configPlatformAction = new QAction(tr("&Platforms"), this);
     configPlatformAction->setStatusTip(tr("Configure platforms"));
     connect(configPlatformAction, SIGNAL(triggered()),
-           this, SLOT(configurePlatforms()));
+        this, SLOT(configurePlatforms()));
+
+    configPlatformsAction = new QAction(tr("&Set Platforms"), this);
+    configPlatformsAction->setStatusTip(tr("Add, edit and delete platforms"));
+    connect(configPlatformsAction, SIGNAL(triggered()),
+        this, SLOT(configurePlatformss()));
 
     configMediaTypeAction = new QAction(tr("&Media Types"), this);
     configMediaTypeAction->setStatusTip(tr("Configure media types"));
@@ -123,6 +129,13 @@ void MainWindow::configurePlatforms()
    activateDialog(platformDialog);
 }
 
+void MainWindow::configurePlatformss()
+{
+    plfDialog = new PlatformMainDialog(this);
+    connect(plfDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
+    activateDialog(plfDialog);
+}
+
 void MainWindow::configureMediaTypes()
 {
     if (!mediaTypeDialog)
@@ -222,6 +235,7 @@ void MainWindow::createMenus()
     configMenu->addAction(configTmpDirAction);
     configMenu->addSeparator();
     configMenu->addAction(configPlatformAction);
+    configMenu->addAction(configPlatformsAction);
     configMenu->addAction(configMediaTypeAction);
     configMenu->addAction(configSetupAction);
     configMenu->addAction(configMediaImagePathAction);
index 4ab5e36..10f2d94 100644 (file)
@@ -24,6 +24,7 @@
 
 class QAction;
 class PlatformDialog;
+class PlatformMainDialog;
 class MediaTypeDialog;
 class MediaImagePathMainDialog;
 class SetupMainDialog;
@@ -48,7 +49,8 @@ protected:
        void closeEvent(QCloseEvent *event);
 
 private slots:
-       void configurePlatforms();
+    void configurePlatforms();
+    void configurePlatformss();
     void configureMediaTypes();
     void configureMediaImagePaths();
     void configureSetups();
@@ -72,7 +74,8 @@ private:
     void activateDialog(EmuFrontDialog*) const;
     bool testDB(bool reset);
     void createDB() const;
-       PlatformDialog *platformDialog;
+    PlatformDialog *platformDialog;
+    PlatformMainDialog *plfDialog;
     MediaTypeDialog *mediaTypeDialog;
     MediaImagePathMainDialog *mediaImagePathDialog;
     SetupMainDialog *setupMainDialog;
@@ -82,6 +85,7 @@ private:
     QMenu *fileMenu;
     QMenu *helpMenu;
     QAction *configPlatformAction;
+    QAction *configPlatformsAction;
     QAction *configMediaTypeAction;
     QAction *configMediaImagePathAction;
     QAction *configSetupAction;