2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2013-09-30 15:32:06 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-09-30 15:32:06 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2013-09-30 15:32:06 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2013-09-30 15:32:06 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "androidextralibrarylistmodel.h"
|
2015-02-18 16:01:58 +01:00
|
|
|
|
2018-06-13 17:27:40 +02:00
|
|
|
#include <android/androidqtsupport.h>
|
|
|
|
|
#include <android/androidmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/project.h>
|
2018-12-04 15:49:47 +01:00
|
|
|
#include <projectexplorer/projectnodes.h>
|
2018-05-04 11:13:43 +02:00
|
|
|
#include <projectexplorer/runconfiguration.h>
|
2015-02-18 16:01:58 +01:00
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
2018-12-04 15:49:47 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2018-06-13 17:27:40 +02:00
|
|
|
namespace Android {
|
2013-09-30 15:32:06 +02:00
|
|
|
|
2015-02-18 16:01:58 +01:00
|
|
|
AndroidExtraLibraryListModel::AndroidExtraLibraryListModel(ProjectExplorer::Target *target,
|
2013-09-30 15:32:06 +02:00
|
|
|
QObject *parent)
|
2015-02-18 16:01:58 +01:00
|
|
|
: QAbstractItemModel(parent),
|
|
|
|
|
m_target(target)
|
2013-09-30 15:32:06 +02:00
|
|
|
{
|
2018-06-01 13:48:40 +02:00
|
|
|
updateModel();
|
2013-09-30 15:32:06 +02:00
|
|
|
|
2018-06-01 13:48:40 +02:00
|
|
|
connect(target->project(), &ProjectExplorer::Project::parsingStarted,
|
|
|
|
|
this, &AndroidExtraLibraryListModel::updateModel);
|
|
|
|
|
connect(target->project(), &ProjectExplorer::Project::parsingFinished,
|
|
|
|
|
this, &AndroidExtraLibraryListModel::updateModel);
|
2015-02-18 16:01:58 +01:00
|
|
|
connect(target, &ProjectExplorer::Target::activeRunConfigurationChanged,
|
2018-06-01 13:48:40 +02:00
|
|
|
this, &AndroidExtraLibraryListModel::updateModel);
|
2013-09-30 15:32:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex AndroidExtraLibraryListModel::index(int row, int column, const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
return createIndex(row, column);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex AndroidExtraLibraryListModel::parent(const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AndroidExtraLibraryListModel::rowCount(const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
return m_entries.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AndroidExtraLibraryListModel::columnCount(const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant AndroidExtraLibraryListModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(index.row() >= 0 && index.row() < m_entries.size());
|
2014-03-27 11:42:20 +01:00
|
|
|
const QString &entry = QDir::cleanPath(m_entries.at(index.row()));
|
2013-09-30 15:32:06 +02:00
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole: return entry;
|
|
|
|
|
default: return QVariant();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-01 13:48:40 +02:00
|
|
|
void AndroidExtraLibraryListModel::updateModel()
|
2013-09-30 15:32:06 +02:00
|
|
|
{
|
2018-12-04 16:04:09 +01:00
|
|
|
RunConfiguration *rc = m_target->activeRunConfiguration();
|
|
|
|
|
QTC_ASSERT(rc, return);
|
|
|
|
|
|
|
|
|
|
const ProjectNode *node = m_target->project()->findNodeForBuildKey(rc->buildKey());
|
|
|
|
|
QTC_ASSERT(node, return);
|
|
|
|
|
|
2018-06-13 17:27:40 +02:00
|
|
|
AndroidQtSupport *qtSupport = Android::AndroidManager::androidQtSupport(m_target);
|
|
|
|
|
QTC_ASSERT(qtSupport, return);
|
|
|
|
|
|
2018-12-04 16:04:09 +01:00
|
|
|
if (node->parseInProgress()) {
|
2015-02-18 16:01:58 +01:00
|
|
|
emit enabledChanged(false);
|
2013-09-30 15:32:06 +02:00
|
|
|
return;
|
2015-02-18 16:01:58 +01:00
|
|
|
}
|
2013-09-30 15:32:06 +02:00
|
|
|
|
2014-03-11 18:05:17 +01:00
|
|
|
bool enabled;
|
2013-09-30 15:32:06 +02:00
|
|
|
beginResetModel();
|
2018-12-04 16:04:09 +01:00
|
|
|
if (node->validParse()) {
|
2018-07-27 12:58:10 +02:00
|
|
|
m_entries = qtSupport->targetData(Constants::AndroidExtraLibs, m_target).toStringList();
|
2014-03-11 18:05:17 +01:00
|
|
|
enabled = true;
|
|
|
|
|
} else {
|
2018-12-04 16:04:09 +01:00
|
|
|
// parsing error
|
2014-03-11 18:05:17 +01:00
|
|
|
m_entries.clear();
|
|
|
|
|
enabled = false;
|
|
|
|
|
}
|
2013-09-30 15:32:06 +02:00
|
|
|
endResetModel();
|
2014-03-11 18:05:17 +01:00
|
|
|
|
|
|
|
|
emit enabledChanged(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-30 15:32:06 +02:00
|
|
|
void AndroidExtraLibraryListModel::addEntries(const QStringList &list)
|
|
|
|
|
{
|
2018-06-13 17:27:40 +02:00
|
|
|
AndroidQtSupport *qtSupport = Android::AndroidManager::androidQtSupport(m_target);
|
|
|
|
|
QTC_ASSERT(qtSupport, return);
|
2018-12-04 15:49:47 +01:00
|
|
|
|
|
|
|
|
RunConfiguration *rc = m_target->activeRunConfiguration();
|
|
|
|
|
QTC_ASSERT(rc, return);
|
|
|
|
|
|
|
|
|
|
const ProjectNode *node = m_target->project()->findNodeForBuildKey(rc->buildKey());
|
|
|
|
|
QTC_ASSERT(node, return);
|
2013-09-30 15:32:06 +02:00
|
|
|
|
|
|
|
|
beginInsertRows(QModelIndex(), m_entries.size(), m_entries.size() + list.size());
|
|
|
|
|
|
2018-12-04 15:49:47 +01:00
|
|
|
const QDir dir = node->filePath().toFileInfo().absoluteDir();
|
2018-06-13 17:27:40 +02:00
|
|
|
for (const QString &path : list)
|
|
|
|
|
m_entries += "$$PWD/" + dir.relativeFilePath(path);
|
2013-09-30 15:32:06 +02:00
|
|
|
|
2018-06-13 17:27:40 +02:00
|
|
|
qtSupport->setTargetData(Constants::AndroidExtraLibs, m_entries, m_target);
|
2013-09-30 15:32:06 +02:00
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-02 16:17:25 +02:00
|
|
|
bool greaterModelIndexByRow(const QModelIndex &a, const QModelIndex &b)
|
|
|
|
|
{
|
|
|
|
|
return a.row() > b.row();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidExtraLibraryListModel::removeEntries(QModelIndexList list)
|
2013-09-30 15:32:06 +02:00
|
|
|
{
|
2018-06-13 17:27:40 +02:00
|
|
|
if (list.isEmpty())
|
2013-09-30 15:32:06 +02:00
|
|
|
return;
|
|
|
|
|
|
2013-10-02 16:17:25 +02:00
|
|
|
std::sort(list.begin(), list.end(), greaterModelIndexByRow);
|
|
|
|
|
|
2013-09-30 15:32:06 +02:00
|
|
|
int i = 0;
|
|
|
|
|
while (i < list.size()) {
|
2013-10-02 16:17:25 +02:00
|
|
|
int lastRow = list.at(i++).row();
|
|
|
|
|
int firstRow = lastRow;
|
|
|
|
|
while (i < list.size() && firstRow - list.at(i).row() <= 1)
|
|
|
|
|
firstRow = list.at(i++).row();
|
2013-09-30 15:32:06 +02:00
|
|
|
|
2013-10-02 16:17:25 +02:00
|
|
|
beginRemoveRows(QModelIndex(), firstRow, lastRow);
|
2013-09-30 15:32:06 +02:00
|
|
|
int count = lastRow - firstRow + 1;
|
|
|
|
|
while (count-- > 0)
|
2013-10-02 16:17:25 +02:00
|
|
|
m_entries.removeAt(firstRow);
|
2013-09-30 15:32:06 +02:00
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-13 17:27:40 +02:00
|
|
|
AndroidQtSupport *qtSupport = AndroidManager::androidQtSupport(m_target);
|
|
|
|
|
QTC_ASSERT(qtSupport, return);
|
|
|
|
|
qtSupport->setTargetData(Constants::AndroidExtraLibs, m_entries, m_target);
|
2013-09-30 15:32:06 +02:00
|
|
|
}
|
2018-06-13 17:27:40 +02:00
|
|
|
|
|
|
|
|
} // Android
|