Commit f38b0e7b authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.componentView: cleaning up

There was some dead code I removed.
I also refactored the node removal and made it more robust.

Change-Id: I3bd566011302968c1d798689fcca3b4a3880b306
Reviewed-on: http://codereview.qt.nokia.com/417

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
parent 0793a8df
......@@ -45,7 +45,6 @@ namespace QmlDesigner {
ComponentView::ComponentView(QObject *parent)
: AbstractView(parent),
m_standardItemModel(new QStandardItemModel(this)),
m_listChanged(false),
m_componentAction(new ComponentAction(this))
{
}
......@@ -54,11 +53,7 @@ ComponentView::ComponentView(QObject *parent)
void ComponentView::nodeAboutToBeRemoved(const ModelNode &removedNode)
{
for (int index = 1; index < m_standardItemModel->rowCount(); index++) {
QStandardItem *item = m_standardItemModel->item(index);
if (item->data(ModelNodeRole).value<ModelNode>() == removedNode)
m_standardItemModel->removeRow(index);
}
removeSingleNodeFromList(removedNode);
searchForComponentAndRemoveFromList(removedNode);
}
......@@ -85,6 +80,14 @@ void ComponentView::appendWholeDocumentAsComponent()
m_standardItemModel->appendRow(item);
}
void ComponentView::removeSingleNodeFromList(const ModelNode &node)
{
for (int row = 0; row < m_standardItemModel->rowCount(); row++) {
if (m_standardItemModel->item(row)->data(ModelNodeRole).value<ModelNode>() == node)
m_standardItemModel->removeRow(row);
}
}
void ComponentView::modelAttached(Model *model)
{
if (AbstractView::model() == model)
......@@ -133,6 +136,7 @@ void ComponentView::searchForComponentAndAddToList(const ModelNode &node)
QStandardItem *item = new QStandardItem(node.id());
item->setData(QVariant::fromValue(node), ModelNodeRole);
item->setEditable(false);
removeSingleNodeFromList(node); //remove node if already present
m_standardItemModel->appendRow(item);
} else {
QString description;
......@@ -146,12 +150,9 @@ void ComponentView::searchForComponentAndAddToList(const ModelNode &node)
QStandardItem *item = new QStandardItem(description);
item->setData(QVariant::fromValue(node), ModelNodeRole);
item->setEditable(false);
removeSingleNodeFromList(node); //remove node if already present
m_standardItemModel->appendRow(item);
}
} else if (node.metaInfo().isValid() && node.metaInfo().isComponent() && !m_componentList.contains(node.type())) {
m_componentList.append(node.type());
m_componentList.sort();
m_listChanged = true;
}
}
}
......@@ -169,16 +170,7 @@ void ComponentView::searchForComponentAndRemoveFromList(const ModelNode &node)
foreach (const ModelNode &childNode, nodeList) {
if (childNode.nodeSourceType() == ModelNode::ComponentSource) {
if (!childNode.id().isEmpty()) {
for (int row = 0; row < m_standardItemModel->rowCount(); row++) {
if (m_standardItemModel->item(row)->text() == childNode.id())
m_standardItemModel->removeRow(row);
}
}
} else if (node.metaInfo().isComponent() && !m_componentList.contains(childNode.type())) {
m_componentList.append(childNode.type());
m_componentList.sort();
m_listChanged = true;
removeSingleNodeFromList(childNode);
}
}
}
......
......@@ -113,11 +113,10 @@ private: //functions
void searchForComponentAndAddToList(const ModelNode &node);
void searchForComponentAndRemoveFromList(const ModelNode &node);
void appendWholeDocumentAsComponent();
void removeSingleNodeFromList(const ModelNode &node);
private:
QStringList m_componentList;
QStandardItemModel *m_standardItemModel;
bool m_listChanged;
ComponentAction *m_componentAction;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment