forked from qt-creator/qt-creator
QmlDesigner: Using QQuickWidget in the Property Editor
Change-Id: Ib0bd01a2698e6d8483704de1f8a165696f25ec5e Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
This commit is contained in:
@@ -34,73 +34,12 @@
|
|||||||
#include "gradientmodel.h"
|
#include "gradientmodel.h"
|
||||||
#include "qmlanchorbindingproxy.h"
|
#include "qmlanchorbindingproxy.h"
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
void Quick2PropertyEditorView::execute()
|
|
||||||
{
|
|
||||||
m_view.setSource(m_source);
|
|
||||||
|
|
||||||
if (!m_source.isEmpty()) {
|
|
||||||
m_view.setSource(m_source);
|
|
||||||
connect(&m_view, SIGNAL(statusChanged(QQuickView::Status)), this, SLOT(continueExecute()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Quick2PropertyEditorView::Quick2PropertyEditorView(QWidget *parent) :
|
Quick2PropertyEditorView::Quick2PropertyEditorView(QWidget *parent) :
|
||||||
QWidget(parent)
|
QQuickWidget(parent)
|
||||||
{
|
{
|
||||||
m_containerWidget = createWindowContainer(&m_view);
|
setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
||||||
setLayout(layout);
|
|
||||||
layout->addWidget(m_containerWidget);
|
|
||||||
layout->setMargin(0);
|
|
||||||
m_view.setResizeMode(QQuickView::SizeRootObjectToView);
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl Quick2PropertyEditorView::source() const
|
|
||||||
{
|
|
||||||
return m_source;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Quick2PropertyEditorView::setSource(const QUrl& url)
|
|
||||||
{
|
|
||||||
m_source = url;
|
|
||||||
execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
QQmlEngine* Quick2PropertyEditorView::engine()
|
|
||||||
{
|
|
||||||
return m_view.engine();
|
|
||||||
}
|
|
||||||
|
|
||||||
QQmlContext* Quick2PropertyEditorView::rootContext()
|
|
||||||
{
|
|
||||||
return engine()->rootContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
Quick2PropertyEditorView::Status Quick2PropertyEditorView::status() const
|
|
||||||
{
|
|
||||||
return Quick2PropertyEditorView::Status(m_view.status());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Quick2PropertyEditorView::continueExecute()
|
|
||||||
{
|
|
||||||
disconnect(&m_view, SIGNAL(statusChanged(QQuickView::Status)), this, SLOT(continueExecute()));
|
|
||||||
|
|
||||||
if (!m_view.errors().isEmpty()) {
|
|
||||||
QList<QQmlError> errorList = m_view.errors();
|
|
||||||
foreach (const QQmlError &error, errorList) {
|
|
||||||
qWarning() << error;
|
|
||||||
}
|
|
||||||
emit statusChanged(status());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
emit statusChanged(status());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quick2PropertyEditorView::registerQmlTypes()
|
void Quick2PropertyEditorView::registerQmlTypes()
|
||||||
|
@@ -30,54 +30,19 @@
|
|||||||
#ifndef QUICK2PROERTYEDITORVIEW_H
|
#ifndef QUICK2PROERTYEDITORVIEW_H
|
||||||
#define QUICK2PROERTYEDITORVIEW_H
|
#define QUICK2PROERTYEDITORVIEW_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QQuickWidget>
|
||||||
#include <QUrl>
|
|
||||||
#include <QQuickView>
|
|
||||||
#include <QQmlEngine>
|
|
||||||
#include <QQmlContext>
|
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QQmlError;
|
|
||||||
class QQmlComponent;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class Quick2PropertyEditorView : public QWidget
|
class Quick2PropertyEditorView : public QQuickWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QUrl source READ source WRITE setSource DESIGNABLE true)
|
|
||||||
public:
|
public:
|
||||||
explicit Quick2PropertyEditorView(QWidget *parent = 0);
|
explicit Quick2PropertyEditorView(QWidget *parent = 0);
|
||||||
|
|
||||||
QUrl source() const;
|
|
||||||
void setSource(const QUrl&);
|
|
||||||
|
|
||||||
QQmlEngine* engine();
|
|
||||||
QQmlContext* rootContext();
|
|
||||||
|
|
||||||
enum Status { Null, Ready, Loading, Error };
|
|
||||||
Status status() const;
|
|
||||||
|
|
||||||
static void registerQmlTypes();
|
static void registerQmlTypes();
|
||||||
|
|
||||||
signals:
|
|
||||||
void statusChanged(Quick2PropertyEditorView::Status);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void execute();
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void continueExecute();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QWidget *m_containerWidget;
|
|
||||||
QUrl m_source;
|
|
||||||
QQuickView m_view;
|
|
||||||
QPointer<QQmlComponent> m_component;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} //QmlDesigner
|
} //QmlDesigner
|
||||||
|
Reference in New Issue
Block a user