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 "filesystembrowsedelegate.h"
22 #include "filepathselectorwidget.h"
24 FileSystemBrowseDelegate::FileSystemBrowseDelegate(QWidget *parent) :
25 QStyledItemDelegate(parent)
29 QWidget* FileSystemBrowseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
31 FilePathSelectorWidget *editor = new FilePathSelectorWidget(parent);
32 connect(editor, SIGNAL(filePathUpdated()), this, SLOT(commitAndCloseEditor()));
36 void FileSystemBrowseDelegate::commitAndCloseEditor()
38 FilePathSelectorWidget *editor = qobject_cast<FilePathSelectorWidget *>(sender());
39 emit commitData(editor);
40 emit closeEditor(editor);
43 void FileSystemBrowseDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
45 FilePathSelectorWidget *wdg = qobject_cast<FilePathSelectorWidget *>(editor);
46 QString path = wdg->getFilePath();
47 model->setData(index, path);
50 void FileSystemBrowseDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
52 QString path = index.model()->data(index, Qt::DisplayRole).toString();
53 FilePathSelectorWidget *fpwdg = qobject_cast<FilePathSelectorWidget *>(editor);
54 fpwdg->setFilePath(path);