Commit 386974c9 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner.documentController: adding instance()

Also exposing changeCurrentModelTo() as public API.

Change-Id: I7c9ed3679ef5859b1349f1d1fe3088e78bccc7ad
Reviewed-on: http://codereview.qt.nokia.com/787Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
parent 88ac3daa
......@@ -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;
}
......
......@@ -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<ModelNode>() == node)
return row;
}
return -1;
}
void ComponentView::modelAttached(Model *model)
{
if (AbstractView::model() == model)
......
......@@ -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())
......
......@@ -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
......
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