forked from qt-creator/qt-creator
Android: Move AndroidExtraLibraryListModel to base
Instead of having the full class build-system dependent, by relying on four more AndroidQtSupport functions for now. Change-Id: I26842f3ec70b875ba4481ae36d8c85f86366cb88 Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
@@ -53,7 +53,8 @@ HEADERS += \
|
||||
androidsdkpackage.h \
|
||||
androidsdkmodel.h \
|
||||
androidsdkmanagerwidget.h \
|
||||
androidpackageinstallationstep.h
|
||||
androidpackageinstallationstep.h \
|
||||
androidextralibrarylistmodel.h
|
||||
|
||||
SOURCES += \
|
||||
androidconfigurations.cpp \
|
||||
@@ -100,7 +101,8 @@ SOURCES += \
|
||||
androidsdkpackage.cpp \
|
||||
androidsdkmodel.cpp \
|
||||
androidsdkmanagerwidget.cpp \
|
||||
androidpackageinstallationstep.cpp
|
||||
androidpackageinstallationstep.cpp \
|
||||
androidextralibrarylistmodel.cpp
|
||||
|
||||
FORMS += \
|
||||
androidsettingswidget.ui \
|
||||
|
@@ -55,6 +55,8 @@ Project {
|
||||
"androiddevicefactory.h",
|
||||
"androiderrormessage.h",
|
||||
"androiderrormessage.cpp",
|
||||
"androidextralibrarylistmodel.cpp",
|
||||
"androidextralibrarylistmodel.h",
|
||||
"androidgdbserverkitinformation.cpp",
|
||||
"androidgdbserverkitinformation.h",
|
||||
"androidglobal.h",
|
||||
|
@@ -26,18 +26,14 @@
|
||||
|
||||
#include "androidextralibrarylistmodel.h"
|
||||
|
||||
#include <android/androidqtsupport.h>
|
||||
#include <android/androidmanager.h>
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/runconfiguration.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;
|
||||
namespace Android {
|
||||
|
||||
AndroidExtraLibraryListModel::AndroidExtraLibraryListModel(ProjectExplorer::Target *target,
|
||||
QObject *parent)
|
||||
@@ -86,20 +82,18 @@ QVariant AndroidExtraLibraryListModel::data(const QModelIndex &index, int role)
|
||||
|
||||
void AndroidExtraLibraryListModel::updateModel()
|
||||
{
|
||||
QmakeProjectManager::QmakeProFile *pro = activeProFile();
|
||||
if (!pro || pro->parseInProgress()) {
|
||||
AndroidQtSupport *qtSupport = Android::AndroidManager::androidQtSupport(m_target);
|
||||
QTC_ASSERT(qtSupport, return);
|
||||
|
||||
if (qtSupport->parseInProgress(m_target)) {
|
||||
emit enabledChanged(false);
|
||||
return;
|
||||
}
|
||||
|
||||
m_scope = QLatin1String("contains(ANDROID_TARGET_ARCH,")
|
||||
+ pro->singleVariableValue(QmakeProjectManager::Variable::AndroidArch)
|
||||
+ QLatin1Char(')');
|
||||
|
||||
bool enabled;
|
||||
beginResetModel();
|
||||
if (pro->validParse() && pro->projectType() == QmakeProjectManager::ProjectType::ApplicationTemplate) {
|
||||
m_entries = pro->variableValue(QmakeProjectManager::Variable::AndroidExtraLibs);
|
||||
if (qtSupport->validParse(m_target)) {
|
||||
m_entries = qtSupport->targetData(Constants::AndroidExtraLibs, m_target);
|
||||
enabled = true;
|
||||
} else {
|
||||
// parsing error or not a application template
|
||||
@@ -111,37 +105,19 @@ void AndroidExtraLibraryListModel::updateModel()
|
||||
emit enabledChanged(enabled);
|
||||
}
|
||||
|
||||
QmakeProjectManager::QmakeProFile *AndroidExtraLibraryListModel::activeProFile() const
|
||||
{
|
||||
ProjectExplorer::RunConfiguration *rc = m_target->activeRunConfiguration();
|
||||
if (!rc)
|
||||
return nullptr;
|
||||
auto project = static_cast<QmakeProject *>(m_target->project());
|
||||
return project->rootProFile()->findProFile(Utils::FileName::fromString(rc->buildKey()));
|
||||
}
|
||||
|
||||
bool AndroidExtraLibraryListModel::isEnabled() const
|
||||
{
|
||||
QmakeProjectManager::QmakeProFile *pro = activeProFile();
|
||||
return pro && !pro->parseInProgress() && pro->projectType() == QmakeProjectManager::ProjectType::ApplicationTemplate;
|
||||
}
|
||||
|
||||
void AndroidExtraLibraryListModel::addEntries(const QStringList &list)
|
||||
{
|
||||
QmakeProjectManager::QmakeProFile *pro = activeProFile();
|
||||
if (!pro || pro->projectType() != QmakeProjectManager::ProjectType::ApplicationTemplate)
|
||||
return;
|
||||
AndroidQtSupport *qtSupport = Android::AndroidManager::androidQtSupport(m_target);
|
||||
QTC_ASSERT(qtSupport, return);
|
||||
Utils::FileName projectFilePath = qtSupport->projectFilePath(m_target);
|
||||
|
||||
beginInsertRows(QModelIndex(), m_entries.size(), m_entries.size() + list.size());
|
||||
|
||||
foreach (const QString &path, list)
|
||||
m_entries += QLatin1String("$$PWD/")
|
||||
+ pro->filePath().toFileInfo().absoluteDir().relativeFilePath(path);
|
||||
|
||||
pro->setProVariable("ANDROID_EXTRA_LIBS", m_entries, m_scope,
|
||||
QmakeProjectManager::Internal::ProWriter::ReplaceValues
|
||||
| QmakeProjectManager::Internal::ProWriter::MultiLine);
|
||||
const QDir dir = qtSupport->projectFilePath(m_target).toFileInfo().absoluteDir();
|
||||
for (const QString &path : list)
|
||||
m_entries += "$$PWD/" + dir.relativeFilePath(path);
|
||||
|
||||
qtSupport->setTargetData(Constants::AndroidExtraLibs, m_entries, m_target);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
@@ -152,10 +128,7 @@ bool greaterModelIndexByRow(const QModelIndex &a, const QModelIndex &b)
|
||||
|
||||
void AndroidExtraLibraryListModel::removeEntries(QModelIndexList list)
|
||||
{
|
||||
QmakeProjectManager::QmakeProFile *pro = activeProFile();
|
||||
if (!pro)
|
||||
return;
|
||||
if (list.isEmpty() || !pro || pro->projectType() != QmakeProjectManager::ProjectType::ApplicationTemplate)
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
std::sort(list.begin(), list.end(), greaterModelIndexByRow);
|
||||
@@ -174,5 +147,9 @@ void AndroidExtraLibraryListModel::removeEntries(QModelIndexList list)
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
pro->setProVariable(QLatin1String("ANDROID_EXTRA_LIBS"), m_entries, m_scope);
|
||||
AndroidQtSupport *qtSupport = AndroidManager::androidQtSupport(m_target);
|
||||
QTC_ASSERT(qtSupport, return);
|
||||
qtSupport->setTargetData(Constants::AndroidExtraLibs, m_entries, m_target);
|
||||
}
|
||||
|
||||
} // Android
|
@@ -26,6 +26,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "android_global.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QStringList>
|
||||
|
||||
@@ -34,12 +36,9 @@ class RunConfiguration;
|
||||
class Target;
|
||||
}
|
||||
|
||||
namespace QmakeProjectManager { class QmakeProFile; }
|
||||
namespace Android {
|
||||
|
||||
namespace QmakeAndroidSupport {
|
||||
|
||||
namespace Internal {
|
||||
class AndroidExtraLibraryListModel : public QAbstractItemModel
|
||||
class ANDROID_EXPORT AndroidExtraLibraryListModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -55,19 +54,14 @@ public:
|
||||
void removeEntries(QModelIndexList list);
|
||||
void addEntries(const QStringList &list);
|
||||
|
||||
bool isEnabled() const;
|
||||
|
||||
signals:
|
||||
void enabledChanged(bool);
|
||||
|
||||
private:
|
||||
void updateModel();
|
||||
QmakeProjectManager::QmakeProFile *activeProFile() const;
|
||||
|
||||
ProjectExplorer::Target *m_target;
|
||||
QStringList m_entries;
|
||||
QString m_scope;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmakeAndroidSupport
|
||||
} // namespace Android
|
@@ -47,6 +47,7 @@ namespace Constants {
|
||||
const char AndroidPackageSourceDir[] = "AndroidPackageSourceDir";
|
||||
const char AndroidDeploySettingsFile[] = "AndroidDeploySettingsFile";
|
||||
const char AndroidExtraLibs[] = "AndroidExtraLibs";
|
||||
const char AndroidArch[] = "AndroidArch";
|
||||
|
||||
} // namespace Constants
|
||||
|
||||
@@ -73,6 +74,13 @@ public:
|
||||
|
||||
virtual QString targetDataItem(Core::Id role, const ProjectExplorer::Target *target) const = 0;
|
||||
virtual QStringList targetData(Core::Id role, const ProjectExplorer::Target *target) const = 0;
|
||||
virtual bool setTargetData(Core::Id role, const QStringList &values,
|
||||
const ProjectExplorer::Target *target) const = 0;
|
||||
|
||||
virtual bool parseInProgress(const ProjectExplorer::Target *target) const = 0;
|
||||
virtual bool validParse(const ProjectExplorer::Target *target) const = 0;
|
||||
virtual bool extraLibraryEnabled(const ProjectExplorer::Target *target) const = 0;
|
||||
virtual Utils::FileName projectFilePath(const ProjectExplorer::Target *target) const = 0;
|
||||
};
|
||||
|
||||
} // namespace Android
|
||||
|
@@ -41,6 +41,8 @@
|
||||
#include <QToolButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
using namespace Android;
|
||||
|
||||
namespace QmakeAndroidSupport {
|
||||
namespace Internal {
|
||||
|
||||
@@ -108,7 +110,9 @@ QmakeAndroidBuildApkWidget::QmakeAndroidBuildApkWidget(Android::AndroidBuildApkS
|
||||
connect(m_extraLibraryListModel, &AndroidExtraLibraryListModel::enabledChanged,
|
||||
additionalLibrariesGroupBox, &QWidget::setEnabled);
|
||||
|
||||
additionalLibrariesGroupBox->setEnabled(m_extraLibraryListModel->isEnabled());
|
||||
AndroidQtSupport *qtSupport = AndroidManager::androidQtSupport(m_step->target());
|
||||
QTC_ASSERT(qtSupport, return);
|
||||
additionalLibrariesGroupBox->setEnabled(qtSupport->extraLibraryEnabled(m_step->target()));
|
||||
}
|
||||
|
||||
void QmakeAndroidBuildApkWidget::createAndroidTemplatesButton()
|
||||
|
@@ -25,10 +25,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "androidextralibrarylistmodel.h"
|
||||
|
||||
#include <projectexplorer/buildstep.h>
|
||||
|
||||
#include <android/androidbuildapkstep.h>
|
||||
#include <android/androidextralibrarylistmodel.h>
|
||||
#include <android/androidqtsupport.h>
|
||||
|
||||
#include <QListView>
|
||||
#include <QToolButton>
|
||||
@@ -57,7 +58,7 @@ private:
|
||||
QToolButton *m_removeAndroidExtraLibButton = nullptr;
|
||||
|
||||
Android::AndroidBuildApkStep *m_step = nullptr;
|
||||
AndroidExtraLibraryListModel *m_extraLibraryListModel = nullptr;
|
||||
Android::AndroidExtraLibraryListModel *m_extraLibraryListModel = nullptr;
|
||||
bool m_ignoreChange = false;
|
||||
};
|
||||
|
||||
|
@@ -74,12 +74,67 @@ QStringList QmakeAndroidSupport::targetData(Core::Id role, const Target *target)
|
||||
var = Variable::AndroidDeploySettingsFile;
|
||||
else if (role == Android::Constants::AndroidExtraLibs)
|
||||
var = Variable::AndroidExtraLibs;
|
||||
else if (role == Android::Constants::AndroidArch)
|
||||
var = Variable::AndroidArch;
|
||||
else
|
||||
QTC_CHECK(false);
|
||||
|
||||
return profileNode->variableValue(var);
|
||||
}
|
||||
|
||||
static QmakeProFile *applicationProFile(const Target *target)
|
||||
{
|
||||
ProjectExplorer::RunConfiguration *rc = target->activeRunConfiguration();
|
||||
if (!rc)
|
||||
return nullptr;
|
||||
auto project = static_cast<QmakeProject *>(target->project());
|
||||
return project->rootProFile()->findProFile(FileName::fromString(rc->buildKey()));
|
||||
}
|
||||
|
||||
bool QmakeAndroidSupport::parseInProgress(const Target *target) const
|
||||
{
|
||||
QmakeProjectManager::QmakeProFile *pro = applicationProFile(target);
|
||||
return !pro || pro->parseInProgress();
|
||||
}
|
||||
|
||||
bool QmakeAndroidSupport::validParse(const Target *target) const
|
||||
{
|
||||
QmakeProjectManager::QmakeProFile *pro = applicationProFile(target);
|
||||
return pro->validParse() && pro->projectType() == ProjectType::ApplicationTemplate;
|
||||
}
|
||||
|
||||
bool QmakeAndroidSupport::extraLibraryEnabled(const Target *target) const
|
||||
{
|
||||
QmakeProFile *pro = applicationProFile(target);
|
||||
return pro && !pro->parseInProgress();
|
||||
}
|
||||
|
||||
FileName QmakeAndroidSupport::projectFilePath(const Target *target) const
|
||||
{
|
||||
QmakeProFile *pro = applicationProFile(target);
|
||||
return pro ? pro->filePath() : FileName();
|
||||
}
|
||||
|
||||
bool QmakeAndroidSupport::setTargetData(Core::Id role, const QStringList &values, const Target *target) const
|
||||
{
|
||||
QmakeProFile *pro = applicationProFile(target);
|
||||
if (!pro)
|
||||
return false;
|
||||
|
||||
QString var;
|
||||
if (role == Android::Constants::AndroidExtraLibs)
|
||||
var = "ANDROID_EXTRA_LIBS";
|
||||
|
||||
if (var.isEmpty())
|
||||
return false;
|
||||
|
||||
const QString arch = pro->singleVariableValue(Variable::AndroidArch);
|
||||
const QString scope = "contains(ANDROID_TARGET_ARCH," + arch + ')';
|
||||
return pro->setProVariable(var, values, scope,
|
||||
QmakeProjectManager::Internal::ProWriter::ReplaceValues
|
||||
| QmakeProjectManager::Internal::ProWriter::MultiLine);
|
||||
}
|
||||
|
||||
QString QmakeAndroidSupport::targetDataItem(Core::Id role, const Target *target) const
|
||||
{
|
||||
const QStringList data = targetData(role, target);
|
||||
|
@@ -42,6 +42,13 @@ public:
|
||||
|
||||
QString targetDataItem(Core::Id role, const ProjectExplorer::Target *target) const override;
|
||||
QStringList targetData(Core::Id role, const ProjectExplorer::Target *target) const override;
|
||||
bool setTargetData(Core::Id role, const QStringList &values,
|
||||
const ProjectExplorer::Target *target) const override;
|
||||
|
||||
bool parseInProgress(const ProjectExplorer::Target *target) const override;
|
||||
bool validParse(const ProjectExplorer::Target *target) const override;
|
||||
bool extraLibraryEnabled(const ProjectExplorer::Target *target) const override;
|
||||
Utils::FileName projectFilePath(const ProjectExplorer::Target *target) const override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -5,7 +5,6 @@ DEFINES += \
|
||||
QMAKEANDROID_LIBRARY
|
||||
|
||||
HEADERS += \
|
||||
androidextralibrarylistmodel.h \
|
||||
createandroidmanifestwizard.h \
|
||||
qmakeandroidsupport.h \
|
||||
qmakeandroidbuildapkstep.h \
|
||||
@@ -14,7 +13,6 @@ HEADERS += \
|
||||
qmakeandroidsupportplugin.h
|
||||
|
||||
SOURCES += \
|
||||
androidextralibrarylistmodel.cpp \
|
||||
createandroidmanifestwizard.cpp \
|
||||
qmakeandroidsupport.cpp \
|
||||
qmakeandroidbuildapkstep.cpp \
|
||||
|
@@ -16,8 +16,6 @@ QtcPlugin {
|
||||
Depends { name: "Qt.widgets" }
|
||||
|
||||
files: [
|
||||
"androidextralibrarylistmodel.cpp",
|
||||
"androidextralibrarylistmodel.h",
|
||||
"createandroidmanifestwizard.cpp",
|
||||
"createandroidmanifestwizard.h",
|
||||
"qmakeandroidbuildapkstep.cpp",
|
||||
|
Reference in New Issue
Block a user