2010-01-04 11:39:56 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2009-05-12 14:59:06 +02:00
|
|
|
#include "qtuicodemodelsupport.h"
|
2009-11-25 18:50:20 +01:00
|
|
|
#include "qt4buildconfiguration.h"
|
2009-05-12 14:59:06 +02:00
|
|
|
|
|
|
|
|
#include "qt4project.h"
|
2010-02-08 15:50:06 +01:00
|
|
|
#include "qt4target.h"
|
|
|
|
|
|
2009-05-12 14:59:06 +02:00
|
|
|
#include <designer/formwindoweditor.h>
|
|
|
|
|
|
|
|
|
|
using namespace Qt4ProjectManager;
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
|
|
|
|
Qt4UiCodeModelSupport::Qt4UiCodeModelSupport(CppTools::CppModelManagerInterface *modelmanager,
|
|
|
|
|
Qt4Project *project,
|
|
|
|
|
const QString &source,
|
|
|
|
|
const QString &uiHeaderFile)
|
|
|
|
|
: CppTools::AbstractEditorSupport(modelmanager),
|
|
|
|
|
m_project(project),
|
|
|
|
|
m_sourceName(source),
|
|
|
|
|
m_fileName(uiHeaderFile),
|
|
|
|
|
m_updateIncludingFiles(false)
|
|
|
|
|
{
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"ctor Qt4UiCodeModelSupport for"<<m_sourceName;
|
2009-05-12 14:59:06 +02:00
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt4UiCodeModelSupport::~Qt4UiCodeModelSupport()
|
|
|
|
|
{
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"dtor ~Qt4UiCodeModelSupport for"<<m_sourceName;
|
2009-05-12 14:59:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4UiCodeModelSupport::init()
|
|
|
|
|
{
|
|
|
|
|
QDateTime sourceTime = QFileInfo(m_sourceName).lastModified();
|
|
|
|
|
QFileInfo uiHeaderFileInfo(m_fileName);
|
|
|
|
|
QDateTime uiHeaderTime = uiHeaderFileInfo.exists() ? uiHeaderFileInfo.lastModified() : QDateTime();
|
|
|
|
|
if (uiHeaderTime.isValid() && (uiHeaderTime > sourceTime)) {
|
|
|
|
|
QFile file(m_fileName);
|
|
|
|
|
if (file.open(QFile::ReadOnly)) {
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"ui*h file is more recent then source file, using information from ui*h file"<<m_fileName;
|
2009-05-12 14:59:06 +02:00
|
|
|
QTextStream stream(&file);
|
|
|
|
|
m_contents = stream.readAll().toUtf8();
|
|
|
|
|
m_cacheTime = uiHeaderTime;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"ui*h file not found, or not recent enough, trying to create it on the fly";
|
2009-05-12 14:59:06 +02:00
|
|
|
QFile file(m_sourceName);
|
|
|
|
|
if (file.open(QFile::ReadOnly)) {
|
|
|
|
|
QTextStream stream(&file);
|
|
|
|
|
const QString contents = stream.readAll();
|
|
|
|
|
if (runUic(contents)) {
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"created on the fly";
|
2009-05-12 14:59:06 +02:00
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
// uic run was unsuccesfull
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"uic run wasn't succesfull";
|
2009-05-12 14:59:06 +02:00
|
|
|
m_cacheTime = QDateTime();
|
|
|
|
|
m_contents = QByteArray();
|
|
|
|
|
// and if the header file wasn't there, next time we need to update
|
|
|
|
|
// all of the files that include this header
|
|
|
|
|
if (!uiHeaderFileInfo.exists())
|
|
|
|
|
m_updateIncludingFiles = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"Could open "<<m_sourceName<<"needed for the cpp model";
|
2009-05-12 14:59:06 +02:00
|
|
|
m_contents = QByteArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray Qt4UiCodeModelSupport::contents() const
|
|
|
|
|
{
|
|
|
|
|
return m_contents;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Qt4UiCodeModelSupport::fileName() const
|
|
|
|
|
{
|
|
|
|
|
return m_fileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4UiCodeModelSupport::setFileName(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
if (m_fileName == name && m_cacheTime.isValid())
|
|
|
|
|
return;
|
|
|
|
|
m_fileName = name;
|
|
|
|
|
m_contents.clear();
|
|
|
|
|
m_cacheTime = QDateTime();
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Qt4UiCodeModelSupport::runUic(const QString &ui) const
|
|
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
Qt4BuildConfiguration *qt4bc = m_project->activeTarget()->activeBuildConfiguration();
|
2009-05-12 14:59:06 +02:00
|
|
|
QProcess uic;
|
2010-02-08 15:50:06 +01:00
|
|
|
uic.setEnvironment(qt4bc->environment().toStringList());
|
2009-11-25 18:50:20 +01:00
|
|
|
uic.start(qt4bc->qtVersion()->uicCommand(), QStringList(), QIODevice::ReadWrite);
|
2009-05-12 14:59:06 +02:00
|
|
|
uic.waitForStarted();
|
|
|
|
|
uic.write(ui.toUtf8());
|
|
|
|
|
uic.closeWriteChannel();
|
|
|
|
|
if (uic.waitForFinished()) {
|
|
|
|
|
m_contents = uic.readAllStandardOutput();
|
|
|
|
|
m_cacheTime = QDateTime::currentDateTime();
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
2009-05-14 11:26:57 +02:00
|
|
|
// 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();
|
2009-05-12 14:59:06 +02:00
|
|
|
uic.kill();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
void Qt4UiCodeModelSupport::updateFromEditor(Designer::FormWindowEditor *fw)
|
2009-05-12 14:59:06 +02:00
|
|
|
{
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"Qt4UiCodeModelSupport::updateFromEditor"<<fw;
|
2009-05-12 14:59:06 +02:00
|
|
|
if (runUic(fw->contents())) {
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"runUic: success, updated on the fly";
|
2009-05-12 14:59:06 +02:00
|
|
|
updateDocument();
|
|
|
|
|
} else {
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"runUic: failed, not updated";
|
2009-05-12 14:59:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4UiCodeModelSupport::updateFromBuild()
|
|
|
|
|
{
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"Qt4UiCodeModelSupport::updateFromBuild() for file"<<m_sourceName;
|
2009-05-12 14:59:06 +02:00
|
|
|
// This is mostly a fall back for the cases when uic couldn't be run
|
|
|
|
|
// it pays special attention to the case where a ui_*h was newly created
|
|
|
|
|
QDateTime sourceTime = QFileInfo(m_sourceName).lastModified();
|
|
|
|
|
if (m_cacheTime.isValid() && m_cacheTime >= sourceTime) {
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"Cache is still more recent then source";
|
2009-05-12 14:59:06 +02:00
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
QFileInfo fi(m_fileName);
|
|
|
|
|
QDateTime uiHeaderTime = fi.exists() ? fi.lastModified() : QDateTime();
|
|
|
|
|
if (uiHeaderTime.isValid() && (uiHeaderTime > sourceTime)) {
|
|
|
|
|
if (m_cacheTime >= uiHeaderTime)
|
|
|
|
|
return;
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"found ui*h updating from it";
|
2009-05-12 14:59:06 +02:00
|
|
|
|
|
|
|
|
QFile file(m_fileName);
|
|
|
|
|
if (file.open(QFile::ReadOnly)) {
|
|
|
|
|
QTextStream stream(&file);
|
|
|
|
|
m_contents = stream.readAll().toUtf8();
|
|
|
|
|
m_cacheTime = uiHeaderTime;
|
|
|
|
|
updateDocument();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-14 11:26:57 +02:00
|
|
|
// qDebug()<<"ui*h not found or not more recent then source not changing anything";
|
2009-05-12 14:59:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|