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/GTLineEdit.h>
23 #include <primitives/GTSpinBox.h>
24 #include <primitives/GTTableView.h>
25 #include <primitives/GTWidget.h>
26 
27 #include <QLabel>
28 #include <QTableView>
29 
30 #include <U2Core/AppContext.h>
31 #include <U2Core/AppSettings.h>
32 #include <U2Core/UserApplicationsSettings.h>
33 
34 #include "GTUtilsPcr.h"
35 #include "system/GTFile.h"
36 
37 namespace U2 {
38 
setPrimer(HI::GUITestOpStatus & os,U2Strand::Direction direction,const QByteArray & primer)39 void GTUtilsPcr::setPrimer(HI::GUITestOpStatus &os, U2Strand::Direction direction, const QByteArray &primer) {
40     QLineEdit *primerEdit = dynamic_cast<QLineEdit *>(GTWidget::findWidget(os, "primerEdit", primerBox(os, direction)));
41     GTLineEdit::setText(os, primerEdit, primer, true);
42 }
43 
setMismatches(HI::GUITestOpStatus & os,U2Strand::Direction direction,int mismatches)44 void GTUtilsPcr::setMismatches(HI::GUITestOpStatus &os, U2Strand::Direction direction, int mismatches) {
45     QSpinBox *mismatchesSpinBox = dynamic_cast<QSpinBox *>(GTWidget::findWidget(os, "mismatchesSpinBox", primerBox(os, direction)));
46     GTSpinBox::setValue(os, mismatchesSpinBox, mismatches, GTGlobals::UseKeyBoard);
47 }
48 
setPerfectMatch(HI::GUITestOpStatus & os,int number)49 void GTUtilsPcr::setPerfectMatch(HI::GUITestOpStatus &os, int number) {
50     QSpinBox *spinBox = dynamic_cast<QSpinBox *>(GTWidget::findWidget(os, "perfectSpinBox"));
51     GTSpinBox::setValue(os, spinBox, number, GTGlobals::UseKeyBoard);
52 }
53 
setMaxProductSize(HI::GUITestOpStatus & os,int number)54 void GTUtilsPcr::setMaxProductSize(HI::GUITestOpStatus &os, int number) {
55     QSpinBox *spinBox = dynamic_cast<QSpinBox *>(GTWidget::findWidget(os, "productSizeSpinBox"));
56     GTSpinBox::setValue(os, spinBox, number, GTGlobals::UseKeyBoard);
57 }
58 
browseButton(HI::GUITestOpStatus & os,U2Strand::Direction direction)59 QWidget *GTUtilsPcr::browseButton(HI::GUITestOpStatus &os, U2Strand::Direction direction) {
60     return GTWidget::findWidget(os, "browseButton", primerBox(os, direction));
61 }
62 
productsCount(HI::GUITestOpStatus & os)63 int GTUtilsPcr::productsCount(HI::GUITestOpStatus &os) {
64     return GTTableView::rowCount(os, table(os));
65 }
66 
getResultRegion(HI::GUITestOpStatus & os,int number)67 QString GTUtilsPcr::getResultRegion(HI::GUITestOpStatus &os, int number) {
68     return GTTableView::data(os, table(os), number, 0);
69 }
70 
getResultPoint(HI::GUITestOpStatus & os,int number)71 QPoint GTUtilsPcr::getResultPoint(HI::GUITestOpStatus &os, int number) {
72     return GTTableView::getCellPoint(os, table(os), number, 0);
73 }
74 
getDetailsPoint(HI::GUITestOpStatus & os)75 QPoint GTUtilsPcr::getDetailsPoint(HI::GUITestOpStatus &os) {
76     QWidget *warning = GTWidget::findWidget(os, "detailsLinkLabel");
77     QPoint result = warning->geometry().center();
78     result.setX(result.x() / 2);
79     return warning->parentWidget()->mapToGlobal(result);
80 }
81 
getPrimerInfo(GUITestOpStatus & os,U2Strand::Direction direction)82 QString GTUtilsPcr::getPrimerInfo(GUITestOpStatus &os, U2Strand::Direction direction) {
83     QLabel *primerInfo = GTWidget::findExactWidget<QLabel *>(os, "characteristicsLabel", GTWidget::findWidget(os, direction == U2Strand::Direct ? "forwardPrimerBox" : "reversePrimerBox"));
84     CHECK_SET_ERR_RESULT(primerInfo != nullptr, "Cannot find primer info label", QString());
85     return primerInfo->text();
86 }
87 
primerBox(HI::GUITestOpStatus & os,U2Strand::Direction direction)88 QWidget *GTUtilsPcr::primerBox(HI::GUITestOpStatus &os, U2Strand::Direction direction) {
89     QString boxName = "forwardPrimerBox";
90     if (U2Strand::Complementary == direction) {
91         boxName = "reversePrimerBox";
92     }
93     return GTWidget::findWidget(os, boxName);
94 }
95 
table(HI::GUITestOpStatus & os)96 QTableView *GTUtilsPcr::table(HI::GUITestOpStatus &os) {
97     return dynamic_cast<QTableView *>(GTWidget::findWidget(os, "productsTable"));
98 }
99 
clearPcrDir(HI::GUITestOpStatus & os)100 void GTUtilsPcr::clearPcrDir(HI::GUITestOpStatus &os) {
101     Q_UNUSED(os);
102     QString path = AppContext::getAppSettings()->getUserAppsSettings()->getDefaultDataDirPath() + "/pcr";
103     GTFile::removeDir(path);
104 }
105 
106 }  // namespace U2
107