1 // Copyright (C) 2015-2024 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : PyEditor_Keywords.cxx
20 // Author : Sergey TELKOV, Open CASCADE S.A.S. (sergey.telkov@opencascade.com)
23 #include "PyEditor_Keywords.h"
28 \brief PyEditor_Keywords
34 PyEditor_Keywords::PyEditor_Keywords( QObject* parent )
42 PyEditor_Keywords::~PyEditor_Keywords()
47 QList<int> PyEditor_Keywords::types() const
50 for ( KeywordMap::const_iterator it = myKeywords.begin(); it != myKeywords.end(); ++it ) {
51 map.insert( it.value().type, false );
57 \brief Gets the colors list.
60 QList<QColor> PyEditor_Keywords::colors() const
64 for ( KeywordMap::const_iterator it = myKeywords.begin(); it != myKeywords.end(); ++it ) {
65 const QColor& color = it.value().color;
66 if ( !set.contains( color.rgba() ) ) {
68 set.insert( color.rgba() );
75 \brief Gets the keyword type.
78 int PyEditor_Keywords::type( const QString& keyword ) const
80 return myKeywords.contains(keyword) ? myKeywords[keyword].type : -1;
84 \brief Gets the keyword color.
87 QColor PyEditor_Keywords::color( const QString& keyword ) const
89 return myKeywords.contains(keyword) ? myKeywords[keyword].color : QColor();
93 \brief Gets all keywords.
94 \return keywords string list
96 QStringList PyEditor_Keywords::keywords() const
98 return myKeywords.keys();
102 \brief Gets all keywords of specified type.
103 \return keywords string list
105 QStringList PyEditor_Keywords::keywords( int type ) const
107 QStringList keywords;
108 for ( KeywordMap::const_iterator it = myKeywords.begin(); it != myKeywords.end(); ++it ) {
109 if ( it.value().type == type )
110 keywords.append( it.key() );
116 \brief Gets all keywords with specified color.
117 \return keywords string list
119 QStringList PyEditor_Keywords::keywords( const QColor& color ) const
121 QStringList keywords;
122 for ( KeywordMap::const_iterator it = myKeywords.begin(); it != myKeywords.end(); ++it ) {
123 if ( it.value().color == color )
124 keywords.append( it.key() );
130 \brief Append keyword with type and color.
132 void PyEditor_Keywords::append( const QString& keyword,
133 int type, const QColor& color )
135 append( QStringList() << keyword, type, color );
139 \brief Append keyword list with type and color.
141 void PyEditor_Keywords::append( const QStringList& keywords,
142 int type, const QColor& color )
145 for ( QStringList::const_iterator it = keywords.begin(); it != keywords.end(); ++it ) {
146 const QString& kw = *it;
147 bool changed = false;
148 if ( !myKeywords.contains( kw ) ) {
149 myKeywords.insert( kw, KeywordInfo() );
152 KeywordInfo& info = myKeywords[kw];
153 changed = changed || info.type != type || info.color != color;
157 modif = modif || changed;
161 Q_EMIT keywordsChanged();
165 \brief Remove all keywords with specified type.
167 void PyEditor_Keywords::remove( int type )
169 remove( keywords( type ) );
173 \brief Remove keyword.
175 void PyEditor_Keywords::remove( const QString& keyword )
177 remove( QStringList() << keyword );
181 \brief Remove keywords.
183 void PyEditor_Keywords::remove( const QStringList& keywords )
185 bool changed = false;
186 for ( QStringList::const_iterator it = keywords.begin(); it != keywords.end(); ++it ) {
187 if ( myKeywords.contains( *it ) ) {
188 myKeywords.remove( *it );
193 Q_EMIT keywordsChanged();
197 \brief Remove all keywords.
199 void PyEditor_Keywords::clear()
201 if ( !myKeywords.isEmpty() ) {
203 Q_EMIT keywordsChanged();
208 \brief PyEditor_StandardKeywords
211 PyEditor_StandardKeywords::PyEditor_StandardKeywords( QObject* parent )
212 : PyEditor_Keywords( parent )
215 aBase << "and" << "as" << "assert" << "break" << "class" << "continue"
216 << "def" << "elif" << "else" << "except" << "exec" << "finally"
217 << "False" << "for" << "from" << "global" << "if" << "import"
218 << "in" << "is" << "lambda" << "None" << "not" << "or" << "pass"
219 << "print" << "raise" << "return" << "True" << "try" << "while"
220 << "with" << "yield";
221 append( aBase, Base, Qt::blue );
223 QStringList anExcept;
224 anExcept << "ArithmeticError" << "AssertionError" << "AttributeError"
225 << "EnvironmentError" << "EOFError" << "Exception"
226 << "FloatingPointError" << "ImportError" << "IndentationError"
227 << "IndexError" << "IOError" << "KeyboardInterrupt" << "KeyError"
228 << "LookupError" << "MemoryError" << "NameError" << "OSError"
229 << "NotImplementedError" << "OverflowError" << "ReferenceError"
230 << "RuntimeError" << "StandardError" << "StopIteration"
231 << "SyntaxError" << "SystemError" << "SystemExit" << "TabError"
232 << "TypeError" << "UnboundLocalError" << "UnicodeDecodeError"
233 << "UnicodeEncodeError" << "UnicodeError" << "UnicodeTranslateError"
234 << "ValueError" << "WindowsError" << "ZeroDivisionError"
235 << "Warning" << "UserWarning" << "DeprecationWarning"
236 << "PendingDeprecationWarning" << "SyntaxWarning"
237 << "OverflowWarning" << "RuntimeWarning" << "FutureWarning";
238 append( anExcept, Exceptions, Qt::magenta );
241 PyEditor_StandardKeywords::~PyEditor_StandardKeywords()