Modified the license text comment type.
[emufront] / src / delegates / filesystembrowsedelegate.cpp
1 /*
2 ** EmuFront
3 ** Copyright 2010 Mikko Keinänen
4 **
5 ** This file is part of EmuFront.
6 **
7 **
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.
12 **
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.
17 **
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/>.
20 */
21 #include "filesystembrowsedelegate.h"
22 #include "filepathselectorwidget.h"
23
24 FileSystemBrowseDelegate::FileSystemBrowseDelegate(QWidget *parent) :
25     QStyledItemDelegate(parent)
26 {
27 }
28
29 QWidget* FileSystemBrowseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
30 {
31     FilePathSelectorWidget *editor = new FilePathSelectorWidget(parent);
32     connect(editor, SIGNAL(filePathUpdated()), this, SLOT(commitAndCloseEditor()));
33     return editor;
34 }
35
36 void FileSystemBrowseDelegate::commitAndCloseEditor()
37 {
38     FilePathSelectorWidget *editor = qobject_cast<FilePathSelectorWidget *>(sender());
39     emit commitData(editor);
40     emit closeEditor(editor);
41 }
42
43 void FileSystemBrowseDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
44 {
45     FilePathSelectorWidget *wdg = qobject_cast<FilePathSelectorWidget *>(editor);
46     QString path = wdg->getFilePath();
47     model->setData(index, path);
48 }
49
50 void FileSystemBrowseDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
51 {
52     QString path = index.model()->data(index, Qt::DisplayRole).toString();
53     FilePathSelectorWidget *fpwdg = qobject_cast<FilePathSelectorWidget *>(editor);
54     fpwdg->setFilePath(path);
55 }