Commit defcfadd authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Add master to component view



Change-Id: I236f78b73b8eea2b780e64d833fdedcfa7d246d1
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 0b82b54c
......@@ -147,15 +147,18 @@ void CrumbleBar::onCrumblePathElementClicked(const QVariant &data)
&& clickedCrumbleBarInfo.fileName == currentDesignDocument()->fileName()) {
nextFileIsCalledInternally();
currentDesignDocument()->changeToDocumentModel();
QmlDesignerPlugin::instance()->viewManager().setComponentViewToMaster();
} else {
crumblePath()->popElement();
nextFileIsCalledInternally();
Core::EditorManager::openEditor(clickedCrumbleBarInfo.fileName, Core::Id(),
Core::EditorManager::DoNotMakeVisible);
if (!clickedCrumbleBarInfo.componentId.isEmpty()) {
currentDesignDocument()->changeToSubComponent(
currentDesignDocument()->rewriterView()->modelNodeForId(clickedCrumbleBarInfo.componentId));
//pushInFileComponent(clickedCrumbleBarInfo.componentId);
ModelNode componentNode = currentDesignDocument()->rewriterView()->modelNodeForId(clickedCrumbleBarInfo.componentId);
currentDesignDocument()->changeToSubComponent(componentNode);
QmlDesignerPlugin::instance()->viewManager().setComponentNode(componentNode);
} else {
QmlDesignerPlugin::instance()->viewManager().setComponentViewToMaster();
}
}
updateVisibility();
......
......@@ -68,9 +68,12 @@ void ComponentAction::emitCurrentComponentChanged(int index)
if (dontEmitCurrentComponentChanged)
return;
ModelNode componentNode = m_componentView->modelNode(index);
ModelNode componentModelNode = m_componentView->modelNode(index);
emit currentComponentChanged(componentNode);
if (componentModelNode.isRootNode())
emit changedToMaster();
else
emit currentComponentChanged(componentModelNode);
}
} // namespace QmlDesigner
......@@ -56,6 +56,7 @@ protected:
signals:
void currentComponentChanged(const ModelNode &node);
void changedToMaster();
void currentIndexChanged(int index);
public slots:
......
......@@ -71,6 +71,11 @@ void ComponentView::setComponentNode(const ModelNode &node)
m_componentAction->setCurrentIndex(indexForNode(node));
}
void ComponentView::setComponentToMaster()
{
m_componentAction->setCurrentIndex(indexOfMaster());
}
void ComponentView::removeSingleNodeFromList(const ModelNode &node)
{
for (int row = 0; row < m_standardItemModel->rowCount(); row++) {
......@@ -89,6 +94,24 @@ int ComponentView::indexForNode(const ModelNode &node)
return -1;
}
int ComponentView::indexOfMaster()
{
for (int row = 0; row < m_standardItemModel->rowCount(); row++) {
if (m_standardItemModel->item(row)->data(ModelNodeRole).toInt() == 0)
return row;
}
return -1;
}
void ComponentView::addMasterDocument()
{
QStandardItem *item = new QStandardItem("master");
item->setData(QVariant::fromValue(0), ModelNodeRole);
item->setEditable(false);
m_standardItemModel->appendRow(item);
}
void ComponentView::modelAttached(Model *model)
{
if (AbstractView::model() == model)
......@@ -129,8 +152,15 @@ void ComponentView::searchForComponentAndAddToList(const ModelNode &node)
nodeList.append(node.allSubModelNodes());
bool masterNotAdded = true;
foreach (const ModelNode &node, nodeList) {
if (node.nodeSourceType() == ModelNode::NodeWithComponentSource) {
if (masterNotAdded) {
masterNotAdded = true;
addMasterDocument();
}
if (!node.id().isEmpty()) {
QStandardItem *item = new QStandardItem(node.id());
item->setData(QVariant::fromValue(node.internalId()), ModelNodeRole);
......
......@@ -116,6 +116,7 @@ public:
ModelNode modelNode(int index) const;
void setComponentNode(const ModelNode &node);
void setComponentToMaster();
signals:
void componentListChanged(const QStringList &componentList);
......@@ -126,6 +127,8 @@ private: //functions
void searchForComponentAndRemoveFromList(const ModelNode &node);
void removeSingleNodeFromList(const ModelNode &node);
int indexForNode(const ModelNode &node);
int indexOfMaster();
void addMasterDocument();
private:
QStandardItemModel *m_standardItemModel;
......
......@@ -264,6 +264,7 @@ void DesignDocument::changeToDocumentModel()
viewManager().detachRewriterView();
viewManager().detachViewsExceptRewriterAndComponetView();
m_inFileComponentModel.reset();
viewManager().attachRewriterView();
......@@ -297,6 +298,19 @@ void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
attachRewriterToModel();
QmlDesignerPlugin::instance()->viewManager().pushInFileComponentOnCrumbleBar(componentNode);
QmlDesignerPlugin::instance()->viewManager().setComponentNode(componentNode);
}
void DesignDocument::changeToMaster()
{
if (QmlDesignerPlugin::instance()->currentDesignDocument() != this)
return;
if (m_inFileComponentModel)
changeToDocumentModel();
QmlDesignerPlugin::instance()->viewManager().pushFileOnCrumbleBar(fileName());
QmlDesignerPlugin::instance()->viewManager().setComponentNode(rootModelNode());
}
void DesignDocument::attachRewriterToModel()
......
......@@ -118,6 +118,7 @@ public slots:
void redo();
void updateActiveQtVersion();
void changeToSubComponent(const ModelNode &componentNode);
void changeToMaster();
private slots:
void updateFileName(const QString &oldFileName, const QString &newFileName);
......
......@@ -70,6 +70,7 @@ public:
void setItemLibraryViewResourcePath(const QString &resourcePath);
void setComponentNode(const ModelNode &componentNode);
void setComponentViewToMaster();
void setNodeInstanceViewQtPath(const QString & qtPath);
void resetPropertyEditorView();
......
......@@ -132,11 +132,14 @@ void ViewManager::attachComponentView()
{
documentModel()->attachView(&m_componentView);
QObject::connect(m_componentView.action(), SIGNAL(currentComponentChanged(ModelNode)), currentDesignDocument(), SLOT(changeToSubComponent(ModelNode)));
QObject::connect(m_componentView.action(), SIGNAL(changedToMaster()), currentDesignDocument(), SLOT(changeToMaster()));
}
void ViewManager::detachComponentView()
{
QObject::disconnect(m_componentView.action(), SIGNAL(currentComponentChanged(ModelNode)), currentDesignDocument(), SLOT(changeToSubComponent(ModelNode)));
QObject::disconnect(m_componentView.action(), SIGNAL(changedToMaster()), currentDesignDocument(), SLOT(changeToMaster()));
documentModel()->detachView(&m_componentView);
}
......@@ -166,6 +169,11 @@ void ViewManager::setComponentNode(const ModelNode &componentNode)
m_componentView.setComponentNode(componentNode);
}
void ViewManager::setComponentViewToMaster()
{
m_componentView.setComponentToMaster();
}
void ViewManager::setNodeInstanceViewQtPath(const QString &qtPath)
{
m_nodeInstanceView.setPathToQt(qtPath);
......
......@@ -233,6 +233,7 @@ void QmlDesignerPlugin::changeEditor()
if (m_documentManager.hasCurrentDesignDocument()) {
activateAutoSynchronization();
m_viewManager.pushFileOnCrumbleBar(m_documentManager.currentDesignDocument()->fileName());
m_viewManager.setComponentViewToMaster();
}
m_shortCutManager.updateUndoActions(currentDesignDocument());
......
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