-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugindetailsview.cpp
147 lines (129 loc) · 4.79 KB
/
plugindetailsview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "plugindetailsview.h"
#include "extensionsystemtr.h"
#include "pluginmanager.h"
#include "pluginspec.h"
#include <utils/algorithm.h>
#include <QtWidgets>
using namespace ExtensionSystem;
/*!
\class ExtensionSystem::PluginDetailsView
\inheaderfile extensionsystem/plugindetailsview.h
\inmodule QtCreator
\brief The PluginDetailsView class implements a widget that displays the
contents of a PluginSpec.
Can be used for integration in the application that
uses the plugin manager.
\sa ExtensionSystem::PluginView
*/
namespace ExtensionSystem::Internal {
class PluginDetailsViewPrivate
{
public:
explicit PluginDetailsViewPrivate(PluginDetailsView *detailsView)
: q(detailsView)
, name(createContentsLabel())
, version(createContentsLabel())
, compatVersion(createContentsLabel())
, vendor(createContentsLabel())
, component(createContentsLabel())
, url(createContentsLabel())
, location(createContentsLabel())
, platforms(createContentsLabel())
, description(createTextEdit())
, copyright(createContentsLabel())
, license(createTextEdit())
, dependencies(new QListWidget(q))
{
auto layout = new QFormLayout(q);
layout->setContentsMargins(QMargins());
layout->addRow(Tr::tr("Name:"), name);
layout->addRow(Tr::tr("Version:"), version);
layout->addRow(Tr::tr("Compatibility version:"), compatVersion);
layout->addRow(Tr::tr("Vendor:"), vendor);
layout->addRow(Tr::tr("Group:"), component);
layout->addRow(Tr::tr("URL:"), url);
layout->addRow(Tr::tr("Location:"), location);
layout->addRow(Tr::tr("Platforms:"), platforms);
layout->addRow(Tr::tr("Description:"), description);
layout->addRow(Tr::tr("Copyright:"), copyright);
layout->addRow(Tr::tr("License:"), license);
layout->addRow(Tr::tr("Dependencies:"), dependencies);
}
PluginDetailsView *q = nullptr;
QLabel *name = nullptr;
QLabel *version = nullptr;
QLabel *compatVersion = nullptr;
QLabel *vendor = nullptr;
QLabel *component = nullptr;
QLabel *url = nullptr;
QLabel *location = nullptr;
QLabel *platforms = nullptr;
QTextEdit *description = nullptr;
QLabel *copyright = nullptr;
QTextEdit *license = nullptr;
QListWidget *dependencies = nullptr;
private:
auto createContentsLabel() -> QLabel *
{
QLabel *label = new QLabel(q);
label->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::TextSelectableByMouse);
label->setOpenExternalLinks(true);
return label;
}
auto createTextEdit() -> QTextEdit *
{
QTextEdit *textEdit = new QTextEdit(q);
textEdit->setTabChangesFocus(true);
textEdit->setReadOnly(true);
return textEdit;
}
};
} // namespace ExtensionSystem::Internal
using namespace Internal;
/*!
Constructs a new view with given \a parent widget.
*/
PluginDetailsView::PluginDetailsView(QWidget *parent)
: QWidget(parent)
, d(new PluginDetailsViewPrivate(this))
{}
/*!
\internal
*/
PluginDetailsView::~PluginDetailsView()
{
delete d;
}
/*!
Reads the given \a spec and displays its values
in this PluginDetailsView.
*/
void PluginDetailsView::update(PluginSpec *spec)
{
d->name->setText(spec->name());
const QString revision = spec->revision();
const QString versionString = spec->version()
+ (revision.isEmpty() ? QString() : " (" + revision + ")");
d->version->setText(versionString);
d->compatVersion->setText(spec->compatVersion());
d->vendor->setText(spec->vendor());
d->component->setText(spec->category().isEmpty() ? Tr::tr("None") : spec->category());
d->url->setText(QString::fromLatin1("<a href=\"%1\">%1</a>").arg(spec->url()));
d->location->setText(QDir::toNativeSeparators(spec->filePath()));
const QString pattern = spec->platformSpecification().pattern();
const QString platform = pattern.isEmpty() ? Tr::tr("All") : pattern;
const QString platformString = Tr::tr("%1 (current: \"%2\")")
.arg(platform, PluginManager::platformName());
d->platforms->setText(platformString);
QString description = spec->description();
if (!description.isEmpty() && !spec->longDescription().isEmpty())
description += "\n\n";
description += spec->longDescription();
d->description->setText(description);
d->copyright->setText(spec->copyright());
d->license->setText(spec->license());
d->dependencies->addItems(
Utils::transform<QList>(spec->dependencies(), &PluginDependency::toString));
}