File indexing completed on 2024-05-05 05:52:18
0001 /* This file is part of the Kate project. 0002 * Based on the snippet plugin from KDevelop 4. 0003 * 0004 * SPDX-FileCopyrightText: 2007 Robert Gruber <rgruber@users.sourceforge.net> 0005 * SPDX-FileCopyrightText: 2010 Milian Wolff <mail@milianw.de> 0006 * SPDX-FileCopyrightText: 2012 Christoph Cullmann <cullmann@kde.org> 0007 * 0008 * SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 0011 #pragma once 0012 0013 #include <QStandardItem> 0014 0015 class QAction; 0016 0017 /** 0018 * One object of this class represents a single snippet. 0019 * Multiple snippets are stored in one repository (XML-file). 0020 * 0021 * To access the snippet's name (which should also be used for matching 0022 * during code completion) use @p QStandardItem::text(). 0023 * 0024 * @author Robert Gruber <rgruber@users.sourceforge.net> 0025 * @author Milian Wolff <mail@milianw.de> 0026 */ 0027 class Snippet : public QStandardItem 0028 { 0029 public: 0030 /** 0031 * Construct an empty snippet. 0032 */ 0033 Snippet(); 0034 ~Snippet() override; 0035 0036 static constexpr inline int SnippetItemType = QStandardItem::UserType + 2; 0037 0038 int type() const override 0039 { 0040 return SnippetItemType; 0041 } 0042 0043 static Snippet *fromItem(QStandardItem *item) 0044 { 0045 if (item && item->type() == SnippetItemType) { 0046 return static_cast<Snippet *>(item); 0047 } 0048 return nullptr; 0049 } 0050 0051 /** 0052 * Returns the actual contents of this snippet. 0053 */ 0054 QString snippet() const; 0055 /** 0056 * Sets the actual contents of this snippet. 0057 */ 0058 void setSnippet(const QString &snippet); 0059 0060 /** 0061 * Action to trigger insertion of this snippet. 0062 */ 0063 QAction *action(); 0064 0065 void registerActionForView(QWidget *view); 0066 0067 QVariant data(int role = Qt::UserRole + 1) const override; 0068 0069 private: 0070 /// the actual snippet contents aka \code<fillin>\endcode 0071 QString m_snippet; 0072 /// the insertion action for this snippet. 0073 QAction *m_action = nullptr; 0074 }; 0075 0076 Q_DECLARE_METATYPE(Snippet *)