void redo()
	{
		QModelIndex index = m_model->index(m_sceneXmlNode); 
		Q_ASSERT(index.isValid());
		QXmlTreeNode* node = static_cast<QXmlTreeNode*>(index.internalPointer());
		AttachmentTreeModel* model = static_cast<AttachmentTreeModel*>(node->property("__AttachmentModel").value<void*>());
		QModelIndex parentIndex = m_model->index(m_parentNode);
		model->addNode(model->rowCount(parentIndex), m_addNode, parentIndex);
	}	
	void undo()
	{
		QModelIndex index = m_model->index(m_sceneXmlNode); 
		Q_ASSERT(index.isValid());
		QXmlTreeNode* node = static_cast<QXmlTreeNode*>(index.internalPointer());
		AttachmentTreeModel* model = static_cast<AttachmentTreeModel*>(node->property("__AttachmentModel").value<void*>());
		index = model->index(m_addNode);
		Q_ASSERT(index.isValid());
		model->removeRow(index.row(), index.parent());	
	}
Example #3
0
QPositionNode::~QPositionNode()
{
	unsigned int entityID = GameEngine::entityWorldID( qPrintable(QObject::parent()->property("Name").toString()) );
	GameEngine::setComponentData(entityID, qPrintable( m_xmlNode.tagName() ), 0);
	if( m_dynamicProperty )
	{		
		QXmlTreeNode* root = static_cast<AttachmentTreeModel*>(m_model)->sceneNodeParent();
		root->setProperty("Position", QVariant());
		root->setProperty("Scale", QVariant());
		root->setProperty("__AbsoluteTransformation", QVariant() );
		root->setProperty("__RelativeTransformation", QVariant() );
	}
}
void PipelineTreeView::showRenderTarget(const QModelIndex& index)
{
	if (index.isValid())
	{
		QXmlTreeNode* renderTarget = static_cast<QXmlTreeNode*>(index.internalPointer());
		if (renderTarget->property("Type").toInt() == QPipelineNode::PIPELINERENDERTARGETNODE)
		{
			RenderTargetView* view = new RenderTargetView(this, Qt::Window);
			view->setRenderTarget(renderTarget->xmlNode(), m_pipelineID);
			view->setVisible(true);
			connect(view, SIGNAL(closed(RenderTargetView*)), this, SLOT(removeView(RenderTargetView*)));
			m_renderTargetViews.push_back(view);
		}
void QXmlTreeNode::removeChild(int i)
{
    // Is index valid?
    if (child(i))
    {
        QXmlTreeNode* item = m_childItems.takeAt(i);
        m_xmlNode.removeChild(item->xmlNode());
        delete item;
        // Ensure valid row index of items
        for (int j=i; j<m_childItems.size(); ++j)
            m_childItems.at(j)->m_row = j;
    }
}
Example #6
0
void QXmlTreeView::pasteNode()
{
	QXmlTreeModel* treeModel = static_cast<QXmlTreeModel*>(model());
	if( !treeModel ) return;

	QXmlTreeNode* xmlNode = treeModel->rootNode();
	if (currentIndex().isValid())
		xmlNode = static_cast<QXmlTreeNode*>(currentIndex().internalPointer());		

	const QMimeData* mime = QApplication::clipboard()->mimeData();;
	if (mime->hasFormat("text/plain"))
	{
		QDomDocument dom("Paste");
		if (dom.setContent(mime->data("text/plain")))
			treeModel->undoStack()->push(createAddUndoCommand(dom.documentElement(), xmlNode->xmlNode(), treeModel, tr("Paste nodes")));
	}
}
Example #7
0
void QXmlTreeView::copyCurrentNode()
{
	QXmlTreeModel* treeModel = static_cast<QXmlTreeModel*>(model());
	if (!treeModel)	return;
	QString data;
	QTextStream stream(&data);	
	QDomDocument document("Paste");		
	QXmlTreeNode* xmlNode = treeModel->rootNode();
	if (currentIndex().isValid())
		xmlNode = static_cast<QXmlTreeNode*>(currentIndex().internalPointer());		
	document.appendChild(xmlNode->xmlNode().cloneNode());					
	document.save(stream,4);
	QClipboard* clipboard = QApplication::clipboard();
	QMimeData* mime = new QMimeData();
	mime->setData("text/plain", data.toUtf8());	
	clipboard->setMimeData(mime);
}
Example #8
0
QPositionNode::QPositionNode(const QDomElement& xmlNode, int row, QXmlTreeModel* model, QXmlTreeNode* parent) : QXmlTreeNode(xmlNode, row, model, parent),
m_dynamicProperty(false)
{
	QString data;
	QTextStream stream(&data);
	xmlNode.save(stream, 4);
	m_entityID = GameEngine::entityWorldID( qPrintable(parent->property("Name").toString()) );
	GameEngine::setComponentData(m_entityID, qPrintable( xmlNode.tagName() ), qPrintable(data));
	QXmlTreeNode* root = static_cast<AttachmentTreeModel*>(model)->sceneNodeParent();
	// If the entity has no position we have to create one for the crowd particle
	if( !root->property("Position").isValid() )
	{
		QVec3f pos( m_xmlNode.attribute("x").toFloat(), m_xmlNode.attribute("y").toFloat(), m_xmlNode.attribute("z").toFloat() );
		// Since the parent doesn't have a position yet we create one dynamically (not necessary if the particle is a child of 
		// an entity created by an attachment of a Horde3D scene graph node )
		m_dynamicProperty = true;
		root->setProperty( "Position", QVariant::fromValue(pos) );
		// We have to add scale too, otherwise the transformation changes in the editor are not possible
		root->setProperty( "Scale", QVariant::fromValue( QVec3f(1, 1, 1) ) );
		root->installEventFilter(this);
		QVariant transProp = root->property("__AbsoluteTransformation");
		if( !transProp.isValid() )
		{
			root->setProperty("__AbsoluteTransformation", 
				QVariant::fromValue(QMatrix4f::TransMat( pos.X, pos.Y, pos.Z) ) );
			root->setProperty("__RelativeTransformation", 
				QVariant::fromValue(QMatrix4f::TransMat( pos.X, pos.Y, pos.Z) ) );
		}
	}
	else // Remove any position attribute, since the position should be used from the scene node
	{
		m_xmlNode.removeAttribute("x");
		m_xmlNode.removeAttribute("y");
		m_xmlNode.removeAttribute("z");
	}
}
Example #9
0
QVariant ExtraTreeModel::data(const QModelIndex &index, int role) const
{
	if (!index.isValid()) return QVariant();

	QXmlTreeNode *item = static_cast<QXmlTreeNode*>(index.internalPointer());
	switch(role)
	{
	case Qt::ToolTipRole:
		return item->property("__ToolTip");
	case Qt::StatusTipRole:
		return item->property("__StatusTip");
	case Qt::DisplayRole:
	case Qt::EditRole:		
		{
			QGameEntityNode* node = qobject_cast<QGameEntityNode*>(item);
			if( node )
			{
				switch( index.column() )
				{
				case 0:
					return node->name();
				case 1:
					return item->xmlNode().tagName();
				case 2:
					return node->ID();
				}
			}
			else return item->xmlNode().tagName();
		}
	case Qt::CheckStateRole:		
		if( index.column() == 0 && item->property("Enabled").isValid() )
			return item->property("Enabled").toBool() ? Qt::Checked : Qt::Unchecked;
	default:
		return QVariant();
	};
}
	AddNodeUndoCommand(const QDomElement& node, const QDomElement& parent, AttachmentTreeModel* model, const QString& text) : QAddXmlNodeUndoCommand(node, parent, model, text)
	{
		QXmlTreeNode* sceneNode = model->sceneNodeParent();
		m_sceneXmlNode = sceneNode->xmlNode();
		m_model = static_cast<QXmlTreeModel*>(sceneNode->model());
	}
	RemoveNodeUndoCommand(QXmlTreeNode* node, const QString& text) : QRemoveXmlNodeUndoCommand(node, text)
	{
		QXmlTreeNode* sceneNode = qobject_cast<AttachmentTreeModel*>(node->model())->sceneNodeParent();
		m_sceneXmlNode = sceneNode->xmlNode();
		m_model = static_cast<QXmlTreeModel*>(sceneNode->model());
	}