Commit 4dc36974 authored by Daniel Teske's avatar Daniel Teske

Android: Adding libraries to subdirs projects

Task-number: QTCREATORBUG-11625

Change-Id: I1017546463e819fc05846af74582cb9f5739ff08
Reviewed-by: default avatarBogDan Vatra <bogdan@kde.org>
parent 3cd9bbb5
......@@ -30,23 +30,33 @@
****************************************************************************/
#include "androidextralibrarylistmodel.h"
#include "qmakeandroidrunconfiguration.h"
#include <projectexplorer/target.h>
#include <qmakeprojectmanager/qmakeproject.h>
#include <qmakeprojectmanager/qmakenodes.h>
#include <proparser/prowriter.h>
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<QmakeProject *>(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<QmakeAndroidRunConfiguration *>(rc);
if (!qarc)
return 0;
auto project = static_cast<QmakeProject *>(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 (node->parseInProgress())
return false;
if (root->projectType() != QmakeProjectManager::ApplicationTemplate)
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);
}
......@@ -35,11 +35,13 @@
#include <QAbstractItemModel>
#include <QStringList>
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;
};
......
......@@ -84,7 +84,7 @@ QmakeAndroidBuildApkWidget::QmakeAndroidBuildApkWidget(QmakeAndroidBuildApkStep
oldFilesWarningIcon->setVisible(oldFiles);
oldFilesWarningLabel->setVisible(oldFiles);
m_extraLibraryListModel = new AndroidExtraLibraryListModel(static_cast<QmakeProject *>(m_step->project()), this);
m_extraLibraryListModel = new AndroidExtraLibraryListModel(m_step->target(), this);
m_ui->androidExtraLibsListView->setModel(m_extraLibraryListModel);
connect(m_ui->createAndroidTemplatesButton, SIGNAL(clicked()),
......
......@@ -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<QmakeProFileNode *>(this);
foreach (ProjectNode *pn, subProjectNodes())
if (QmakeProFileNode *qmakeProFileNode = dynamic_cast<QmakeProFileNode *>(pn))
if (const QmakeProFileNode *result = qmakeProFileNode->findProFileFor(fileName))
if (QmakeProFileNode *result = qmakeProFileNode->findProFileFor(fileName))
return result;
return 0;
}
......
......@@ -357,7 +357,7 @@ public:
static QString uiHeaderFile(const QString &uiDir, const Utils::FileName &formFile);
QHash<QString, QString> uiFiles() const;
const QmakeProFileNode *findProFileFor(const Utils::FileName &string) const;
QmakeProFileNode *findProFileFor(const Utils::FileName &string) const;
TargetInformation targetInformation() const;
InstallsList installsList() const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment