src/terralib/qt/widgets/ceditor/Utils.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
3 
4  This file is part of the TerraLib - a Framework for building GIS enabled
5  applications.
6 
7  TerraLib is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License,
10  or (at your option) any later version.
11 
12  TerraLib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with TerraLib. See COPYING. If not, write to
19  TerraLib Team at <terralib-team@terralib.org>.
20  */
21 
22 /*!
23  \file terralib/qt/widgets/ceditor/Utils.cpp
24 
25  \brief Utility functions for dealing with code editor.
26 */
27 
28 // TerraLib
29 #include "Utils.h"
30 
31 // Qt
32 #include <QFileInfo>
33 #include <QString>
34 
35 #include <Qsci/qscilexerlua.h>
36 #include <Qsci/qscilexerpython.h>
37 #include <Qsci/qscilexersql.h>
38 
39 QsciLexer* te::qt::widgets::LexerFactory(const QString& lang)
40 {
41  const QString ulang = lang.toUpper();
42 
43  if(ulang == "LUA")
44  return new QsciLexerLua();
45 
46  if((ulang == "PY") || (ulang == "PYTHON"))
47  return new QsciLexerPython();
48 
49  if(ulang == "SQL")
50  return new QsciLexerSQL();
51 
52  return nullptr;
53 }
54 
55 QIcon te::qt::widgets::ScriptIconFactory(const QString& lang)
56 {
57  const QString ulang = lang.toUpper();
58 
59  if(ulang == "LUA")
60  return QIcon::fromTheme("lang-lua");
61 
62  if((ulang == "PY") || (ulang == "PYTHON"))
63  return QIcon::fromTheme("lang-python");
64 
65  return QIcon::fromTheme("lang-unknown");
66 }
67 
68 QIcon te::qt::widgets::CreateLangIcon(const QString& fileName)
69 {
70  QFileInfo in(fileName);
71 
72  QString lang(in.suffix()), ulang = lang.toUpper();
73 
74  return ScriptIconFactory(ulang);
75 }
TEQTWIDGETSEXPORT QsciLexer * LexerFactory(const QString &lang)
A factory method for language lexers.
TEQTWIDGETSEXPORT QIcon ScriptIconFactory(const QString &lang)
A factory method for language icons.
Utility functions for dealing with code editor.
TEQTWIDGETSEXPORT QIcon CreateLangIcon(const QString &fileName)
Returns the icon related to the extension of the file.