File indexing completed on 2024-05-05 04:39:49

0001 /*
0002     SPDX-FileCopyrightText: 2012 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #ifndef KDEVPLATFORM_PLUGIN_TEMPLATEPREVIEW_H
0008 #define KDEVPLATFORM_PLUGIN_TEMPLATEPREVIEW_H
0009 
0010 #include <QWidget>
0011 #include <QHash>
0012 
0013 #include <language/codegen/templaterenderer.h>
0014 
0015 namespace KTextEditor {
0016 class Document;
0017 class View;
0018 }
0019 
0020 /**
0021  * A renderer that adds some common variables for previewing purposes.
0022  */
0023 class TemplatePreviewRenderer : public KDevelop::TemplateRenderer
0024 {
0025 public:
0026     TemplatePreviewRenderer();
0027     ~TemplatePreviewRenderer() override;
0028 };
0029 
0030 /**
0031  * A KTextEditor::View wrapper to show a preview of a template.
0032  */
0033 class TemplatePreview : public QWidget
0034 {
0035     Q_OBJECT
0036 public:
0037     explicit TemplatePreview(QWidget* parent);
0038     ~TemplatePreview() override;
0039 
0040     /**
0041      * Set the template contents which will be rendered.
0042      *
0043      * @p text the template contents
0044      * @p isProject set to true if the contents resemble a project template
0045      * @return an error message, or an empty string if everything worked
0046      */
0047     QString setText(const QString& text, bool isProject = false,
0048                     KDevelop::TemplateRenderer::EmptyLinesPolicy policy = KDevelop::TemplateRenderer::TrimEmptyLines);
0049 
0050     /**
0051      * @return The read-only document.
0052      */
0053     KTextEditor::Document* document() const;
0054 
0055 private:
0056     Q_DISABLE_COPY(TemplatePreview)
0057 
0058     QHash<QString, QString> m_variables;
0059     QScopedPointer<KTextEditor::Document> m_preview;
0060     KTextEditor::View* m_view;
0061 
0062 };
0063 
0064 #endif // KDEVPLATFORM_PLUGIN_TEMPLATEPREVIEW_H