Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "feature.h"
43#include <QTextStream>
44#include <QRegExp>
45#include <QLibraryInfo>
46#include <QFileInfo>
47#include <QApplication>
48#include <QPalette>
49
50QT_BEGIN_NAMESPACE
51
52QMap<QString, Feature*> Feature::instances;
53
54Feature* Feature::getInstance(const QString &key)
55{
56 QString ukey = key.toUpper();
57 if (!instances.contains(ukey))
58 instances[ukey] = new Feature(ukey);
59 return instances[ukey];
60}
61
62Feature::~Feature()
63{
64 delete d;
65}
66
67void Feature::clear()
68{
69 foreach (Feature *f, instances.values())
70 delete f;
71 instances.clear();
72}
73
74static QString listToHtml(const QString &title, const QStringList &list)
75{
76 if (list.isEmpty())
77 return QString();
78
79 QString str;
80 QTextStream stream(&str);
81
82 stream << "<h3>" << title << ":</h3>";
83 stream << "<ul>";
84 foreach (QString l, list)
85 stream << "<li>" << l << "</li>";
86 stream << "</ul>";
87
88 return str;
89}
90
91static QString listToHtml(const QString &title, const QList<Feature*> &list)
92{
93 QStringList stringlist;
94 foreach (Feature *f, list) {
95 QString s("[%3] <a href=\"feature://%1\">%2</a>");
96 s = s.arg(f->key()).arg(f->key());
97 s = s.arg(f->selectable() && f->enabled() ? "On" : "Off");
98 stringlist << s;
99 }
100 return listToHtml(title, stringlist);
101}
102
103static QString linkify(const QString &src)
104{
105 static QRegExp classRegexp("\\b(Q[\\w]+)");
106 QString docRoot = QLibraryInfo::location(QLibraryInfo::DocumentationPath);
107 QString result = src;
108 int pos = 0;
109 while ((pos = classRegexp.indexIn(result, pos)) != -1) {
110 QString className = classRegexp.cap(1);
111 QString file = docRoot + "/html/" + className.toLower() + ".html";
112 QFileInfo info(file);
113 if (info.isFile()) {
114 QString link = QString("<a href=\"file://%1\">%2</a>")
115 .arg(file).arg(className);
116 result.replace(pos, className.length(), link);
117 pos += link.length();
118 } else {
119 pos += className.length();
120 }
121 }
122
123 return result;
124}
125
126QString Feature::toHtml() const
127{
128 QString str;
129 QTextStream stream(&str);
130
131 const QString linkColor = QApplication::palette().color(QPalette::Link).name();
132 stream << "<h2><font size=\"+2\" color=\"" << linkColor << "\">"
133 << key() << "</font></h2>"
134 << "<h2><font size=\"+2\">" << title() << "</font></h2>";
135 if (!description().isEmpty())
136 stream << "<p>" << description() << "</p>";
137 stream << listToHtml("Section", QStringList(section()))
138 << listToHtml("Requires", dependencies())
139 << listToHtml("Required for", supports())
140 << listToHtml("See also", relations());
141
142 return linkify(str);
143}
144
145Feature::Feature(const QString &key) : d(new FeaturePrivate(key)) {}
146
147void Feature::setTitle(const QString &title)
148{
149 d->title = title;
150}
151
152void Feature::setSection(const QString &section)
153{
154 d->section = section;
155}
156
157void Feature::setDescription(const QString &description)
158{
159 d->description = description;
160}
161
162void Feature::addRelation(const QString &key)
163{
164 d->relations.insert(getInstance(key));
165}
166
167void Feature::setRelations(const QStringList &keys)
168{
169 foreach(QString key, keys)
170 if (key != "???")
171 addRelation(key);
172}
173
174QList<Feature*> Feature::relations() const
175{
176 return d->relations.toList();
177}
178
179void Feature::addDependency(const QString &key)
180{
181 Feature *f = getInstance(key);
182 d->dependencies.insert(f);
183 f->d->supports.insert(this);
184}
185
186void Feature::setDependencies(const QStringList &keys)
187{
188 foreach(QString key, keys)
189 addDependency(key);
190}
191
192QList<Feature*> Feature::dependencies() const
193{
194 return d->dependencies.toList();
195}
196
197QList<Feature*> Feature::supports() const
198{
199 return d->supports.toList();
200}
201
202/*
203 Returns a html formatted detailed description of this Feature.
204*/
205QString Feature::getDocumentation() const
206{
207 return QString() + "<h2>" + d->title + "</h2>";
208
209}
210
211void Feature::setEnabled(bool on)
212{
213 if (on == d->enabled)
214 return;
215
216 d->enabled = on;
217 foreach (Feature *f, supports())
218 f->updateSelectable();
219 emit changed();
220}
221
222/*
223 Update whether this feature should be selectable.
224 A feature is selectable if all its dependencies are enabled.
225*/
226void Feature::updateSelectable()
227{
228 bool selectable = true;
229 foreach (Feature *f, dependencies())
230 if (!f->selectable() || !f->enabled())
231 selectable = false;
232 if (selectable != d->selectable) {
233 d->selectable = selectable;
234 foreach (Feature *f, supports())
235 f->updateSelectable();
236 emit changed();
237 }
238}
239
240QT_END_NAMESPACE
241

Warning: That file was not part of the compilation database. It may have many parsing errors.