| 
									
										
										
										
											2012-11-06 15:35:19 +01:00
										 |  |  | /****************************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:59:14 +01:00
										 |  |  | ** Copyright (C) 2016 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: https://www.qt.io/licensing/
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-11-06 15:35:19 +01:00
										 |  |  | ** This file is part of Qt Creator. | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-11-06 15:35:19 +01:00
										 |  |  | ** Commercial License Usage | 
					
						
							|  |  |  | ** Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							| 
									
										
										
										
											2016-01-15 14:59:14 +01:00
										 |  |  | ** a written agreement between you and The Qt Company. For licensing terms | 
					
						
							|  |  |  | ** and conditions see https://www.qt.io/terms-conditions. For further
 | 
					
						
							|  |  |  | ** information use the contact form at https://www.qt.io/contact-us.
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2015-09-18 11:34:48 +02:00
										 |  |  | ** GNU General Public License Usage | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU | 
					
						
							| 
									
										
										
										
											2016-01-15 14:59:14 +01:00
										 |  |  | ** General Public License version 3 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
					
						
							|  |  |  | ** included in the packaging of this file. Please review the following | 
					
						
							|  |  |  | ** information to ensure the GNU General Public License requirements will | 
					
						
							|  |  |  | ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-11-06 15:35:19 +01:00
										 |  |  | ****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2016-01-15 14:59:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | #include "componentnodeinstance.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QQmlComponent>
 | 
					
						
							|  |  |  | #include <QQmlContext>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace QmlDesigner { | 
					
						
							|  |  |  | namespace Internal { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ComponentNodeInstance::ComponentNodeInstance(QQmlComponent *component) | 
					
						
							|  |  |  |    : ObjectNodeInstance(component) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QQmlComponent *ComponentNodeInstance::component() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Q_ASSERT(qobject_cast<QQmlComponent*>(object())); | 
					
						
							|  |  |  |     return static_cast<QQmlComponent*>(object()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ComponentNodeInstance::Pointer ComponentNodeInstance::create(QObject  *object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QQmlComponent *component = qobject_cast<QQmlComponent *>(object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Q_ASSERT(component); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Pointer instance(new ComponentNodeInstance(component)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     instance->populateResetHashes(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return instance; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ComponentNodeInstance::hasContent() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ComponentNodeInstance::setNodeSource(const QString &source) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-09-25 12:57:57 +02:00
										 |  |  |     QByteArray data(source.toUtf8() + "\n"); | 
					
						
							|  |  |  |     data.prepend(nodeInstanceServer()->importCode()); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     component()->setData(data, QUrl(nodeInstanceServer()->fileUrl().toString() + | 
					
						
							|  |  |  |                                     QLatin1Char('_')+ id())); | 
					
						
							|  |  |  |     setId(id()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (component()->isError()) { | 
					
						
							| 
									
										
										
										
											2019-07-25 16:58:50 +02:00
										 |  |  |         const QList<QQmlError> errors = component()->errors(); | 
					
						
							|  |  |  |         for (const QQmlError &error : errors) | 
					
						
							| 
									
										
										
										
											2014-10-09 13:35:12 +02:00
										 |  |  |             qWarning() << error; | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // Internal
 | 
					
						
							|  |  |  | } // QmlDesigner
 |