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 #ifndef _U2_ACTOR_CFG_H_
23 #define _U2_ACTOR_CFG_H_
24 
25 #include <QAbstractTableModel>
26 #include <QList>
27 #include <QObject>
28 #include <QPair>
29 #include <QString>
30 
31 #include <U2Designer/DelegateEditors.h>
32 
33 #include <U2Lang/ActorModel.h>
34 #include <U2Lang/IntegralBusModel.h>
35 #include <U2Lang/Schema.h>
36 #include <U2Lang/SchemaConfig.h>
37 
38 namespace U2 {
39 
40 using namespace Workflow;
41 
42 class ActorCfgModel : public QAbstractTableModel {
43     Q_OBJECT
44 public:
45     ActorCfgModel(QObject *parent, SchemaConfig *schemaConfig);
46     ~ActorCfgModel();
47 
48     void setActor(Actor *cfg);
49 
50     void update();
51 
52     int columnCount(const QModelIndex &) const;
53 
54     int rowCount(const QModelIndex &parent = QModelIndex()) const;
55 
56     Qt::ItemFlags flags(const QModelIndex &index) const;
57 
58     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
59 
60     /*Used to supply item data to views and delegates.
61     Generally, models only need to supply data for Qt::DisplayRole and any application-specific user roles,
62     but it is also good practice to provide data for Qt::ToolTipRole, Qt::AccessibleTextRole, and Qt::AccessibleDescriptionRole.*/
63     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
64 
65     /*Used to modify the item of data associated with a specified model index.
66     To be able to accept user input, provided by user interface elements, this function must handle data associated with Qt::EditRole.
67     The implementation may also accept data associated with many different kinds of roles specified by Qt::ItemDataRole.
68     After changing the item of data, models must emit the dataChanged() signal to inform other components of the change.*/
69     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
70 
71     void changeScriptMode(bool _mode);
72     bool getScriptMode() const;
73 
74     QModelIndex modelIndexById(const QString &id) const;
75 
76     Attribute *getAttributeByRow(int row) const;
77     bool isVisible(Attribute *a) const;
78 
79 private:
80     bool setAttributeValue(const Attribute *attr, QVariant &attrValue) const;
81     void setupAttributesScripts();
82     bool canSetData(Attribute *attr, const QVariant &value);
83 
84     QMap<Attribute *, bool> getAttributeRelatedVisibility(Attribute *changedAttr,
85                                                           const QMap<Attribute *, bool> &foundRelatedAttrs = (QMap<Attribute *, bool>())) const;
86     void checkIfAttributeVisibilityChanged(const QMap<Attribute *, bool> &attributeVisibility);
87 
88 private:
89     SchemaConfig *schemaConfig;
90     Actor *subject;
91     QList<Attribute *> attrs;
92     AttributeScriptDelegate *scriptDelegate;
93     QVariantMap listValues;
94     bool scriptMode;
95 
96 };  // ActorCfgModel
97 
98 }  // namespace U2
99 
100 #endif  // _U2_ACTOR_CFG_H_
101