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/GTWidget.h>
23 
24 #include <U2View/MsaEditorWgt.h>
25 
26 #include "GTMSAEditorStatusWidget.h"
27 #include "GTUtilsMsaEditor.h"
28 
29 namespace U2 {
30 
31 #define GT_CLASS_NAME "GTMSAEditorStatusWidget"
32 
33 #define GT_METHOD_NAME "getStatusWidget"
getStatusWidget(GUITestOpStatus & os)34 QWidget *GTMSAEditorStatusWidget::getStatusWidget(GUITestOpStatus &os) {
35     QWidget *editor = GTUtilsMsaEditor::getEditorUi(os);
36     return GTWidget::findExactWidget<QWidget *>(os, "msa_editor_status_bar", editor);
37 }
38 #undef GT_METHOD_NAME
39 
40 #define GT_METHOD_NAME "length"
length(HI::GUITestOpStatus & os,QWidget * w)41 int GTMSAEditorStatusWidget::length(HI::GUITestOpStatus &os, QWidget *w) {
42     QLabel *label = qobject_cast<QLabel *>(GTWidget::findWidget(os, "Column", w));
43     GT_CHECK_RESULT(label != nullptr, "label is NULL", -1);
44 
45     QString labelText = label->text();
46     QString lengthString = labelText.section('/', -1, -1);
47 
48     bool ok = false;
49     int lengthInt = lengthString.toInt(&ok);
50     GT_CHECK_RESULT(ok == true, "toInt returned false", -1);
51 
52     return lengthInt;
53 }
54 #undef GT_METHOD_NAME
55 
56 #define GT_METHOD_NAME "getSequencesCount"
getSequencesCount(HI::GUITestOpStatus & os,QWidget * w)57 int GTMSAEditorStatusWidget::getSequencesCount(HI::GUITestOpStatus &os, QWidget *w) {
58     QLabel *label = GTWidget::findExactWidget<QLabel *>(os, "Line", w);
59     GT_CHECK_RESULT(label != nullptr, "label is NULL", -1);
60 
61     QString labelText = label->text();
62     QString countString = labelText.section('/', -1, -1);
63 
64     bool ok = false;
65     int countInt = countString.toInt(&ok);
66     GT_CHECK_RESULT(ok == true, "toInt returned false", -1);
67 
68     return countInt;
69 }
70 #undef GT_METHOD_NAME
71 
72 #define GT_METHOD_NAME "getRowNumberString"
getRowNumberString(GUITestOpStatus & os)73 QString GTMSAEditorStatusWidget::getRowNumberString(GUITestOpStatus &os) {
74     QLabel *lineLabel = GTWidget::findExactWidget<QLabel *>(os, "Line", getStatusWidget(os));
75     GT_CHECK_RESULT(lineLabel != nullptr, "Line label is NULL", "-1");
76 
77     const QString labelText = lineLabel->text();
78     return labelText.mid(QString("Seq ").length() - 1).section('/', 0, 0).trimmed();
79 }
80 #undef GT_METHOD_NAME
81 
82 #define GT_METHOD_NAME "getRowsCountString"
getRowsCountString(GUITestOpStatus & os)83 QString GTMSAEditorStatusWidget::getRowsCountString(GUITestOpStatus &os) {
84     QLabel *lineLabel = GTWidget::findExactWidget<QLabel *>(os, "Line", getStatusWidget(os));
85     GT_CHECK_RESULT(lineLabel != nullptr, "Line label is NULL", "-1");
86 
87     const QString labelText = lineLabel->text();
88     return labelText.mid(QString("Seq ").length() - 1).section('/', 1, 1).trimmed();
89 }
90 #undef GT_METHOD_NAME
91 
92 #define GT_METHOD_NAME "getColumnNumberString"
getColumnNumberString(GUITestOpStatus & os)93 QString GTMSAEditorStatusWidget::getColumnNumberString(GUITestOpStatus &os) {
94     QLabel *columnLabel = GTWidget::findExactWidget<QLabel *>(os, "Column", getStatusWidget(os));
95     GT_CHECK_RESULT(columnLabel != nullptr, "Column label is NULL", "-1");
96 
97     const QString labelText = columnLabel->text();
98     return labelText.mid(QString("Col ").length() - 1).section('/', 0, 0).trimmed();
99 }
100 #undef GT_METHOD_NAME
101 
102 #define GT_METHOD_NAME "getColumnsCountString"
getColumnsCountString(GUITestOpStatus & os)103 QString GTMSAEditorStatusWidget::getColumnsCountString(GUITestOpStatus &os) {
104     QLabel *columnLabel = GTWidget::findExactWidget<QLabel *>(os, "Column", getStatusWidget(os));
105     GT_CHECK_RESULT(columnLabel != nullptr, "Column label is NULL", "-1");
106 
107     const QString labelText = columnLabel->text();
108     return labelText.mid(QString("Col ").length() - 1).section('/', 1, 1).trimmed();
109 }
110 #undef GT_METHOD_NAME
111 
112 #define GT_METHOD_NAME "getSequenceUngappedPositionString"
getSequenceUngappedPositionString(GUITestOpStatus & os)113 QString GTMSAEditorStatusWidget::getSequenceUngappedPositionString(GUITestOpStatus &os) {
114     QLabel *positionLabel = GTWidget::findExactWidget<QLabel *>(os, "Position", getStatusWidget(os));
115     GT_CHECK_RESULT(positionLabel != nullptr, "Position label is NULL", "-1");
116 
117     const QString labelText = positionLabel->text();
118     return labelText.mid(QString("Pos ").length() - 1).section('/', 0, 0).trimmed();
119 }
120 #undef GT_METHOD_NAME
121 
122 #define GT_METHOD_NAME "getSequenceUngappedLengthString"
getSequenceUngappedLengthString(GUITestOpStatus & os)123 QString GTMSAEditorStatusWidget::getSequenceUngappedLengthString(GUITestOpStatus &os) {
124     QLabel *positionLabel = GTWidget::findExactWidget<QLabel *>(os, "Position", getStatusWidget(os));
125     GT_CHECK_RESULT(positionLabel != nullptr, "Position label is NULL", "-1");
126 
127     const QString labelText = positionLabel->text();
128     return labelText.mid(QString("Pos ").length() - 1).section('/', 1, 1).trimmed();
129 }
130 #undef GT_METHOD_NAME
131 
132 #undef GT_CLASS_NAME
133 
134 }  // namespace U2
135