summaryrefslogtreecommitdiff
path: root/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp')
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp83
1 files changed, 59 insertions, 24 deletions
diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
index 3b959f83af..3e3e75ffeb 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
@@ -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*)));
- setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
+ Qt4ProjectManager::QtVersionManager *qtVersions = Qt4ProjectManager::QtVersionManager::instance();
+ connect(qtVersions, SIGNAL(qtVersionsChanged(QList<int>)), this, SLOT(updateEnabled()));
- // 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);
+ setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
}
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();
+ }
+
+ bool newValue = QFileInfo(viewerPath()).exists() && qmlFileFound;
- setEnabled(enable);
+ 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