File: propertypreviewwidget.h

package info (click to toggle)
kdevelop 4%3A5.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 26,356 kB
  • ctags: 23,249
  • sloc: cpp: 160,775; python: 2,137; lex: 621; ansic: 617; sh: 577; xml: 142; ruby: 120; makefile: 52; php: 12; sed: 12
file content (101 lines) | stat: -rw-r--r-- 4,962 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*************************************************************************************
 *  Copyright (C) 2013 by Sven Brauch <svenbrauch@gmail.com>                         *
 *                                                                                   *
 *  This program is free software; you can redistribute it and/or                    *
 *  modify it under the terms of the GNU General Public License                      *
 *  as published by the Free Software Foundation; either version 2                   *
 *  of the License, or (at your option) any later version.                           *
 *                                                                                   *
 *  This program is distributed in the hope that it will be useful,                  *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
 *  GNU General Public License for more details.                                     *
 *                                                                                   *
 *  You should have received a copy of the GNU General Public License                *
 *  along with this program; if not, write to the Free Software                      *
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
 *************************************************************************************/

#ifndef PROPERTYPREVIEWWIDGET_H
#define PROPERTYPREVIEWWIDGET_H

#include <QWidget>

#include <ktexteditor/range.h>
#include <language/duchain/declaration.h>
#include <interfaces/idocument.h>

using namespace KDevelop;
class QQuickWidget;

// Describes one supported property, such as "width"
struct SupportedProperty {
    SupportedProperty(const QUrl& qmlfile,
                      const QString &typeContains = QString(),
                      const QString &classContains = QString())
    : qmlfile(qmlfile),
      typeContains(typeContains),
      classContains(classContains)
    {
    }

    // the absolute (!) URL to the qml file to load when creating a widget
    // for this property
    QUrl qmlfile;
    // A string that must be contained into the string representation of the
    // type of the key being matched.
    QString typeContains;
    // A string that must be contained into the name of the class in which the
    // key is declared
    QString classContains;
};

// This class is responsible for creating the property widgets for editing QML properties
// with e.g. sliders. It knows which properties are supported, and creates a widget from
// a QML file for each supported property when requested. For the actual implementations
// of the widgets, see the propertywidgets/ subfolder, especially the README file.
class PropertyPreviewWidget : public QWidget {
Q_OBJECT
public:
    // Constructs a widget operating on the given document if the given key is in the list
    // of supported properties.
    // key and value must be the key and the current value of the property in question,
    // without spaces or other extra characters.
    // The ranges must encompass the text which should be replaced by the new values
    // selected by the user.
    // Returns 0 when the property is not supported, which tells kdevplatform not to
    // display any widget when returned from e.g. specialLanguageObjectNavigationWidget.
    static QWidget* constructIfPossible(KTextEditor::Document* doc,
                                        KTextEditor::Range keyRange,
                                        KTextEditor::Range valueRange,
                                        Declaration* decl,
                                        const QString& key,
                                        const QString& value);
    ~PropertyPreviewWidget() override;

private:
    // private because you should use the static constructIfPossible function to create instances,
    // to make sure you don't have widgets which operate on unsupported properties.
    explicit PropertyPreviewWidget(KTextEditor::Document* doc, KTextEditor::Range keyRange, KTextEditor::Range valueRange,
                                   const SupportedProperty& property, const QString& value);
    static QHash<QString, SupportedProperty> supportedProperties;

    QQuickWidget* view;

    // the document the widget replaces text in
    KTextEditor::Document* document;
    // the range of the key
    KTextEditor::Range const keyRange;
    // the range of the value to be modified. Not const because the range might change
    // if the newly inserted text is smaller or larger than what was there before
    // (e.g. 9 -> 10)
    KTextEditor::Range valueRange;
    // the SupportedProperty instance for this widget
    SupportedProperty const property;

private slots:
    // updates the text in the document to contain the new value in valueRange
    void updateValue();
};

#endif