• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevplatform/language/codegen

  • sources
  • kfour-appscomplete
  • kdevelop
  • kdevplatform
  • language
  • codegen
templateengine.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of KDevelop
3  *
4  * Copyright 2012 Milian Wolff <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Library General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #include "templateengine.h"
23 #include "templateengine_p.h"
24 
25 #include "debug.h"
26 
27 #include "codedescription.h"
28 #include "codedescriptionmetatypes.h"
29 #include "archivetemplateloader.h"
30 
31 #include <interfaces/icore.h>
32 #include <QStandardPaths>
33 
34 using namespace KDevelop;
35 using namespace Grantlee;
36 
37 TemplateEngine* TemplateEngine::self()
38 {
39  static auto* engine = new TemplateEngine;
40  return engine;
41 }
42 
43 TemplateEngine::TemplateEngine()
44  : d_ptr(new TemplateEnginePrivate)
45 {
46  Q_D(TemplateEngine);
47 
48  d->engine.setSmartTrimEnabled(true);
49 
50  qCDebug(LANGUAGE) << "Generic data locations:" << QStandardPaths::standardLocations(
51  QStandardPaths::GenericDataLocation);
52 
53  const auto templateDirectories = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
54  QStringLiteral(
55  "kdevcodegen/templates"),
56  QStandardPaths::LocateDirectory);
57 
58  if (!templateDirectories.isEmpty()) {
59  qCDebug(LANGUAGE) << "Found template directories:" << templateDirectories;
60  addTemplateDirectories(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
61  QStringLiteral("kdevcodegen/templates"),
62  QStandardPaths::LocateDirectory));
63  } else {
64  qCWarning(LANGUAGE) << "No template directories found -- templating engine will not work!";
65  }
66 
67  Grantlee::registerMetaType<KDevelop::VariableDescription>();
68  Grantlee::registerMetaType<KDevelop::FunctionDescription>();
69  Grantlee::registerMetaType<KDevelop::InheritanceDescription>();
70  Grantlee::registerMetaType<KDevelop::ClassDescription>();
71 
72  d->engine.addTemplateLoader(QSharedPointer<AbstractTemplateLoader>(ArchiveTemplateLoader::self()));
73 }
74 
75 TemplateEngine::~TemplateEngine()
76 {
77 }
78 
79 void TemplateEngine::addTemplateDirectories(const QStringList& directories)
80 {
81  Q_D(TemplateEngine);
82 
83  auto* loader = new FileSystemTemplateLoader;
84  loader->setTemplateDirs(directories);
85  d->engine.addTemplateLoader(QSharedPointer<AbstractTemplateLoader>(loader));
86 }
KDevelop::TemplateEngine::addTemplateDirectories
void addTemplateDirectories(const QStringList &directories)
Adds directories to the list of directories searched for templates.
Definition: templateengine.cpp:79
templateengine_p.h
KDevelop::ArchiveTemplateLoader::self
static ArchiveTemplateLoader * self()
Definition: archivetemplateloader.cpp:34
QSharedPointer
codedescription.h
KDevelop::TemplateEnginePrivate
Definition: templateengine_p.h:30
KDevelop::TemplateEngine
Central template engine where template directories and archives can be registered.
Definition: templateengine.h:38
KDevelop::TemplateEngine::self
static TemplateEngine * self()
Definition: templateengine.cpp:37
KDevelop
NOTE: changes in this file will quite probably also require changes in codedescriptionmetatype....
Definition: applychangeswidget.cpp:42
templateengine.h
archivetemplateloader.h
QStringList
codedescriptionmetatypes.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Jan 14 2021 23:34:51 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevplatform/language/codegen

Skip menu "kdevplatform/language/codegen"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  • kdevplatform
  •   debugger
  •   documentation
  •   interfaces
  •   language
  •     assistant
  •     backgroundparser
  •     checks
  •     classmodel
  •     codecompletion
  •     codegen
  •     duchain
  •     editor
  •     highlighting
  •     interfaces
  •     util
  •   outputview
  •   project
  •   serialization
  •   shell
  •   sublime
  •   tests
  •   util
  •   vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal