forked from qt-creator/qt-creator
QmlDesigner: Remove DeclarativeWidgetViewPrivate
Change-Id: I96fab51078169aa4fdf405609ccfb4b1a3a1e937 Reviewed-by: Alessandro Portale <alessandro.portale@nokia.com>
This commit is contained in:
@@ -38,94 +38,71 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class DeclarativeWidgetViewPrivate
|
void DeclarativeWidgetView::execute()
|
||||||
{
|
{
|
||||||
public:
|
if (m_root)
|
||||||
DeclarativeWidgetViewPrivate(DeclarativeWidgetView *view)
|
delete m_root.data();
|
||||||
: q(view), root(0), component(0) {}
|
|
||||||
~DeclarativeWidgetViewPrivate() { delete root; }
|
|
||||||
void execute();
|
|
||||||
|
|
||||||
DeclarativeWidgetView *q;
|
if (m_component)
|
||||||
|
delete m_component.data();
|
||||||
|
|
||||||
QPointer<QWidget> root;
|
if (!m_source.isEmpty()) {
|
||||||
QUrl source;
|
m_component = new QDeclarativeComponent(&m_engine, m_source, this);
|
||||||
QDeclarativeEngine engine;
|
if (!m_component->isLoading()) {
|
||||||
QDeclarativeComponent *component;
|
continueExecute();
|
||||||
};
|
|
||||||
|
|
||||||
void DeclarativeWidgetViewPrivate::execute()
|
|
||||||
{
|
|
||||||
if (root) {
|
|
||||||
delete root;
|
|
||||||
root = 0;
|
|
||||||
}
|
|
||||||
if (component) {
|
|
||||||
delete component;
|
|
||||||
component = 0;
|
|
||||||
}
|
|
||||||
if (!source.isEmpty()) {
|
|
||||||
component = new QDeclarativeComponent(&engine, source, q);
|
|
||||||
if (!component->isLoading()) {
|
|
||||||
q->continueExecute();
|
|
||||||
} else {
|
} else {
|
||||||
QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), q, SLOT(continueExecute()));
|
connect(m_component.data(), SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(continueExecute()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeclarativeWidgetView::DeclarativeWidgetView(QWidget *parent) :
|
DeclarativeWidgetView::DeclarativeWidgetView(QWidget *parent) :
|
||||||
QWidget(parent), d(new DeclarativeWidgetViewPrivate(this))
|
QWidget(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeclarativeWidgetView::~DeclarativeWidgetView()
|
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl DeclarativeWidgetView::source() const
|
QUrl DeclarativeWidgetView::source() const
|
||||||
{
|
{
|
||||||
return d->source;
|
return m_source;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclarativeWidgetView::setSource(const QUrl& url)
|
void DeclarativeWidgetView::setSource(const QUrl& url)
|
||||||
{
|
{
|
||||||
d->source = url;
|
m_source = url;
|
||||||
d->execute();
|
execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
QDeclarativeEngine* DeclarativeWidgetView::engine()
|
QDeclarativeEngine* DeclarativeWidgetView::engine()
|
||||||
{
|
{
|
||||||
return &d->engine;
|
return &m_engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *DeclarativeWidgetView::rootWidget() const
|
QWidget *DeclarativeWidgetView::rootWidget() const
|
||||||
{
|
{
|
||||||
return d->root;
|
return m_root.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
QDeclarativeContext* DeclarativeWidgetView::rootContext()
|
QDeclarativeContext* DeclarativeWidgetView::rootContext()
|
||||||
{
|
{
|
||||||
return d->engine.rootContext();
|
return m_engine.rootContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeclarativeWidgetView::Status DeclarativeWidgetView::status() const
|
DeclarativeWidgetView::Status DeclarativeWidgetView::status() const
|
||||||
{
|
{
|
||||||
if (!d->component)
|
if (!m_component)
|
||||||
return DeclarativeWidgetView::Null;
|
return DeclarativeWidgetView::Null;
|
||||||
|
|
||||||
return DeclarativeWidgetView::Status(d->component->status());
|
return DeclarativeWidgetView::Status(m_component->status());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DeclarativeWidgetView::continueExecute()
|
void DeclarativeWidgetView::continueExecute()
|
||||||
{
|
{
|
||||||
|
|
||||||
disconnect(d->component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(continueExecute()));
|
disconnect(m_component.data(), SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(continueExecute()));
|
||||||
|
|
||||||
if (d->component->isError()) {
|
if (m_component->isError()) {
|
||||||
QList<QDeclarativeError> errorList = d->component->errors();
|
QList<QDeclarativeError> errorList = m_component->errors();
|
||||||
foreach (const QDeclarativeError &error, errorList) {
|
foreach (const QDeclarativeError &error, errorList) {
|
||||||
qWarning() << error;
|
qWarning() << error;
|
||||||
}
|
}
|
||||||
@@ -133,10 +110,10 @@ void DeclarativeWidgetView::continueExecute()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *obj = d->component->create();
|
QObject *obj = m_component->create();
|
||||||
|
|
||||||
if(d->component->isError()) {
|
if (m_component->isError()) {
|
||||||
QList<QDeclarativeError> errorList = d->component->errors();
|
QList<QDeclarativeError> errorList = m_component->errors();
|
||||||
foreach (const QDeclarativeError &error, errorList) {
|
foreach (const QDeclarativeError &error, errorList) {
|
||||||
qWarning() << error;
|
qWarning() << error;
|
||||||
}
|
}
|
||||||
@@ -150,7 +127,7 @@ void DeclarativeWidgetView::continueExecute()
|
|||||||
|
|
||||||
void DeclarativeWidgetView::setRootWidget(QWidget *widget)
|
void DeclarativeWidgetView::setRootWidget(QWidget *widget)
|
||||||
{
|
{
|
||||||
if (d->root == widget)
|
if (m_root.data() == widget)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
window()->setAttribute(Qt::WA_OpaquePaintEvent, false);
|
window()->setAttribute(Qt::WA_OpaquePaintEvent, false);
|
||||||
@@ -160,10 +137,10 @@ void DeclarativeWidgetView::setRootWidget(QWidget *widget)
|
|||||||
widget->setVisible(true);
|
widget->setVisible(true);
|
||||||
}
|
}
|
||||||
resize(widget->size());
|
resize(widget->size());
|
||||||
d->root = widget;
|
m_root.reset(widget);
|
||||||
|
|
||||||
if (d->root) {
|
if (m_root) {
|
||||||
QSize initialSize = d->root->size();
|
QSize initialSize = m_root->size();
|
||||||
if (initialSize != size()) {
|
if (initialSize != size()) {
|
||||||
resize(initialSize);
|
resize(initialSize);
|
||||||
}
|
}
|
||||||
|
@@ -33,17 +33,16 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QDeclarativeEngine>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QDeclarativeEngine;
|
|
||||||
class QDeclarativeContext;
|
class QDeclarativeContext;
|
||||||
class QDeclarativeError;
|
class QDeclarativeError;
|
||||||
|
class QDeclarativeComponent;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class DeclarativeWidgetViewPrivate;
|
|
||||||
|
|
||||||
class DeclarativeWidgetView : public QWidget
|
class DeclarativeWidgetView : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -52,8 +51,6 @@ class DeclarativeWidgetView : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit DeclarativeWidgetView(QWidget *parent = 0);
|
explicit DeclarativeWidgetView(QWidget *parent = 0);
|
||||||
|
|
||||||
virtual ~DeclarativeWidgetView();
|
|
||||||
|
|
||||||
QUrl source() const;
|
QUrl source() const;
|
||||||
void setSource(const QUrl&);
|
void setSource(const QUrl&);
|
||||||
|
|
||||||
@@ -69,14 +66,17 @@ signals:
|
|||||||
void statusChanged(DeclarativeWidgetView::Status);
|
void statusChanged(DeclarativeWidgetView::Status);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setRootWidget(QWidget *);
|
void setRootWidget(QWidget *);
|
||||||
|
void execute();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void continueExecute();
|
void continueExecute();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class DeclarativeWidgetViewPrivate;
|
QScopedPointer<QWidget> m_root;
|
||||||
DeclarativeWidgetViewPrivate *d;
|
QUrl m_source;
|
||||||
|
QDeclarativeEngine m_engine;
|
||||||
|
QWeakPointer<QDeclarativeComponent> m_component;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user