ctkPluginGeneratorAbstractTemplate.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkPluginGeneratorAbstractTemplate.h"
  16. #include <QHash>
  17. #include <QFile>
  18. class ctkPluginGeneratorAbstractTemplatePrivate
  19. {
  20. public:
  21. QHash<QString, QStringList> contentMap;
  22. };
  23. ctkPluginGeneratorAbstractTemplate::ctkPluginGeneratorAbstractTemplate(
  24. const QString& name, ctkPluginGeneratorAbstractTemplate* parent)
  25. : QObject(parent), d_ptr(new ctkPluginGeneratorAbstractTemplatePrivate)
  26. {
  27. this->setObjectName(name);
  28. }
  29. ctkPluginGeneratorAbstractTemplate::~ctkPluginGeneratorAbstractTemplate()
  30. {
  31. }
  32. void ctkPluginGeneratorAbstractTemplate::addContent(const QString &marker, const QString &content, Position pos)
  33. {
  34. Q_D(ctkPluginGeneratorAbstractTemplate);
  35. if (pos == START)
  36. {
  37. d->contentMap[marker].prepend(content);
  38. }
  39. else if (pos == END)
  40. {
  41. d->contentMap[marker].append(content);
  42. }
  43. }
  44. QStringList ctkPluginGeneratorAbstractTemplate::getContent(const QString &marker) const
  45. {
  46. Q_D(const ctkPluginGeneratorAbstractTemplate);
  47. if (d->contentMap.contains(marker))
  48. {
  49. return d->contentMap[marker];
  50. }
  51. return QStringList();
  52. }
  53. void ctkPluginGeneratorAbstractTemplate::create(const QString& location)
  54. {
  55. const QString filename = location + "/" + this->objectName();
  56. QFile file(filename);
  57. file.open(QIODevice::WriteOnly | QIODevice::Text);
  58. file.write(this->generateContent().toAscii());
  59. file.close();
  60. }
  61. QStringList ctkPluginGeneratorAbstractTemplate::getMarkers() const
  62. {
  63. return QStringList();
  64. }