Commit af8b262e authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Maemo: Don't create a deployment widget per sub project.

This makes use of a Maemo target perform acceptably for big projects.

Task-number: QTCREATORBUG-2703
Reviewed-by: kh1
parent b576f502
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "maemodeployablelistwidget.h"
#include "ui_maemodeployablelistwidget.h"
#include "maemodeployablelistmodel.h"
#include <utils/qtcassert.h>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
namespace Qt4ProjectManager {
namespace Internal {
MaemoDeployableListWidget::MaemoDeployableListWidget(QWidget *parent,
MaemoDeployableListModel *model)
: QWidget(parent), m_ui(new Ui::MaemoDeployableListWidget), m_model(model)
{
m_ui->setupUi(this);
m_ui->addFileButton->hide();
m_ui->removeFileButton->hide();
m_ui->deployablesView->setWordWrap(false);
m_ui->deployablesView->setModel(m_model);
connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
m_ui->deployablesView, SLOT(resizeColumnsToContents()));
connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)),
m_ui->deployablesView, SLOT(resizeColumnsToContents()));
connect(m_ui->deployablesView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this,
SLOT(enableOrDisableRemoveButton()));
m_ui->deployablesView->resizeColumnsToContents();
m_ui->deployablesView->resizeRowsToContents();
m_ui->deployablesView->horizontalHeader()->setStretchLastSection(true);
enableOrDisableRemoveButton();
}
MaemoDeployableListWidget::~MaemoDeployableListWidget()
{
delete m_ui;
}
void MaemoDeployableListWidget::addFile()
{
const QString title = tr("Choose a local file");
const QString localFile = QFileDialog::getOpenFileName(this, title, m_model->projectDir()); // TODO: Support directories.
if (localFile.isEmpty())
return;
const MaemoDeployable
deployable(QDir::toNativeSeparators(QFileInfo(localFile).absoluteFilePath()),
"/");
QString errorString;
if (!m_model->addDeployable(deployable, &errorString)) {
QMessageBox::information(this, tr("Error adding file"), errorString);
} else {
const QModelIndex newIndex
= m_model->index(m_model->rowCount() - 1, 1);
m_ui->deployablesView->selectionModel()->clear();
m_ui->deployablesView->scrollTo(newIndex);
m_ui->deployablesView->edit(newIndex);
}
}
void MaemoDeployableListWidget::removeFile()
{
const QModelIndexList selectedRows
= m_ui->deployablesView->selectionModel()->selectedRows();
if (selectedRows.isEmpty())
return;
const int row = selectedRows.first().row();
if (row != 0) {
QString errorString;
if (!m_model->removeDeployableAt(row, &errorString)) {
QMessageBox::information(this, tr("Error removing file"),
errorString);
}
}
}
void MaemoDeployableListWidget::enableOrDisableRemoveButton()
{
const QModelIndexList selectedRows
= m_ui->deployablesView->selectionModel()->selectedRows();
m_ui->removeFileButton->setEnabled(!selectedRows.isEmpty()
&& selectedRows.first().row() != 0);
}
} // namespace Internal
} // namespace Qt4ProjectManager
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef MAEMODEPLOYABLELISTWIDGET_H
#define MAEMODEPLOYABLELISTWIDGET_H
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
namespace Ui {
class MaemoDeployableListWidget;
}
QT_END_NAMESPACE
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeployableListModel;
class MaemoDeployableListWidget : public QWidget
{
Q_OBJECT
public:
MaemoDeployableListWidget(QWidget *parent, MaemoDeployableListModel *model);
~MaemoDeployableListWidget();
MaemoDeployableListModel *model() const { return m_model; }
private slots:
void addFile();
void removeFile();
void enableOrDisableRemoveButton();
private:
Ui::MaemoDeployableListWidget *m_ui;
MaemoDeployableListModel * const m_model;
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // MAEMODEPLOYABLELISTWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MaemoDeployableListWidget</class>
<widget class="QWidget" name="MaemoDeployableListWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>491</width>
<height>289</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTableView" name="deployablesView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>200</height>
</size>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QToolButton" name="addFileButton">
<property name="toolTip">
<string>Add File to Package</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../coreplugin/core.qrc">
<normaloff>:/core/images/plus.png</normaloff>:/core/images/plus.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="removeFileButton">
<property name="toolTip">
<string>Remove File from Package</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../coreplugin/core.qrc">
<normaloff>:/core/images/minus.png</normaloff>:/core/images/minus.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../../coreplugin/core.qrc"/>
</resources>
<connections>
<connection>
<sender>addFileButton</sender>
<signal>clicked()</signal>
<receiver>MaemoDeployableListWidget</receiver>
<slot>addFile()</slot>
<hints>
<hint type="sourcelabel">
<x>475</x>
<y>32</y>
</hint>
<hint type="destinationlabel">
<x>488</x>
<y>242</y>
</hint>
</hints>
</connection>
<connection>
<sender>removeFileButton</sender>
<signal>clicked()</signal>
<receiver>MaemoDeployableListWidget</receiver>
<slot>removeFile()</slot>
<hints>
<hint type="sourcelabel">
<x>456</x>
<y>66</y>
</hint>
<hint type="destinationlabel">
<x>490</x>
<y>182</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>addFile()</slot>
<slot>removeFile()</slot>
</slots>
</ui>
......@@ -79,18 +79,19 @@ void MaemoDeployables::createModels()
|| qt4BuildConfiguration()->qt4Target()->project()->activeTarget()->id()
!= QLatin1String(Qt4ProjectManager::Constants::MAEMO_DEVICE_TARGET_ID))
return;
disconnect(qt4BuildConfiguration()->qt4Target()->qt4Project(),
SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)),
m_updateTimer, SLOT(start()));
const Qt4ProFileNode *const rootNode
= qt4BuildConfiguration()->qt4Target()->qt4Project()->rootProjectNode();
if (!rootNode) // Happens on project creation by wizard.
return;
m_updateTimer->stop();
m_proFileOption = QSharedPointer<ProFileOption>(new ProFileOption);
m_proFileOption->properties
= qt4BuildConfiguration()->qtVersion()->versionInfo();
m_proFileOption->target_mode = ProFileOption::TARG_UNIX_MODE;
const Qt4ProFileNode *const rootNode
= qt4BuildConfiguration()->qt4Target()->qt4Project()->rootProjectNode();
if (!rootNode) // Happens on project creation by wizard.
return;
disconnect(qt4BuildConfiguration()->qt4Target()->qt4Project(),
SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)),
m_updateTimer, SLOT(start()));
beginResetModel();
qDeleteAll(m_listModels);
m_listModels.clear();
createModels(rootNode);
......@@ -118,7 +119,7 @@ void MaemoDeployables::createModels()
}
}
emit modelsCreated();
endResetModel();
connect(qt4BuildConfiguration()->qt4Target()->qt4Project(),
SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)),
m_updateTimer, SLOT(start()));
......@@ -209,5 +210,26 @@ const Qt4BuildConfiguration *MaemoDeployables::qt4BuildConfiguration() const
return bc;
}
int MaemoDeployables::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : modelCount();
}
QVariant MaemoDeployables::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= modelCount()
|| index.column() != 0)
return QVariant();
const MaemoDeployableListModel *const model = m_listModels.at(index.row());
if (role == Qt::ForegroundRole && !model->hasTargetPath()) {
QBrush brush;
brush.setColor(Qt::red);
return brush;
}
if (role == Qt::DisplayRole)
return QFileInfo(model->proFilePath()).fileName();
return QVariant();
}
} // namespace Qt4ProjectManager
} // namespace Internal
......@@ -45,9 +45,9 @@
#include "maemodeployable.h"
#include "maemodeployablelistmodel.h"
#include <QtCore/QAbstractListModel>
#include <QtCore/QHash>
#include <QtCore/QList>
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
QT_FORWARD_DECLARE_CLASS(QTimer);
......@@ -61,7 +61,7 @@ namespace Internal {
class Qt4BuildConfiguration;
class Qt4ProFileNode;
class MaemoDeployables : public QObject
class MaemoDeployables : public QAbstractListModel
{
Q_OBJECT
public:
......@@ -76,12 +76,12 @@ public:
MaemoDeployableListModel *modelAt(int i) const { return m_listModels.at(i); }
const ProjectExplorer::BuildStep *buildStep() const { return m_buildStep; }
signals:
void modelsCreated();
private:
typedef QHash<QString, MaemoDeployableListModel::ProFileUpdateSetting> UpdateSettingsMap;
virtual int rowCount(const QModelIndex &parent) const;
virtual QVariant data(const QModelIndex &index, int role) const;
Q_SLOT void createModels();
Q_SLOT void init();
void createModels(const Qt4ProFileNode *proFileNode);
......
......@@ -3,13 +3,13 @@
#include "maemodeploystep.h"
#include "maemodeployablelistmodel.h"
#include "maemodeployablelistwidget.h"
#include "maemodeployables.h"
#include "maemodeviceconfiglistmodel.h"
#include "maemorunconfiguration.h"
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/target.h>
#include <utils/qtcassert.h>
namespace Qt4ProjectManager {
namespace Internal {
......@@ -20,10 +20,19 @@ MaemoDeployStepWidget::MaemoDeployStepWidget(MaemoDeployStep *step) :
m_step(step)
{
ui->setupUi(this);
connect(m_step->deployables(), SIGNAL(modelsCreated()), this,
SLOT(handleModelsCreated()));
handleModelsCreated();
ui->tableView->setTextElideMode(Qt::ElideMiddle);
ui->modelComboBox->setModel(m_step->deployables());
connect(m_step->deployables(), SIGNAL(modelAboutToBeReset()),
SLOT(handleModelListToBeReset()));
// Queued connection because of race condition with combo box's reaction
// to modelReset().
connect(m_step->deployables(), SIGNAL(modelReset()),
SLOT(handleModelListReset()), Qt::QueuedConnection);
connect(ui->modelComboBox, SIGNAL(currentIndexChanged(int)),
SLOT(setModel(int)));
handleModelListReset();
}
MaemoDeployStepWidget::~MaemoDeployStepWidget()
......@@ -77,18 +86,6 @@ QString MaemoDeployStepWidget::displayName() const
return QString();
}
void MaemoDeployStepWidget::handleModelsCreated()
{
ui->tabWidget->clear();
for (int i = 0; i < m_step->deployables()->modelCount(); ++i) {
MaemoDeployableListModel * const model
= m_step->deployables()->modelAt(i);
ui->tabWidget->addTab(new MaemoDeployableListWidget(this, model),
model->projectName());
}
}
void MaemoDeployStepWidget::setCurrentDeviceConfig(int index)
{
m_step->deviceConfigModel()->setCurrentIndex(index);
......@@ -99,5 +96,29 @@ void MaemoDeployStepWidget::setDeployToSysroot(bool doDeploy)
m_step->setDeployToSysrootEnabled(doDeploy);
}
void MaemoDeployStepWidget::handleModelListToBeReset()
{
ui->tableView->setModel(0);
}
void MaemoDeployStepWidget::handleModelListReset()
{
QTC_ASSERT(m_step->deployables()->modelCount() == ui->modelComboBox->count(), return);
if (m_step->deployables()->modelCount() > 0) {
if (ui->modelComboBox->currentIndex() == -1)
ui->modelComboBox->setCurrentIndex(0);
else
setModel(ui->modelComboBox->currentIndex());
}
}
void MaemoDeployStepWidget::setModel(int row)
{
if (row != -1) {
ui->tableView->setModel(m_step->deployables()->modelAt(row));
ui->tableView->resizeRowsToContents();
}
}
} // namespace Internal
} // namespace Qt4ProjectManager
......@@ -23,10 +23,12 @@ public:
private:
Q_SLOT void handleDeviceUpdate();
Q_SLOT void handleModelsCreated();
Q_SLOT void handleDeviceConfigModelChanged();
Q_SLOT void setCurrentDeviceConfig(int index);
Q_SLOT void setDeployToSysroot(bool doDeloy);
Q_SLOT void setModel(int row);
Q_SLOT void handleModelListToBeReset();
Q_SLOT void handleModelListReset();
virtual void init();
virtual QString summaryText() const;
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>460</width>
<height>277</height>
<width>662</width>
<height>418</height>
</rect>
</property>
<property name="windowTitle">
......@@ -15,58 +15,118 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="deviceConfigLabel">
<property name="text">
<string>Device configuration:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="deviceConfigComboBox"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>