File indexing completed on 2024-04-14 03:54:00

0001 /*
0002     SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef SCRIPTABLEREPARENTINGWIDGET_H
0008 #define SCRIPTABLEREPARENTINGWIDGET_H
0009 
0010 #include <QJSValue>
0011 #include <QWidget>
0012 
0013 #include "kreparentingproxymodel.h"
0014 
0015 class QComboBox;
0016 class QTreeView;
0017 class QPlainTextEdit;
0018 class QJSEngine;
0019 
0020 class ScriptableReparentingProxyModel : public KReparentingProxyModel
0021 {
0022     Q_OBJECT
0023 public:
0024     ScriptableReparentingProxyModel(QObject *parent = nullptr);
0025 
0026     bool isDescendantOf(const QModelIndex &ancestor, const QModelIndex &descendant) const override;
0027 
0028     void setImplementation(const QString &implementation);
0029 
0030 private:
0031     QJSEngine *m_scriptEngine;
0032     mutable QJSValue m_implementationFunction;
0033 };
0034 
0035 class ScriptableReparentingWidget : public QWidget
0036 {
0037     Q_OBJECT
0038 public:
0039     ScriptableReparentingWidget(QAbstractItemModel *rootModel, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
0040 
0041 private Q_SLOTS:
0042     void textChanged();
0043     void setExampleFunction(int index);
0044 
0045 private:
0046     QComboBox *m_comboBox;
0047     ScriptableReparentingProxyModel *m_reparentingProxyModel;
0048     QTreeView *m_treeView;
0049     QPlainTextEdit *m_textEdit;
0050 };
0051 
0052 #endif // SCRIPTABLEREPARENTINGWIDGET_H