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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "feature.h"
#include <QTextStream>
#include <QRegExp>
#include <QLibraryInfo>
#include <QFileInfo>
#include <QApplication>
#include <QPalette>
QT_BEGIN_NAMESPACE
QMap<QString, Feature*> Feature::instances;
Feature* Feature::getInstance(const QString &key)
{
QString ukey = key.toUpper();
if (!instances.contains(ukey))
instances[ukey] = new Feature(ukey);
return instances[ukey];
}
Feature::~Feature()
{
delete d;
}
void Feature::clear()
{
foreach (Feature *f, instances.values())
delete f;
instances.clear();
}
static QString listToHtml(const QString &title, const QStringList &list)
{
if (list.isEmpty())
return QString();
QString str;
QTextStream stream(&str);
stream << "<h3>" << title << ":</h3>";
stream << "<ul>";
foreach (QString l, list)
stream << "<li>" << l << "</li>";
stream << "</ul>";
return str;
}
static QString listToHtml(const QString &title, const QList<Feature*> &list)
{
QStringList stringlist;
foreach (Feature *f, list) {
QString s("[%3] <a href=\"feature://%1\">%2</a>");
s = s.arg(f->key()).arg(f->key());
s = s.arg(f->selectable() && f->enabled() ? "On" : "Off");
stringlist << s;
}
return listToHtml(title, stringlist);
}
static QString linkify(const QString &src)
{
static QRegExp classRegexp("\\b(Q[\\w]+)");
QString docRoot = QLibraryInfo::location(QLibraryInfo::DocumentationPath);
QString result = src;
int pos = 0;
while ((pos = classRegexp.indexIn(result, pos)) != -1) {
QString className = classRegexp.cap(1);
QString file = docRoot + "/html/" + className.toLower() + ".html";
QFileInfo info(file);
if (info.isFile()) {
QString link = QString("<a href=\"file://%1\">%2</a>")
.arg(file).arg(className);
result.replace(pos, className.length(), link);
pos += link.length();
} else {
pos += className.length();
}
}
return result;
}
QString Feature::toHtml() const
{
QString str;
QTextStream stream(&str);
const QString linkColor = QApplication::palette().color(QPalette::Link).name();
stream << "<h2><font size=\"+2\" color=\"" << linkColor << "\">"
<< key() << "</font></h2>"
<< "<h2><font size=\"+2\">" << title() << "</font></h2>";
if (!description().isEmpty())
stream << "<p>" << description() << "</p>";
stream << listToHtml("Section", QStringList(section()))
<< listToHtml("Requires", dependencies())
<< listToHtml("Required for", supports())
<< listToHtml("See also", relations());
return linkify(str);
}
Feature::Feature(const QString &key) : d(new FeaturePrivate(key)) {}
void Feature::setTitle(const QString &title)
{
d->title = title;
}
void Feature::setSection(const QString §ion)
{
d->section = section;
}
void Feature::setDescription(const QString &description)
{
d->description = description;
}
void Feature::addRelation(const QString &key)
{
d->relations.insert(getInstance(key));
}
void Feature::setRelations(const QStringList &keys)
{
foreach(QString key, keys)
if (key != "???")
addRelation(key);
}
QList<Feature*> Feature::relations() const
{
return d->relations.toList();
}
void Feature::addDependency(const QString &key)
{
Feature *f = getInstance(key);
d->dependencies.insert(f);
f->d->supports.insert(this);
}
void Feature::setDependencies(const QStringList &keys)
{
foreach(QString key, keys)
addDependency(key);
}
QList<Feature*> Feature::dependencies() const
{
return d->dependencies.toList();
}
QList<Feature*> Feature::supports() const
{
return d->supports.toList();
}
/*
Returns a html formatted detailed description of this Feature.
*/
QString Feature::getDocumentation() const
{
return QString() + "<h2>" + d->title + "</h2>";
}
void Feature::setEnabled(bool on)
{
if (on == d->enabled)
return;
d->enabled = on;
foreach (Feature *f, supports())
f->updateSelectable();
emit changed();
}
/*
Update whether this feature should be selectable.
A feature is selectable if all its dependencies are enabled.
*/
void Feature::updateSelectable()
{
bool selectable = true;
foreach (Feature *f, dependencies())
if (!f->selectable() || !f->enabled())
selectable = false;
if (selectable != d->selectable) {
d->selectable = selectable;
foreach (Feature *f, supports())
f->updateSelectable();
emit changed();
}
}
QT_END_NAMESPACE
|