1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the examples of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:BSD$ 9 ** You may use this file under the terms of the BSD license as follows: 10 ** 11 ** "Redistribution and use in source and binary forms, with or without 12 ** modification, are permitted provided that the following conditions are 13 ** met: 14 ** * Redistributions of source code must retain the above copyright 15 ** notice, this list of conditions and the following disclaimer. 16 ** * Redistributions in binary form must reproduce the above copyright 17 ** notice, this list of conditions and the following disclaimer in 18 ** the documentation and/or other materials provided with the 19 ** distribution. 20 ** * Neither the name of The Qt Company Ltd nor the names of its 21 ** contributors may be used to endorse or promote products derived 22 ** from this software without specific prior written permission. 23 ** 24 ** 25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 ** 37 ** $QT_END_LICENSE$ 38 ** 39 ****************************************************************************/ 40 41 #ifndef SCRIPTBREAKPOINTMANAGER_H 42 #define SCRIPTBREAKPOINTMANAGER_H 43 44 #include <QtCore/qlist.h> 45 #include <QtCore/qstring.h> 46 #include <QtScript/qscriptvalue.h> 47 48 class ScriptBreakpointInfo 49 { 50 public: 51 enum Type { 52 File, 53 FunctionName, 54 Function, 55 Invalid 56 }; 57 58 Type type; 59 QString functionName; 60 QString fileName; 61 int lineNumber; 62 QScriptValue function; 63 bool enabled; 64 QString condition; 65 int ignoreCount; 66 bool singleShot; 67 ScriptBreakpointInfo(const QString & fileName,int lineNumber)68 ScriptBreakpointInfo(const QString &fileName, int lineNumber) 69 : type(File), fileName(fileName), lineNumber(lineNumber), 70 enabled(true), ignoreCount(0), singleShot(false) 71 { } 72 ScriptBreakpointInfo(const QString &functionName, const QString &fileName = QString()) type(FunctionName)73 : type(FunctionName), functionName(functionName), fileName(fileName), 74 enabled(true), ignoreCount(0), singleShot(false) 75 { } ScriptBreakpointInfo(const QScriptValue & function)76 ScriptBreakpointInfo(const QScriptValue &function) 77 : type(Function), function(function), 78 enabled(true), ignoreCount(0), singleShot(false) 79 { } ScriptBreakpointInfo()80 ScriptBreakpointInfo() 81 : type(Invalid) 82 { } 83 }; 84 85 class ScriptBreakpointManager 86 { 87 public: 88 ScriptBreakpointManager(); 89 ~ScriptBreakpointManager(); 90 91 bool hasBreakpoints() const; 92 93 int setBreakpoint(const QString &fileName, int lineNumber); 94 int setBreakpoint(const QString &functionName, const QString &fileName = QString()); 95 int setBreakpoint(const QScriptValue &function); 96 97 void removeBreakpoint(int id); 98 99 int findBreakpoint(const QString &fileName, int lineNumber) const; 100 int findBreakpoint(const QString &functionName, const QString &fileName = QString()) const; 101 int findBreakpoint(const QScriptValue &function) const; 102 103 bool isBreakpointEnabled(int id) const; 104 void setBreakpointEnabled(int id, bool enabled); 105 106 QString breakpointCondition(int id) const; 107 void setBreakpointCondition(int id, const QString &expression); 108 109 int breakpointIgnoreCount(int id) const; 110 void setBreakpointIgnoreCount(int id, int ignoreCount); 111 112 bool isBreakpointSingleShot(int id) const; 113 void setBreakpointSingleShot(int id, bool singleShot); 114 115 private: 116 QList<ScriptBreakpointInfo> breakpoints; 117 118 Q_DISABLE_COPY(ScriptBreakpointManager) 119 }; 120 121 #endif // SCRIPTBREAKPOINTMANAGER_H 122