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 <primitives/GTComboBox.h>
23 #include <primitives/GTGroupBox.h>
24 #include <primitives/GTLineEdit.h>
25 #include <primitives/GTSlider.h>
26 #include <primitives/GTSpinBox.h>
27 #include <primitives/GTWidget.h>
28 #include <utils/GTThread.h>
29 
30 #include <QApplication>
31 #include <QComboBox>
32 #include <QLabel>
33 #include <QToolButton>
34 
35 #include "GTUtilsMcaEditor.h"
36 #include "GTUtilsOptionPanelMca.h"
37 
38 namespace U2 {
39 using namespace HI;
40 
41 const QMap<GTUtilsOptionPanelMca::Tabs, QString> GTUtilsOptionPanelMca::tabsNames = {{General, "OP_MCA_GENERAL"},
42                                                                                      {Consensus, "OP_CONSENSUS"},
43                                                                                      {Reads, "OP_MCA_READS"}};
44 const QMap<GTUtilsOptionPanelMca::Tabs, QString> GTUtilsOptionPanelMca::innerWidgetNames = {{General, "McaGeneralTab"},
45                                                                                             {Consensus, "ExportConsensusWidget"},
46                                                                                             {Reads, "McaAlternativeMutationsWidget"}};
47 
48 #define GT_CLASS_NAME "GTUtilsOptionPanelMca"
49 
50 #define GT_METHOD_NAME "toggleTab"
toggleTab(HI::GUITestOpStatus & os,Tabs tab,QWidget * parent)51 void GTUtilsOptionPanelMca::toggleTab(HI::GUITestOpStatus &os, Tabs tab, QWidget *parent) {
52     GTUtilsMcaEditor::checkMcaEditorWindowIsActive(os);
53     GTWidget::click(os, GTWidget::findWidget(os, tabsNames[tab], parent));
54     GTGlobals::sleep(500);
55 }
56 #undef GT_METHOD_NAME
57 
58 #define GT_METHOD_NAME "openTab"
openTab(HI::GUITestOpStatus & os,Tabs tab,QWidget * parent)59 void GTUtilsOptionPanelMca::openTab(HI::GUITestOpStatus &os, Tabs tab, QWidget *parent) {
60     if (!isTabOpened(os, tab, parent)) {
61         toggleTab(os, tab, parent);
62     }
63 }
64 #undef GT_METHOD_NAME
65 
66 #define GT_METHOD_NAME "closeTab"
closeTab(HI::GUITestOpStatus & os,Tabs tab)67 void GTUtilsOptionPanelMca::closeTab(HI::GUITestOpStatus &os, Tabs tab) {
68     if (isTabOpened(os, tab)) {
69         toggleTab(os, tab);
70     }
71 }
72 #undef GT_METHOD_NAME
73 
74 #define GT_METHOD_NAME "isTabOpened"
isTabOpened(HI::GUITestOpStatus & os,Tabs tab,QWidget * parent)75 bool GTUtilsOptionPanelMca::isTabOpened(HI::GUITestOpStatus &os, Tabs tab, QWidget *parent) {
76     GTGlobals::FindOptions options;
77     options.failIfNotFound = false;
78     QWidget *innerTabWidget = GTWidget::findWidget(os, innerWidgetNames[tab], parent, options);
79     return nullptr != innerTabWidget && innerTabWidget->isVisible();
80 }
81 #undef GT_METHOD_NAME
82 
83 #define GT_METHOD_NAME "setConsensusType"
setConsensusType(HI::GUITestOpStatus & os,const QString & consensusTypeName)84 void GTUtilsOptionPanelMca::setConsensusType(HI::GUITestOpStatus &os, const QString &consensusTypeName) {
85     openTab(os, Consensus);
86     GTComboBox::selectItemByText(os, GTWidget::findExactWidget<QComboBox *>(os, "consensusType"), consensusTypeName);
87 }
88 #undef GT_METHOD_NAME
89 
90 #define GT_METHOD_NAME "getConsensusType"
getConsensusType(HI::GUITestOpStatus & os)91 QString GTUtilsOptionPanelMca::getConsensusType(HI::GUITestOpStatus &os) {
92     openTab(os, Consensus);
93     return GTComboBox::getCurrentText(os, GTWidget::findExactWidget<QComboBox *>(os, "consensusType"));
94 }
95 #undef GT_METHOD_NAME
96 
97 #define GT_METHOD_NAME "getConsensusTypes"
getConsensusTypes(HI::GUITestOpStatus & os)98 QStringList GTUtilsOptionPanelMca::getConsensusTypes(HI::GUITestOpStatus &os) {
99     openTab(os, Consensus);
100     QStringList types = GTComboBox::getValues(os, GTWidget::findExactWidget<QComboBox *>(os, "consensusType"));
101     return types;
102 }
103 #undef GT_METHOD_NAME
104 
105 #define GT_METHOD_NAME "getHeight"
getHeight(HI::GUITestOpStatus & os)106 int GTUtilsOptionPanelMca::getHeight(HI::GUITestOpStatus &os) {
107     QLabel *alignmentHeightLabel = qobject_cast<QLabel *>(GTWidget::findWidget(os, "seqNumLabel"));
108     GT_CHECK_RESULT(alignmentHeightLabel != nullptr, "alignmentHeightLabel not found", -1);
109     bool ok;
110     int result = alignmentHeightLabel->text().toInt(&ok);
111     GT_CHECK_RESULT(ok == true, "label text is not int", -1);
112     return result;
113 }
114 #undef GT_METHOD_NAME
115 
116 #define GT_METHOD_NAME "getLength"
getLength(HI::GUITestOpStatus & os)117 int GTUtilsOptionPanelMca::getLength(HI::GUITestOpStatus &os) {
118     QLabel *alignmentLengthLabel = qobject_cast<QLabel *>(GTWidget::findWidget(os, "lengthLabel"));
119     GT_CHECK_RESULT(alignmentLengthLabel != nullptr, "alignmentLengthLabel not found", -1);
120     bool ok;
121     int result = alignmentLengthLabel->text().toInt(&ok);
122     GT_CHECK_RESULT(ok == true, "label text is not int", -1);
123     return result;
124 }
125 #undef GT_METHOD_NAME
126 
127 #define GT_METHOD_NAME "setThreshold"
setThreshold(GUITestOpStatus & os,int threshold)128 void GTUtilsOptionPanelMca::setThreshold(GUITestOpStatus &os, int threshold) {
129     openTab(os, Consensus);
130     GTSlider::setValue(os, GTWidget::findExactWidget<QSlider *>(os, "thresholdSlider"), threshold);
131 }
132 #undef GT_METHOD_NAME
133 
134 #define GT_METHOD_NAME "getThreshold"
getThreshold(GUITestOpStatus & os)135 int GTUtilsOptionPanelMca::getThreshold(GUITestOpStatus &os) {
136     openTab(os, Consensus);
137     QSlider *thresholdSlider = GTWidget::findExactWidget<QSlider *>(os, "thresholdSlider");
138     GT_CHECK_RESULT(nullptr != thresholdSlider, "thresholdSlider is NULL", -1);
139     return thresholdSlider->value();
140 }
141 #undef GT_METHOD_NAME
142 
143 #define GT_METHOD_NAME "setExportFileName"
setExportFileName(HI::GUITestOpStatus & os,QString exportFileName)144 void GTUtilsOptionPanelMca::setExportFileName(HI::GUITestOpStatus &os, QString exportFileName) {
145     openTab(os, Consensus);
146     QLineEdit *exportToFileLineEdit = GTWidget::findExactWidget<QLineEdit *>(os, "pathLe");
147     GT_CHECK_RESULT(exportToFileLineEdit != nullptr, "exportToFileLineEdit is NULL", );
148     GTLineEdit::setText(os, exportToFileLineEdit, exportFileName);
149 }
150 #undef GT_METHOD_NAME
151 
152 #define GT_METHOD_NAME "getExportFileName"
getExportFileName(HI::GUITestOpStatus & os)153 QString GTUtilsOptionPanelMca::getExportFileName(HI::GUITestOpStatus &os) {
154     openTab(os, Consensus);
155     QLineEdit *exportToFileLineEdit = GTWidget::findExactWidget<QLineEdit *>(os, "pathLe");
156     GT_CHECK_RESULT(exportToFileLineEdit != nullptr, "exportToFileLineEdit is NULL", QString());
157     return GTLineEdit::getText(os, exportToFileLineEdit);
158 }
159 #undef GT_METHOD_NAME
160 
161 #define GT_METHOD_NAME "setFileFormat"
setFileFormat(HI::GUITestOpStatus & os,FileFormat fileFormat)162 void GTUtilsOptionPanelMca::setFileFormat(HI::GUITestOpStatus &os, FileFormat fileFormat) {
163     openTab(os, Consensus);
164     QComboBox *formatCb = GTWidget::findExactWidget<QComboBox *>(os, "formatCb");
165     GTComboBox::selectItemByIndex(os, formatCb, fileFormat);
166     GTGlobals::sleep(1000);
167 }
168 #undef GT_METHOD_NAME
169 
170 #define GT_METHOD_NAME "pushResetButton"
pushResetButton(HI::GUITestOpStatus & os)171 void GTUtilsOptionPanelMca::pushResetButton(HI::GUITestOpStatus &os) {
172     openTab(os, Consensus);
173     QToolButton *result = GTWidget::findExactWidget<QToolButton *>(os, "thresholdResetButton");
174     result->click();
175 }
176 #undef GT_METHOD_NAME
177 
178 #define GT_METHOD_NAME "pushExportButton"
pushExportButton(HI::GUITestOpStatus & os)179 void GTUtilsOptionPanelMca::pushExportButton(HI::GUITestOpStatus &os) {
180     openTab(os, Consensus);
181     QToolButton *result = GTWidget::findExactWidget<QToolButton *>(os, "exportBtn");
182     result->click();
183 }
184 #undef GT_METHOD_NAME
185 
186 #define GT_METHOD_NAME "showAlternativeMutations"
showAlternativeMutations(HI::GUITestOpStatus & os,bool show,int value,bool withSpinbox,QWidget * parent)187 void GTUtilsOptionPanelMca::showAlternativeMutations(HI::GUITestOpStatus &os, bool show, int value, bool withSpinbox, QWidget *parent) {
188     GTUtilsOptionPanelMca::openTab(os, Tabs::Reads, parent);
189     GTGroupBox::setChecked(os, "mutationsGroupBox", show, parent);
190     if (!show) {
191         GTThread::waitForMainThread();
192         return;
193     }
194 
195     if (withSpinbox) {
196         GTSpinBox::setValue(os, "mutationsThresholdSpinBox", value, parent);
197     } else {
198         GTSlider::setValue(os, GTWidget::findExactWidget<QSlider *>(os, "mutationsThresholdSlider", parent), value);
199     }
200 
201     GTWidget::click(os, GTWidget::findExactWidget<QPushButton *>(os, "updateMutationsPushButton", parent));
202     GTThread::waitForMainThread();
203 }
204 #undef GT_METHOD_NAME
205 
206 #undef GT_METHOD_NAME
207 
208 }  // namespace U2
209