1 /**
2 * UGENE - Integrated Bioinformatics Tools.
3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4 * http://ugene.net
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 #include "GenomicLibraryDelegate.h"
23
24 #include <U2Core/L10n.h>
25
26 #include <U2Lang/URLContainer.h>
27
28 #include "GenomicLibraryPropertyWidget.h"
29
30 namespace U2 {
31 namespace LocalWorkflow {
32
GenomicLibraryDelegate(QObject * parent)33 GenomicLibraryDelegate::GenomicLibraryDelegate(QObject *parent)
34 : PropertyDelegate(parent) {
35 }
36
getDisplayValue(const QVariant & value) const37 QVariant GenomicLibraryDelegate::getDisplayValue(const QVariant &value) const {
38 const QList<Dataset> datasets = value.value<QList<Dataset>>();
39 const bool isEmpty = datasets.isEmpty() || datasets.first().getUrls().isEmpty();
40 return isEmpty ? GenomicLibraryPropertyWidget::PLACEHOLDER : GenomicLibraryPropertyWidget::FILLED_VALUE;
41 }
42
createEditor(QWidget * parent,const QStyleOptionViewItem &,const QModelIndex &) const43 QWidget *GenomicLibraryDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const {
44 GenomicLibraryPropertyWidget *editor = new GenomicLibraryPropertyWidget(parent);
45 connect(editor, SIGNAL(si_valueChanged(QVariant)), SLOT(sl_commit()));
46 return editor;
47 }
48
createWizardWidget(U2OpStatus &,QWidget * parent) const49 PropertyWidget *GenomicLibraryDelegate::createWizardWidget(U2OpStatus &, QWidget *parent) const {
50 return new GenomicLibraryPropertyWidget(parent);
51 }
52
setEditorData(QWidget * editor,const QModelIndex & index) const53 void GenomicLibraryDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
54 const QVariant value = index.model()->data(index, ConfigurationEditor::ItemValueRole);
55 GenomicLibraryPropertyWidget *propertyWidget = qobject_cast<GenomicLibraryPropertyWidget *>(editor);
56 SAFE_POINT(nullptr != editor, L10N::nullPointerError("GenomicLibraryPropertyWidget"), );
57 propertyWidget->setValue(value);
58 }
59
setModelData(QWidget * editor,QAbstractItemModel * model,const QModelIndex & index) const60 void GenomicLibraryDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
61 GenomicLibraryPropertyWidget *propertyWidget = qobject_cast<GenomicLibraryPropertyWidget *>(editor);
62 model->setData(index, propertyWidget->value(), ConfigurationEditor::ItemValueRole);
63 }
64
clone()65 PropertyDelegate *GenomicLibraryDelegate::clone() {
66 return new GenomicLibraryDelegate(parent());
67 }
68
sl_commit()69 void GenomicLibraryDelegate::sl_commit() {
70 GenomicLibraryPropertyWidget *editor = qobject_cast<GenomicLibraryPropertyWidget *>(sender());
71 CHECK(editor != nullptr, );
72 emit commitData(editor);
73 }
74
75 } // namespace LocalWorkflow
76 } // namespace U2
77