forked from qt-creator/qt-creator
ProjectExplorer: Compactify DeploymentDataView implementation
Change-Id: I30a4a772e9a54068566be0cab435044c073becf9 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -41,8 +41,7 @@ add_qtc_plugin(ProjectExplorer
|
||||
deployablefile.cpp deployablefile.h
|
||||
deployconfiguration.cpp deployconfiguration.h
|
||||
deploymentdata.cpp deploymentdata.h
|
||||
deploymentdatamodel.cpp deploymentdatamodel.h
|
||||
deploymentdataview.cpp deploymentdataview.h deploymentdataview.ui
|
||||
deploymentdataview.cpp deploymentdataview.h
|
||||
desktoprunconfiguration.cpp desktoprunconfiguration.h
|
||||
devicesupport/desktopdevice.cpp devicesupport/desktopdevice.h
|
||||
devicesupport/desktopdevicefactory.cpp devicesupport/desktopdevicefactory.h
|
||||
|
@@ -164,7 +164,7 @@ void DeployConfigurationFactory::setConfigWidgetCreator(const std::function<QWid
|
||||
|
||||
void DeployConfigurationFactory::setUseDeploymentDataView()
|
||||
{
|
||||
m_configWidgetCreator = [](Target *target) { return new DeploymentDataView(target); };
|
||||
m_configWidgetCreator = [](Target *target) { return new Internal::DeploymentDataView(target); };
|
||||
}
|
||||
|
||||
void DeployConfigurationFactory::setConfigBaseId(Core::Id deployConfigBaseId)
|
||||
|
@@ -1,71 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** 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 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "deploymentdatamodel.h"
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
DeploymentDataModel::DeploymentDataModel(QObject *parent) : QAbstractTableModel(parent)
|
||||
{ }
|
||||
|
||||
void DeploymentDataModel::setDeploymentData(const DeploymentData &deploymentData)
|
||||
{
|
||||
beginResetModel();
|
||||
m_deploymentData = deploymentData;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int DeploymentDataModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : m_deploymentData.fileCount();
|
||||
}
|
||||
|
||||
int DeploymentDataModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : 2;
|
||||
}
|
||||
|
||||
QVariant DeploymentDataModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (orientation == Qt::Vertical || role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
return section == 0 ? tr("Local File Path") : tr("Remote Directory");
|
||||
}
|
||||
|
||||
QVariant DeploymentDataModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= rowCount() || index.column() >= columnCount())
|
||||
return QVariant();
|
||||
|
||||
const DeployableFile &d = m_deploymentData.fileAt(index.row());
|
||||
if (index.column() == 0 && role == Qt::DisplayRole)
|
||||
return d.localFilePath().toUserOutput();
|
||||
if (role == Qt::DisplayRole)
|
||||
return d.remoteDirectory();
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
@@ -1,52 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** 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 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "deploymentdata.h"
|
||||
#include "projectexplorer_export.h"
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
class PROJECTEXPLORER_EXPORT DeploymentDataModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DeploymentDataModel(QObject *parent = nullptr);
|
||||
|
||||
void setDeploymentData(const DeploymentData &deploymentData);
|
||||
|
||||
private:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
DeploymentData m_deploymentData;
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
@@ -24,56 +24,75 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "deploymentdataview.h"
|
||||
#include "ui_deploymentdataview.h"
|
||||
|
||||
#include "deploymentdatamodel.h"
|
||||
#include "deploymentdata.h"
|
||||
#include "target.h"
|
||||
|
||||
#include <utils/treemodel.h>
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QLabel>
|
||||
#include <QHeaderView>
|
||||
#include <QTreeView>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace ProjectExplorer {
|
||||
namespace Internal {
|
||||
|
||||
class DeploymentDataViewPrivate
|
||||
class DeploymentDataItem : public TreeItem
|
||||
{
|
||||
public:
|
||||
Ui::DeploymentDataView ui;
|
||||
Target *target;
|
||||
DeploymentDataModel deploymentDataModel;
|
||||
DeploymentDataItem() = default;
|
||||
DeploymentDataItem(const DeployableFile &file) : file(file) {}
|
||||
|
||||
QVariant data(int column, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
return column == 0 ? file.localFilePath().toUserOutput() : file.remoteDirectory();
|
||||
return QVariant();
|
||||
}
|
||||
DeployableFile file;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
DeploymentDataView::DeploymentDataView(Target *target, QWidget *parent) : NamedWidget(parent),
|
||||
d(std::make_unique<DeploymentDataViewPrivate>())
|
||||
DeploymentDataView::DeploymentDataView(Target *target)
|
||||
{
|
||||
d->ui.setupUi(this);
|
||||
d->ui.deploymentDataView->setTextElideMode(Qt::ElideMiddle);
|
||||
d->ui.deploymentDataView->setWordWrap(false);
|
||||
d->ui.deploymentDataView->setUniformRowHeights(true);
|
||||
d->ui.deploymentDataView->setModel(&d->deploymentDataModel);
|
||||
auto model = new TreeModel<DeploymentDataItem>(this);
|
||||
model->setHeader({tr("Local File Path"), tr("Remote Directory")});
|
||||
|
||||
d->target = target;
|
||||
auto view = new QTreeView(this);
|
||||
view->setMinimumSize(QSize(100, 100));
|
||||
view->setTextElideMode(Qt::ElideMiddle);
|
||||
view->setWordWrap(false);
|
||||
view->setUniformRowHeights(true);
|
||||
view->setModel(model);
|
||||
|
||||
connect(target, &Target::deploymentDataChanged,
|
||||
this, &DeploymentDataView::updateDeploymentDataModel);
|
||||
updateDeploymentDataModel();
|
||||
}
|
||||
auto label = new QLabel(tr("Files to deploy:"), this);
|
||||
|
||||
DeploymentDataView::~DeploymentDataView() = default;
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(label);
|
||||
layout->addWidget(view);
|
||||
|
||||
void DeploymentDataView::updateDeploymentDataModel()
|
||||
{
|
||||
d->deploymentDataModel.setDeploymentData(d->target->deploymentData());
|
||||
QHeaderView *header = d->ui.deploymentDataView->header();
|
||||
auto updatModel = [this, target, model, view] {
|
||||
model->clear();
|
||||
for (const DeployableFile &file : target->deploymentData().allFiles())
|
||||
model->rootItem()->appendChild(new DeploymentDataItem(file));
|
||||
|
||||
QHeaderView *header = view->header();
|
||||
header->setSectionResizeMode(0, QHeaderView::Interactive);
|
||||
header->setSectionResizeMode(1, QHeaderView::Interactive);
|
||||
d->ui.deploymentDataView->resizeColumnToContents(0);
|
||||
d->ui.deploymentDataView->resizeColumnToContents(1);
|
||||
if (header->sectionSize(0) + header->sectionSize(1)
|
||||
< d->ui.deploymentDataView->header()->width()) {
|
||||
d->ui.deploymentDataView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
}
|
||||
view->resizeColumnToContents(0);
|
||||
view->resizeColumnToContents(1);
|
||||
if (header->sectionSize(0) + header->sectionSize(1) < header->width())
|
||||
header->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
};
|
||||
|
||||
connect(target, &Target::deploymentDataChanged, this, updatModel);
|
||||
updatModel();
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
} // Internal
|
||||
} // ProjectExplorer
|
||||
|
@@ -25,28 +25,21 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "namedwidget.h"
|
||||
#include "projectexplorer_export.h"
|
||||
|
||||
#include <memory>
|
||||
#include <QWidget>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
class Target;
|
||||
|
||||
namespace Internal { class DeploymentDataViewPrivate; }
|
||||
namespace Internal {
|
||||
|
||||
class PROJECTEXPLORER_EXPORT DeploymentDataView : public NamedWidget
|
||||
class DeploymentDataView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DeploymentDataView(Target *target, QWidget *parent = nullptr);
|
||||
~DeploymentDataView() override;
|
||||
|
||||
private:
|
||||
void updateDeploymentDataModel();
|
||||
|
||||
const std::unique_ptr<Internal::DeploymentDataViewPrivate> d;
|
||||
explicit DeploymentDataView(Target *target);
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
} // Internal
|
||||
} // ProjectExplorer
|
||||
|
@@ -1,50 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ProjectExplorer::DeploymentDataView</class>
|
||||
<widget class="QWidget" name="ProjectExplorer::DeploymentDataView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>617</width>
|
||||
<height>361</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Files to deploy:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeView" name="deploymentDataView">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@@ -137,7 +137,6 @@ HEADERS += projectexplorer.h \
|
||||
devicesupport/sshsettingspage.h \
|
||||
devicesupport/desktopprocesssignaloperation.h \
|
||||
deploymentdata.h \
|
||||
deploymentdatamodel.h \
|
||||
deploymentdataview.h \
|
||||
buildtargetinfo.h \
|
||||
customtoolchain.h \
|
||||
@@ -285,7 +284,6 @@ SOURCES += projectexplorer.cpp \
|
||||
devicesupport/desktopprocesssignaloperation.cpp \
|
||||
deployablefile.cpp \
|
||||
deploymentdata.cpp \
|
||||
deploymentdatamodel.cpp \
|
||||
deploymentdataview.cpp \
|
||||
customtoolchain.cpp \
|
||||
projectmacroexpander.cpp \
|
||||
@@ -315,7 +313,6 @@ FORMS += \
|
||||
sessiondialog.ui \
|
||||
projectwizardpage.ui \
|
||||
projectexplorersettingspage.ui \
|
||||
deploymentdataview.ui \
|
||||
codestylesettingspropertiespage.ui \
|
||||
devicesupport/devicefactoryselectiondialog.ui \
|
||||
devicesupport/devicesettingswidget.ui \
|
||||
|
@@ -59,9 +59,6 @@ Project {
|
||||
"deploymentdata.h",
|
||||
"deploymentdataview.cpp",
|
||||
"deploymentdataview.h",
|
||||
"deploymentdataview.ui",
|
||||
"deploymentdatamodel.cpp",
|
||||
"deploymentdatamodel.h",
|
||||
"desktoprunconfiguration.cpp", "desktoprunconfiguration.h",
|
||||
"editorconfiguration.cpp", "editorconfiguration.h",
|
||||
"editorsettingspropertiespage.cpp", "editorsettingspropertiespage.h", "editorsettingspropertiespage.ui",
|
||||
|
Reference in New Issue
Block a user