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 "WizardPage.h"
23 
24 #include <U2Core/U2SafePoints.h>
25 
26 namespace U2 {
27 
28 /**********************************
29  * WizardPage
30  *********************************/
WizardPage(const QString & _id,const QString & _title)31 WizardPage::WizardPage(const QString &_id, const QString &_title)
32     : id(_id), title(_title) {
33 }
34 
~WizardPage()35 WizardPage::~WizardPage() {
36     delete content;
37 }
38 
validate(const QList<Workflow::Actor * > & actors,U2OpStatus & os) const39 void WizardPage::validate(const QList<Workflow::Actor *> &actors, U2OpStatus &os) const {
40     if (nullptr == content) {
41         os.setError(QObject::tr("NULL page content"));
42         return;
43     }
44     content->validate(actors, os);
45     CHECK_OP(os, );
46 }
47 
setNext(const QString & nextId)48 void WizardPage::setNext(const QString &nextId) {
49     this->nextId = nextId;
50     nextIds.clear();
51 }
52 
setNext(const QString & nextId,const Predicate & predicate,U2OpStatus & os)53 void WizardPage::setNext(const QString &nextId, const Predicate &predicate, U2OpStatus &os) {
54     if (nextIds.contains(predicate)) {
55         os.setError(QObject::tr("Double condition: %1").arg(predicate.toString()));
56         return;
57     }
58     this->nextId.clear();
59     nextIds[predicate] = nextId;
60 }
61 
getNextId(const QMap<QString,Variable> & vars) const62 QString WizardPage::getNextId(const QMap<QString, Variable> &vars) const {
63     if (nextIds.isEmpty()) {
64         return nextId;
65     }
66     foreach (const Predicate &p, nextIds.keys()) {
67         if (p.isTrue(vars)) {
68             return nextIds[p];
69         }
70     }
71     return "";
72 }
73 
isFinal() const74 bool WizardPage::isFinal() const {
75     return (nextId.isEmpty() && nextIds.isEmpty());
76 }
77 
getId() const78 const QString &WizardPage::getId() const {
79     return id;
80 }
81 
getTitle() const82 const QString &WizardPage::getTitle() const {
83     return title;
84 }
85 
setContent(TemplatedPageContent * value)86 void WizardPage::setContent(TemplatedPageContent *value) {
87     content = value;
88 }
89 
getContent()90 TemplatedPageContent *WizardPage::getContent() {
91     return content;
92 }
93 
94 /** for serializing */
nextIdMap() const95 const QMap<Predicate, QString> &WizardPage::nextIdMap() const {
96     return nextIds;
97 }
98 
plainNextId() const99 const QString &WizardPage::plainNextId() const {
100     return nextId;
101 }
102 
103 /**********************************
104  * TemplatedPage
105  *********************************/
TemplatedPageContent(const QString & _templateId)106 TemplatedPageContent::TemplatedPageContent(const QString &_templateId)
107     : templateId(_templateId) {
108 }
109 
~TemplatedPageContent()110 TemplatedPageContent::~TemplatedPageContent() {
111 }
112 
getTemplateId() const113 const QString &TemplatedPageContent::getTemplateId() const {
114     return templateId;
115 }
116 
createContent(const QString & id,U2OpStatus & os)117 TemplatedPageContent *PageContentFactory::createContent(const QString &id, U2OpStatus &os) {
118     if (DefaultPageContent::ID == id) {
119         return new DefaultPageContent();
120     }
121     os.setError(QObject::tr("Unknown page template id: %1").arg(id));
122     return nullptr;
123 }
124 
125 /**********************************
126  * DefaultTemplatePage
127  *********************************/
128 const QString DefaultPageContent::ID("default");
129 const QString DefaultPageContent::PARAMETERS("parameters-area");
130 const int DefaultPageContent::HEIGHT = 400;
131 const int DefaultPageContent::WIDTH = 720;
132 
DefaultPageContent()133 DefaultPageContent::DefaultPageContent()
134     : TemplatedPageContent(ID) {
135     logoArea = new LogoWidget();
136     paramsArea = new WidgetsArea(PARAMETERS);
137 }
138 
~DefaultPageContent()139 DefaultPageContent::~DefaultPageContent() {
140     delete logoArea;
141     delete paramsArea;
142 }
143 
accept(TemplatedPageVisitor * visitor)144 void DefaultPageContent::accept(TemplatedPageVisitor *visitor) {
145     visitor->visit(this);
146 }
147 
validate(const QList<Workflow::Actor * > & actors,U2OpStatus & os) const148 void DefaultPageContent::validate(const QList<Workflow::Actor *> &actors, U2OpStatus &os) const {
149     if (nullptr == logoArea) {
150         os.setError(QObject::tr("NULL logo area"));
151         return;
152     }
153     if (nullptr == paramsArea) {
154         os.setError(QObject::tr("NULL parameters area"));
155         return;
156     }
157 
158     logoArea->validate(actors, os);
159     CHECK_OP(os, );
160     paramsArea->validate(actors, os);
161     CHECK_OP(os, );
162 }
163 
addParamWidget(WizardWidget * widget)164 void DefaultPageContent::addParamWidget(WizardWidget *widget) {
165     paramsArea->addWidget(widget);
166 }
167 
setLogoPath(const QString & path)168 void DefaultPageContent::setLogoPath(const QString &path) {
169     logoArea->setLogoPath(path);
170 }
171 
getLogoArea()172 LogoWidget *DefaultPageContent::getLogoArea() {
173     return logoArea;
174 }
175 
getParamsArea()176 WidgetsArea *DefaultPageContent::getParamsArea() {
177     return paramsArea;
178 }
179 
getPageDefaultHeight() const180 int DefaultPageContent::getPageDefaultHeight() const {
181     return HEIGHT;
182 }
183 
getPageWidth() const184 int DefaultPageContent::getPageWidth() const {
185     return WIDTH;
186 }
187 
188 }  // namespace U2
189