forked from qt-creator/qt-creator
QmlProject: Search for qmlviewer in configured Qt versions (if not found in $PATH)
If no 'qmlviewer' executable is found in the PATH, iterate through the list of configured Qt versions and try to find a qmlviewer there. This should help users configuring creator such to play with Qml. Right now the first qmlviewer found in a Qt version is selected. A UI to let the user select one explicitly was not possible any more (string freeze). This requires a dependency from QmlProjectManager to Qt4ProjectManager. Reviewed-by: dt
This commit is contained in:
@@ -190,6 +190,7 @@ plugin_qmlprojectmanager.depends = plugin_texteditor
|
||||
plugin_qmlprojectmanager.depends += plugin_projectexplorer
|
||||
plugin_qmlprojectmanager.depends += plugin_qmljseditor
|
||||
plugin_qmlprojectmanager.depends += plugin_debugger
|
||||
plugin_qmlprojectmanager.depends += plugin_qt4projectmanager
|
||||
|
||||
plugin_qmldesigner.subdir = qmldesigner
|
||||
plugin_qmldesigner.depends = plugin_coreplugin
|
||||
|
@@ -18,5 +18,7 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General
|
||||
<dependency name="TextEditor" version="2.1.0"/>
|
||||
<dependency name="QmlJSEditor" version="2.1.0"/>
|
||||
<dependency name="Debugger" version="2.1.0" />
|
||||
<dependency name="ProjectExplorer" version="2.1.0"/>
|
||||
<dependency name="Qt4ProjectManager" version="2.1.0" />
|
||||
</dependencyList>
|
||||
</plugin>
|
||||
|
@@ -2,3 +2,4 @@ include(../../plugins/projectexplorer/projectexplorer.pri)
|
||||
include(../../plugins/texteditor/texteditor.pri)
|
||||
include(../../plugins/qmljseditor/qmljseditor.pri)
|
||||
include(../../plugins/debugger/debugger.pri)
|
||||
include(../../plugins/qt4projectmanager/qt4projectmanager.pri)
|
||||
|
@@ -41,6 +41,8 @@
|
||||
#include <coreplugin/ifile.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <qt4projectmanager/qtversionmanager.h>
|
||||
#include <qt4projectmanager/qt4projectmanagerconstants.h>
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QComboBox>
|
||||
@@ -94,20 +96,10 @@ void QmlProjectRunConfiguration::ctor()
|
||||
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)),
|
||||
this, SLOT(changeCurrentFile(Core::IEditor*)));
|
||||
|
||||
Qt4ProjectManager::QtVersionManager *qtVersions = Qt4ProjectManager::QtVersionManager::instance();
|
||||
connect(qtVersions, SIGNAL(qtVersionsChanged(QList<int>)), this, SLOT(updateEnabled()));
|
||||
|
||||
setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
|
||||
|
||||
// prepend creator/bin dir to search path (only useful for special creator-qml package)
|
||||
const QString searchPath = QCoreApplication::applicationDirPath()
|
||||
+ Utils::SynchronousProcess::pathSeparator()
|
||||
+ QString(qgetenv("PATH"));
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
const QString qmlViewerName = QLatin1String("QMLViewer");
|
||||
#else
|
||||
const QString qmlViewerName = QLatin1String("qmlviewer");
|
||||
#endif
|
||||
|
||||
m_qmlViewerDefaultPath = Utils::SynchronousProcess::locateBinary(searchPath, qmlViewerName);
|
||||
}
|
||||
|
||||
QmlProjectRunConfiguration::~QmlProjectRunConfiguration()
|
||||
@@ -128,7 +120,8 @@ QString QmlProjectRunConfiguration::viewerPath() const
|
||||
{
|
||||
if (!m_qmlViewerCustomPath.isEmpty())
|
||||
return m_qmlViewerCustomPath;
|
||||
return m_qmlViewerDefaultPath;
|
||||
|
||||
return viewerDefaultPath();
|
||||
}
|
||||
|
||||
QStringList QmlProjectRunConfiguration::viewerArguments() const
|
||||
@@ -182,8 +175,11 @@ QWidget *QmlProjectRunConfiguration::createConfigurationWidget()
|
||||
Utils::PathChooser *qmlViewer = new Utils::PathChooser;
|
||||
qmlViewer->setExpectedKind(Utils::PathChooser::Command);
|
||||
qmlViewer->setPath(viewerPath());
|
||||
|
||||
connect(qmlViewer, SIGNAL(changed(QString)), this, SLOT(onViewerChanged()));
|
||||
|
||||
QToolButton *qtVersionSelector = new QToolButton;
|
||||
|
||||
QLineEdit *qmlViewerArgs = new QLineEdit;
|
||||
qmlViewerArgs->setText(m_qmlViewerArgs);
|
||||
connect(qmlViewerArgs, SIGNAL(textChanged(QString)), this, SLOT(onViewerArgsChanged()));
|
||||
@@ -267,7 +263,7 @@ void QmlProjectRunConfiguration::setMainScript(const QString &scriptFile)
|
||||
} else {
|
||||
m_usingCurrentFile = false;
|
||||
m_mainScriptFilename = qmlTarget()->qmlProject()->projectDir().absoluteFilePath(scriptFile);
|
||||
setEnabled(true);
|
||||
updateEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,40 +311,79 @@ bool QmlProjectRunConfiguration::fromMap(const QVariantMap &map)
|
||||
return RunConfiguration::fromMap(map);
|
||||
}
|
||||
|
||||
void QmlProjectRunConfiguration::changeCurrentFile(Core::IEditor *editor)
|
||||
void QmlProjectRunConfiguration::changeCurrentFile(Core::IEditor * /*editor*/)
|
||||
{
|
||||
updateEnabled();
|
||||
}
|
||||
|
||||
void QmlProjectRunConfiguration::updateEnabled()
|
||||
{
|
||||
bool qmlFileFound = false;
|
||||
if (m_usingCurrentFile) {
|
||||
bool enable = false;
|
||||
Core::IEditor *editor = Core::EditorManager::instance()->currentEditor();
|
||||
if (editor) {
|
||||
m_currentFileFilename = editor->file()->fileName();
|
||||
if (Core::ICore::instance()->mimeDatabase()->findByFile(mainScript()).type() == QLatin1String("application/x-qml"))
|
||||
enable = true;
|
||||
qmlFileFound = true;
|
||||
}
|
||||
if (!editor
|
||||
|| Core::ICore::instance()->mimeDatabase()->findByFile(mainScript()).type() == QLatin1String("application/x-qmlproject")) {
|
||||
// find a qml file with lowercase filename. This is slow but only done in initialization/other border cases.
|
||||
foreach(const QString& filename, m_projectTarget->qmlProject()->files()) {
|
||||
foreach(const QString &filename, m_projectTarget->qmlProject()->files()) {
|
||||
const QFileInfo fi(filename);
|
||||
|
||||
if (!filename.isEmpty() && fi.baseName()[0].isLower()
|
||||
&& Core::ICore::instance()->mimeDatabase()->findByFile(fi).type() == QLatin1String("application/x-qml"))
|
||||
{
|
||||
m_currentFileFilename = filename;
|
||||
enable = true;
|
||||
qmlFileFound = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else { // use default one
|
||||
qmlFileFound = !m_mainScriptFilename.isEmpty();
|
||||
}
|
||||
|
||||
setEnabled(enable);
|
||||
bool newValue = QFileInfo(viewerPath()).exists() && qmlFileFound;
|
||||
|
||||
if (m_isEnabled != newValue) {
|
||||
m_isEnabled = newValue;
|
||||
emit isEnabledChanged(m_isEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
void QmlProjectRunConfiguration::setEnabled(bool value)
|
||||
QString QmlProjectRunConfiguration::viewerDefaultPath() const
|
||||
{
|
||||
m_isEnabled = value;
|
||||
emit isEnabledChanged(m_isEnabled);
|
||||
QString path;
|
||||
|
||||
// prepend creator/bin dir to search path (only useful for special creator-qml package)
|
||||
const QString searchPath = QCoreApplication::applicationDirPath()
|
||||
+ Utils::SynchronousProcess::pathSeparator()
|
||||
+ QString::fromLocal8Bit(qgetenv("PATH"));
|
||||
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
const QString qmlViewerName = QLatin1String("QMLViewer");
|
||||
#else
|
||||
const QString qmlViewerName = QLatin1String("qmlviewer");
|
||||
#endif
|
||||
|
||||
path = Utils::SynchronousProcess::locateBinary(searchPath, qmlViewerName);
|
||||
if (!path.isEmpty())
|
||||
return path;
|
||||
|
||||
// Try to locate default path in Qt Versions
|
||||
Qt4ProjectManager::QtVersionManager *qtVersions = Qt4ProjectManager::QtVersionManager::instance();
|
||||
foreach (Qt4ProjectManager::QtVersion *version, qtVersions->validVersions()) {
|
||||
if (!version->qmlviewerCommand().isEmpty()
|
||||
&& version->supportsTargetId(Qt4ProjectManager::Constants::DESKTOP_TARGET_ID)) {
|
||||
return version->qmlviewerCommand();
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
} // namespace QmlProjectManager
|
||||
|
@@ -88,18 +88,19 @@ public slots:
|
||||
void changeCurrentFile(Core::IEditor*);
|
||||
|
||||
private slots:
|
||||
|
||||
QString mainScript() const;
|
||||
void setMainScript(const QString &scriptFile);
|
||||
void updateFileComboBox();
|
||||
|
||||
void updateEnabled();
|
||||
|
||||
void onViewerChanged();
|
||||
void onViewerArgsChanged();
|
||||
void onDebugServerAddressChanged();
|
||||
void onDebugServerPortChanged();
|
||||
|
||||
|
||||
protected:
|
||||
QString viewerDefaultPath() const;
|
||||
QmlProjectRunConfiguration(Internal::QmlProjectTarget *parent, QmlProjectRunConfiguration *source);
|
||||
virtual bool fromMap(const QVariantMap &map);
|
||||
void setEnabled(bool value);
|
||||
@@ -114,7 +115,6 @@ private:
|
||||
|
||||
QString m_scriptFile;
|
||||
QString m_qmlViewerCustomPath;
|
||||
QString m_qmlViewerDefaultPath;
|
||||
QString m_qmlViewerArgs;
|
||||
QmlProjectRunConfigurationDebugData m_debugData;
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = Qt4ProjectManager
|
||||
DEFINES += QT4PROJECTMANAGER_LIBRARY
|
||||
QT += network
|
||||
include(../../qtcreatorplugin.pri)
|
||||
include(qt4projectmanager_dependencies.pri)
|
||||
@@ -44,7 +45,8 @@ HEADERS += qt4projectmanagerplugin.h \
|
||||
gettingstartedwelcomepage.h \
|
||||
qt4buildconfiguration.h \
|
||||
qt4target.h \
|
||||
qmakeparser.h
|
||||
qmakeparser.h \
|
||||
qt4projectmanager_global.h
|
||||
SOURCES += qt4projectmanagerplugin.cpp \
|
||||
qt4projectmanager.cpp \
|
||||
qt4project.cpp \
|
||||
|
41
src/plugins/qt4projectmanager/qt4projectmanager_global.h
Normal file
41
src/plugins/qt4projectmanager/qt4projectmanager_global.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** 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 QT4PROJECTMANAGER_GLOBAL_H
|
||||
#define QT4PROJECTMANAGER_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(QT4PROJECTMANAGER_LIBRARY)
|
||||
# define QT4PROJECTMANAGER_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define QT4PROJECTMANAGER_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // QT4PROJECTMANAGER_GLOBAL_H
|
@@ -749,6 +749,7 @@ void QtVersion::setQMakeCommand(const QString& qmakeCommand)
|
||||
#endif
|
||||
m_designerCommand.clear();
|
||||
m_linguistCommand.clear();
|
||||
m_qmlviewerCommand.clear();
|
||||
m_uicCommand.clear();
|
||||
m_toolChainUpToDate = false;
|
||||
// TODO do i need to optimize this?
|
||||
@@ -1202,6 +1203,22 @@ QString QtVersion::linguistCommand() const
|
||||
return m_linguistCommand;
|
||||
}
|
||||
|
||||
QString QtVersion::qmlviewerCommand() const
|
||||
{
|
||||
if (!isValid())
|
||||
return QString();
|
||||
if (m_qmlviewerCommand.isNull()) {
|
||||
#ifdef Q_OS_MAC
|
||||
const QString qmlViewerName = QLatin1String("QMLViewer");
|
||||
#else
|
||||
const QString qmlViewerName = QLatin1String("qmlviewer");
|
||||
#endif
|
||||
|
||||
m_qmlviewerCommand = findQtBinary(possibleGuiBinaries(qmlViewerName));
|
||||
}
|
||||
return m_qmlviewerCommand;
|
||||
}
|
||||
|
||||
bool QtVersion::supportsTargetId(const QString &id) const
|
||||
{
|
||||
updateToolChainAndMkspec();
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#ifndef QTVERSIONMANAGER_H
|
||||
#define QTVERSIONMANAGER_H
|
||||
|
||||
#include "qt4projectmanager_global.h"
|
||||
#include <projectexplorer/taskwindow.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
#include <QSharedPointer>
|
||||
@@ -45,7 +46,7 @@ class QtOptionsPageWidget;
|
||||
class QtOptionsPage;
|
||||
}
|
||||
|
||||
class QtVersion
|
||||
class QT4PROJECTMANAGER_EXPORT QtVersion
|
||||
{
|
||||
friend class QtVersionManager;
|
||||
public:
|
||||
@@ -70,6 +71,7 @@ public:
|
||||
QString uicCommand() const;
|
||||
QString designerCommand() const;
|
||||
QString linguistCommand() const;
|
||||
QString qmlviewerCommand() const;
|
||||
|
||||
bool supportsTargetId(const QString &id) const;
|
||||
QSet<QString> supportedTargetIds() const;
|
||||
@@ -189,6 +191,7 @@ private:
|
||||
mutable QString m_uicCommand;
|
||||
mutable QString m_designerCommand;
|
||||
mutable QString m_linguistCommand;
|
||||
mutable QString m_qmlviewerCommand;
|
||||
mutable QSet<QString> m_targetIds;
|
||||
};
|
||||
|
||||
@@ -199,7 +202,7 @@ struct QMakeAssignment
|
||||
QString value;
|
||||
};
|
||||
|
||||
class QtVersionManager : public QObject
|
||||
class QT4PROJECTMANAGER_EXPORT QtVersionManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
// for getUniqueId();
|
||||
|
Reference in New Issue
Block a user