From 4dc36974a8d85569612a68544f8edeacc8622b48 Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Wed, 18 Feb 2015 16:01:58 +0100 Subject: [PATCH] Android: Adding libraries to subdirs projects Task-number: QTCREATORBUG-11625 Change-Id: I1017546463e819fc05846af74582cb9f5739ff08 Reviewed-by: BogDan Vatra --- .../androidextralibrarylistmodel.cpp | 75 +++++++++++++------ .../androidextralibrarylistmodel.h | 19 +++-- .../qmakeandroidbuildapkwidget.cpp | 2 +- .../qmakeprojectmanager/qmakenodes.cpp | 6 +- src/plugins/qmakeprojectmanager/qmakenodes.h | 2 +- 5 files changed, 67 insertions(+), 37 deletions(-) diff --git a/src/plugins/qmakeandroidsupport/androidextralibrarylistmodel.cpp b/src/plugins/qmakeandroidsupport/androidextralibrarylistmodel.cpp index 8d70d4df595..b8f2caa6c55 100644 --- a/src/plugins/qmakeandroidsupport/androidextralibrarylistmodel.cpp +++ b/src/plugins/qmakeandroidsupport/androidextralibrarylistmodel.cpp @@ -30,23 +30,33 @@ ****************************************************************************/ #include "androidextralibrarylistmodel.h" +#include "qmakeandroidrunconfiguration.h" + +#include + #include #include #include + using namespace QmakeAndroidSupport; using namespace Internal; +using QmakeProjectManager::QmakeProject; -AndroidExtraLibraryListModel::AndroidExtraLibraryListModel(QmakeProjectManager::QmakeProject *project, +AndroidExtraLibraryListModel::AndroidExtraLibraryListModel(ProjectExplorer::Target *target, QObject *parent) - : QAbstractItemModel(parent) - , m_project(project) + : QAbstractItemModel(parent), + m_target(target) { - QmakeProjectManager::QmakeProFileNode *node = m_project->rootQmakeProjectNode(); - proFileUpdated(node, node->validParse(), node->parseInProgress()); - connect(m_project, SIGNAL(proFileUpdated(QmakeProjectManager::QmakeProFileNode*,bool,bool)), - this, SLOT(proFileUpdated(QmakeProjectManager::QmakeProFileNode*,bool,bool))); + activeRunConfigurationChanged(); + + auto project = static_cast(target->project()); + connect(project, &QmakeProject::proFileUpdated, + this, &AndroidExtraLibraryListModel::proFileUpdated); + + connect(target, &ProjectExplorer::Target::activeRunConfigurationChanged, + this, &AndroidExtraLibraryListModel::activeRunConfigurationChanged); } QModelIndex AndroidExtraLibraryListModel::index(int row, int column, const QModelIndex &) const @@ -79,24 +89,21 @@ QVariant AndroidExtraLibraryListModel::data(const QModelIndex &index, int role) }; } -void AndroidExtraLibraryListModel::proFileUpdated(QmakeProjectManager::QmakeProFileNode *node, bool success, bool parseInProgress) +void AndroidExtraLibraryListModel::activeRunConfigurationChanged() { - QmakeProjectManager::QmakeProFileNode *root = m_project->rootQmakeProjectNode(); - if (node != root) + const QmakeProjectManager::QmakeProFileNode *node = activeNode(); + if (!node || node->parseInProgress()) { + emit enabledChanged(false); return; + } m_scope = QLatin1String("contains(ANDROID_TARGET_ARCH,") + node->singleVariableValue(QmakeProjectManager::AndroidArchVar) + QLatin1Char(')'); - if (parseInProgress) { - emit enabledChanged(false); - return; - } - bool enabled; beginResetModel(); - if (success && root->projectType() == QmakeProjectManager::ApplicationTemplate) { + if (node->validParse() && node->projectType() == QmakeProjectManager::ApplicationTemplate) { m_entries = node->variableValue(QmakeProjectManager::AndroidExtraLibs); enabled = true; } else { @@ -109,27 +116,47 @@ void AndroidExtraLibraryListModel::proFileUpdated(QmakeProjectManager::QmakeProF emit enabledChanged(enabled); } +QmakeProjectManager::QmakeProFileNode *AndroidExtraLibraryListModel::activeNode() const +{ + ProjectExplorer::RunConfiguration *rc = m_target->activeRunConfiguration(); + QmakeAndroidRunConfiguration *qarc = qobject_cast(rc); + if (!qarc) + return 0; + auto project = static_cast(m_target->project()); + return project->rootQmakeProjectNode()->findProFileFor(qarc->proFilePath()); +} + +void AndroidExtraLibraryListModel::proFileUpdated(QmakeProjectManager::QmakeProFileNode *node) +{ + if (node != activeNode()) + return; + activeRunConfigurationChanged(); +} + bool AndroidExtraLibraryListModel::isEnabled() const { - QmakeProjectManager::QmakeProFileNode *root = m_project->rootQmakeProjectNode(); - if (root->parseInProgress()) + QmakeProjectManager::QmakeProFileNode *node = activeNode(); + if (!node) return false; - if (root->projectType() != QmakeProjectManager::ApplicationTemplate) + if (node->parseInProgress()) + return false; + if (node->projectType() != QmakeProjectManager::ApplicationTemplate) return false; return true; } void AndroidExtraLibraryListModel::addEntries(const QStringList &list) { - if (m_project->rootQmakeProjectNode()->projectType() != QmakeProjectManager::ApplicationTemplate) + QmakeProjectManager::QmakeProFileNode *node = activeNode(); + if (!node || node->projectType() != QmakeProjectManager::ApplicationTemplate) return; beginInsertRows(QModelIndex(), m_entries.size(), m_entries.size() + list.size()); foreach (const QString &path, list) - m_entries += QLatin1String("$$PWD/") + QDir(m_project->projectDirectory().toString()).relativeFilePath(path); + m_entries += QLatin1String("$$PWD/") + + node->path().toFileInfo().absoluteDir().relativeFilePath(path); - QmakeProjectManager::QmakeProFileNode *node = m_project->rootQmakeProjectNode(); node->setProVariable(QLatin1String("ANDROID_EXTRA_LIBS"), m_entries, m_scope, QmakeProjectManager::Internal::ProWriter::ReplaceValues | QmakeProjectManager::Internal::ProWriter::MultiLine); @@ -144,7 +171,8 @@ bool greaterModelIndexByRow(const QModelIndex &a, const QModelIndex &b) void AndroidExtraLibraryListModel::removeEntries(QModelIndexList list) { - if (list.isEmpty() || m_project->rootQmakeProjectNode()->projectType() != QmakeProjectManager::ApplicationTemplate) + QmakeProjectManager::QmakeProFileNode *node = activeNode(); + if (list.isEmpty() || !node || node->projectType() != QmakeProjectManager::ApplicationTemplate) return; std::sort(list.begin(), list.end(), greaterModelIndexByRow); @@ -163,6 +191,5 @@ void AndroidExtraLibraryListModel::removeEntries(QModelIndexList list) endRemoveRows(); } - QmakeProjectManager::QmakeProFileNode *node = m_project->rootQmakeProjectNode(); node->setProVariable(QLatin1String("ANDROID_EXTRA_LIBS"), m_entries, m_scope); } diff --git a/src/plugins/qmakeandroidsupport/androidextralibrarylistmodel.h b/src/plugins/qmakeandroidsupport/androidextralibrarylistmodel.h index f810a363875..7b8c9321958 100644 --- a/src/plugins/qmakeandroidsupport/androidextralibrarylistmodel.h +++ b/src/plugins/qmakeandroidsupport/androidextralibrarylistmodel.h @@ -35,11 +35,13 @@ #include #include -namespace QmakeProjectManager { -class QmakeProject; -class QmakeProFileNode; +namespace ProjectExplorer { +class RunConfiguration; +class Target; } +namespace QmakeProjectManager { class QmakeProFileNode; } + namespace QmakeAndroidSupport { namespace Internal { @@ -47,7 +49,7 @@ class AndroidExtraLibraryListModel : public QAbstractItemModel { Q_OBJECT public: - explicit AndroidExtraLibraryListModel(QmakeProjectManager::QmakeProject *project, + explicit AndroidExtraLibraryListModel(ProjectExplorer::Target *target, QObject *parent = 0); QModelIndex index(int row, int column, const QModelIndex &parent) const; @@ -64,11 +66,12 @@ public: signals: void enabledChanged(bool); -private slots: - void proFileUpdated(QmakeProjectManager::QmakeProFileNode *node, bool success, bool parseInProgress); - private: - QmakeProjectManager::QmakeProject *m_project; + void proFileUpdated(QmakeProjectManager::QmakeProFileNode *node); + void activeRunConfigurationChanged(); + QmakeProjectManager::QmakeProFileNode *activeNode() const; + + ProjectExplorer::Target *m_target; QStringList m_entries; QString m_scope; }; diff --git a/src/plugins/qmakeandroidsupport/qmakeandroidbuildapkwidget.cpp b/src/plugins/qmakeandroidsupport/qmakeandroidbuildapkwidget.cpp index 186f1918d62..518f801c9a7 100644 --- a/src/plugins/qmakeandroidsupport/qmakeandroidbuildapkwidget.cpp +++ b/src/plugins/qmakeandroidsupport/qmakeandroidbuildapkwidget.cpp @@ -84,7 +84,7 @@ QmakeAndroidBuildApkWidget::QmakeAndroidBuildApkWidget(QmakeAndroidBuildApkStep oldFilesWarningIcon->setVisible(oldFiles); oldFilesWarningLabel->setVisible(oldFiles); - m_extraLibraryListModel = new AndroidExtraLibraryListModel(static_cast(m_step->project()), this); + m_extraLibraryListModel = new AndroidExtraLibraryListModel(m_step->target(), this); m_ui->androidExtraLibsListView->setModel(m_extraLibraryListModel); connect(m_ui->createAndroidTemplatesButton, SIGNAL(clicked()), diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.cpp b/src/plugins/qmakeprojectmanager/qmakenodes.cpp index 4c66f67b2ae..9a10b03850b 100644 --- a/src/plugins/qmakeprojectmanager/qmakenodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakenodes.cpp @@ -1527,13 +1527,13 @@ namespace { }; } -const QmakeProFileNode *QmakeProFileNode::findProFileFor(const FileName &fileName) const +QmakeProFileNode *QmakeProFileNode::findProFileFor(const FileName &fileName) const { if (fileName == path()) - return this; + return const_cast(this); foreach (ProjectNode *pn, subProjectNodes()) if (QmakeProFileNode *qmakeProFileNode = dynamic_cast(pn)) - if (const QmakeProFileNode *result = qmakeProFileNode->findProFileFor(fileName)) + if (QmakeProFileNode *result = qmakeProFileNode->findProFileFor(fileName)) return result; return 0; } diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.h b/src/plugins/qmakeprojectmanager/qmakenodes.h index 3b501d245ec..2a005c4a351 100644 --- a/src/plugins/qmakeprojectmanager/qmakenodes.h +++ b/src/plugins/qmakeprojectmanager/qmakenodes.h @@ -357,7 +357,7 @@ public: static QString uiHeaderFile(const QString &uiDir, const Utils::FileName &formFile); QHash uiFiles() const; - const QmakeProFileNode *findProFileFor(const Utils::FileName &string) const; + QmakeProFileNode *findProFileFor(const Utils::FileName &string) const; TargetInformation targetInformation() const; InstallsList installsList() const;