Added setup edit dialog and a string list widget. WARNING: The changes
authorMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 8 Jun 2010 22:08:00 +0000 (01:08 +0300)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 8 Jun 2010 22:08:00 +0000 (01:08 +0300)
were not tested at all!

src/dialogs/dataobjecteditdialog.cpp
src/dialogs/dataobjecteditdialog.h
src/dialogs/mediaimagepathdialog.cpp
src/dialogs/mediaimagepathdialog.h
src/dialogs/setupeditdialog.cpp [new file with mode: 0644]
src/dialogs/setupeditdialog.h [new file with mode: 0644]
src/emufront.pro
src/widgets/stringlistwidget.cpp [new file with mode: 0644]
src/widgets/stringlistwidget.h [new file with mode: 0644]

index 43e9e85..2ac6bcf 100644 (file)
@@ -18,6 +18,9 @@
 // along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <QDialogButtonBox>
+#include <QSqlQueryModel>
+#include <QSqlRecord>
+#include <QComboBox>
 #include "dataobjecteditdialog.h"
 
 DataObjectEditDialog::DataObjectEditDialog(QWidget *parent, EmuFrontObject *ob, Qt::Orientation orientation)
@@ -32,3 +35,18 @@ void DataObjectEditDialog::connectSignals()
     connect(buttonBox, SIGNAL(accepted()), this, SLOT(acceptChanges()));
     connect(buttonBox, SIGNAL(rejected()), this, SLOT(rejectChanges()));
 }
+
+void DataObjectEditDialog::setSelected(QComboBox *cbox, const EmuFrontObject *ob, int idIndex)
+{
+    if (!ob) return;
+    QSqlQueryModel *model = dynamic_cast<QSqlQueryModel*>(cbox->model());
+    for (int i = 0; i < model->rowCount(); ++i)
+    {
+        QSqlRecord rec = model->record(i);
+        if (rec.value(idIndex) == ob->getId())
+        {
+            cbox->setCurrentIndex(i);
+            break;
+        }
+    }
+}
index ffe74ce..b5400e4 100644 (file)
@@ -24,6 +24,7 @@
 #include "../dataobjects/emufrontobject.h"
 
 class QDialogButtonBox;
+class QComboBox;
 
 class DataObjectEditDialog : public EmuFrontDialog
 {
@@ -41,6 +42,7 @@ protected:
     virtual void connectSignals();
     EmuFrontObject *efObject;
     QDialogButtonBox *buttonBox;
+    void setSelected(QComboBox*, const EmuFrontObject*, int idIndex);
 
 protected slots:
     virtual void acceptChanges() =0;
index 4e2e84d..b479e1a 100644 (file)
@@ -155,21 +155,6 @@ 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)
-{
-    if (!ob) return;
-    QSqlTableModel *model = dynamic_cast<QSqlTableModel*>(cbox->model());
-    for (int i = 0; i < model->rowCount(); ++i)
-    {
-        QSqlRecord rec = model->record(i);
-        if (rec.value(idIndex) == ob->getId())
-        {
-            cbox->setCurrentIndex(i);
-            break;
-        }
-    }
-}
 
 Setup* MediaImagePathDialog::getSelectedSetup()
 {
index 7c07cec..ec9e75a 100644 (file)
@@ -67,7 +67,6 @@ private:
     void setSelectedSetup(const Setup *);
     //void setSelectedMediaType(const MediaType *);
     //void setSelectedPlatform(const Platform *);
-    void setSelected(QComboBox*, const EmuFrontObject*, int idIndex);
     Setup* getSelectedSetup();
     //Platform* getSelectedPlatform() const;
     //MediaType* getSelectedMediaType() const;
diff --git a/src/dialogs/setupeditdialog.cpp b/src/dialogs/setupeditdialog.cpp
new file mode 100644 (file)
index 0000000..562f9c7
--- /dev/null
@@ -0,0 +1,49 @@
+// 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 <QtGui>
+#include "setupeditdialog.h"
+#include "../widgets/stringlistwidget.h"
+#include "../db/dbmediatype.h"
+#include "../db/dbplatform.h"
+#include "../db/dbsetup.h"
+
+
+SetupEditDialog::SetupEditDialog(QWidget *parent, EmuFrontObject* obj)
+    : DataObjectEditDialog(parent, obj)
+{
+    mediaTypeComBox = new QComboBox;
+    platformComBox = new QComboBox;
+    dbSetup = new DbSetup(this);
+    dbPlatform = new DbPlatform(this);
+    dbMediaType = new DbMediaType(this);
+    supportedFileTypesList = new StringListWidget;
+}
+
+void SetupEditDialog::acceptChanges()
+{
+}
+
+void SetupEditDialog::rejectChanges()
+{
+}
+
+void SetupEditDialog::setDataObject(EmuFrontObject *ob)
+{
+}
diff --git a/src/dialogs/setupeditdialog.h b/src/dialogs/setupeditdialog.h
new file mode 100644 (file)
index 0000000..ce5c7ac
--- /dev/null
@@ -0,0 +1,53 @@
+// 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 SETUPEDITDIALOG_H
+#define SETUPEDITDIALOG_H
+
+#include "dataobjecteditdialog.h"
+
+class QComboBox;
+class DbSetup;
+class DbMediaType;
+class DbPlatform;
+class StringListWidget;
+
+class SetupEditDialog : public DataObjectEditDialog
+{
+    Q_OBJECT
+
+public:
+    SetupEditDialog(QWidget *parent, EmuFrontObject*);
+    //~SetupEditDialog();
+    virtual void setDataObject(EmuFrontObject *);
+
+protected slots:
+    virtual void acceptChanges();
+    virtual void rejectChanges();
+
+private:
+    QComboBox *mediaTypeComBox;
+    QComboBox *platformComBox;
+    DbSetup *dbSetup;
+    DbPlatform *dbPlatform;
+    DbMediaType *dbMediaType;
+    StringListWidget *supportedFileTypesList;
+};
+
+#endif // SETUPEDITDIALOG_H
index a634a46..b98ff4e 100644 (file)
@@ -40,7 +40,9 @@ HEADERS += mainwindow.h \
     db/dbsetup.h \
     db/dbtablemodelmanager.h \
     db/dbquerymodelmanager.h \
-    dialogs/setupmaindialog.h
+    dialogs/setupmaindialog.h \
+    dialogs/setupeditdialog.h \
+    widgets/stringlistwidget.h
 SOURCES += main.cpp \
     mainwindow.cpp \
     db/databasemanager.cpp \
@@ -70,6 +72,8 @@ SOURCES += main.cpp \
     db/dbsetup.cpp \
     db/dbtablemodelmanager.cpp \
     db/dbquerymodelmanager.cpp \
-    dialogs/setupmaindialog.cpp
+    dialogs/setupmaindialog.cpp \
+    dialogs/setupeditdialog.cpp \
+    widgets/stringlistwidget.cpp
 
 OTHER_FILES +=
diff --git a/src/widgets/stringlistwidget.cpp b/src/widgets/stringlistwidget.cpp
new file mode 100644 (file)
index 0000000..334b6e4
--- /dev/null
@@ -0,0 +1,94 @@
+// 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 "stringlistwidget.h"
+#include <QtGui>
+
+StringListWidget::StringListWidget(QWidget *parent, bool sort, int sortIndex) :
+    QWidget(parent), sort(sort), sortIndex(sortIndex)
+{
+    //model = new QStringListModel(this);
+    initUi();
+    connectSignals();
+}
+
+void StringListWidget::initUi()
+{
+    stringList = new QListWidget(this);
+    //stringList->setModel(model);
+    btnAdd = new QPushButton(tr("&Add"), this);
+    btnRemove = new QPushButton(tr("&Remove"), this);
+
+    QVBoxLayout *rightLayout = new QVBoxLayout;
+    rightLayout->addWidget(btnAdd);
+    rightLayout->addWidget(btnRemove);
+    rightLayout->addStretch();
+
+    QHBoxLayout *mainLayout = new QHBoxLayout;
+    mainLayout->addWidget(stringList);
+    mainLayout->addLayout(rightLayout);
+
+    setLayout(mainLayout);
+}
+
+void StringListWidget::connectSignals()
+{
+    connect(btnAdd, SIGNAL(clicked()), this, SLOT(addClicked()));
+    connect(btnRemove, SIGNAL(clicked()), this, SLOT(removeClicked()));
+}
+
+void StringListWidget::addClicked()
+{
+    QString input = QInputDialog::getText(this, tr("Add"), tr("Add new item"));
+    if (input.isEmpty()) return;
+    stringList->addItem(input);
+    stringList->sortItems();
+    /*QStringList l = model->stringList();
+    l << input;
+    model->setStringList(l);
+    if (sort) model->sort(sortIndex);*/
+    //emit stringListUpdated;
+}
+
+void StringListWidget::removeClicked()
+{
+    qDebug() << "StringListWidget::removeClicked";
+    /*QModelIndexList selected = stringList->selectedIndexes();
+    if (selected.count() < 1) return;
+    qDebug() <<  selected.count() << " items selected for removal.";
+    foreach(QModelIndex i, selected)
+    {
+        if (!i.isValid()) continue;
+        int row = i.row();
+        model->removeRows(row, 1);
+    }*/
+    //emit stringListUpdated;
+}
+
+QStringList StringListWidget::getItems()
+{
+    //return model->stringList();
+    QStringList l;
+    return l;
+}
+
+void StringListWidget::setItems(QStringList list)
+{
+    //model->setStringList(list);
+}
diff --git a/src/widgets/stringlistwidget.h b/src/widgets/stringlistwidget.h
new file mode 100644 (file)
index 0000000..80b9608
--- /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 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 STRINGLISTWIDGET_H
+#define STRINGLISTWIDGET_H
+
+#include <QWidget>
+
+//class QStringListModel;
+class QListWidget;
+class QPushButton;
+
+class StringListWidget : public QWidget
+{
+    Q_OBJECT
+public:
+    explicit StringListWidget(QWidget *parent = 0, bool sort = true, int sortIndex = 0);
+    QStringList getItems();
+    void setItems(QStringList);
+
+signals:
+    void stringListUpdated();
+
+private slots:
+    void addClicked();
+    void removeClicked();
+
+private:
+    void initUi();
+    void connectSignals();
+    //QStringListModel *model;
+    QListWidget *stringList;
+    QPushButton *btnAdd;
+    QPushButton *btnRemove;
+    bool sort;
+    int sortIndex;
+};
+
+#endif // STRINGLISTWIDGET_H