KTextEditor

katevariableexpansionhelpers.h
1/*
2 SPDX-FileCopyrightText: 2019 Dominik Haumann <dhaumann@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KTEXTEDITOR_VARIABLE_EXPANSION_HELPERS_H
8#define KTEXTEDITOR_VARIABLE_EXPANSION_HELPERS_H
9
10#include <QDialog>
11#include <QHash>
12#include <QList>
13#include <QPointer>
14#include <QString>
15
16class QListView;
17class QLineEdit;
19class VariableItemModel;
20class TextEditButton;
21
22namespace KTextEditor
23{
24class View;
25class Variable;
26}
27
28/**
29 * Helper for macro expansion.
30 */
31namespace KateMacroExpander
32{
33/**
34 * Expands the @p input text based on the @p view.
35 * @return the expanded text.
36 */
37QString expandMacro(const QString &input, KTextEditor::View *view);
38}
39
40/**
41 * Helper dialog that shows a non-modal dialog listing all available
42 * variables. If the user selects a variable, the variable is inserted
43 * into the respective widget.
44 */
46{
47public:
50
51 /**
52 * Adds @p variable to the expansion list view.
53 */
54 void addVariable(const KTextEditor::Variable &variable);
55
56 /**
57 * Returns true if no variables were added at all to the dialog.
58 */
59 int isEmpty() const;
60
61 /**
62 * Adds @p widget to the list of widgets that trigger showing this dialog.
63 */
64 void addWidget(QWidget *widget);
65
66protected:
67 /**
68 * Reimplemented for the following reasons:
69 * - Show this dialog if one of the widgets added with addWidget() has focus.
70 * - Catch the resize-event for widgets (e.g. QTextEdit) where we manually
71 * added a clickable action in the corner
72 */
73 bool eventFilter(QObject *watched, QEvent *event) override;
74
75 /**
76 * Called whenever a widget was deleted. If all widgets are deleted,
77 * this dialog deletes itself via deleteLater().
78 */
79 void onObjectDeleted(QObject *object);
80
81private:
82 QAction *m_showAction;
84 QList<QObject *> m_widgets;
86 VariableItemModel *m_variableModel;
87 QSortFilterProxyModel *m_filterModel;
88 QListView *m_listView;
89 QLineEdit *m_filterEdit;
90};
91
92#endif // KTEXTEDITOR_VARIABLE_EXPANSION_HELPERS_H
93
94// kate: space-indent on; indent-width 4; replace-tabs on;
Variable for variable expansion.
Definition variable.h:35
A text widget with KXMLGUIClient that represents a Document.
Definition view.h:244
Helper dialog that shows a non-modal dialog listing all available variables.
void addWidget(QWidget *widget)
Adds widget to the list of widgets that trigger showing this dialog.
void onObjectDeleted(QObject *object)
Called whenever a widget was deleted.
void addVariable(const KTextEditor::Variable &variable)
Adds variable to the expansion list view.
bool eventFilter(QObject *watched, QEvent *event) override
Reimplemented for the following reasons:
int isEmpty() const
Returns true if no variables were added at all to the dialog.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Helper for macro expansion.
QString expandMacro(const QString &input, KTextEditor::View *view)
Expands the input text based on the view.
QObject * parent() const const
virtual bool event(QEvent *event) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:53:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.