aboutsummaryrefslogtreecommitdiffstats
path: root/tests/system/shared/classes.py
blob: b3de5a34dd3047e9c12fb40e9701a5226aab50ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#############################################################################
##
## Copyright (C) 2015 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing
##
## This file is part of Qt Creator.
##
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company.  For licensing terms and
## conditions see http://www.qt.io/terms-conditions.  For further information
## use the contact form at http://www.qt.io/contact-us.
##
## GNU Lesser General Public License Usage
## Alternatively, this file may be used under the terms of the GNU Lesser
## General Public License version 2.1 or version 3 as published by the Free
## Software Foundation and appearing in the file LICENSE.LGPLv21 and
## LICENSE.LGPLv3 included in the packaging of this file.  Please review the
## following information to ensure the GNU Lesser General Public License
## requirements will be met: https://www.gnu.org/licenses/lgpl.html and
## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
##
## In addition, as a special exception, The Qt Company gives you certain additional
## rights.  These rights are described in The Qt Company LGPL Exception
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
##
#############################################################################

import operator

# for easier re-usage (because Python hasn't an enum type)
class Targets:
    DESKTOP_474_GCC = 1
    DESKTOP_480_DEFAULT = 2
    SIMULATOR = 4
    MAEMO5 = 8
    HARMATTAN = 16
    EMBEDDED_LINUX = 32
    DESKTOP_521_DEFAULT = 64
    DESKTOP_531_DEFAULT = 128
    DESKTOP_541_GCC = 256

    @staticmethod
    def desktopTargetClasses():
        desktopTargets = (Targets.DESKTOP_474_GCC | Targets.DESKTOP_480_DEFAULT
                          | Targets.DESKTOP_521_DEFAULT | Targets.DESKTOP_531_DEFAULT)
        if platform.system() != 'Darwin':
            desktopTargets |= Targets.DESKTOP_541_GCC
        return desktopTargets

    @staticmethod
    def getStringForTarget(target):
        if target == Targets.DESKTOP_474_GCC:
            return "Desktop 474 GCC"
        elif target == Targets.DESKTOP_480_DEFAULT:
            if platform.system() in ('Windows', 'Microsoft'):
                return "Desktop 480 MSVC2010"
            else:
                return "Desktop 480 GCC"
        elif target == Targets.MAEMO5:
            return "Fremantle"
        elif target == Targets.SIMULATOR:
            return "Qt Simulator"
        elif target == Targets.HARMATTAN:
            return "Harmattan"
        elif target == Targets.EMBEDDED_LINUX:
            return "Embedded Linux"
        elif target == Targets.DESKTOP_521_DEFAULT:
            return "Desktop 521 default"
        elif target == Targets.DESKTOP_531_DEFAULT:
            return "Desktop 531 default"
        elif target == Targets.DESKTOP_541_GCC:
            return "Desktop 541 GCC"
        else:
            return None

    @staticmethod
    def getTargetsAsStrings(targets):
        if not isinstance(targets, (tuple,list)):
            test.fatal("Wrong usage... This function handles only tuples or lists.")
            return None
        result = map(Targets.getStringForTarget, targets)
        if None in result:
            test.fatal("You've passed at least one unknown target!")
        return result

    @staticmethod
    def intToArray(targets):
        available = [Targets.DESKTOP_474_GCC, Targets.DESKTOP_480_DEFAULT, Targets.SIMULATOR,
                     Targets.MAEMO5, Targets.HARMATTAN, Targets.EMBEDDED_LINUX,
                     Targets.DESKTOP_521_DEFAULT, Targets.DESKTOP_531_DEFAULT, Targets.DESKTOP_541_GCC]
        return filter(lambda x: x & targets == x, available)

    @staticmethod
    def arrayToInt(targetArr):
        return reduce(operator.or_, targetArr, 0)

    @staticmethod
    def getDefaultKit():
        return Targets.DESKTOP_521_DEFAULT

# this class holds some constants for easier usage inside the Projects view
class ProjectSettings:
    BUILD = 1
    RUN = 2

# this class defines some constants for the views of the creator's MainWindow
class ViewConstants:
    WELCOME, EDIT, DESIGN, DEBUG, PROJECTS, ANALYZE, HELP = range(7)
    FIRST_AVAILABLE = 0
    # always adjust the following to the highest value of the available ViewConstants when adding new
    LAST_AVAILABLE = HELP

    # this function returns a regex of the tooltip of the FancyTabBar elements
    # this is needed because the keyboard shortcut is OS specific
    # if the provided argument does not match any of the ViewConstants it returns None
    @staticmethod
    def getToolTipForViewTab(viewTab):
        if viewTab == ViewConstants.WELCOME:
            toolTip = ur'Switch to <b>Welcome</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
        elif viewTab == ViewConstants.EDIT:
            toolTip = ur'Switch to <b>Edit</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
        elif viewTab == ViewConstants.DESIGN:
            toolTip = ur'Switch to <b>Design</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
        elif viewTab == ViewConstants.DEBUG:
            toolTip = ur'Switch to <b>Debug</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
        elif viewTab == ViewConstants.PROJECTS:
            toolTip = ur'Switch to <b>Projects</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
        elif viewTab == ViewConstants.ANALYZE:
            toolTip = ur'Switch to <b>Analyze</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
        elif viewTab == ViewConstants.HELP:
            toolTip = ur'Switch to <b>Help</b> mode <span style="color: gray; font-size: small">(Ctrl\+|\u2303)%d</span>'
        else:
            return None
        return toolTip % (viewTab + 1)

class SubprocessType:
    QT_WIDGET=0
    QT_QUICK_APPLICATION=1
    QT_QUICK_UI=2
    USER_DEFINED=3

    @staticmethod
    def getWindowType(subprocessType, qtQuickVersion="1.1"):
        if subprocessType == SubprocessType.QT_WIDGET:
            return "QMainWindow"
        if subprocessType == SubprocessType.QT_QUICK_APPLICATION:
            qqv = "2"
            if qtQuickVersion[0] == "1":
                qqv = "1"
            return "QtQuick%sApplicationViewer" % qqv
        if subprocessType == SubprocessType.QT_QUICK_UI:
            if qtQuickVersion == "1.1":
                return "QDeclarativeViewer"
            else:
                return "QQuickView"
        if subprocessType == SubprocessType.USER_DEFINED:
            return "user-defined"
        test.fatal("Could not determine the WindowType for SubprocessType %s" % subprocessType)
        return None

class QtInformation:
    QT_VERSION = 0
    QT_BINPATH = 1
    QT_LIBPATH = 2

class LibType:
    SHARED = 0
    STATIC = 1
    QT_PLUGIN = 2

    @staticmethod
    def getStringForLib(libType):
        if libType == LibType.SHARED:
            return "Shared Library"
        if libType == LibType.STATIC:
            return "Statically Linked Library"
        if libType == LibType.QT_PLUGIN:
            return "Qt Plugin"
        return None