Commit 13a608f8 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

uic-Codemodel-updating: Decouple form editor.



Pass around contents as string, saving repeated
invocation of FormWindowEditor::contents().
Remove dependency to FormWindowEditor.
Reviewed-by: default avatardt <qtc-committer@nokia.com>
parent f1192c41
......@@ -1244,16 +1244,16 @@ void Qt4ProFileNode::updateCodeModelSupportFromBuild(const QStringList &files)
}
}
void Qt4ProFileNode::updateCodeModelSupportFromEditor(const QString &uiFileName, Designer::FormWindowEditor *fw)
void Qt4ProFileNode::updateCodeModelSupportFromEditor(const QString &uiFileName,
const QString &contents)
{
QMap<QString, Qt4UiCodeModelSupport *>::const_iterator it;
it = m_uiCodeModelSupport.constFind(uiFileName);
if (it != m_uiCodeModelSupport.constEnd()) {
it.value()->updateFromEditor(fw);
}
const QMap<QString, Qt4UiCodeModelSupport *>::const_iterator it =
m_uiCodeModelSupport.constFind(uiFileName);
if (it != m_uiCodeModelSupport.constEnd())
it.value()->updateFromEditor(contents);
foreach (ProjectExplorer::ProjectNode *pro, subProjectNodes())
if (Qt4ProFileNode *qt4proFileNode = qobject_cast<Qt4ProFileNode *>(pro))
qt4proFileNode->updateCodeModelSupportFromEditor(uiFileName, fw);
qt4proFileNode->updateCodeModelSupportFromEditor(uiFileName, contents);
}
QString Qt4ProFileNode::uiDirectory() const
......
......@@ -49,10 +49,6 @@ namespace Core {
class ICore;
}
namespace Designer {
class FormWindowEditor;
}
namespace Qt4ProjectManager {
// Import base classes into namespace
......@@ -207,7 +203,7 @@ public:
QStringList variableValue(const Qt4Variable var) const;
void updateCodeModelSupportFromBuild(const QStringList &files);
void updateCodeModelSupportFromEditor(const QString &uiFileName, Designer::FormWindowEditor *fw);
void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
QString buildDir() const;
......
......@@ -115,13 +115,14 @@ void Qt4Manager::init()
void Qt4Manager::editorChanged(Core::IEditor *editor)
{
// Handle old editor
Designer::FormWindowEditor *lastEditor = qobject_cast<Designer::FormWindowEditor *>(m_lastEditor);
if (lastEditor) {
disconnect(lastEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
Designer::FormWindowEditor *lastFormEditor = qobject_cast<Designer::FormWindowEditor *>(m_lastEditor);
if (lastFormEditor) {
disconnect(lastFormEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
if (m_dirty) {
const QString contents = lastFormEditor->contents();
foreach(Qt4Project *project, m_projects)
project->rootProjectNode()->updateCodeModelSupportFromEditor(lastEditor->file()->fileName(), lastEditor);
project->rootProjectNode()->updateCodeModelSupportFromEditor(lastFormEditor->file()->fileName(), contents);
m_dirty = false;
}
}
......@@ -142,8 +143,9 @@ void Qt4Manager::editorAboutToClose(Core::IEditor *editor)
if (lastEditor) {
disconnect(lastEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
if (m_dirty) {
const QString contents = lastEditor->contents();
foreach(Qt4Project *project, m_projects)
project->rootProjectNode()->updateCodeModelSupportFromEditor(lastEditor->file()->fileName(), lastEditor);
project->rootProjectNode()->updateCodeModelSupportFromEditor(lastEditor->file()->fileName(), contents);
m_dirty = false;
}
}
......
......@@ -33,11 +33,11 @@
#include "qt4project.h"
#include "qt4target.h"
#include <designer/formwindoweditor.h>
using namespace Qt4ProjectManager;
using namespace Internal;
enum { debug = 0 };
Qt4UiCodeModelSupport::Qt4UiCodeModelSupport(CppTools::CppModelManagerInterface *modelmanager,
Qt4Project *project,
const QString &source,
......@@ -123,33 +123,32 @@ bool Qt4UiCodeModelSupport::runUic(const QString &ui) const
Qt4BuildConfiguration *qt4bc = m_project->activeTarget()->activeBuildConfiguration();
QProcess uic;
uic.setEnvironment(qt4bc->environment().toStringList());
uic.start(qt4bc->qtVersion()->uicCommand(), QStringList(), QIODevice::ReadWrite);
uic.waitForStarted();
const QString uicCommand = qt4bc->qtVersion()->uicCommand();
if (debug)
qDebug() << "Qt4UiCodeModelSupport::runUic " << uicCommand << " on " << ui.size() << " bytes";
uic.start(uicCommand, QStringList(), QIODevice::ReadWrite);
if (!uic.waitForStarted())
return false;
uic.write(ui.toUtf8());
uic.closeWriteChannel();
if (uic.waitForFinished()) {
if (uic.waitForFinished() && uic.exitStatus() == QProcess::NormalExit && uic.exitCode() == 0) {
m_contents = uic.readAllStandardOutput();
m_cacheTime = QDateTime::currentDateTime();
return true;
if (debug)
qDebug() << "ok" << m_contents.size() << "bytes.";
return true;
} else {
// qDebug()<<"running uic failed"<<" using uic: "<<m_project->qtVersion(m_project->activeBuildConfiguration())->uicCommand();
// qDebug()<<uic.readAllStandardError();
// qDebug()<<uic.readAllStandardOutput();
// qDebug()<<uic.errorString();
// qDebug()<<uic.error();
if (debug)
qDebug() << "failed" << uic.readAllStandardError();
uic.kill();
}
return false;
}
void Qt4UiCodeModelSupport::updateFromEditor(Designer::FormWindowEditor *fw)
void Qt4UiCodeModelSupport::updateFromEditor(const QString &formEditorContents)
{
// qDebug()<<"Qt4UiCodeModelSupport::updateFromEditor"<<fw;
if (runUic(fw->contents())) {
// qDebug()<<"runUic: success, updated on the fly";
if (runUic(formEditorContents)) {
updateDocument();
} else {
// qDebug()<<"runUic: failed, not updated";
}
}
......
......@@ -34,10 +34,6 @@
#include <QtCore/QDateTime>
namespace Designer {
class FormWindowEditor;
}
namespace Qt4ProjectManager {
class Qt4Project;
namespace Internal {
......@@ -54,7 +50,7 @@ public:
void setSourceName(const QString &name);
virtual QByteArray contents() const;
virtual QString fileName() const;
void updateFromEditor(Designer::FormWindowEditor *);
void updateFromEditor(const QString &formEditorContents);
void updateFromBuild();
private:
void init();
......
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