From 02707ecdad63f8997a03294ae29d9adc38d054f3 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 20 Aug 2019 16:53:28 +0200 Subject: [PATCH] ProjectExplorer: Compactify DeploymentDataView implementation Change-Id: I30a4a772e9a54068566be0cab435044c073becf9 Reviewed-by: Christian Kandeler --- src/plugins/projectexplorer/CMakeLists.txt | 3 +- .../projectexplorer/deployconfiguration.cpp | 2 +- .../projectexplorer/deploymentdatamodel.cpp | 71 -------------- .../projectexplorer/deploymentdatamodel.h | 52 ----------- .../projectexplorer/deploymentdataview.cpp | 93 +++++++++++-------- .../projectexplorer/deploymentdataview.h | 21 ++--- .../projectexplorer/deploymentdataview.ui | 50 ---------- .../projectexplorer/projectexplorer.pro | 3 - .../projectexplorer/projectexplorer.qbs | 3 - 9 files changed, 65 insertions(+), 233 deletions(-) delete mode 100644 src/plugins/projectexplorer/deploymentdatamodel.cpp delete mode 100644 src/plugins/projectexplorer/deploymentdatamodel.h delete mode 100644 src/plugins/projectexplorer/deploymentdataview.ui diff --git a/src/plugins/projectexplorer/CMakeLists.txt b/src/plugins/projectexplorer/CMakeLists.txt index f3074cef325..2e065ea3bf4 100644 --- a/src/plugins/projectexplorer/CMakeLists.txt +++ b/src/plugins/projectexplorer/CMakeLists.txt @@ -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 diff --git a/src/plugins/projectexplorer/deployconfiguration.cpp b/src/plugins/projectexplorer/deployconfiguration.cpp index 274d665a508..29c80cb175a 100644 --- a/src/plugins/projectexplorer/deployconfiguration.cpp +++ b/src/plugins/projectexplorer/deployconfiguration.cpp @@ -164,7 +164,7 @@ void DeployConfigurationFactory::setConfigWidgetCreator(const std::function= 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 diff --git a/src/plugins/projectexplorer/deploymentdatamodel.h b/src/plugins/projectexplorer/deploymentdatamodel.h deleted file mode 100644 index a2437cb4bc1..00000000000 --- a/src/plugins/projectexplorer/deploymentdatamodel.h +++ /dev/null @@ -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 - -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 diff --git a/src/plugins/projectexplorer/deploymentdataview.cpp b/src/plugins/projectexplorer/deploymentdataview.cpp index bce3bff0b49..f620cf4a5b5 100644 --- a/src/plugins/projectexplorer/deploymentdataview.cpp +++ b/src/plugins/projectexplorer/deploymentdataview.cpp @@ -24,56 +24,75 @@ ****************************************************************************/ #include "deploymentdataview.h" -#include "ui_deploymentdataview.h" -#include "deploymentdatamodel.h" +#include "deploymentdata.h" #include "target.h" +#include + +#include +#include +#include +#include +#include + +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()) +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(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); + + auto layout = new QVBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(label); + layout->addWidget(view); + + 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); + 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(); } -DeploymentDataView::~DeploymentDataView() = default; - -void DeploymentDataView::updateDeploymentDataModel() -{ - d->deploymentDataModel.setDeploymentData(d->target->deploymentData()); - QHeaderView *header = d->ui.deploymentDataView->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); - } -} - -} // namespace ProjectExplorer +} // Internal +} // ProjectExplorer diff --git a/src/plugins/projectexplorer/deploymentdataview.h b/src/plugins/projectexplorer/deploymentdataview.h index 9cc49eaa8f9..178a96e3bb9 100644 --- a/src/plugins/projectexplorer/deploymentdataview.h +++ b/src/plugins/projectexplorer/deploymentdataview.h @@ -25,28 +25,21 @@ #pragma once -#include "namedwidget.h" -#include "projectexplorer_export.h" - -#include +#include 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 d; + explicit DeploymentDataView(Target *target); }; -} // namespace ProjectExplorer +} // Internal +} // ProjectExplorer diff --git a/src/plugins/projectexplorer/deploymentdataview.ui b/src/plugins/projectexplorer/deploymentdataview.ui deleted file mode 100644 index 325740bd2d9..00000000000 --- a/src/plugins/projectexplorer/deploymentdataview.ui +++ /dev/null @@ -1,50 +0,0 @@ - - - ProjectExplorer::DeploymentDataView - - - - 0 - 0 - 617 - 361 - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Files to deploy: - - - - - - - - 100 - 100 - - - - - - - - - diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro index 5c6bd5b77fa..90e9ed264c9 100644 --- a/src/plugins/projectexplorer/projectexplorer.pro +++ b/src/plugins/projectexplorer/projectexplorer.pro @@ -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 \ diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index 8d6578ba313..926e6fc0815 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -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",