QLanguage.cpp
Go to the documentation of this file.
1 // QCodeEditor
2 #include <QLanguage>
3 
4 // Qt
5 #include <QIODevice>
6 #include <QXmlStreamReader>
7 
8 QLanguage::QLanguage(QIODevice* device, QObject* parent) :
9  QObject(parent),
10  m_loaded(false),
11  m_list()
12 {
13  load(device);
14 }
15 
16 bool QLanguage::load(QIODevice* device)
17 {
18  if (device == nullptr)
19  {
20  return false;
21  }
22 
23  QXmlStreamReader reader(device);
24 
25  QString name;
26  QStringList list;
27  bool readText = false;
28 
29  while (!reader.atEnd() && !reader.hasError())
30  {
31  auto type = reader.readNext();
32 
33  if (type == QXmlStreamReader::TokenType::StartElement)
34  {
35  if (reader.name() == "section")
36  {
37  if (!list.empty())
38  {
39  m_list[name] = list;
40  list.clear();
41  }
42 
43  name = reader.attributes().value("name").toString();
44  }
45  else if (reader.name() == "name")
46  {
47  readText = true;
48  }
49  }
50  else if (type == QXmlStreamReader::TokenType::Characters &&
51  readText)
52  {
53  list << reader.text().toString();
54  readText = false;
55  }
56 
57  }
58 
59  if (!list.empty())
60  {
61  m_list[name] = list;
62  }
63 
64  m_loaded = !reader.hasError();
65 
66  return m_loaded;
67 }
68 
69 QStringList QLanguage::keys()
70 {
71  return m_list.keys();
72 }
73 
74 QStringList QLanguage::names(const QString& key)
75 {
76  return m_list[key];
77 }
78 
79 bool QLanguage::isLoaded() const
80 {
81  return m_loaded;
82 }
backward::ColorMode::type
type
Definition: backward.hpp:3600
QLanguage::m_list
QMap< QString, QStringList > m_list
Definition: QLanguage.hpp:58
QLanguage::names
QStringList names(const QString &key)
Method for getting names from key.
Definition: QLanguage.cpp:74
QLanguage::keys
QStringList keys()
Method for getting available keys.
Definition: QLanguage.cpp:69
QLanguage::QLanguage
QLanguage(QIODevice *device=nullptr, QObject *parent=nullptr)
Constructor.
Definition: QLanguage.cpp:8
QLanguage::m_loaded
bool m_loaded
Definition: QLanguage.hpp:53
reader
static const char * reader(lua_State *L, void *ud, size_t *size)
Definition: luac.c:126
QLanguage::load
bool load(QIODevice *device)
Method for parsing.
Definition: QLanguage.cpp:16
QLanguage::isLoaded
bool isLoaded() const
Method for getting is object loaded.
Definition: QLanguage.cpp:79


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45