// along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
#include "stringlistdelegate.h"
+#include "fileextensionwidget.h"
-StringListDelegate::StringListDelegate(QObject *parent) :
- QStyledItemDelegate(parent)
+StringListDelegate::StringListDelegate(QString separator, QObject *parent) :
+ QStyledItemDelegate(parent), separator(separator)
{
}
+
+/*void StringListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ QString str = index.model()->data(index, Qt::DisplayRole).toString();
+ // TODO:...
+}*/
+
+QWidget* StringListDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ StringListWidget *editor = new StringListWidget(parent);
+ QString str = index.model()->data(index, Qt::DisplayRole).toString();
+ editor->setItems(str.split(separator, QString::SkipEmptyParts));
+ connect(editor, SIGNAL(stringListUpdated()), this, SLOT(commitAndCloseEditor()));
+ return editor;
+}
+
+void StringListDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
+{
+ QString str = index.model()->data(index, Qt::DisplayRole).toString();
+ StringListWidget *strListWdg = qobject_cast<StringListWidget *>(editor);
+ strListWdg->setItems(str.split(separator, QString::SkipEmptyParts));
+}
+
+void StringListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
+{
+ StringListWidget *strListWdg = qobject_cast<StringListWidget *>(editor);
+ QStringList ls = strListWdg->getItems();
+ model->setData(index, ls.empty() ? "" : ls.join(separator));
+}
+
+void StringListDelegate::commitAndCloseEditor()
+{
+ StringListWidget *editor = qobject_cast<StringListWidget *>(sender());
+ emit commitData(editor);
+ emit closeEditor(editor);
+}
+
+QSize StringListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ QSize sz(300,300);
+ return sz;
+}
{
Q_OBJECT
public:
- explicit StringListDelegate(QObject *parent = 0);
+ StringListDelegate(QString separator, QObject *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;
-signals:
-
-public slots:
+private slots:
+ void commitAndCloseEditor();
+private:
+ QString separator;
};
#endif // STRINGLISTDELEGATE_H
#include "setupmodel.h"
#include <QtSql>
+const QString SetupModel::FILE_TYPE_EXTENSION_SEPARATOR = QString("|");
+
SetupModel::SetupModel(QObject *parent) :
EmuFrontQueryModel(parent)
{
Qt::ItemFlags SetupModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags flags = QSqlQueryModel::flags(index);
- if (index.column() == Setup_PlatformId || index.column() == Setup_MediaTypeId) {
+ int col = index.column();
+ if (col == Setup_PlatformId ||
+ col == Setup_MediaTypeId ||
+ col == Setup_FileTypeExtensions) {
flags |= Qt::ItemIsEditable;
}
return flags;
bool SetupModel::setData(const QModelIndex &index, const QVariant &value, int /*role*/)
{
- if(index.column() != Setup_PlatformId && index.column() != Setup_MediaTypeId)
+ int col = index.column();
+ if(col != Setup_PlatformId &&
+ col != Setup_MediaTypeId &&
+ col != Setup_FileTypeExtensions)
return false;
QModelIndex primaryKeyIndex
case Setup_MediaTypeId:
ok = setMediaType(id, value.toInt());
break;
+
+ case Setup_FileTypeExtensions:
+ ok = setSupportedExtensions(id, value.toString());
+ break;
+
+ default:
+ qDebug() << "Setup model, this shouldn't be happening!";
};
refresh();
return ok;
query.bindValue(":id", id);
return query.exec();
}
+
+bool SetupModel::setSupportedExtensions(int id, QString exts)
+{
+ QSqlQuery query;
+ query.prepare(QString("update setup set filetypeextensions = :exts where id = :id"));
+ query.bindValue(":exts", exts);
+ query.bindValue(":id", id);
+ return query.exec();
+}
+
+
virtual QString constructSelect(QString where = "") const;
virtual bool setPlatform(int id, int platformId);
virtual bool setMediaType(int id, int platformId);
+ virtual bool setSupportedExtensions(int id, QString);
};
#endif // SETUPMODEL_H
#include "setupeditview.h"
#include "setupmodel.h"
#include "comboboxdelegate.h"
+#include "stringlistdelegate.h"
#include "platformmodel.h"
#include "mediatypemodel.h"
#include <QSqlTableModel>
this
);
objectList->setItemDelegateForColumn(SetupModel::Setup_MediaTypeId, mediatypeDelegate);
+
+ StringListDelegate *fileTypeDelegate = new StringListDelegate(SetupModel::FILE_TYPE_EXTENSION_SEPARATOR, this);
+ objectList->setItemDelegateForColumn(SetupModel::Setup_FileTypeExtensions, fileTypeDelegate);
postInit();
}