2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02: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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
#include "componentview.h"
|
2011-05-24 18:47:33 +02:00
|
|
|
#include "componentaction.h"
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2011-05-24 18:47:33 +02:00
|
|
|
#include <nodeabstractproperty.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <QStandardItemModel>
|
|
|
|
|
|
|
|
|
|
// silence gcc warnings about unused parameters
|
|
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
ComponentView::ComponentView(QObject *parent)
|
|
|
|
|
: AbstractView(parent),
|
|
|
|
|
m_standardItemModel(new QStandardItemModel(this)),
|
2011-05-24 18:47:33 +02:00
|
|
|
m_componentAction(new ComponentAction(this))
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentView::nodeAboutToBeRemoved(const ModelNode &removedNode)
|
|
|
|
|
{
|
2011-06-09 11:34:13 +02:00
|
|
|
removeSingleNodeFromList(removedNode);
|
2011-05-24 18:47:33 +02:00
|
|
|
searchForComponentAndRemoveFromList(removedNode);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStandardItemModel *ComponentView::standardItemModel() const
|
|
|
|
|
{
|
|
|
|
|
return m_standardItemModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModelNode ComponentView::modelNode(int index) const
|
|
|
|
|
{
|
|
|
|
|
if (m_standardItemModel->hasIndex(index, 0)) {
|
|
|
|
|
QStandardItem *item = m_standardItemModel->item(index, 0);
|
2013-09-25 18:08:50 +02:00
|
|
|
return modelNodeForInternalId(qint32(item->data(ModelNodeRole).toInt()));
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ModelNode();
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-27 17:46:44 +02:00
|
|
|
void ComponentView::setComponentNode(const ModelNode &node)
|
|
|
|
|
{
|
|
|
|
|
m_componentAction->setCurrentIndex(indexForNode(node));
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-26 18:46:39 +02:00
|
|
|
void ComponentView::setComponentToMaster()
|
|
|
|
|
{
|
|
|
|
|
m_componentAction->setCurrentIndex(indexOfMaster());
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-09 11:34:13 +02:00
|
|
|
void ComponentView::removeSingleNodeFromList(const ModelNode &node)
|
|
|
|
|
{
|
|
|
|
|
for (int row = 0; row < m_standardItemModel->rowCount(); row++) {
|
2013-09-25 18:08:50 +02:00
|
|
|
if (m_standardItemModel->item(row)->data(ModelNodeRole).toInt() == node.internalId())
|
2011-06-09 11:34:13 +02:00
|
|
|
m_standardItemModel->removeRow(row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-27 17:46:44 +02:00
|
|
|
|
2013-10-16 18:02:31 +02:00
|
|
|
int ComponentView::indexForNode(const ModelNode &node) const
|
2011-06-27 17:46:44 +02:00
|
|
|
{
|
|
|
|
|
for (int row = 0; row < m_standardItemModel->rowCount(); row++) {
|
2013-09-25 18:08:50 +02:00
|
|
|
if (m_standardItemModel->item(row)->data(ModelNodeRole).toInt() == node.internalId())
|
2011-06-27 17:46:44 +02:00
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-16 18:02:31 +02:00
|
|
|
int ComponentView::indexOfMaster() const
|
2013-09-26 18:46:39 +02:00
|
|
|
{
|
|
|
|
|
for (int row = 0; row < m_standardItemModel->rowCount(); row++) {
|
|
|
|
|
if (m_standardItemModel->item(row)->data(ModelNodeRole).toInt() == 0)
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-16 18:02:31 +02:00
|
|
|
bool ComponentView::hasMasterEntry() const
|
|
|
|
|
{
|
|
|
|
|
return indexOfMaster() >= 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ComponentView::hasEntryForNode(const ModelNode &node) const
|
|
|
|
|
{
|
|
|
|
|
return indexForNode(node) >= 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-26 18:46:39 +02:00
|
|
|
void ComponentView::addMasterDocument()
|
|
|
|
|
{
|
2013-10-16 18:02:31 +02:00
|
|
|
if (!hasMasterEntry()) {
|
|
|
|
|
QStandardItem *item = new QStandardItem("master");
|
|
|
|
|
item->setData(QVariant::fromValue(0), ModelNodeRole);
|
|
|
|
|
item->setEditable(false);
|
|
|
|
|
m_standardItemModel->appendRow(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentView::removeMasterDocument()
|
|
|
|
|
{
|
2013-12-17 17:36:42 +01:00
|
|
|
m_standardItemModel->removeRow(indexOfMaster());
|
2013-10-16 18:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ComponentView::descriptionForNode(const ModelNode &node) const
|
|
|
|
|
{
|
|
|
|
|
QString description;
|
|
|
|
|
|
|
|
|
|
if (!node.id().isEmpty()) {
|
|
|
|
|
description = node.id();
|
|
|
|
|
} else if (node.hasParentProperty()) {
|
|
|
|
|
ModelNode parentNode = node.parentProperty().parentModelNode();
|
|
|
|
|
|
|
|
|
|
if (parentNode.id().isEmpty())
|
|
|
|
|
description = parentNode.simplifiedTypeName() + QLatin1Char(' ');
|
|
|
|
|
else
|
|
|
|
|
description = parentNode.id() + QLatin1Char(' ');
|
|
|
|
|
|
|
|
|
|
description += node.parentProperty().name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentView::updateDescription(const ModelNode &node)
|
|
|
|
|
{
|
|
|
|
|
int nodeIndex = indexForNode(node);
|
|
|
|
|
|
|
|
|
|
if (nodeIndex > -1)
|
|
|
|
|
m_standardItemModel->item(nodeIndex)->setText(descriptionForNode(node));
|
2013-09-26 18:46:39 +02:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void ComponentView::modelAttached(Model *model)
|
|
|
|
|
{
|
|
|
|
|
if (AbstractView::model() == model)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-05-24 18:47:33 +02:00
|
|
|
bool block = m_componentAction->blockSignals(true);
|
|
|
|
|
m_standardItemModel->clear();
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
AbstractView::modelAttached(model);
|
|
|
|
|
|
|
|
|
|
searchForComponentAndAddToList(rootModelNode());
|
2011-05-24 18:47:33 +02:00
|
|
|
|
|
|
|
|
m_componentAction->blockSignals(block);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentView::modelAboutToBeDetached(Model *model)
|
|
|
|
|
{
|
2011-05-24 18:47:33 +02:00
|
|
|
bool block = m_componentAction->blockSignals(true);
|
2010-01-07 12:14:35 +01:00
|
|
|
m_standardItemModel->clear();
|
|
|
|
|
AbstractView::modelAboutToBeDetached(model);
|
2011-05-24 18:47:33 +02:00
|
|
|
m_componentAction->blockSignals(block);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ComponentAction *ComponentView::action()
|
|
|
|
|
{
|
|
|
|
|
return m_componentAction;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentView::nodeCreated(const ModelNode &createdNode)
|
|
|
|
|
{
|
|
|
|
|
searchForComponentAndAddToList(createdNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentView::searchForComponentAndAddToList(const ModelNode &node)
|
|
|
|
|
{
|
2013-09-26 18:46:39 +02:00
|
|
|
bool masterNotAdded = true;
|
|
|
|
|
|
2014-04-23 13:02:06 +02:00
|
|
|
foreach (const ModelNode &node, node.allSubModelNodesAndThisNode()) {
|
2011-06-28 13:21:16 +02:00
|
|
|
if (node.nodeSourceType() == ModelNode::NodeWithComponentSource) {
|
2013-09-26 18:46:39 +02:00
|
|
|
if (masterNotAdded) {
|
|
|
|
|
masterNotAdded = true;
|
|
|
|
|
addMasterDocument();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-16 18:02:31 +02:00
|
|
|
if (!hasEntryForNode(node)) {
|
|
|
|
|
QString description = descriptionForNode(node);
|
|
|
|
|
|
2013-07-24 15:58:51 +02:00
|
|
|
|
2013-10-15 18:02:40 +02:00
|
|
|
|
|
|
|
|
|
2011-05-24 18:47:33 +02:00
|
|
|
QStandardItem *item = new QStandardItem(description);
|
2013-09-25 18:08:50 +02:00
|
|
|
item->setData(QVariant::fromValue(node.internalId()), ModelNodeRole);
|
2011-05-24 18:47:33 +02:00
|
|
|
item->setEditable(false);
|
2011-06-09 11:34:13 +02:00
|
|
|
removeSingleNodeFromList(node); //remove node if already present
|
2011-05-24 18:47:33 +02:00
|
|
|
m_standardItemModel->appendRow(item);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
2011-05-24 18:47:33 +02:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-24 18:47:33 +02:00
|
|
|
void ComponentView::searchForComponentAndRemoveFromList(const ModelNode &node)
|
|
|
|
|
{
|
|
|
|
|
QList<ModelNode> nodeList;
|
|
|
|
|
nodeList.append(node);
|
|
|
|
|
nodeList.append(node.allSubModelNodes());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (const ModelNode &childNode, nodeList) {
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (childNode.nodeSourceType() == ModelNode::NodeWithComponentSource)
|
2011-06-09 11:34:13 +02:00
|
|
|
removeSingleNodeFromList(childNode);
|
2011-05-24 18:47:33 +02:00
|
|
|
}
|
2013-10-16 18:02:31 +02:00
|
|
|
|
|
|
|
|
if (m_standardItemModel->rowCount() == 1)
|
|
|
|
|
removeMasterDocument();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2011-06-09 10:53:22 +02:00
|
|
|
void ComponentView::nodeReparented(const ModelNode &node, const NodeAbstractProperty &/*newPropertyParent*/, const NodeAbstractProperty &/*oldPropertyParent*/, AbstractView::PropertyChangeFlags /*propertyChange*/)
|
|
|
|
|
{
|
|
|
|
|
searchForComponentAndAddToList(node);
|
2013-10-16 18:02:31 +02:00
|
|
|
|
|
|
|
|
updateDescription(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentView::nodeIdChanged(const ModelNode& node, const QString& /*newId*/, const QString& /*oldId*/)
|
|
|
|
|
{
|
|
|
|
|
updateDescription(node);
|
2011-06-09 10:53:22 +02:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
} // namespace QmlDesigner
|