From 41ceaf28217d73f0af3cbd67de42b87b70bfa8d2 Mon Sep 17 00:00:00 2001 From: dt Date: Thu, 23 Sep 2010 14:40:22 +0200 Subject: [PATCH] Ui Code Model Support: Refactor code in preparation for cmake support --- src/plugins/cpptools/cpptools.pro | 6 +- .../cpptools/uicodecompletionsupport.cpp | 193 ++++++++++++++++++ .../cpptools/uicodecompletionsupport.h | 69 +++++++ src/plugins/plugins.pro | 1 + .../qtuicodemodelsupport.cpp | 151 +------------- .../qt4projectmanager/qtuicodemodelsupport.h | 19 +- 6 files changed, 281 insertions(+), 158 deletions(-) create mode 100644 src/plugins/cpptools/uicodecompletionsupport.cpp create mode 100644 src/plugins/cpptools/uicodecompletionsupport.h diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 346d10f86c8..04d10bc11e5 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -25,7 +25,8 @@ HEADERS += completionsettingspage.h \ cppfilesettingspage.h \ cppfindreferences.h \ cppcodeformatter.h \ - symbolsfindfilter.h + symbolsfindfilter.h \ + uicodecompletionsupport.h SOURCES += completionsettingspage.cpp \ cppclassesfilter.cpp \ @@ -42,7 +43,8 @@ SOURCES += completionsettingspage.cpp \ abstracteditorsupport.cpp \ cppfindreferences.cpp \ cppcodeformatter.cpp \ - symbolsfindfilter.cpp + symbolsfindfilter.cpp \ + uicodecompletionsupport.cpp FORMS += completionsettingspage.ui \ cppfilesettingspage.ui diff --git a/src/plugins/cpptools/uicodecompletionsupport.cpp b/src/plugins/cpptools/uicodecompletionsupport.cpp new file mode 100644 index 00000000000..36af62f4a31 --- /dev/null +++ b/src/plugins/cpptools/uicodecompletionsupport.cpp @@ -0,0 +1,193 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 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. +** +**************************************************************************/ + +#include "uicodecompletionsupport.h" +#include + +enum { debug = 0 }; + +using namespace CppTools; + +UiCodeModelSupport::UiCodeModelSupport(CppTools::CppModelManagerInterface *modelmanager, + const QString &source, + const QString &uiHeaderFile) + : CppTools::AbstractEditorSupport(modelmanager), + m_sourceName(source), + m_fileName(uiHeaderFile), + m_updateIncludingFiles(false) +{ + if (debug) + qDebug()<<"ctor UiCodeModelSupport for"< sourceTime)) { + QFile file(m_fileName); + if (file.open(QFile::ReadOnly)) { + if (debug) + qDebug()<<"ui*h file is more recent then source file, using information from ui*h file"<= sourceTime) { + if (debug) + qDebug()<<"Cache is still more recent then source"; + return; + } else { + QFileInfo fi(m_fileName); + QDateTime uiHeaderTime = fi.exists() ? fi.lastModified() : QDateTime(); + if (uiHeaderTime.isValid() && (uiHeaderTime > sourceTime)) { + if (m_cacheTime >= uiHeaderTime) + return; + if (debug) + qDebug()<<"found ui*h updating from it"; + + QFile file(m_fileName); + if (file.open(QFile::ReadOnly)) { + QTextStream stream(&file); + m_contents = stream.readAll().toUtf8(); + m_cacheTime = uiHeaderTime; + updateDocument(); + return; + } + } + if (debug) + qDebug()<<"ui*h not found or not more recent then source not changing anything"; + } +} + diff --git a/src/plugins/cpptools/uicodecompletionsupport.h b/src/plugins/cpptools/uicodecompletionsupport.h new file mode 100644 index 00000000000..a274b540da0 --- /dev/null +++ b/src/plugins/cpptools/uicodecompletionsupport.h @@ -0,0 +1,69 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 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. +** +**************************************************************************/ + + +#ifndef UICODECOMPLETIONSUPPORT_H +#define UICODECOMPLETIONSUPPORT_H + +#include "cppmodelmanagerinterface.h" +#include "cpptools_global.h" + +#include + +namespace CppTools { + +class CPPTOOLS_EXPORT UiCodeModelSupport : public CppTools::AbstractEditorSupport +{ +public: + UiCodeModelSupport(CppTools::CppModelManagerInterface *modelmanager, + const QString &sourceFile, + const QString &uiHeaderFile); + ~UiCodeModelSupport(); + void setFileName(const QString &name); + void setSourceName(const QString &name); + virtual QByteArray contents() const; + virtual QString fileName() const; + void updateFromEditor(const QString &formEditorContents); + void updateFromBuild(); +protected: + virtual QString uicCommand() const = 0; + virtual QStringList environment() const = 0; +private: + void init(); + bool runUic(const QString &ui) const; + QString m_sourceName; + QString m_fileName; + mutable bool m_updateIncludingFiles; + mutable QByteArray m_contents; + mutable QDateTime m_cacheTime; +}; + +} // CppTools + +#endif // UICODECOMPLETIONSUPPORT_H diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 9702fb785d5..b2887e24fee 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -120,6 +120,7 @@ plugin_projectexplorer.depends = plugin_locator plugin_projectexplorer.depends += plugin_find plugin_projectexplorer.depends += plugin_coreplugin plugin_projectexplorer.depends += plugin_texteditor +plugin_projectexplorer.depends += plugin_cpptools plugin_qt4projectmanager.subdir = qt4projectmanager plugin_qt4projectmanager.depends = plugin_texteditor diff --git a/src/plugins/qt4projectmanager/qtuicodemodelsupport.cpp b/src/plugins/qt4projectmanager/qtuicodemodelsupport.cpp index 695666ba0e2..31907c3e02d 100644 --- a/src/plugins/qt4projectmanager/qtuicodemodelsupport.cpp +++ b/src/plugins/qt4projectmanager/qtuicodemodelsupport.cpp @@ -44,158 +44,25 @@ Qt4UiCodeModelSupport::Qt4UiCodeModelSupport(CppTools::CppModelManagerInterface Qt4Project *project, const QString &source, const QString &uiHeaderFile) - : CppTools::AbstractEditorSupport(modelmanager), - m_project(project), - m_sourceName(source), - m_fileName(uiHeaderFile), - m_updateIncludingFiles(false) + : UiCodeModelSupport(modelmanager, source, uiHeaderFile), + m_project(project) { - if (debug) - qDebug()<<"ctor Qt4UiCodeModelSupport for"< sourceTime)) { - QFile file(m_fileName); - if (file.open(QFile::ReadOnly)) { - if (debug) - qDebug()<<"ui*h file is more recent then source file, using information from ui*h file"<activeTarget()->activeBuildConfiguration(); - QProcess uic; - uic.setEnvironment(qt4bc->environment().toStringList()); - 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() && uic.exitStatus() == QProcess::NormalExit && uic.exitCode() == 0) { - m_contents = uic.readAllStandardOutput(); - m_cacheTime = QDateTime::currentDateTime(); - if (debug) - qDebug() << "ok" << m_contents.size() << "bytes."; - return true; - } else { - if (debug) - qDebug() << "failed" << uic.readAllStandardError(); - uic.kill(); - } - return false; + return qt4bc->qtVersion()->uicCommand(); } -void Qt4UiCodeModelSupport::updateFromEditor(const QString &formEditorContents) +QStringList Qt4UiCodeModelSupport::environment() const { - if (runUic(formEditorContents)) { - updateDocument(); - } + Qt4BuildConfiguration *qt4bc = m_project->activeTarget()->activeBuildConfiguration(); + return qt4bc->environment().toStringList(); } - -void Qt4UiCodeModelSupport::updateFromBuild() -{ - if (debug) - qDebug()<<"Qt4UiCodeModelSupport::updateFromBuild() for file"<= sourceTime) { - if (debug) - qDebug()<<"Cache is still more recent then source"; - return; - } else { - QFileInfo fi(m_fileName); - QDateTime uiHeaderTime = fi.exists() ? fi.lastModified() : QDateTime(); - if (uiHeaderTime.isValid() && (uiHeaderTime > sourceTime)) { - if (m_cacheTime >= uiHeaderTime) - return; - if (debug) - qDebug()<<"found ui*h updating from it"; - - QFile file(m_fileName); - if (file.open(QFile::ReadOnly)) { - QTextStream stream(&file); - m_contents = stream.readAll().toUtf8(); - m_cacheTime = uiHeaderTime; - updateDocument(); - return; - } - } - if (debug) - qDebug()<<"ui*h not found or not more recent then source not changing anything"; - } -} - diff --git a/src/plugins/qt4projectmanager/qtuicodemodelsupport.h b/src/plugins/qt4projectmanager/qtuicodemodelsupport.h index 8f753617eb0..ed36d9787f3 100644 --- a/src/plugins/qt4projectmanager/qtuicodemodelsupport.h +++ b/src/plugins/qt4projectmanager/qtuicodemodelsupport.h @@ -31,6 +31,7 @@ #define QTUICODEMODELSUPPORT_H #include +#include #include @@ -38,7 +39,7 @@ namespace Qt4ProjectManager { class Qt4Project; namespace Internal { -class Qt4UiCodeModelSupport : public CppTools::AbstractEditorSupport +class Qt4UiCodeModelSupport : public ProjectExplorer::UiCodeModelSupport { public: Qt4UiCodeModelSupport(CppTools::CppModelManagerInterface *modelmanager, @@ -46,21 +47,11 @@ public: const QString &sourceFile, const QString &uiHeaderFile); ~Qt4UiCodeModelSupport(); - void setFileName(const QString &name); - void setSourceName(const QString &name); - virtual QByteArray contents() const; - virtual QString fileName() const; - void updateFromEditor(const QString &formEditorContents); - void updateFromBuild(); +protected: + virtual QString uicCommand() const; + virtual QStringList environment() const; private: - void init(); - bool runUic(const QString &ui) const; Qt4Project *m_project; - QString m_sourceName; - QString m_fileName; - mutable bool m_updateIncludingFiles; - mutable QByteArray m_contents; - mutable QDateTime m_cacheTime; };