Doc: Compile qfontdatabase snippets

* Extend GUI snippets by adding the qfontdatabase project.
* Rename the snippet file and replace main() with wrapper().
* Minor adjustments of the snippet itself.
* Update documentation that includes the snippet.

Done-with: Nico Vertriest <nico.vertriest@qt.io>
Task-number: QTBUG-81486
Change-Id: Id23aff01a4c919c5264f7059971cb63398c2298c
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
bb10
Paul Wicking 2020-08-20 14:40:06 +02:00
parent b5a0baa061
commit 2870c201dc
4 changed files with 31 additions and 30 deletions

View File

@ -50,38 +50,33 @@
#include <QtWidgets>
int main(int argc, char **argv)
namespace qfontdatabase_snippets {
void wrapper()
{
QApplication app(argc, argv);
//! [0]
QFontDatabase database;
QTreeWidget fontTree;
fontTree.setColumnCount(2);
fontTree.setHeaderLabels(QStringList() << "Font" << "Smooth Sizes");
QFontDatabase database;
QTreeWidget fontTree;
fontTree.setColumnCount(2);
fontTree.setHeaderLabels(QStringList() << "Font" << "Smooth Sizes");
const QStringList fontFamilies = database.families();
for (const QString &family : fontFamilies) {
QTreeWidgetItem *familyItem = new QTreeWidgetItem(&fontTree);
familyItem->setText(0, family);
const QStringList fontFamilies = database.families();
for (const QString &family : fontFamilies) {
QTreeWidgetItem *familyItem = new QTreeWidgetItem(&fontTree);
familyItem->setText(0, family);
const QStringList fontStyles = database.styles(family);
for (const QString &style : fontStyles) {
QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem);
styleItem->setText(0, style);
const QStringList fontStyles = database.styles(family);
for (const QString &style : fontStyles) {
QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem);
styleItem->setText(0, style);
QString sizes;
const QList<int> smoothSizes = database.smoothSizes(family, style)
for (int points : smoothSizes)
sizes += QString::number(points) + ' ';
QString sizes;
const QList<int> smoothSizes = database.smoothSizes(family, style);
for (const auto &points : smoothSizes)
sizes += QString::number(points) + ' ';
styleItem->setText(1, sizes.trimmed());
}
//! [0] //! [1]
styleItem->setText(1, sizes.trimmed());
}
//! [1]
fontTree.resizeColumnToContents(0);
fontTree.show();
return app.exec();
}
//! [0]
} // wrapper
} // qfontdatabase_snippets

View File

@ -0,0 +1,5 @@
TEMPLATE = lib
TARGET = qfontdatabase_snippets
QT += core gui widgets
SOURCES = qfontdatabase_snippets.cpp

View File

@ -2,5 +2,7 @@ TEMPLATE = subdirs
SUBDIRS =
contains(QT_BUILD_PARTS, tests) {
SUBDIRS +=
SUBDIRS += \
qfontdatabase
}

View File

@ -1237,8 +1237,7 @@ QString QFontDatabase::styleString(const QFontInfo &fontInfo)
Example:
\snippet qfontdatabase/main.cpp 0
\snippet qfontdatabase/main.cpp 1
\snippet qfontdatabase/qfontdatabase_snippets.cpp 0
This example gets the list of font families, the list of
styles for each family, and the point sizes that are available for