~ubuntu-branches/ubuntu/karmic/ugene/karmic

« back to all changes in this revision

Viewing changes to src/plugins/workflow_designer/src/ProxyDelegate.h

  • Committer: Bazaar Package Importer
  • Author(s): Ivan Efremov
  • Date: 2009-01-26 19:17:51 UTC
  • Revision ID: james.westby@ubuntu.com-20090126191751-9kqqevd3yf4o098r
Tags: upstream-1.3.2+repack
ImportĀ upstreamĀ versionĀ 1.3.2+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
* Unipro UGENE - Integrated Bioinformatics Suite
 
3
* Copyright (C) 2008 Unipro, Russia (http://ugene.unipro.ru)
 
4
* All Rights Reserved
 
5
 
6
*     This source code is distributed under the terms of the
 
7
*     GNU General Public License. See the files COPYING and LICENSE
 
8
*     for details.
 
9
*****************************************************************/
 
10
 
 
11
#ifndef _GB2_PROXY_DELEGATE_H_
 
12
#define _GB2_PROXY_DELEGATE_H_
 
13
 
 
14
#include <workflow/ConfigurationEditor.h>
 
15
#include <QtGui/QItemDelegate>
 
16
 
 
17
Q_DECLARE_METATYPE(GB2::PropertyDelegate*)
 
18
 
 
19
namespace GB2 {
 
20
 
 
21
enum {
 
22
    DelegateRole = Qt::UserRole + 100,
 
23
    DescriptorRole
 
24
};
 
25
 
 
26
class ProxyDelegate : public QItemDelegate {
 
27
public:
 
28
    ProxyDelegate(QWidget *parent = 0) : QItemDelegate(parent) {}
 
29
 
 
30
    virtual void setPropertyValue(const QString& name, QVariant val) const {Q_UNUSED(name); Q_UNUSED(val);}
 
31
    virtual bool handlePropertyValueList(const QString& name, QVariant list) const {
 
32
        Q_UNUSED(name);Q_UNUSED(list);
 
33
        return false;
 
34
    }
 
35
 
 
36
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
 
37
        //if (owner->custom) 
 
38
        {
 
39
            QItemDelegate* d = index.model()->data(index, DelegateRole).value<PropertyDelegate*>();
 
40
            if (d) {
 
41
                return d->createEditor(parent, option, index);
 
42
            }
 
43
        }
 
44
        return QItemDelegate::createEditor(parent, option, index);
 
45
    }
 
46
 
 
47
    void setEditorData(QWidget *editor, const QModelIndex &index) const {
 
48
        //if (owner->custom) 
 
49
        {
 
50
            QItemDelegate* d = index.model()->data(index, DelegateRole).value<PropertyDelegate*>();
 
51
            if (d) {
 
52
                d->setEditorData(editor, index);
 
53
                return;
 
54
            }
 
55
        }
 
56
        QItemDelegate::setEditorData(editor, index);
 
57
    }
 
58
 
 
59
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
 
60
        //QTableWidgetItem* item = owner->table->item(index.row(), index.column());
 
61
        PropertyDelegate* d = NULL;
 
62
        QVariant old;
 
63
        QVariant expanded;
 
64
        if (/*owner->custom &&*/ (d = model->data(index, DelegateRole).value<PropertyDelegate*>())) {
 
65
            old = model->data(index, ConfigurationEditor::ItemValueRole);
 
66
            d->setModelData(editor, model, index);
 
67
            expanded = model->data(index, ConfigurationEditor::ItemListValueRole);
 
68
        } else {
 
69
            old = model->data(index, Qt::EditRole);
 
70
            QItemDelegate::setModelData(editor, model, index);
 
71
        }
 
72
        QString name = model->data(index, DescriptorRole).value<Descriptor>().getId();
 
73
        if (handlePropertyValueList(name, expanded)) {
 
74
            return;
 
75
        }
 
76
        QVariant val = model->data(index, (d == NULL) ? (int)Qt::EditRole : (int)ConfigurationEditor::ItemValueRole);
 
77
        if (val != old) {
 
78
            setPropertyValue(name, val);
 
79
            if (d) {
 
80
                model->setData(index, d->getDisplayValue(val), Qt::DisplayRole);
 
81
            }
 
82
            model->setData(index, model->data(index, Qt::DisplayRole).toString(), Qt::ToolTipRole);
 
83
        }
 
84
    }
 
85
};
 
86
 
 
87
}//namespace
 
88
#endif