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 /************************************************************************/
23 /* Copy of "workflow_designer/ProxyDelegate.h" */
24 /************************************************************************/
25
26 #ifndef _U2_QUERY_PROC_CFG_DELEGATE_H_
27 #define _U2_QUERY_PROC_CFG_DELEGATE_H_
28
29 #include <QItemDelegate>
30
31 #include <U2Lang/ConfigurationEditor.h>
32
33 #include "QueryEditor.h"
34
Q_DECLARE_METATYPE(U2::PropertyDelegate *)35 Q_DECLARE_METATYPE(U2::PropertyDelegate *)
36
37 namespace U2 {
38
39 enum {
40 DelegateRole = Qt::UserRole + 100,
41 DescriptorRole
42 };
43
44 class QueryProcCfgDelegate : public QItemDelegate {
45 public:
46 QueryProcCfgDelegate(QueryEditor *parent)
47 : QItemDelegate(parent) {
48 }
49
50 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
51 PropertyDelegate *d = index.model()->data(index, DelegateRole).value<PropertyDelegate *>();
52 if (d) {
53 connect(d, SIGNAL(commitData(QWidget *)), SIGNAL(commitData(QWidget *)));
54 return d->createEditor(parent, option, index);
55 }
56 return QItemDelegate::createEditor(parent, option, index);
57 }
58
59 void setEditorData(QWidget *editor, const QModelIndex &index) const {
60 PropertyDelegate *d = index.model()->data(index, DelegateRole).value<PropertyDelegate *>();
61 if (d) {
62 d->setEditorData(editor, index);
63 return;
64 }
65 QItemDelegate::setEditorData(editor, index);
66 }
67
68 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
69 QVariant old;
70 PropertyDelegate *d = model->data(index, DelegateRole).value<PropertyDelegate *>();
71 if (d) {
72 old = model->data(index, ConfigurationEditor::ItemValueRole);
73 d->setModelData(editor, model, index);
74 } else {
75 old = model->data(index, Qt::EditRole);
76 QItemDelegate::setModelData(editor, model, index);
77 }
78
79 QVariant val = model->data(index, (d == nullptr) ? (int)Qt::EditRole : (int)ConfigurationEditor::ItemValueRole);
80 if (val != old) {
81 if (d) {
82 model->setData(index, d->getDisplayValue(val), Qt::DisplayRole);
83 }
84 model->setData(index, model->data(index, Qt::DisplayRole).toString(), Qt::ToolTipRole);
85 }
86 }
87 };
88
89 } // namespace U2
90
91 #endif
92