1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the tools applications of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
43 #include <QTextStream>
45 #include <QLibraryInfo>
47 #include <QApplication>
52 QMap
<QString
, Feature
*> Feature::instances
;
54 Feature
* Feature::getInstance(const QString
&key
)
56 QString ukey
= key
.toUpper();
57 if (!instances
.contains(ukey
))
58 instances
[ukey
] = new Feature(ukey
);
59 return instances
[ukey
];
69 foreach (Feature
*f
, instances
.values())
74 static QString
listToHtml(const QString
&title
, const QStringList
&list
)
80 QTextStream
stream(&str
);
82 stream
<< "<h3>" << title
<< ":</h3>";
84 foreach (QString l
, list
)
85 stream
<< "<li>" << l
<< "</li>";
91 static QString
listToHtml(const QString
&title
, const QList
<Feature
*> &list
)
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");
100 return listToHtml(title
, stringlist
);
103 static QString
linkify(const QString
&src
)
105 static QRegExp
classRegexp("\\b(Q[\\w]+)");
106 QString docRoot
= QLibraryInfo::location(QLibraryInfo::DocumentationPath
);
107 QString result
= src
;
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
);
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();
119 pos
+= className
.length();
126 QString
Feature::toHtml() const
129 QTextStream
stream(&str
);
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());
145 Feature::Feature(const QString
&key
) : d(new FeaturePrivate(key
)) {}
147 void Feature::setTitle(const QString
&title
)
152 void Feature::setSection(const QString
§ion
)
154 d
->section
= section
;
157 void Feature::setDescription(const QString
&description
)
159 d
->description
= description
;
162 void Feature::addRelation(const QString
&key
)
164 d
->relations
.insert(getInstance(key
));
167 void Feature::setRelations(const QStringList
&keys
)
169 foreach(QString key
, keys
)
174 QList
<Feature
*> Feature::relations() const
176 return d
->relations
.toList();
179 void Feature::addDependency(const QString
&key
)
181 Feature
*f
= getInstance(key
);
182 d
->dependencies
.insert(f
);
183 f
->d
->supports
.insert(this);
186 void Feature::setDependencies(const QStringList
&keys
)
188 foreach(QString key
, keys
)
192 QList
<Feature
*> Feature::dependencies() const
194 return d
->dependencies
.toList();
197 QList
<Feature
*> Feature::supports() const
199 return d
->supports
.toList();
203 Returns a html formatted detailed description of this Feature.
205 QString
Feature::getDocumentation() const
207 return QString() + "<h2>" + d
->title
+ "</h2>";
211 void Feature::setEnabled(bool on
)
213 if (on
== d
->enabled
)
217 foreach (Feature
*f
, supports())
218 f
->updateSelectable();
223 Update whether this feature should be selectable.
224 A feature is selectable if all its dependencies are enabled.
226 void Feature::updateSelectable()
228 bool selectable
= true;
229 foreach (Feature
*f
, dependencies())
230 if (!f
->selectable() || !f
->enabled())
232 if (selectable
!= d
->selectable
) {
233 d
->selectable
= selectable
;
234 foreach (Feature
*f
, supports())
235 f
->updateSelectable();