Initial implementation of Setup model and view (new generation).
authorMikko Keinänen <mikko.keinanen@gmail.com>
Fri, 3 Dec 2010 21:40:11 +0000 (23:40 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Fri, 3 Dec 2010 21:40:11 +0000 (23:40 +0200)
doc/models.dia [new file with mode: 0644]
src/db/emufrontfileobjectmodel.h
src/db/setupmodel.cpp [new file with mode: 0644]
src/db/setupmodel.h [new file with mode: 0644]
src/dialogs/emufrontdatadialog.cpp
src/dialogs/emufrontdatadialog.h
src/dialogs/setupmainview.cpp [new file with mode: 0644]
src/dialogs/setupmainview.h [new file with mode: 0644]
src/emufront.pro
src/mainwindow.cpp
src/mainwindow.h

diff --git a/doc/models.dia b/doc/models.dia
new file mode 100644 (file)
index 0000000..ac61d21
Binary files /dev/null and b/doc/models.dia differ
index 3a8a4f5..5b8aaad 100644 (file)
@@ -27,10 +27,10 @@ class EmuFrontFileObjectModel : public EmuFrontQueryModel
     Q_OBJECT
 public:
     EmuFrontFileObjectModel(QObject *parent = 0);
-    Qt::ItemFlags flags(const QModelIndex &index) const;
-    bool setData(const QModelIndex &index, const QVariant &value, int role);
-    bool insertRows(int row, int count, const QModelIndex &parent);
-    bool removeRows(int row, int count, const QModelIndex &parent);
+    virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+    virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
+    virtual bool insertRows(int row, int count, const QModelIndex &parent);
+    virtual bool removeRows(int row, int count, const QModelIndex &parent);
     enum {
         EmuFrontFileObject_Id,
         EmuFrontFileObject_Name,
@@ -43,9 +43,9 @@ public:
     };
 
 protected:
-    void refresh();
-    QString constructSelect(QString where = "") const;
-    bool setName(int id, const QString &name);
+    virtual void refresh();
+    virtual QString constructSelect(QString where = "") const;
+    virtual bool setName(int id, const QString &name);
 };
 
 #endif // EMUFRONTFILEOBJECTMODEL_H
diff --git a/src/db/setupmodel.cpp b/src/db/setupmodel.cpp
new file mode 100644 (file)
index 0000000..cea5ccc
--- /dev/null
@@ -0,0 +1,51 @@
+// 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 "setupmodel.h"
+
+SetupModel::SetupModel(QObject *parent) :
+    EmuFrontQueryModel(parent)
+{
+    refresh();
+}
+
+void SetupModel::refresh()
+{
+    setQuery(constructSelect());
+    setHeaderData(Setup_Id, Qt::Horizontal, tr("Id"));
+    setHeaderData(Setup_PlatformId, Qt::Horizontal, tr("Platform id"));
+    setHeaderData(Setup_MediaTypeId, Qt::Horizontal, tr("Media type id"));
+    setHeaderData(Setup_FileTypeExtensions, Qt::Horizontal, tr("File types"));
+    setHeaderData(Setup_Name, Qt::Horizontal, tr("Name"));
+}
+
+QString SetupModel::constructSelect(QString where) const
+{
+    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 "
+        "INNER JOIN platform ON setup.platformid=platform.id "
+        "INNER JOIN mediatype ON setup.mediatypeid=mediatype.id %1 "
+        "ORDER BY SetupName"
+        ).arg(where);
+}
diff --git a/src/db/setupmodel.h b/src/db/setupmodel.h
new file mode 100644 (file)
index 0000000..036a016
--- /dev/null
@@ -0,0 +1,42 @@
+// 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 SETUPMODEL_H
+#define SETUPMODEL_H
+
+#include "emufrontquerymodel.h"
+
+class SetupModel : public EmuFrontQueryModel
+{
+    Q_OBJECT
+public:
+    SetupModel(QObject *parent = 0);
+    enum { Setup_Id = 0,
+           Setup_PlatformId,
+           Setup_MediaTypeId,
+           Setup_FileTypeExtensions,
+           Setup_Name };
+    static const QString FILE_TYPE_EXTENSION_SEPARATOR;
+
+protected:
+    virtual void refresh();
+    virtual QString constructSelect(QString where = "") const;
+};
+
+#endif // SETUPMODEL_H
index 0d54504..65b5635 100644 (file)
@@ -110,3 +110,8 @@ void EmuFrontDataDialog::setButtonsEnabled(bool b)
     editButton->setEnabled(b);
     deleteButton->setEnabled(b);
 }
+
+void EmuFrontDataDialog::setHiddenColumns()
+{
+    // default implementation
+}
index 1809dd0..302591d 100644 (file)
@@ -50,7 +50,7 @@ private:
     QPushButton *addButton;
     QPushButton *deleteButton;
     void layout();
-    virtual void setHiddenColumns() = 0;
+    virtual void setHiddenColumns();
     void hideColumns();
     virtual void connectSignals();
     void setButtonsEnabled(bool);
diff --git a/src/dialogs/setupmainview.cpp b/src/dialogs/setupmainview.cpp
new file mode 100644 (file)
index 0000000..f05d987
--- /dev/null
@@ -0,0 +1,30 @@
+// 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 "setupmainview.h"
+#include "db/setupmodel.h"
+
+SetupMainView::SetupMainView(QWidget *parent) :
+    EmuFrontDataDialog(parent)
+{
+    model = new SetupModel(this);
+    objectList->setModel(model);
+    postInit();
+}
diff --git a/src/dialogs/setupmainview.h b/src/dialogs/setupmainview.h
new file mode 100644 (file)
index 0000000..11b299f
--- /dev/null
@@ -0,0 +1,37 @@
+// 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 SETUPMAINVIEW_H
+#define SETUPMAINVIEW_H
+
+#include "emufrontdatadialog.h"
+
+class SetupMainView : public EmuFrontDataDialog
+{
+    Q_OBJECT
+public:
+    SetupMainView(QWidget *parent = 0);
+
+signals:
+
+public slots:
+
+};
+
+#endif // SETUPMAINVIEW_H
index e12e98a..5f51636 100644 (file)
@@ -78,7 +78,9 @@ HEADERS += mainwindow.h \
     db/emufrontfileobjectmodel.h \
     db/mediatypemodel.h \
     dialogs/emufrontfileobjectmaindialog.h \
-    dialogs/mediatypemaindialog.h
+    dialogs/mediatypemaindialog.h \
+    db/setupmodel.h \
+    dialogs/setupmainview.h
 SOURCES += main.cpp \
     mainwindow.cpp \
     db/databasemanager.cpp \
@@ -144,7 +146,9 @@ SOURCES += main.cpp \
     db/emufrontfileobjectmodel.cpp \
     db/mediatypemodel.cpp \
     dialogs/emufrontfileobjectmaindialog.cpp \
-    dialogs/mediatypemaindialog.cpp
+    dialogs/mediatypemaindialog.cpp \
+    db/setupmodel.cpp \
+    dialogs/setupmainview.cpp
 OTHER_FILES +=  
 
 CONFIG += mobility
index 858aede..af3a8d0 100644 (file)
@@ -27,7 +27,9 @@
 // TODO: deprecated
 #include "dialogs/mediatypemaindialog.h"
 #include "dialogs/mediaimagepathmaindialog.h"
+// TODO: deprecated
 #include "dialogs/setupmaindialog.h"
+#include "dialogs/setupmainview.h"
 #include "dialogs/executablemaindialog.h"
 #include "utils/datfileutil.h"
 #include "db/databasemanager.h"
@@ -67,7 +69,9 @@ MainWindow::MainWindow(bool reset)
     mediaTypeDialog = 0;
     mdtDialog = 0;
     mediaImagePathDialog = 0;
+    // TODO: deprecated
     setupMainDialog = 0;
+    setupMainView = 0;
     executableMainDialog = 0;
 }
 
@@ -102,10 +106,15 @@ void MainWindow::createActions()
     connect(configMediaImagePathAction, SIGNAL(triggered()),
         this, SLOT(configureMediaImagePaths()));
 
+    // TODO: deprecated
     configSetupAction = new QAction(tr("S&etups"), this);
     configSetupAction->setStatusTip(tr("Configure set ups"));
     connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));
 
+    configSetupsAction = new QAction(tr("Configure S&etups"), this);
+    configSetupsAction->setStatusTip(tr("Add, edit and delete setups"));
+    connect(configSetupsAction, SIGNAL(triggered()), this, SLOT(configureSetupss()));
+
     configEmulatorAction = new QAction(tr("Em&ulators"), this);
     configEmulatorAction->setStatusTip(tr("Configure emulators"));
     connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));
@@ -183,17 +192,26 @@ void MainWindow::configureMediaImagePaths()
     activateDialog(mediaImagePathDialog);
 }
 
+// TODO: deprecated
 void MainWindow::configureSetups()
 {
     if (!setupMainDialog)
     {
-        qDebug() << "MainWindow: Creating a setup main dialog.";
         setupMainDialog = new SetupMainDialog(this);
     }
     activateDialog(setupMainDialog);
     setupMainDialog->refreshDataModel();
 }
 
+void MainWindow::configureSetupss()
+{
+    if (!setupMainView) {
+        setupMainView = new SetupMainView(this);
+    }
+    activateDialog(setupMainView);
+}
+
+
 void MainWindow::configureEmulators()
 {
     if (!executableMainDialog) {
@@ -268,7 +286,9 @@ void MainWindow::createMenus()
     // TODO: deprecated
     configMenu->addAction(configMediaTypeAction);
     configMenu->addAction(configMediaTypesAction);
+    // TODO: deprecated
     configMenu->addAction(configSetupAction);
+    configMenu->addAction(configSetupsAction);
     configMenu->addAction(configMediaImagePathAction);
     configMenu->addAction(configEmulatorAction);
     configMenu->addSeparator();
index 0c824c5..6e92c67 100644 (file)
@@ -31,7 +31,9 @@ class MediaTypeMainDialog;
 class MediaTypeDialog;
 class MediaTypeMainDialog;
 class MediaImagePathMainDialog;
+// TODO: DEPRECATED
 class SetupMainDialog;
+class SetupMainView;
 class ExecutableMainDialog;
 //class TmpFolderEditDialog;
 class QLabel;
@@ -60,7 +62,9 @@ private slots:
     void configureMediaTypes();
     void configureMediaTypess();
     void configureMediaImagePaths();
+    // TODO: DEPRECATED
     void configureSetups();
+    void configureSetupss();
     void configureEmulators();
     void configureTmpDir();
     void resetDb();
@@ -89,7 +93,9 @@ private:
     MediaTypeDialog *mediaTypeDialog;
     MediaTypeMainDialog *mdtDialog;
     MediaImagePathMainDialog *mediaImagePathDialog;
+    // TODO: deprecated
     SetupMainDialog *setupMainDialog;
+    SetupMainView *setupMainView;
     ExecutableMainDialog *executableMainDialog;
     //TmpFolderEditDialog *tmpFolderDialog;
        QMenu *configMenu;
@@ -102,7 +108,9 @@ private:
     QAction *configMediaTypeAction;
     QAction *configMediaTypesAction;
     QAction *configMediaImagePathAction;
+    // TODO: deprecated
     QAction *configSetupAction;
+    QAction *configSetupsAction;
     QAction *configEmulatorAction;
     QAction *exitAction;
     QAction *resetDbAction;