diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp index 9522e7df58388b62637adb5bf8c34f5f402f4a74..55390aeac5418379372e0ee2ace7e3e5ada44952 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp @@ -30,6 +30,12 @@ #include "maemopackagecontents.h" #include "maemopackagecreationstep.h" +#include "maemotoolchain.h" + +#include <qt4projectmanager/qt4buildconfiguration.h> + +#include <QtCore/QDir> +#include <QtCore/QFileInfo> namespace { const char * const MODIFIED_KEY @@ -63,7 +69,7 @@ MaemoPackageContents::Deployable MaemoPackageContents::deployableAt(int row) con bool MaemoPackageContents::addDeployable(const Deployable &deployable) { - if (m_deployables.contains(deployable)) + if (m_deployables.contains(deployable) || deployableAt(0) == deployable) return false; beginInsertRows(QModelIndex(), rowCount(), rowCount()); @@ -77,7 +83,7 @@ void MaemoPackageContents::removeDeployableAt(int row) { Q_ASSERT(row > 0 && row < rowCount()); beginRemoveRows(QModelIndex(), row, row); - m_deployables.removeAt(row); + m_deployables.removeAt(row - 1); endRemoveRows(); m_modified = true; } @@ -94,12 +100,40 @@ int MaemoPackageContents::columnCount(const QModelIndex &parent) const QVariant MaemoPackageContents::data(const QModelIndex &index, int role) const { - if (!index.isValid() || role != Qt::DisplayRole - || index.row() >= rowCount()) + if (!index.isValid() || index.row() >= rowCount()) return QVariant(); const Deployable &d = deployableAt(index.row()); - return index.column() == 0 ? d.localFilePath : d.remoteFilePath; + if (index.column() == 0 && role == Qt::DisplayRole) + return d.localFilePath; + if (role == Qt::DisplayRole || role == Qt::EditRole) + return d.remoteFilePath; + return QVariant(); +} + +Qt::ItemFlags MaemoPackageContents::flags(const QModelIndex &index) const +{ + Qt::ItemFlags parentFlags = QAbstractTableModel::flags(index); + if (index.column() == 1) + return parentFlags | Qt::ItemIsEditable; + return parentFlags; +} + +bool MaemoPackageContents::setData(const QModelIndex &index, + const QVariant &value, int role) +{ + if (!index.isValid() || index.row() >= rowCount() || index.column() != 1 + || role != Qt::EditRole) + return false; + + const QString &remoteFilePath = value.toString(); + if (index.row() == 0) + m_remoteExecutableFilePath = remoteFilePath; + else + m_deployables[index.row() - 1].remoteFilePath = remoteFilePath; + m_modified = true; + emit dataChanged(index, index); + return true; } QVariant MaemoPackageContents::headerData(int section, diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h index 6e50fd3885aac4cc1933ce884d5d6641447f6889..2f039f7176429f95607572c4a96e52a3ce453904 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h @@ -79,9 +79,9 @@ private: int role = Qt::DisplayRole) const; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - - // TODO: setData - + virtual Qt::ItemFlags flags(const QModelIndex &index) const; + virtual bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); private: const MaemoPackageCreationStep * const m_packageStep; diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp index 7dd0d2fd4f4faa757e053a1ba2dda9d7fa8bc8d9..109bd548e36ab618dba15a14f2ed54df284de11c 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp @@ -97,42 +97,23 @@ void MaemoPackageCreationWidget::addFile() const Qt4BuildConfiguration * const bc = static_cast<Qt4BuildConfiguration *>(m_step->buildConfiguration()); QTC_ASSERT(bc, return); - QString title = tr("Choose a local file"); - QString baseDir = bc->target()->project()->projectDirectory(); + const QString title = tr("Choose a local file"); + const QString baseDir = bc->target()->project()->projectDirectory(); const QString localFile = QFileDialog::getOpenFileName(this, title, baseDir); if (localFile.isEmpty()) return; - title = tr("Choose a remote file path"); - QTC_ASSERT(bc->toolChainType() == ProjectExplorer::ToolChain::GCC_MAEMO, return); - baseDir = static_cast<MaemoToolChain *>(bc->toolChain())->sysrootRoot(); - QString remoteFile; - const QString canonicalSysRoot = QFileInfo(baseDir).canonicalFilePath(); - do { - QFileDialog d(this, title, baseDir); - d.setFileMode(QFileDialog::AnyFile); - d.selectFile(QFileInfo(localFile).fileName()); - if (!d.exec()) - return; - remoteFile = d.selectedFiles().first(); - if (remoteFile.isEmpty()) - return; - const QFileInfo remoteFileInfo(remoteFile); - QString remoteDir = remoteFileInfo.dir().canonicalPath(); - if (!remoteDir.startsWith(canonicalSysRoot)) { - QMessageBox::warning(this, tr("Invalid path"), - tr("Please choose a location inside your sysroot directory.")); - remoteFile.clear(); - } else { - remoteDir.remove(canonicalSysRoot); - remoteFile = remoteDir + '/' + remoteFileInfo.fileName(); - } - } while (remoteFile.isEmpty()); - const MaemoPackageContents::Deployable - deployable(QFileInfo(localFile).absoluteFilePath(), remoteFile); - if (!m_step->packageContents()->addDeployable(deployable)) { + deployable(QFileInfo(localFile).absoluteFilePath(), "/"); + MaemoPackageContents * const contents = m_step->packageContents(); + if (!contents->addDeployable(deployable)) { QMessageBox::information(this, tr("File already in package"), tr("You have already added this file.")); + } else { + const QModelIndex newIndex + = contents->index(contents->rowCount() - 1, 1); + m_ui->packageContentsView->selectionModel()->clear(); + m_ui->packageContentsView->scrollTo(newIndex); + m_ui->packageContentsView->edit(newIndex); } } diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui index ef741e3815604805d9f4757e827fcdf99b090647..a650baa0cbc58a6b6de696c34be6f9bc018a9586 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui @@ -40,6 +40,12 @@ <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>