diff --git a/src/plugins/qmldesigner/components/integration/componentaction.cpp b/src/plugins/qmldesigner/components/integration/componentaction.cpp index cc7d30b4415..f705bcd8a05 100644 --- a/src/plugins/qmldesigner/components/integration/componentaction.cpp +++ b/src/plugins/qmldesigner/components/integration/componentaction.cpp @@ -45,6 +45,11 @@ ComponentAction::ComponentAction(ComponentView *componentView) { } +void ComponentAction::setCurrentIndex(int i) +{ + emit currentIndexChanged(i); +} + QWidget *ComponentAction::createWidget(QWidget *parent) { QComboBox *comboBox = new QComboBox(parent); @@ -52,6 +57,7 @@ QWidget *ComponentAction::createWidget(QWidget *parent) comboBox->setToolTip(tr("Edit sub components defined in this file")); comboBox->setModel(m_componentView->standardItemModel()); connect(comboBox, SIGNAL(currentIndexChanged(int)), SLOT(emitCurrentComponentChanged(int))); + connect(this, SIGNAL(currentIndexChanged(int)), comboBox, SLOT(setCurrentIndex(int))); return comboBox; } diff --git a/src/plugins/qmldesigner/components/integration/componentview.cpp b/src/plugins/qmldesigner/components/integration/componentview.cpp index 4adc4a57dd6..887773319eb 100644 --- a/src/plugins/qmldesigner/components/integration/componentview.cpp +++ b/src/plugins/qmldesigner/components/integration/componentview.cpp @@ -72,6 +72,11 @@ ModelNode ComponentView::modelNode(int index) const return ModelNode(); } +void ComponentView::setComponentNode(const ModelNode &node) +{ + m_componentAction->setCurrentIndex(indexForNode(node)); +} + void ComponentView::appendWholeDocumentAsComponent() { QStandardItem *item = new QStandardItem(tr("whole document")); @@ -88,6 +93,16 @@ void ComponentView::removeSingleNodeFromList(const ModelNode &node) } } + +int ComponentView::indexForNode(const ModelNode &node) +{ + for (int row = 0; row < m_standardItemModel->rowCount(); row++) { + if (m_standardItemModel->item(row)->data(ModelNodeRole).value() == node) + return row; + } + return -1; +} + void ComponentView::modelAttached(Model *model) { if (AbstractView::model() == model) diff --git a/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp b/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp index 6ce87b58547..df58e0cda40 100644 --- a/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp +++ b/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp @@ -123,6 +123,8 @@ public: int qt_versionId; }; +DesignDocumentController *DesignDocumentController::m_this = 0; + /** \class QmlDesigner::DesignDocumentController @@ -133,6 +135,7 @@ DesignDocumentController::DesignDocumentController(QObject *parent) : QObject(parent), m_d(new DesignDocumentControllerPrivate) { + m_this = this; m_d->documentLoaded = false; m_d->syncBlocked = false; @@ -143,6 +146,7 @@ DesignDocumentController::DesignDocumentController(QObject *parent) : DesignDocumentController::~DesignDocumentController() { + m_this = 0; delete m_d->model.data(); delete m_d->subComponentModel.data(); @@ -296,6 +300,11 @@ void DesignDocumentController::setComponentView(ComponentView *componentView) connect(m_d->componentView->action(), SIGNAL(currentComponentChanged(ModelNode)), SLOT(changeCurrentModelTo(ModelNode))); } +DesignDocumentController *DesignDocumentController::instance() +{ + return m_this; +} + QString DesignDocumentController::displayName() const { if (fileName().isEmpty()) diff --git a/src/plugins/qmldesigner/components/integration/designdocumentcontroller.h b/src/plugins/qmldesigner/components/integration/designdocumentcontroller.h index 5e497262eea..533c5a14c2f 100644 --- a/src/plugins/qmldesigner/components/integration/designdocumentcontroller.h +++ b/src/plugins/qmldesigner/components/integration/designdocumentcontroller.h @@ -101,6 +101,8 @@ public: void setNodeInstanceView(NodeInstanceView *nodeInstanceView); void setComponentView(ComponentView *componentView); + static DesignDocumentController *instance(); + signals: void displayNameChanged(const QString &newFileName); void dirtyStateChanged(bool newState); @@ -123,6 +125,7 @@ public slots: void undo(); void redo(); void activeQtVersionChanged(); + void changeCurrentModelTo(const ModelNode &node); #ifdef ENABLE_TEXT_VIEW void showText(); @@ -131,7 +134,6 @@ public slots: private slots: void doRealSaveAs(const QString &fileName); - void changeCurrentModelTo(const ModelNode &node); private: void detachNodeInstanceView(); @@ -142,6 +144,8 @@ private: QString pathToQt() const; class DesignDocumentControllerPrivate *m_d; + + static DesignDocumentController* m_this; }; } // namespace QmlDesigner