3 ** Copyright 2010 Mikko Keinänen
5 ** This file is part of EmuFront.
8 ** EmuFront is free software: you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License version 2 as published by
10 ** the Free Software Foundation and appearing in the file gpl.txt included in the
11 ** packaging of this file.
13 ** EmuFront is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
18 ** You should have received a copy of the GNU General Public License
19 ** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
21 #include "stringlistdelegate.h"
22 #include "fileextensionwidget.h"
24 StringListDelegate::StringListDelegate(QString separator, QObject *parent) :
25 QStyledItemDelegate(parent), separator(separator)
29 /*void StringListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
31 QString str = index.model()->data(index, Qt::DisplayRole).toString();
35 QWidget* StringListDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
37 StringListWidget *editor = new StringListWidget(parent);
38 QString str = index.model()->data(index, Qt::DisplayRole).toString();
39 editor->setItems(str.split(separator, QString::SkipEmptyParts));
40 connect(editor, SIGNAL(stringListUpdated()), this, SLOT(commitAndCloseEditor()));
44 void StringListDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
46 QString str = index.model()->data(index, Qt::DisplayRole).toString();
47 StringListWidget *strListWdg = qobject_cast<StringListWidget *>(editor);
48 strListWdg->setItems(str.split(separator, QString::SkipEmptyParts));
51 void StringListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
53 StringListWidget *strListWdg = qobject_cast<StringListWidget *>(editor);
54 QStringList ls = strListWdg->getItems();
55 model->setData(index, ls.empty() ? "" : ls.join(separator));
58 void StringListDelegate::commitAndCloseEditor()
60 StringListWidget *editor = qobject_cast<StringListWidget *>(sender());
61 emit commitData(editor);
62 emit closeEditor(editor);
65 QSize StringListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const