File indexing completed on 2024-05-26 16:15:27
0001 /* This file is part of the KDE project 0002 Copyright (C) 2010 KO GmbH <ben.martin@kogmbh.com> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoSopranoTableModelDelegate.h" 0021 0022 // lib 0023 #include "KoSopranoTableModel.h" 0024 #include "KoDocumentRdf.h" 0025 // main 0026 #include <KoDocument.h> 0027 // KF5 0028 #include <klocalizedstring.h> 0029 // Qt 0030 #include <QComboBox> 0031 0032 KoSopranoTableModelDelegate::KoSopranoTableModelDelegate(QObject *parent) 0033 : QStyledItemDelegate(parent) 0034 { 0035 } 0036 0037 QWidget *KoSopranoTableModelDelegate::createEditor(QWidget *parent, 0038 const QStyleOptionViewItem &option, 0039 const QModelIndex &index) const 0040 { 0041 QComboBox *comboBox = new QComboBox(parent); 0042 if (index.column() == KoSopranoTableModel::ColObjType) { 0043 comboBox->addItem(i18n("URI")); 0044 comboBox->addItem(i18n("Literal")); 0045 comboBox->addItem(i18n("Blank")); 0046 } else { 0047 return QStyledItemDelegate::createEditor(parent, option, index); 0048 } 0049 connect(comboBox, SIGNAL(activated(int)), this, SLOT(emitCommitData())); 0050 return comboBox; 0051 } 0052 0053 void KoSopranoTableModelDelegate::setEditorData(QWidget *editor, 0054 const QModelIndex &index) const 0055 { 0056 QComboBox *comboBox = qobject_cast<QComboBox *>(editor); 0057 if (!comboBox) { 0058 return QStyledItemDelegate::setEditorData(editor, index); 0059 } 0060 int pos = comboBox->findText(index.model()->data(index).toString(), 0061 Qt::MatchExactly); 0062 comboBox->setCurrentIndex(pos); 0063 } 0064 0065 void KoSopranoTableModelDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, 0066 const QModelIndex &index) const 0067 { 0068 QComboBox *comboBox = qobject_cast<QComboBox *>(editor); 0069 if (!comboBox) { 0070 return QStyledItemDelegate::setModelData(editor, model, index); 0071 } 0072 model->setData(index, comboBox->currentText()); 0073 } 0074 0075 void KoSopranoTableModelDelegate::emitCommitData() 0076 { 0077 emit commitData(qobject_cast<QWidget *>(sender())); 0078 }