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 <drivers/GTKeyboardDriver.h>
23 #include <primitives/GTCheckBox.h>
24 #include <primitives/GTComboBox.h>
25 #include <primitives/GTLineEdit.h>
26 #include <primitives/GTRadioButton.h>
27 #include <primitives/GTSlider.h>
28 #include <primitives/GTSpinBox.h>
29 #include <primitives/GTTextEdit.h>
30 #include <primitives/GTWidget.h>
31 #include <system/GTClipboard.h>
32 #include <utils/GTThread.h>
33 
34 #include <QComboBox>
35 #include <QLabel>
36 #include <QLineEdit>
37 #include <QPushButton>
38 #include <QSpinBox>
39 #include <QTextEdit>
40 #include <QToolButton>
41 #include <QTreeWidget>
42 
43 #include <U2Core/U2IdTypes.h>
44 
45 #include "GTUtilsMsaEditorSequenceArea.h"
46 #include "GTUtilsOptionPanelMSA.h"
47 #include "GTUtilsTaskTreeView.h"
48 #include "api/GTBaseCompleter.h"
49 
50 namespace U2 {
51 using namespace HI;
52 
initNames()53 QMap<GTUtilsOptionPanelMsa::Tabs, QString> GTUtilsOptionPanelMsa::initNames() {
54     QMap<Tabs, QString> result;
55     result.insert(General, "OP_MSA_GENERAL");
56     result.insert(Highlighting, "OP_MSA_HIGHLIGHTING");
57     result.insert(PairwiseAlignment, "OP_PAIRALIGN");
58     result.insert(TreeSettings, "OP_MSA_ADD_TREE_WIDGET");
59     result.insert(ExportConsensus, "OP_EXPORT_CONSENSUS");
60     result.insert(Statistics, "OP_SEQ_STATISTICS_WIDGET");
61     result.insert(Search, "OP_MSA_FIND_PATTERN_WIDGET");
62     return result;
63 }
64 
initInnerWidgetNames()65 QMap<GTUtilsOptionPanelMsa::Tabs, QString> GTUtilsOptionPanelMsa::initInnerWidgetNames() {
66     QMap<Tabs, QString> result;
67     result.insert(General, "MsaGeneralTab");
68     result.insert(Highlighting, "HighlightingOptionsPanelWidget");
69     result.insert(PairwiseAlignment, "PairwiseAlignmentOptionsPanelWidget");
70     result.insert(TreeSettings, "AddTreeWidget");
71     result.insert(ExportConsensus, "ExportConsensusWidget");
72     result.insert(Statistics, "SequenceStatisticsOptionsPanelTab");
73     result.insert(Search, "FindPatternMsaWidget");
74     return result;
75 }
76 const QMap<GTUtilsOptionPanelMsa::Tabs, QString> GTUtilsOptionPanelMsa::tabsNames = initNames();
77 const QMap<GTUtilsOptionPanelMsa::Tabs, QString> GTUtilsOptionPanelMsa::innerWidgetNames = initInnerWidgetNames();
78 
79 #define GT_CLASS_NAME "GTUtilsOptionPanelMSA"
80 
81 #define GT_METHOD_NAME "toggleTab"
toggleTab(HI::GUITestOpStatus & os,GTUtilsOptionPanelMsa::Tabs tab)82 void GTUtilsOptionPanelMsa::toggleTab(HI::GUITestOpStatus &os, GTUtilsOptionPanelMsa::Tabs tab) {
83     GTWidget::click(os, GTWidget::findWidget(os, tabsNames[tab]));
84     GTGlobals::sleep(500);
85 }
86 #undef GT_METHOD_NAME
87 
88 #define GT_METHOD_NAME "openTab"
openTab(HI::GUITestOpStatus & os,Tabs tab)89 QWidget *GTUtilsOptionPanelMsa::openTab(HI::GUITestOpStatus &os, Tabs tab) {
90     if (!isTabOpened(os, tab)) {
91         toggleTab(os, tab);
92     }
93     GTThread::waitForMainThread();
94     QString widgetName = innerWidgetNames[tab];
95     return GTWidget::findWidget(os, widgetName);
96 }
97 #undef GT_METHOD_NAME
98 
99 #define GT_METHOD_NAME "closeTab"
closeTab(HI::GUITestOpStatus & os,Tabs tab)100 void GTUtilsOptionPanelMsa::closeTab(HI::GUITestOpStatus &os, Tabs tab) {
101     if (isTabOpened(os, tab)) {
102         toggleTab(os, tab);
103     }
104 }
105 #undef GT_METHOD_NAME
106 
107 #define GT_METHOD_NAME "isTabOpened"
isTabOpened(HI::GUITestOpStatus & os,Tabs tab)108 bool GTUtilsOptionPanelMsa::isTabOpened(HI::GUITestOpStatus &os, Tabs tab) {
109     QWidget *innerTabWidget = GTWidget::findWidget(os, innerWidgetNames[tab], nullptr, GTGlobals::FindOptions(false));
110     return innerTabWidget != nullptr && innerTabWidget->isVisible();
111 }
112 #undef GT_METHOD_NAME
113 
114 #define GT_METHOD_NAME "checkTabIsOpened"
checkTabIsOpened(HI::GUITestOpStatus & os,Tabs tab)115 void GTUtilsOptionPanelMsa::checkTabIsOpened(HI::GUITestOpStatus &os, Tabs tab) {
116     QString name = innerWidgetNames[tab];
117     QWidget *innerTabWidget = GTWidget::findWidget(os, name);
118     GT_CHECK(innerTabWidget->isVisible(), "MSA Editor options panel is not opened: " + name);
119 }
120 #undef GT_METHOD_NAME
121 
122 #define GT_METHOD_NAME "addReference"
addReference(HI::GUITestOpStatus & os,QString seqName,AddRefMethod method)123 void GTUtilsOptionPanelMsa::addReference(HI::GUITestOpStatus &os, QString seqName, AddRefMethod method) {
124     GT_CHECK(!seqName.isEmpty(), "sequence name is empty");
125     // Option panel should be opned to use this method
126     QStringList nameList = GTUtilsMSAEditorSequenceArea::getNameList(os);
127 
128     GT_CHECK(nameList.contains(seqName), QString("sequence with name %1 not found").arg(seqName));
129 
130     switch (method) {
131         case Button:
132             GTUtilsMSAEditorSequenceArea::selectSequence(os, seqName);
133             GTWidget::click(os, GTWidget::findWidget(os, "addSeq"));
134             break;
135         case Completer:
136             QWidget *sequenceLineEdit = GTWidget::findWidget(os, "sequenceLineEdit");
137             GTWidget::click(os, sequenceLineEdit);
138             GTKeyboardDriver::keyClick(seqName.at(0).toLatin1());
139             GTGlobals::sleep(200);
140             GTBaseCompleter::click(os, sequenceLineEdit, seqName);
141             break;
142     }
143     GTThread::waitForMainThread();
144 }
145 #undef GT_METHOD_NAME
146 
147 #define GT_METHOD_NAME "removeReference"
removeReference(HI::GUITestOpStatus & os)148 void GTUtilsOptionPanelMsa::removeReference(HI::GUITestOpStatus &os) {
149     GTWidget::click(os, GTWidget::findWidget(os, "deleteSeq"));
150 }
151 #undef GT_METHOD_NAME
152 
153 #define GT_METHOD_NAME "getReference"
getReference(HI::GUITestOpStatus & os)154 QString GTUtilsOptionPanelMsa::getReference(HI::GUITestOpStatus &os) {
155     openTab(os, General);
156     QLineEdit *leReference = GTWidget::findExactWidget<QLineEdit *>(os, "sequenceLineEdit");
157     GT_CHECK_RESULT(nullptr != leReference, "Reference sequence name lineedit is NULL", QString());
158     return leReference->text();
159 }
160 #undef GT_METHOD_NAME
161 
162 #define GT_METHOD_NAME "getLength"
getLength(HI::GUITestOpStatus & os)163 int GTUtilsOptionPanelMsa::getLength(HI::GUITestOpStatus &os) {
164     QLabel *alignmentLengthLabel = qobject_cast<QLabel *>(GTWidget::findWidget(os, "alignmentLength"));
165     GT_CHECK_RESULT(alignmentLengthLabel != nullptr, "alignmentLengthLabel not found", -1);
166     bool ok;
167     int result = alignmentLengthLabel->text().toInt(&ok);
168     GT_CHECK_RESULT(ok, "label text is not int", -1);
169     return result;
170 }
171 #undef GT_METHOD_NAME
172 
173 #define GT_METHOD_NAME "getHeight"
getHeight(HI::GUITestOpStatus & os)174 int GTUtilsOptionPanelMsa::getHeight(HI::GUITestOpStatus &os) {
175     QLabel *alignmentHeightLabel = qobject_cast<QLabel *>(GTWidget::findWidget(os, "alignmentHeight"));
176     GT_CHECK_RESULT(alignmentHeightLabel != nullptr, "alignmentHeightLabel not found", -1);
177     bool ok;
178     int result = alignmentHeightLabel->text().toInt(&ok);
179     GT_CHECK_RESULT(ok, "label text is not int", -1);
180     return result;
181 }
182 #undef GT_METHOD_NAME
183 
184 #define GT_METHOD_NAME "copySelection"
copySelection(HI::GUITestOpStatus & os,const CopyFormat format)185 void GTUtilsOptionPanelMsa::copySelection(HI::GUITestOpStatus &os, const CopyFormat format) {
186     openTab(os, General);
187     QComboBox *copyType = qobject_cast<QComboBox *>(GTWidget::findWidget(os, "copyType"));
188     GT_CHECK_RESULT(copyType != nullptr, "copyType not found", );
189 
190     QString stringFormat;
191     switch (format) {
192         case CopyFormat::Fasta:
193             stringFormat = "Fasta";
194             break;
195         case CopyFormat::CLUSTALW:
196             stringFormat = "CLUSTALW";
197             break;
198         case CopyFormat::Stocholm:
199             stringFormat = "Stocholm";
200             break;
201         case CopyFormat::MSF:
202             stringFormat = "MSF";
203             break;
204         case CopyFormat::NEXUS:
205             stringFormat = "NEXUS";
206             break;
207         case CopyFormat::Mega:
208             stringFormat = "Mega";
209             break;
210         case CopyFormat::PHYLIP_Interleaved:
211             stringFormat = "PHYLIP Interleaved";
212             break;
213         case CopyFormat::PHYLIP_Sequential:
214             stringFormat = "PHYLIP Sequential";
215             break;
216         case CopyFormat::Rich_text:
217             stringFormat = "Rich text (HTML)";
218             break;
219 
220         default:
221             GT_CHECK_RESULT(false, "Unexpected format", );
222             break;
223     }
224     GTComboBox::selectItemByText(os, copyType, stringFormat);
225 
226     QToolButton *copyButton = qobject_cast<QToolButton *>(GTWidget::findWidget(os, "copyButton"));
227     GT_CHECK_RESULT(copyButton != nullptr, "copyType not found", );
228 
229     GTWidget::click(os, copyButton);
230 }
231 #undef GT_METHOD_NAME
232 
233 #define GT_METHOD_NAME "setColorScheme"
setColorScheme(HI::GUITestOpStatus & os,const QString & colorSchemeName,GTGlobals::UseMethod method)234 void GTUtilsOptionPanelMsa::setColorScheme(HI::GUITestOpStatus &os, const QString &colorSchemeName, GTGlobals::UseMethod method) {
235     openTab(os, Highlighting);
236     GTComboBox::selectItemByText(os, GTWidget::findExactWidget<QComboBox *>(os, "colorScheme"), colorSchemeName, method);
237 }
238 #undef GT_METHOD_NAME
239 
240 #define GT_METHOD_NAME "getColorScheme"
getColorScheme(HI::GUITestOpStatus & os)241 QString GTUtilsOptionPanelMsa::getColorScheme(HI::GUITestOpStatus &os) {
242     openTab(os, Highlighting);
243     QComboBox *colorScheme = GTWidget::findExactWidget<QComboBox *>(os, "colorScheme");
244     GT_CHECK_RESULT(colorScheme != nullptr, "ColorSCheme combobox is NULL", "");
245     return colorScheme->currentText();
246 }
247 #undef GT_METHOD_NAME
248 
249 #define GT_METHOD_NAME "setHighlightingScheme"
setHighlightingScheme(GUITestOpStatus & os,const QString & highlightingSchemeName)250 void GTUtilsOptionPanelMsa::setHighlightingScheme(GUITestOpStatus &os, const QString &highlightingSchemeName) {
251     openTab(os, Highlighting);
252     GTComboBox::selectItemByText(os, GTWidget::findExactWidget<QComboBox *>(os, "highlightingScheme"), highlightingSchemeName);
253 }
254 #undef GT_METHOD_NAME
255 
256 #define GT_METHOD_NAME "addFirstSeqToPA"
addFirstSeqToPA(HI::GUITestOpStatus & os,QString seqName,AddRefMethod method)257 void GTUtilsOptionPanelMsa::addFirstSeqToPA(HI::GUITestOpStatus &os, QString seqName, AddRefMethod method) {
258     addSeqToPA(os, seqName, method, 1);
259 }
260 #undef GT_METHOD_NAME
261 
262 #define GT_METHOD_NAME "addSecondSeqToPA"
addSecondSeqToPA(HI::GUITestOpStatus & os,QString seqName,AddRefMethod method)263 void GTUtilsOptionPanelMsa::addSecondSeqToPA(HI::GUITestOpStatus &os, QString seqName, AddRefMethod method) {
264     addSeqToPA(os, seqName, method, 2);
265 }
266 #undef GT_METHOD_NAME
267 
getSeqFromPAlineEdit(HI::GUITestOpStatus & os,int num)268 QString GTUtilsOptionPanelMsa::getSeqFromPAlineEdit(HI::GUITestOpStatus &os, int num) {
269     QLineEdit *le = qobject_cast<QLineEdit *>(getWidget(os, "sequenceLineEdit", num));
270     return le->text();
271 }
272 
273 #define GT_METHOD_NAME "addSeqToPA"
addSeqToPA(HI::GUITestOpStatus & os,QString seqName,AddRefMethod method,int number)274 void GTUtilsOptionPanelMsa::addSeqToPA(HI::GUITestOpStatus &os, QString seqName, AddRefMethod method, int number) {
275     GT_CHECK(number == 1 || number == 2, "number must be 1 or 2");
276     GT_CHECK(!seqName.isEmpty(), "sequence name is empty");
277     // Option panel should be opned to use this method
278     QStringList nameList = GTUtilsMSAEditorSequenceArea::getNameList(os);
279 
280     GT_CHECK(nameList.contains(seqName), QString("sequence with name %1 not found").arg(seqName));
281 
282     switch (method) {
283         case Button:
284             GTUtilsMSAEditorSequenceArea::selectSequence(os, seqName);
285             GTWidget::click(os, getAddButton(os, number));
286             break;
287         case Completer:
288             QWidget *sequenceLineEdit = getSeqLineEdit(os, number);
289             GTWidget::click(os, sequenceLineEdit);
290             GTKeyboardDriver::keyClick(seqName.at(0).toLatin1());
291             GTGlobals::sleep(200);
292             GTBaseCompleter::click(os, sequenceLineEdit, seqName);
293             break;
294     }
295 }
296 #undef GT_METHOD_NAME
297 
298 #define GT_METHOD_NAME "getAddButton"
getAddButton(HI::GUITestOpStatus & os,int number)299 QToolButton *GTUtilsOptionPanelMsa::getAddButton(HI::GUITestOpStatus &os, int number) {
300     QToolButton *result = qobject_cast<QToolButton *>(getWidget(os, "addSeq", number));
301     GT_CHECK_RESULT(result != nullptr, "toolbutton is NULL", nullptr);
302     return result;
303 }
304 #undef GT_METHOD_NAME
305 
306 #define GT_METHOD_NAME "getDeleteButton"
getDeleteButton(HI::GUITestOpStatus & os,int number)307 QToolButton *GTUtilsOptionPanelMsa::getDeleteButton(HI::GUITestOpStatus &os, int number) {
308     QToolButton *result = qobject_cast<QToolButton *>(getWidget(os, "deleteSeq", number));
309     GT_CHECK_RESULT(result != nullptr, "toolbutton is NULL", nullptr);
310     return result;
311 }
312 #undef GT_METHOD_NAME
313 
314 #define GT_METHOD_NAME "getAlignButton"
getAlignButton(HI::GUITestOpStatus & os)315 QPushButton *GTUtilsOptionPanelMsa::getAlignButton(HI::GUITestOpStatus &os) {
316     openTab(os, PairwiseAlignment);
317     return GTWidget::findExactWidget<QPushButton *>(os, "alignButton");
318 }
319 #undef GT_METHOD_NAME
320 
321 #define GT_METHOD_NAME "setPairwiseAlignmentAlgorithm"
setPairwiseAlignmentAlgorithm(HI::GUITestOpStatus & os,const QString & algorithm)322 void GTUtilsOptionPanelMsa::setPairwiseAlignmentAlgorithm(HI::GUITestOpStatus &os, const QString &algorithm) {
323     openTab(os, PairwiseAlignment);
324     GTComboBox::selectItemByText(os, GTWidget::findExactWidget<QComboBox *>(os, "algorithmListComboBox"), algorithm);
325 }
326 #undef GT_METHOD_NAME
327 
328 #define GT_METHOD_NAME "setThreshold"
setThreshold(GUITestOpStatus & os,int threshold)329 void GTUtilsOptionPanelMsa::setThreshold(GUITestOpStatus &os, int threshold) {
330     openTab(os, General);
331     GTSlider::setValue(os, GTWidget::findExactWidget<QSlider *>(os, "thresholdSlider"), threshold);
332 }
333 #undef GT_METHOD_NAME
334 
335 #define GT_METHOD_NAME "getThreshold"
getThreshold(GUITestOpStatus & os)336 int GTUtilsOptionPanelMsa::getThreshold(GUITestOpStatus &os) {
337     openTab(os, General);
338     QSlider *thresholdSlider = GTWidget::findExactWidget<QSlider *>(os, "thresholdSlider");
339     GT_CHECK_RESULT(nullptr != thresholdSlider, "thresholdSlider is NULL", -1);
340     return thresholdSlider->value();
341 }
342 #undef GT_METHOD_NAME
343 
344 #define GT_METHOD_NAME "setThresholdComparison"
setThresholdComparison(GUITestOpStatus & os,GTUtilsOptionPanelMsa::ThresholdComparison comparison)345 void GTUtilsOptionPanelMsa::setThresholdComparison(GUITestOpStatus &os, GTUtilsOptionPanelMsa::ThresholdComparison comparison) {
346     openTab(os, Highlighting);
347     switch (comparison) {
348         case LessOrEqual:
349             GTRadioButton::click(os, GTWidget::findExactWidget<QRadioButton *>(os, "thresholdLessRb"));
350             break;
351         case GreaterOrEqual:
352             GTRadioButton::click(os, GTWidget::findExactWidget<QRadioButton *>(os, "thresholdMoreRb"));
353             break;
354         default:
355             GT_CHECK(false, QString("An unknown threshold comparison type: %1").arg(comparison));
356     }
357 }
358 #undef GT_METHOD_NAME
359 
360 #define GT_METHOD_NAME "getThresholdComparison"
getThresholdComparison(GUITestOpStatus & os)361 GTUtilsOptionPanelMsa::ThresholdComparison GTUtilsOptionPanelMsa::getThresholdComparison(GUITestOpStatus &os) {
362     openTab(os, Highlighting);
363     QRadioButton *thresholdLessRb = GTWidget::findExactWidget<QRadioButton *>(os, "thresholdLessRb");
364     GT_CHECK_RESULT(nullptr != thresholdLessRb, "thresholdLessRb is NULL", LessOrEqual);
365     QRadioButton *thresholdMoreRb = GTWidget::findExactWidget<QRadioButton *>(os, "thresholdMoreRb");
366     GT_CHECK_RESULT(nullptr != thresholdMoreRb, "thresholdMoreRb is NULL", LessOrEqual);
367     const bool lessOrEqual = thresholdLessRb->isChecked();
368     const bool greaterOrEqual = thresholdMoreRb->isChecked();
369     GT_CHECK_RESULT(lessOrEqual ^ greaterOrEqual, "Incorrect state of threshold comparison radiobuttons", LessOrEqual);
370     return lessOrEqual ? LessOrEqual : GreaterOrEqual;
371 }
372 #undef GT_METHOD_NAME
373 
374 #define GT_METHOD_NAME "setUseDotsOption"
setUseDotsOption(GUITestOpStatus & os,bool useDots)375 void GTUtilsOptionPanelMsa::setUseDotsOption(GUITestOpStatus &os, bool useDots) {
376     openTab(os, Highlighting);
377     GTCheckBox::setChecked(os, GTWidget::findExactWidget<QCheckBox *>(os, "useDots"), useDots);
378 }
379 #undef GT_METHOD_NAME
380 
381 #define GT_METHOD_NAME "isUseDotsOptionSet"
isUseDotsOptionSet(GUITestOpStatus & os)382 bool GTUtilsOptionPanelMsa::isUseDotsOptionSet(GUITestOpStatus &os) {
383     openTab(os, Highlighting);
384     QCheckBox *useDots = GTWidget::findExactWidget<QCheckBox *>(os, "useDots");
385     GT_CHECK_RESULT(nullptr != useDots, "useDots checkbox is NULL", false);
386     return useDots->isChecked();
387 }
388 #undef GT_METHOD_NAME
389 
390 #define GT_METHOD_NAME "setExportConsensusOutputPath"
setExportConsensusOutputPath(GUITestOpStatus & os,const QString & filePath)391 void GTUtilsOptionPanelMsa::setExportConsensusOutputPath(GUITestOpStatus &os, const QString &filePath) {
392     openTab(os, ExportConsensus);
393     GTLineEdit::setText(os, "pathLe", filePath, nullptr);
394 }
395 #undef GT_METHOD_NAME
396 
397 #define GT_METHOD_NAME "getExportConsensusOutputPath"
getExportConsensusOutputPath(GUITestOpStatus & os)398 QString GTUtilsOptionPanelMsa::getExportConsensusOutputPath(GUITestOpStatus &os) {
399     return GTLineEdit::getText(os, "pathLe");
400 }
401 #undef GT_METHOD_NAME
402 
403 #define GT_METHOD_NAME "getExportConsensusOutputFormat"
getExportConsensusOutputFormat(GUITestOpStatus & os)404 QString GTUtilsOptionPanelMsa::getExportConsensusOutputFormat(GUITestOpStatus &os) {
405     return GTComboBox::getCurrentText(os, "formatCb");
406 }
407 #undef GT_METHOD_NAME
408 
409 #define GT_METHOD_NAME "enterPattern"
enterPattern(HI::GUITestOpStatus & os,QString pattern,bool useCopyPaste)410 void GTUtilsOptionPanelMsa::enterPattern(HI::GUITestOpStatus &os, QString pattern, bool useCopyPaste /*= false*/) {
411     QTextEdit *patternEdit = GTWidget::findTextEdit(os, "textPattern");
412     GTWidget::click(os, patternEdit);
413 
414     if (!patternEdit->toPlainText().isEmpty()) {
415         GTTextEdit::clear(os, patternEdit);
416     }
417     if (useCopyPaste) {
418         GTClipboard::setText(os, pattern);
419         GTKeyboardDriver::keyClick('v', Qt::ControlModifier);
420     } else {
421         GTTextEdit::setText(os, patternEdit, pattern);
422     }
423 }
424 #undef GT_METHOD_NAME
425 
426 #define GT_METHOD_NAME "getPattern"
getPattern(GUITestOpStatus & os)427 QString GTUtilsOptionPanelMsa::getPattern(GUITestOpStatus &os) {
428     QTextEdit *patternEdit = GTWidget::findTextEdit(os, "textPattern");
429     return patternEdit->toPlainText();
430 }
431 #undef GT_METHOD_NAME
432 
433 #define GT_METHOD_NAME "setAlgorithm"
setAlgorithm(HI::GUITestOpStatus & os,QString algorithm)434 void GTUtilsOptionPanelMsa::setAlgorithm(HI::GUITestOpStatus &os, QString algorithm) {
435     QComboBox *algoBox = qobject_cast<QComboBox *>(GTWidget::findWidget(os, "boxAlgorithm"));
436     GT_CHECK(algoBox != nullptr, "algoBox is NULL");
437 
438     if (!algoBox->isVisible()) {
439         GTWidget::click(os, GTWidget::findWidget(os, "ArrowHeader_Search algorithm"));
440     }
441     GTComboBox::selectItemByText(os, algoBox, algorithm);
442     GTGlobals::sleep(2500);
443 }
444 #undef GT_METHOD_NAME
445 
446 #define GT_METHOD_NAME "setMatchPercentage"
setMatchPercentage(HI::GUITestOpStatus & os,int percentage)447 void GTUtilsOptionPanelMsa::setMatchPercentage(HI::GUITestOpStatus &os, int percentage) {
448     QSpinBox *spinMatchBox = qobject_cast<QSpinBox *>(GTWidget::findWidget(os, "spinBoxMatch"));
449 
450     GTSpinBox::setValue(os, spinMatchBox, percentage, GTGlobals::UseKeyBoard);
451     GTGlobals::sleep(2500);
452 }
453 #undef GT_METHOD_NAME
454 
455 #define GT_METHOD_NAME "setCheckedRemoveOverlappedResults"
setCheckedRemoveOverlappedResults(HI::GUITestOpStatus & os,bool setChecked)456 void GTUtilsOptionPanelMsa::setCheckedRemoveOverlappedResults(HI::GUITestOpStatus &os, bool setChecked) {
457     QCheckBox *overlapsBox = qobject_cast<QCheckBox *>(GTWidget::findWidget(os, "removeOverlapsBox"));
458     GT_CHECK(overlapsBox != nullptr, "overlapsBox is NULL");
459 
460     if (!overlapsBox->isVisible()) {
461         GTWidget::click(os, GTWidget::findWidget(os, "ArrowHeader_Other settings"));
462     }
463     GTCheckBox::setChecked(os, "removeOverlapsBox", setChecked);
464 }
465 #undef GT_METHOD_NAME
466 
467 #define GT_METHOD_NAME "checkResultsText"
checkResultsText(HI::GUITestOpStatus & os,QString expectedText)468 void GTUtilsOptionPanelMsa::checkResultsText(HI::GUITestOpStatus &os, QString expectedText) {
469     GTUtilsTaskTreeView::waitTaskFinished(os);
470     QLabel *label = qobject_cast<QLabel *>(GTWidget::findWidget(os, "resultLabel"));
471     QString actualText = label->text();
472     CHECK_SET_ERR(actualText == expectedText, QString("Wrong result. Expected: %1, got: %2").arg(expectedText).arg(actualText));
473 }
474 #undef GT_METHOD_NAME
475 
476 #define GT_METHOD_NAME "clickNext"
477 
clickNext(HI::GUITestOpStatus & os)478 void GTUtilsOptionPanelMsa::clickNext(HI::GUITestOpStatus &os) {
479     QPushButton *next = qobject_cast<QPushButton *>(GTWidget::findWidget(os, "nextPushButton"));
480     GTWidget::click(os, next);
481 }
482 
483 #undef GT_METHOD_NAME
484 
485 #define GT_METHOD_NAME "clickPrev"
clickPrev(HI::GUITestOpStatus & os)486 void GTUtilsOptionPanelMsa::clickPrev(HI::GUITestOpStatus &os) {
487     QPushButton *prev = qobject_cast<QPushButton *>(GTWidget::findWidget(os, "prevPushButton"));
488     GTWidget::click(os, prev);
489 }
490 #undef GT_METHOD_NAME
491 
492 #define GT_METHOD_NAME "getSeqLineEdit"
getSeqLineEdit(HI::GUITestOpStatus & os,int number)493 QLineEdit *GTUtilsOptionPanelMsa::getSeqLineEdit(HI::GUITestOpStatus &os, int number) {
494     QLineEdit *result = qobject_cast<QLineEdit *>(getWidget(os, "sequenceLineEdit", number));
495     GT_CHECK_RESULT(result != nullptr, "sequenceLineEdit is NULL", nullptr);
496     return result;
497 }
498 #undef GT_METHOD_NAME
499 
500 #define GT_METHOD_NAME "isSearchInShowHideWidgetOpened"
isSearchInShowHideWidgetOpened(HI::GUITestOpStatus & os)501 bool GTUtilsOptionPanelMsa::isSearchInShowHideWidgetOpened(HI::GUITestOpStatus &os) {
502     QWidget *searchInInnerWidget = GTWidget::findWidget(os, "widgetSearchIn");
503     GT_CHECK_RESULT(searchInInnerWidget != nullptr, "searchInInnerWidget is NULL", false);
504     return searchInInnerWidget->isVisible();
505 }
506 #undef GT_METHOD_NAME
507 
508 #define GT_METHOD_NAME "openSearchInShowHideWidget"
openSearchInShowHideWidget(HI::GUITestOpStatus & os,bool open)509 void GTUtilsOptionPanelMsa::openSearchInShowHideWidget(HI::GUITestOpStatus &os, bool open) {
510     CHECK(open != isSearchInShowHideWidgetOpened(os), );
511     GTWidget::click(os, GTWidget::findWidget(os, "ArrowHeader_Search in"));
512 }
513 #undef GT_METHOD_NAME
514 
515 #define GT_METHOD_NAME "setRegionType"
setRegionType(HI::GUITestOpStatus & os,const QString & regionType)516 void GTUtilsOptionPanelMsa::setRegionType(HI::GUITestOpStatus &os, const QString &regionType) {
517     openSearchInShowHideWidget(os);
518     GTComboBox::selectItemByText(os, GTWidget::findExactWidget<QComboBox *>(os, "boxRegion"), regionType);
519 }
520 #undef GT_METHOD_NAME
521 
522 #define GT_METHOD_NAME "setRegion"
setRegion(HI::GUITestOpStatus & os,int from,int to)523 void GTUtilsOptionPanelMsa::setRegion(HI::GUITestOpStatus &os, int from, int to) {
524     openSearchInShowHideWidget(os);
525     GTLineEdit::setText(os, GTWidget::findExactWidget<QLineEdit *>(os, "editStart"), QString::number(from));
526     GTLineEdit::setText(os, GTWidget::findExactWidget<QLineEdit *>(os, "editEnd"), QString::number(to));
527 }
528 #undef GT_METHOD_NAME
529 
530 #define GT_METHOD_NAME "setSearchContext"
setSearchContext(HI::GUITestOpStatus & os,const QString & context)531 void GTUtilsOptionPanelMsa::setSearchContext(HI::GUITestOpStatus &os, const QString &context) {
532     QComboBox *searchContextBox = qobject_cast<QComboBox *>(GTWidget::findWidget(os, "searchContextComboBox"));
533     GT_CHECK(searchContextBox != nullptr, "searchContextBox is NULL");
534     GTComboBox::selectItemByText(os, searchContextBox, context);
535 }
536 #undef GT_METHOD_NAME
537 
538 #define GT_METHOD_NAME "getWidget"
getWidget(HI::GUITestOpStatus & os,const QString & widgetName,int number)539 QWidget *GTUtilsOptionPanelMsa::getWidget(HI::GUITestOpStatus &os, const QString &widgetName, int number) {
540     QWidget *sequenceContainerWidget = GTWidget::findWidget(os, "sequenceContainerWidget");
541     GT_CHECK_RESULT(sequenceContainerWidget != nullptr, "sequenceContainerWidget not found", nullptr);
542     QList<QWidget *> widgetList = sequenceContainerWidget->findChildren<QWidget *>(widgetName);
543     GT_CHECK_RESULT(widgetList.count() == 2, QString("unexpected number of widgets: %1").arg(widgetList.count()), nullptr);
544     QWidget *w1 = widgetList[0];
545     QWidget *w2 = widgetList[1];
546     int y1 = w1->mapToGlobal(w1->rect().center()).y();
547     int y2 = w2->mapToGlobal(w2->rect().center()).y();
548     GT_CHECK_RESULT(y1 != y2, "coordinates are unexpectidly equal", nullptr);
549 
550     if (number == 1) {
551         if (y1 < y2) {
552             return w1;
553         } else {
554             return w2;
555         }
556     } else if (number == 2) {
557         if (y1 < y2) {
558             return w2;
559         } else {
560             return w1;
561         }
562     } else {
563         GT_CHECK_RESULT(false, "number should be 1 or 2", nullptr);
564     }
565 }
566 #undef GT_METHOD_NAME
567 
568 #define GT_METHOD_NAME "getAlphabetLabelText"
getAlphabetLabelText(HI::GUITestOpStatus & os)569 QString GTUtilsOptionPanelMsa::getAlphabetLabelText(HI::GUITestOpStatus &os) {
570     checkTabIsOpened(os, General);
571     auto label = GTWidget::findExactWidget<QLabel *>(os, "alignmentAlphabet");
572     return label->text();
573 }
574 #undef GT_METHOD_NAME
575 
576 #undef GT_CLASS_NAME
577 }  // namespace U2
578