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 "WizardWidget.h"
23 
24 #include <U2Core/U2SafePoints.h>
25 
26 #include <U2Lang/BaseAttributes.h>
27 #include <U2Lang/WizardWidgetVisitor.h>
28 #include <U2Lang/WorkflowUtils.h>
29 
30 namespace U2 {
31 
32 /**********************************
33  * WizardWidget
34  *********************************/
WizardWidget()35 WizardWidget::WizardWidget() {
36 }
37 
~WizardWidget()38 WizardWidget::~WizardWidget() {
39 }
40 
validate(const QList<Actor * > &,U2OpStatus &) const41 void WizardWidget::validate(const QList<Actor *> & /*actors*/, U2OpStatus & /*os*/) const {
42 }
43 
44 /**********************************
45  * LogoWidget
46  *********************************/
47 const QString LogoWidget::ID("logo");
48 
LogoWidget(const QString & _logoPath)49 LogoWidget::LogoWidget(const QString &_logoPath)
50     : WizardWidget(), logoPath(_logoPath) {
51 }
52 
~LogoWidget()53 LogoWidget::~LogoWidget() {
54 }
55 
accept(WizardWidgetVisitor * visitor)56 void LogoWidget::accept(WizardWidgetVisitor *visitor) {
57     visitor->visit(this);
58 }
59 
setLogoPath(const QString & value)60 void LogoWidget::setLogoPath(const QString &value) {
61     logoPath = value;
62 }
63 
getLogoPath() const64 const QString &LogoWidget::getLogoPath() const {
65     return logoPath;
66 }
67 
isDefault() const68 bool LogoWidget::isDefault() const {
69     return ("" == logoPath);
70 }
71 
72 /**********************************
73  * WidgetsArea
74  *********************************/
WidgetsArea(const QString & _name,const QString & _title)75 WidgetsArea::WidgetsArea(const QString &_name, const QString &_title)
76     : WizardWidget(), titleable(true), name(_name), title(_title) {
77     labelSize = -1;
78 }
79 
WidgetsArea(const QString & _name)80 WidgetsArea::WidgetsArea(const QString &_name)
81     : WizardWidget(), titleable(false), name(_name) {
82     labelSize = -1;
83 }
84 
~WidgetsArea()85 WidgetsArea::~WidgetsArea() {
86 }
87 
accept(WizardWidgetVisitor * visitor)88 void WidgetsArea::accept(WizardWidgetVisitor *visitor) {
89     visitor->visit(this);
90 }
91 
validate(const QList<Actor * > & actors,U2OpStatus & os) const92 void WidgetsArea::validate(const QList<Actor *> &actors, U2OpStatus &os) const {
93     foreach (WizardWidget *w, widgets) {
94         w->validate(actors, os);
95         CHECK_OP(os, );
96     }
97 }
98 
addWidget(WizardWidget * widget)99 void WidgetsArea::addWidget(WizardWidget *widget) {
100     widgets << widget;
101 }
102 
getWidgets() const103 const QList<WizardWidget *> &WidgetsArea::getWidgets() const {
104     return widgets;
105 }
106 
getName() const107 const QString &WidgetsArea::getName() const {
108     return name;
109 }
110 
getTitle() const111 const QString &WidgetsArea::getTitle() const {
112     return title;
113 }
114 
setTitle(const QString & value)115 void WidgetsArea::setTitle(const QString &value) {
116     titleable = true;
117     title = value;
118 }
119 
hasLabelSize() const120 bool WidgetsArea::hasLabelSize() const {
121     return (-1 != labelSize);
122 }
123 
getLabelSize() const124 int WidgetsArea::getLabelSize() const {
125     return labelSize;
126 }
127 
setLabelSize(int value)128 void WidgetsArea::setLabelSize(int value) {
129     labelSize = value;
130 }
131 
132 /**********************************
133  * GroupWidget
134  *********************************/
135 const QString GroupWidget::ID("group");
136 
GroupWidget()137 GroupWidget::GroupWidget()
138     : WidgetsArea(ID), type(DEFAULT) {
139 }
140 
GroupWidget(const QString & title,Type _type)141 GroupWidget::GroupWidget(const QString &title, Type _type)
142     : WidgetsArea(ID, title), type(_type) {
143 }
144 
~GroupWidget()145 GroupWidget::~GroupWidget() {
146 }
147 
accept(WizardWidgetVisitor * visitor)148 void GroupWidget::accept(WizardWidgetVisitor *visitor) {
149     visitor->visit(this);
150 }
151 
setType(Type value)152 void GroupWidget::setType(Type value) {
153     type = value;
154 }
155 
getType() const156 GroupWidget::Type GroupWidget::getType() const {
157     return type;
158 }
159 
160 /**********************************
161  * AttributeWidget
162  *********************************/
AttributeWidget()163 AttributeWidget::AttributeWidget()
164     : WizardWidget(), info("", "") {
165 }
166 
~AttributeWidget()167 AttributeWidget::~AttributeWidget() {
168 }
169 
accept(WizardWidgetVisitor * visitor)170 void AttributeWidget::accept(WizardWidgetVisitor *visitor) {
171     visitor->visit(this);
172 }
173 
validate(const QList<Actor * > & actors,U2OpStatus & os) const174 void AttributeWidget::validate(const QList<Actor *> &actors, U2OpStatus &os) const {
175     info.validate(actors, os);
176 }
177 
getActorId() const178 QString AttributeWidget::getActorId() const {
179     return info.actorId;
180 }
181 
getAttributeId() const182 QString AttributeWidget::getAttributeId() const {
183     return info.attrId;
184 }
185 
setInfo(const AttributeInfo & value)186 void AttributeWidget::setInfo(const AttributeInfo &value) {
187     info = value;
188 }
189 
getInfo() const190 const AttributeInfo &AttributeWidget::getInfo() const {
191     return info;
192 }
193 
getWigdetHints() const194 const QVariantMap &AttributeWidget::getWigdetHints() const {
195     return info.hints;
196 }
197 
getProperties() const198 QVariantMap AttributeWidget::getProperties() const {
199     QVariantMap extHints = info.hints;
200     extHints[AttributeInfo::TYPE] = getProperty(AttributeInfo::TYPE);
201     extHints[AttributeInfo::LABEL] = getProperty(AttributeInfo::LABEL);
202     return extHints;
203 }
204 
getProperty(const QString & id) const205 QString AttributeWidget::getProperty(const QString &id) const {
206     QString value = info.hints.value(id, "").toString();
207     if (AttributeInfo::TYPE == id && value.isEmpty()) {
208         return AttributeInfo::DEFAULT;
209     } else if (AttributeInfo::LABEL == id && value.isEmpty()) {
210         return "";
211     }
212     return value;
213 }
214 
215 /************************************************************************/
216 /* DatasetsWizardWidget */
217 /************************************************************************/
218 const QString PairedReadsWidget::ID = "paired-reads-datasets";
219 
PairedReadsWidget()220 PairedReadsWidget::PairedReadsWidget()
221     : WizardWidget() {
222 }
223 
accept(WizardWidgetVisitor * visitor)224 void PairedReadsWidget::accept(WizardWidgetVisitor *visitor) {
225     visitor->visit(this);
226 }
227 
validate(const QList<Actor * > & actors,U2OpStatus & os) const228 void PairedReadsWidget::validate(const QList<Actor *> &actors, U2OpStatus &os) const {
229     foreach (const AttributeInfo &info, infos) {
230         info.validate(actors, os);
231         CHECK_OP(os, );
232     }
233 }
234 
addInfo(const AttributeInfo & value)235 void PairedReadsWidget::addInfo(const AttributeInfo &value) {
236     infos << value;
237 }
238 
getInfos() const239 QList<AttributeInfo> PairedReadsWidget::getInfos() const {
240     return infos;
241 }
242 
243 /************************************************************************/
244 /* UrlAndDatasetWidget */
245 /************************************************************************/
246 const QString UrlAndDatasetWidget::ID = "lineedit-and-dataset";
247 
UrlAndDatasetWidget()248 UrlAndDatasetWidget::UrlAndDatasetWidget()
249     : WizardWidget() {
250 }
251 
accept(WizardWidgetVisitor * visitor)252 void UrlAndDatasetWidget::accept(WizardWidgetVisitor *visitor) {
253     visitor->visit(this);
254 }
255 
validate(const QList<Actor * > & actors,U2OpStatus & os) const256 void UrlAndDatasetWidget::validate(const QList<Actor *> &actors, U2OpStatus &os) const {
257     foreach (const AttributeInfo &info, infos) {
258         info.validate(actors, os);
259         CHECK_OP(os, );
260     }
261 }
262 
addInfo(const AttributeInfo & value)263 void UrlAndDatasetWidget::addInfo(const AttributeInfo &value) {
264     infos << value;
265 }
266 
getInfos() const267 QList<AttributeInfo> UrlAndDatasetWidget::getInfos() const {
268     return infos;
269 }
270 
271 /************************************************************************/
272 /* RadioWidget */
273 /************************************************************************/
274 const QString RadioWidget::ID("radio");
Value(QString _id,QString _label)275 RadioWidget::Value::Value(QString _id, QString _label)
276     : id(_id), label(_label) {
277 }
278 
RadioWidget()279 RadioWidget::RadioWidget()
280     : WizardWidget() {
281 }
282 
accept(WizardWidgetVisitor * visitor)283 void RadioWidget::accept(WizardWidgetVisitor *visitor) {
284     visitor->visit(this);
285 }
286 
var() const287 const QString &RadioWidget::var() const {
288     return _var;
289 }
290 
setVar(const QString & value)291 void RadioWidget::setVar(const QString &value) {
292     _var = value;
293 }
294 
values() const295 const QList<RadioWidget::Value> &RadioWidget::values() const {
296     return _values;
297 }
298 
add(const Value & value)299 void RadioWidget::add(const Value &value) {
300     _values << value;
301 }
302 
303 /************************************************************************/
304 /* SettingsWidget */
305 /************************************************************************/
306 const QString SettingsWidget::ID("settings-widget");
307 const QString SettingsWidget::SETTING_PREFIX = "%setting%";
SettingsWidget()308 SettingsWidget::SettingsWidget()
309     : WizardWidget() {
310 }
311 
accept(WizardWidgetVisitor * visitor)312 void SettingsWidget::accept(WizardWidgetVisitor *visitor) {
313     visitor->visit(this);
314 }
315 
var() const316 const QString &SettingsWidget::var() const {
317     return _var;
318 }
setVar(const QString & value)319 void SettingsWidget::setVar(const QString &value) {
320     _var = value;
321 }
322 
type() const323 const QString &SettingsWidget::type() const {
324     return _type;
325 }
326 
setType(const QString & value)327 void SettingsWidget::setType(const QString &value) {
328     _type = value;
329 }
330 
label() const331 const QString &SettingsWidget::label() const {
332     return _label;
333 }
setLabel(const QString & value)334 void SettingsWidget::setLabel(const QString &value) {
335     _label = value;
336 }
337 
338 /************************************************************************/
339 /* BowtieWidget */
340 /************************************************************************/
341 const QString BowtieWidget::ID("bowtie-index");
BowtieWidget()342 BowtieWidget::BowtieWidget()
343     : WizardWidget(), idxDir("", ""), idxName("", "") {
344 }
345 
accept(WizardWidgetVisitor * visitor)346 void BowtieWidget::accept(WizardWidgetVisitor *visitor) {
347     visitor->visit(this);
348 }
349 
validate(const QList<Actor * > & actors,U2OpStatus & os) const350 void BowtieWidget::validate(const QList<Actor *> &actors, U2OpStatus &os) const {
351     idxName.validate(actors, os);
352     idxDir.validate(actors, os);
353 }
354 
355 /************************************************************************/
356 /* TophatSamplesWidget */
357 /************************************************************************/
358 const QString TophatSamplesWidget::ID("tophat-samples");
TophatSamplesWidget()359 TophatSamplesWidget::TophatSamplesWidget()
360     : WizardWidget(), samplesAttr("", "") {
361 }
362 
accept(WizardWidgetVisitor * visitor)363 void TophatSamplesWidget::accept(WizardWidgetVisitor *visitor) {
364     visitor->visit(this);
365 }
366 
validate(const QList<Actor * > & actors,U2OpStatus & os) const367 void TophatSamplesWidget::validate(const QList<Actor *> &actors, U2OpStatus &os) const {
368     samplesAttr.validate(actors, os);
369     CHECK_OP(os, );
370 
371     foreach (const Actor *a, actors) {
372         if (a->getId() == datasetsProvider) {
373             Attribute *attr = a->getParameter(BaseAttributes::URL_IN_ATTRIBUTE().getId());
374             URLAttribute *datasetAttr = dynamic_cast<URLAttribute *>(attr);
375             if (nullptr == datasetAttr) {
376                 os.setError(QObject::tr("The actor has not the dataset attribute"));
377             }
378             return;
379         }
380     }
381     os.setError(QObject::tr("Unknown actor ID: ") + datasetsProvider);
382 }
383 
384 /************************************************************************/
385 /* LabelWidget */
386 /************************************************************************/
387 const QString LabelWidget::ID("label");
388 const QString LabelWidget::DEFAULT_BG_COLOR("");
389 const QString LabelWidget::DEFAULT_TEXT_COLOR("black");
390 
LabelWidget()391 LabelWidget::LabelWidget()
392     : WizardWidget() {
393     textColor = DEFAULT_TEXT_COLOR;
394     backgroundColor = DEFAULT_BG_COLOR;
395 }
396 
accept(WizardWidgetVisitor * visitor)397 void LabelWidget::accept(WizardWidgetVisitor *visitor) {
398     visitor->visit(this);
399 }
400 
401 }  // namespace U2
402