1 /**
2 * UGENE - Integrated Bioinformatics Tools.
3 * Copyright (C) 2008-2017 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/GTTableView.h"
23 #include <primitives/GTWidget.h>
24 #include <utils/GTThread.h>
25
26 namespace HI {
27
28 #define GT_CLASS_NAME "GTSpinBox"
29 #define GT_METHOD_NAME "getCellPosition"
getCellPosition(GUITestOpStatus & os,QTableView * table,int column,int row)30 QPoint GTTableView::getCellPosition(GUITestOpStatus &os, QTableView *table, int column, int row) {
31 GT_CHECK_RESULT(table, "table view is NULL", QPoint());
32 QPoint p(table->columnViewportPosition(column) + table->columnWidth(column) / 2,
33 table->rowViewportPosition(row) + table->rowHeight(row) * 1.5);
34 QPoint pGlob = table->mapToGlobal(p);
35 return pGlob;
36 }
37 #undef GT_METHOD_NAME
38
39 #define GT_METHOD_NAME "scrollTo"
scrollTo(GUITestOpStatus & os,QTableView * table,const QModelIndex & index)40 void GTTableView::scrollTo(GUITestOpStatus &os, QTableView *table, const QModelIndex &index) {
41 // TODO: set index by mouse/keyboard
42 class MainThreadAction : public CustomScenario {
43 public:
44 MainThreadAction(QTableView *table, const QModelIndex &index)
45 : CustomScenario(), table(table), index(index) {
46 }
47 void run(HI::GUITestOpStatus &os) {
48 Q_UNUSED(os);
49 table->scrollTo(index);
50 }
51 QTableView *table;
52 QModelIndex index;
53 };
54 GTThread::runInMainThread(os, new MainThreadAction(table, index));
55 }
56 #undef GT_METHOD_NAME
57
58 #define GT_METHOD_NAME "getCellPoint"
getCellPoint(GUITestOpStatus & os,QTableView * table,int row,int column)59 QPoint GTTableView::getCellPoint(GUITestOpStatus &os, QTableView *table, int row, int column) {
60 QModelIndex idx = table->model()->index(row, column);
61 scrollTo(os, table, idx);
62 QRect rect = table->visualRect(idx);
63 QWidget *content = GTWidget::findWidget(os, "qt_scrollarea_viewport", table);
64 return content->mapToGlobal(rect.center());
65 }
66 #undef GT_METHOD_NAME
67
68 #define GT_METHOD_NAME "rowCount"
rowCount(GUITestOpStatus & os,QTableView * table)69 int GTTableView::rowCount(GUITestOpStatus &os, QTableView *table) {
70 GT_CHECK_RESULT(table != NULL, "Table view is NULL", -1);
71 GT_CHECK_RESULT(table->model() != NULL, "Table view model is NULL", -1);
72 return table->model()->rowCount(QModelIndex());
73 }
74 #undef GT_METHOD_NAME
75
76 #define GT_METHOD_NAME "data"
data(GUITestOpStatus & os,QTableView * table,int row,int column)77 QString GTTableView::data(GUITestOpStatus &os, QTableView *table, int row, int column) {
78 GT_CHECK_RESULT(NULL != table, "Table view is NULL", "");
79 GT_CHECK_RESULT(NULL != table->model(), "Table view model is NULL", "");
80
81 QModelIndex idx = table->model()->index(row, column);
82 GT_CHECK_RESULT(idx.isValid(), "Item index is invalid", "");
83 return table->model()->data(idx, Qt::DisplayRole).toString();
84 }
85 #undef GT_METHOD_NAME
86 #undef GT_CLASS_NAME
87
88 } // namespace HI
89