--- /dev/null
+#include <QtGui>
+#include "comboboxdelegate.h"
+#include "emufrontquerymodel.h"
+#include "emufrontobject.h"
+
+ComboBoxDelegate::ComboBoxDelegate(int column, EmuFrontQueryModel *model, QWidget *parent) :
+ QStyledItemDelegate(parent), column(column), model(model)
+{ }
+
+void ComboBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ if (index.column() != column) {
+ QStyledItemDelegate::paint(painter, option, index);
+ return;
+ }
+
+ int objid = index.model()->data(index, Qt::DisplayRole).toInt();
+ EmuFrontObject *efo = model->getObject(objid);
+ QString txt = efo->getName();
+ painter->save();
+ //initStyleOption(&option, index);
+ painter->drawText(option.rect, txt);
+ painter->restore();
+}
+
+//QSize ComboBoxDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { }
+
+QWidget* ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ if (index.column() != column) {
+ return QStyledItemDelegate::createEditor(parent, option, index);
+ }
+
+ QComboBox *editor = new QComboBox(parent);
+ editor->setEditable(false);
+ editor->setModel(model);
+ connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
+ return editor;
+}
+
+void ComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
+{
+
+}
+
+void ComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
+{
+}
+
+void ComboBoxDelegate::commitAndCloseEditor()
+{
+}
+
--- /dev/null
+#ifndef COMBOBOXDELEGATE_H
+#define COMBOBOXDELEGATE_H
+
+#include <QStyledItemDelegate>
+
+class EmuFrontQueryModel;
+
+class ComboBoxDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ ComboBoxDelegate(int column, EmuFrontQueryModel *, QWidget *parent = 0);
+ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
+ //QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
+ QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
+
+private slots:
+ void commitAndCloseEditor();
+private:
+ EmuFrontQueryModel *model;
+ int column;
+};
+
+#endif // COMBOBOXDELEGATE_H
views/platformeditview.h \
views/mediatypeeditview.h \
views/emufrontfileobjecteditview.h \
- views/emufronteditview.h
+ views/emufronteditview.h \
+ delegates/comboboxdelegate.h
SOURCES += main.cpp \
mainwindow.cpp \
db/databasemanager.cpp \
views/platformeditview.cpp \
views/mediatypeeditview.cpp \
views/emufrontfileobjecteditview.cpp \
- views/emufronteditview.cpp
+ views/emufronteditview.cpp \
+ delegates/comboboxdelegate.cpp
OTHER_FILES +=
CONFIG += mobility
// along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
#include "emufrontquerymodel.h"
+#include "emufrontobject.h"
EmuFrontQueryModel::EmuFrontQueryModel(QObject *parent) :
QSqlQueryModel(parent)
{
}
+
+EmuFrontObject* EmuFrontQueryModel::getObject(int id) const
+{
+ // TODO
+ return 0;
+}
#include <QSqlQueryModel>
+class EmuFrontObject;
+
class EmuFrontQueryModel : public QSqlQueryModel
{
Q_OBJECT
public:
EmuFrontQueryModel(QObject *parent = 0);
+ EmuFrontObject* getObject(int id) const;
signals: