2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-08-01 16:44:59 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-08-01 16:44:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-08-01 16:44:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2011-08-01 16:44:59 +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.
|
2011-08-01 16:44:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2014-03-27 18:00:55 +01:00
|
|
|
#include "deploymentdataview.h"
|
2011-08-01 16:44:59 +02:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
#include "buildsystem.h"
|
2020-01-24 14:38:13 +01:00
|
|
|
#include "deployconfiguration.h"
|
2019-08-20 16:53:28 +02:00
|
|
|
#include "deploymentdata.h"
|
2014-03-27 18:00:55 +01:00
|
|
|
#include "target.h"
|
2011-08-01 16:44:59 +02:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2019-08-20 16:53:28 +02:00
|
|
|
#include <utils/treemodel.h>
|
|
|
|
|
|
|
|
|
|
#include <QAbstractTableModel>
|
2020-01-24 14:38:13 +01:00
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QHBoxLayout>
|
2019-08-20 16:53:28 +02:00
|
|
|
#include <QHeaderView>
|
2020-01-24 14:38:13 +01:00
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPushButton>
|
2019-08-20 16:53:28 +02:00
|
|
|
#include <QTreeView>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
2014-03-27 18:00:55 +01:00
|
|
|
namespace ProjectExplorer {
|
2011-08-01 16:44:59 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2019-08-20 16:53:28 +02:00
|
|
|
class DeploymentDataItem : public TreeItem
|
2011-08-01 16:44:59 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2019-08-20 16:53:28 +02:00
|
|
|
DeploymentDataItem() = default;
|
2020-01-24 14:38:13 +01:00
|
|
|
DeploymentDataItem(const DeployableFile &file, bool isEditable)
|
|
|
|
|
: file(file), isEditable(isEditable) {}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags flags(int column) const override
|
|
|
|
|
{
|
|
|
|
|
Qt::ItemFlags f = TreeItem::flags(column);
|
|
|
|
|
if (isEditable)
|
|
|
|
|
f |= Qt::ItemIsEditable;
|
|
|
|
|
return f;
|
|
|
|
|
}
|
2011-08-01 16:44:59 +02:00
|
|
|
|
2020-01-24 14:38:13 +01:00
|
|
|
QVariant data(int column, int role) const override
|
2019-08-20 16:53:28 +02:00
|
|
|
{
|
2020-01-24 14:38:13 +01:00
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
2019-08-20 16:53:28 +02:00
|
|
|
return column == 0 ? file.localFilePath().toUserOutput() : file.remoteDirectory();
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
2020-01-24 14:38:13 +01:00
|
|
|
|
|
|
|
|
bool setData(int column, const QVariant &data, int role) override
|
|
|
|
|
{
|
|
|
|
|
if (role != Qt::EditRole)
|
|
|
|
|
return false;
|
|
|
|
|
if (column == 0)
|
|
|
|
|
file = DeployableFile(data.toString(), file.remoteDirectory());
|
|
|
|
|
else if (column == 1)
|
|
|
|
|
file = DeployableFile(file.localFilePath().toString(), data.toString());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-20 16:53:28 +02:00
|
|
|
DeployableFile file;
|
2020-01-24 14:38:13 +01:00
|
|
|
bool isEditable = false;
|
2019-08-20 16:53:28 +02:00
|
|
|
};
|
2011-08-01 16:44:59 +02:00
|
|
|
|
|
|
|
|
|
2020-01-24 14:38:13 +01:00
|
|
|
DeploymentDataView::DeploymentDataView(DeployConfiguration *dc)
|
2011-08-01 16:44:59 +02:00
|
|
|
{
|
2019-08-20 16:53:28 +02:00
|
|
|
auto model = new TreeModel<DeploymentDataItem>(this);
|
|
|
|
|
model->setHeader({tr("Local File Path"), tr("Remote Directory")});
|
2012-11-08 15:21:34 +01:00
|
|
|
|
2019-08-20 16:53:28 +02:00
|
|
|
auto view = new QTreeView(this);
|
|
|
|
|
view->setMinimumSize(QSize(100, 100));
|
|
|
|
|
view->setTextElideMode(Qt::ElideMiddle);
|
|
|
|
|
view->setWordWrap(false);
|
|
|
|
|
view->setUniformRowHeights(true);
|
|
|
|
|
view->setModel(model);
|
2012-11-08 15:21:34 +01:00
|
|
|
|
2020-01-24 14:38:13 +01:00
|
|
|
const auto buttonsLayout = new QVBoxLayout;
|
|
|
|
|
const auto addButton = new QPushButton(tr("Add"));
|
|
|
|
|
const auto removeButton = new QPushButton(tr("Remove"));
|
|
|
|
|
buttonsLayout->addWidget(addButton);
|
|
|
|
|
buttonsLayout->addWidget(removeButton);
|
|
|
|
|
buttonsLayout->addStretch(1);
|
|
|
|
|
|
|
|
|
|
const auto viewLayout = new QHBoxLayout;
|
|
|
|
|
viewLayout->addWidget(view);
|
|
|
|
|
viewLayout->addLayout(buttonsLayout);
|
|
|
|
|
|
2019-08-20 16:53:28 +02:00
|
|
|
auto label = new QLabel(tr("Files to deploy:"), this);
|
2020-01-24 14:38:13 +01:00
|
|
|
const auto sourceCheckBox = new QCheckBox(tr("Override deployment data from build system"));
|
|
|
|
|
sourceCheckBox->setChecked(dc->usesCustomDeploymentData());
|
2011-08-01 16:44:59 +02:00
|
|
|
|
2019-08-20 16:53:28 +02:00
|
|
|
auto layout = new QVBoxLayout(this);
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
layout->addWidget(label);
|
2020-01-24 14:38:13 +01:00
|
|
|
layout->addWidget(sourceCheckBox);
|
|
|
|
|
layout->addLayout(viewLayout);
|
2011-08-01 16:44:59 +02:00
|
|
|
|
2020-01-24 14:38:13 +01:00
|
|
|
const auto updateModel = [dc, model, view] {
|
2019-08-20 16:53:28 +02:00
|
|
|
model->clear();
|
2020-01-24 14:38:13 +01:00
|
|
|
for (const DeployableFile &file : dc->target()->deploymentData().allFiles()) {
|
|
|
|
|
model->rootItem()->appendChild(
|
|
|
|
|
new DeploymentDataItem(file, dc->usesCustomDeploymentData()));
|
|
|
|
|
}
|
2019-08-20 16:53:28 +02:00
|
|
|
|
|
|
|
|
QHeaderView *header = view->header();
|
|
|
|
|
header->setSectionResizeMode(0, QHeaderView::Interactive);
|
|
|
|
|
header->setSectionResizeMode(1, QHeaderView::Interactive);
|
|
|
|
|
view->resizeColumnToContents(0);
|
|
|
|
|
view->resizeColumnToContents(1);
|
|
|
|
|
if (header->sectionSize(0) + header->sectionSize(1) < header->width())
|
|
|
|
|
header->setSectionResizeMode(1, QHeaderView::Stretch);
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-24 14:38:13 +01:00
|
|
|
const auto deploymentDataFromModel = [model] {
|
|
|
|
|
DeploymentData deployData;
|
|
|
|
|
for (int i = 0; i < model->rowCount(); ++i) {
|
|
|
|
|
const auto item = static_cast<DeploymentDataItem *>(
|
|
|
|
|
model->itemForIndex(model->index(i, 0)));
|
|
|
|
|
if (!item->file.localFilePath().isEmpty() && !item->file.remoteDirectory().isEmpty())
|
|
|
|
|
deployData.addFile(item->file);
|
|
|
|
|
}
|
|
|
|
|
return deployData;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const auto updateButtons = [dc, view, addButton, removeButton] {
|
|
|
|
|
addButton->setEnabled(dc->usesCustomDeploymentData());
|
|
|
|
|
removeButton->setEnabled(dc->usesCustomDeploymentData()
|
|
|
|
|
&& view->selectionModel()->hasSelection());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
connect(dc->target(), &Target::deploymentDataChanged, this, [dc, updateModel] {
|
|
|
|
|
if (!dc->usesCustomDeploymentData())
|
|
|
|
|
updateModel();
|
|
|
|
|
});
|
|
|
|
|
connect(sourceCheckBox, &QCheckBox::toggled, this, [dc, updateModel, updateButtons](bool checked) {
|
|
|
|
|
dc->setUseCustomDeploymentData(checked);
|
|
|
|
|
updateModel();
|
|
|
|
|
updateButtons();
|
|
|
|
|
});
|
|
|
|
|
connect(addButton, &QPushButton::clicked, this, [model, view] {
|
|
|
|
|
const auto newItem = new DeploymentDataItem(DeployableFile(), true);
|
|
|
|
|
model->rootItem()->appendChild(newItem);
|
|
|
|
|
view->edit(model->indexForItem(newItem));
|
|
|
|
|
});
|
|
|
|
|
connect(removeButton, &QPushButton::clicked, this, [dc, model, view, deploymentDataFromModel] {
|
|
|
|
|
const QModelIndexList selectedIndexes = view->selectionModel()->selectedIndexes();
|
|
|
|
|
if (!selectedIndexes.isEmpty()) {
|
|
|
|
|
model->destroyItem(model->itemForIndex(selectedIndexes.first()));
|
|
|
|
|
dc->setCustomDeploymentData(deploymentDataFromModel());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
connect(model, &QAbstractItemModel::dataChanged, this, [dc, deploymentDataFromModel] {
|
|
|
|
|
if (dc->usesCustomDeploymentData())
|
|
|
|
|
dc->setCustomDeploymentData(deploymentDataFromModel());
|
|
|
|
|
});
|
|
|
|
|
connect(view->selectionModel(), &QItemSelectionModel::selectionChanged, this, [updateButtons] {
|
|
|
|
|
updateButtons();
|
|
|
|
|
});
|
|
|
|
|
updateModel();
|
|
|
|
|
updateButtons();
|
2011-08-01 16:44:59 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-20 16:53:28 +02:00
|
|
|
} // Internal
|
|
|
|
|
} // ProjectExplorer
|