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 "GTUtilsPrimerLibrary.h"
23 #include <drivers/GTMouseDriver.h>
24 #include <primitives/GTTableView.h>
25 #include <primitives/GTWidget.h>
26
27 #include <QTableView>
28
29 #include <U2Core/U2SafePoints.h>
30
31 #include <U2Gui/MainWindow.h>
32
33 #include "GTUtilsMdi.h"
34 #include "primitives/GTMenu.h"
35 #include "runnables/ugene/plugins/pcr/AddPrimerDialogFiller.h"
36 #include "utils/GTKeyboardUtils.h"
37 #include "utils/GTUtilsDialog.h"
38
39 namespace U2 {
40 using namespace HI;
41
42 #define GT_CLASS_NAME "GTUtilsPrimerLibrary"
43
openLibrary(HI::GUITestOpStatus & os)44 QWidget *GTUtilsPrimerLibrary::openLibrary(HI::GUITestOpStatus &os) {
45 GTMenu::clickMainMenuItem(os, QStringList() << "Tools"
46 << "Primer"
47 << "Primer library");
48 return GTUtilsMdi::activeWindow(os);
49 }
50
clickButton(HI::GUITestOpStatus & os,Button button)51 void GTUtilsPrimerLibrary::clickButton(HI::GUITestOpStatus &os, Button button) {
52 GTWidget::click(os, getButton(os, button));
53 }
54
getButton(HI::GUITestOpStatus & os,Button button)55 QAbstractButton *GTUtilsPrimerLibrary::getButton(HI::GUITestOpStatus &os, Button button) {
56 QDialogButtonBox *box = GTUtilsDialog::buttonBox(os, GTWidget::findWidget(os, "PrimerLibraryWidget"));
57 switch (button) {
58 case Add:
59 return box->buttons()[1];
60 case Edit:
61 return box->buttons()[2];
62 case Close:
63 return box->button(QDialogButtonBox::Close);
64 case Remove:
65 return box->buttons()[3];
66 case Import:
67 return box->buttons()[4];
68 case Export:
69 return box->buttons()[5];
70 default:
71 return nullptr;
72 }
73 }
74
librarySize(HI::GUITestOpStatus & os)75 int GTUtilsPrimerLibrary::librarySize(HI::GUITestOpStatus &os) {
76 return GTTableView::rowCount(os, table(os));
77 }
78
getPrimerSequence(HI::GUITestOpStatus & os,int number)79 QString GTUtilsPrimerLibrary::getPrimerSequence(HI::GUITestOpStatus &os, int number) {
80 return GTTableView::data(os, table(os), number, 4);
81 }
82
83 #define GT_METHOD_NAME "getPrimerSequence"
getPrimerSequence(HI::GUITestOpStatus & os,const QString & name)84 QString GTUtilsPrimerLibrary::getPrimerSequence(HI::GUITestOpStatus &os, const QString &name) {
85 for (int i = 0; i < GTTableView::rowCount(os, table(os)); i++) {
86 if (name == GTTableView::data(os, table(os), i, 0)) {
87 return getPrimerSequence(os, i);
88 }
89 }
90 GT_CHECK_RESULT(false, QString("Primer with name '%1' not found").arg(name), "");
91 }
92 #undef GT_METHOD_NAME
93
getPrimerPoint(HI::GUITestOpStatus & os,int number)94 QPoint GTUtilsPrimerLibrary::getPrimerPoint(HI::GUITestOpStatus &os, int number) {
95 return GTTableView::getCellPoint(os, table(os), number, 0);
96 }
97
clickPrimer(HI::GUITestOpStatus & os,int number)98 void GTUtilsPrimerLibrary::clickPrimer(HI::GUITestOpStatus &os, int number) {
99 GTMouseDriver::moveTo(getPrimerPoint(os, number));
100 GTMouseDriver::click();
101 }
102
clearLibrary(HI::GUITestOpStatus & os)103 void GTUtilsPrimerLibrary::clearLibrary(HI::GUITestOpStatus &os) {
104 const int size = librarySize(os);
105 CHECK(size > 0, );
106 GTWidget::click(os, table(os));
107 selectAll(os);
108 clickButton(os, Remove);
109 }
110
addPrimer(HI::GUITestOpStatus & os,const QString & name,const QString & data)111 void GTUtilsPrimerLibrary::addPrimer(HI::GUITestOpStatus &os, const QString &name, const QString &data) {
112 AddPrimerDialogFiller::Parameters parameters;
113 parameters.name = name;
114 parameters.primer = data;
115 GTUtilsDialog::waitForDialog(os, new AddPrimerDialogFiller(os, parameters));
116 clickButton(os, Add);
117 GTGlobals::sleep(50);
118 }
119
120 #define GT_METHOD_NAME "selectPrimers"
selectPrimers(HI::GUITestOpStatus & os,const QList<int> & numbers)121 void GTUtilsPrimerLibrary::selectPrimers(HI::GUITestOpStatus &os, const QList<int> &numbers) {
122 const int size = librarySize(os);
123
124 GTKeyboardDriver::keyPress(Qt::Key_Control);
125 foreach (int number, numbers) {
126 GT_CHECK(number < size, "Primer number is out of range");
127 GTUtilsPrimerLibrary::clickPrimer(os, number);
128 }
129 GTKeyboardDriver::keyClick(Qt::Key_Control);
130 }
131 #undef GT_METHOD_NAME
132
selectAll(HI::GUITestOpStatus & os)133 void GTUtilsPrimerLibrary::selectAll(HI::GUITestOpStatus &os) {
134 GTWidget::click(os, table(os));
135 GTKeyboardUtils::selectAll();
136 }
137
table(HI::GUITestOpStatus & os)138 QTableView *GTUtilsPrimerLibrary::table(HI::GUITestOpStatus &os) {
139 return dynamic_cast<QTableView *>(GTWidget::findWidget(os, "primerTable"));
140 }
141
142 #undef GT_CLASS_NAME
143
144 } // namespace U2
145