summaryrefslogtreecommitdiff
path: root/src/plugins/android/androidextralibrarylistmodel.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>2013-09-30 15:32:06 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>2013-10-01 15:41:43 +0200
commitc8393b10fd7be6fa347d2f161a3a0cc9b14c15fb (patch)
tree046b91c5986923b764f12e326751be5555005c59 /src/plugins/android/androidextralibrarylistmodel.cpp
parentbd144ab0f5c477d1a445ae0b4da0a2de4e0286bc (diff)
downloadqt-creator-c8393b10fd7be6fa347d2f161a3a0cc9b14c15fb.tar.gz
Extra library editor for Android
Add a list view to the deployment settings which allows you to add and remove libraries from the ANDROID_EXTRA_LIBS variable in the .pro file. Task-number: QTCREATORBUG-9849 Change-Id: Ic0131c46be8fdef4b226b5ceb0ee82ea4dd82c6a Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Diffstat (limited to 'src/plugins/android/androidextralibrarylistmodel.cpp')
-rw-r--r--src/plugins/android/androidextralibrarylistmodel.cpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/src/plugins/android/androidextralibrarylistmodel.cpp b/src/plugins/android/androidextralibrarylistmodel.cpp
new file mode 100644
index 0000000000..3aed0d1651
--- /dev/null
+++ b/src/plugins/android/androidextralibrarylistmodel.cpp
@@ -0,0 +1,131 @@
+/**************************************************************************
+**
+** Copyright (c) 2013 BogDan Vatra <bog_dan_ro@yahoo.com>
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "androidextralibrarylistmodel.h"
+#include <qt4projectmanager/qt4project.h>
+#include <qt4projectmanager/qt4nodes.h>
+
+using namespace Android;
+using namespace Internal;
+
+AndroidExtraLibraryListModel::AndroidExtraLibraryListModel(Qt4ProjectManager::Qt4Project *project,
+ QObject *parent)
+ : QAbstractItemModel(parent)
+ , m_project(project)
+{
+ reset();
+
+ connect(m_project, SIGNAL(proFilesEvaluated()), this, SLOT(reset()));
+}
+
+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());
+ const QString &entry = m_entries.at(index.row());
+ switch (role) {
+ case Qt::DisplayRole: return entry;
+ default: return QVariant();
+ };
+}
+
+void AndroidExtraLibraryListModel::reset()
+{
+ if (m_project->rootQt4ProjectNode()->projectType() != Qt4ProjectManager::ApplicationTemplate)
+ return;
+
+ beginResetModel();
+ Qt4ProjectManager::Qt4ProFileNode *node = m_project->rootQt4ProjectNode();
+ m_entries = node->variableValue(Qt4ProjectManager::AndroidExtraLibs);
+ endResetModel();
+}
+
+void AndroidExtraLibraryListModel::addEntries(const QStringList &list)
+{
+ if (m_project->rootQt4ProjectNode()->projectType() != Qt4ProjectManager::ApplicationTemplate)
+ return;
+
+ beginInsertRows(QModelIndex(), m_entries.size(), m_entries.size() + list.size());
+
+ foreach (QString path, list)
+ m_entries += QDir(m_project->projectDirectory()).relativeFilePath(path);
+
+ Qt4ProjectManager::Qt4ProFileNode *node = m_project->rootQt4ProjectNode();
+ node->setProVariable(QLatin1String("ANDROID_EXTRA_LIBS"), m_entries.join(QLatin1Char(' ')));
+
+ endInsertRows();
+}
+
+void AndroidExtraLibraryListModel::removeEntries(const QModelIndexList &list)
+{
+ if (list.isEmpty() || m_project->rootQt4ProjectNode()->projectType() != Qt4ProjectManager::ApplicationTemplate)
+ return;
+
+ QStringList oldList = m_entries;
+ int i = 0;
+ while (i < list.size()) {
+ int firstRow = list.at(i++).row();
+ int lastRow = firstRow;
+ while (i < list.size() && list.at(i).row() - lastRow <= 1 && list.at(i).row() > firstRow)
+ lastRow = list.at(i++).row();
+
+ int first = m_entries.indexOf(oldList.at(firstRow));
+ int count = lastRow - firstRow + 1;
+ Q_ASSERT(count > 0);
+ Q_ASSERT(oldList.at(lastRow) == m_entries.at(first + count - 1));
+
+ beginRemoveRows(QModelIndex(), first, first + count - 1);
+ while (count-- > 0)
+ m_entries.removeAt(first);
+ endRemoveRows();
+ }
+
+ Qt4ProjectManager::Qt4ProFileNode *node = m_project->rootQt4ProjectNode();
+ node->setProVariable(QLatin1String("ANDROID_EXTRA_LIBS"), m_entries.join(QLatin1Char(' ')));
+}