本文整理汇总了C++中QMimeDatabase::allMimeTypes方法的典型用法代码示例。如果您正苦于以下问题:C++ QMimeDatabase::allMimeTypes方法的具体用法?C++ QMimeDatabase::allMimeTypes怎么用?C++ QMimeDatabase::allMimeTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMimeDatabase
的用法示例。
在下文中一共展示了QMimeDatabase::allMimeTypes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: KDirModel
DirModel::DirModel(QObject *parent)
: KDirModel(parent),
m_screenshotSize(180, 120)
{
#if 0 // unused here in trash
QMimeDatabase db;
QList<QMimeType> mimeList = db.allMimeTypes();
m_mimeTypes << "inode/directory";
foreach (const QMimeType &mime, mimeList) {
if (mime.name().startsWith(QStringLiteral("image/"))) {
m_mimeTypes << mime.name();
}
}
//TODO: configurable mime filter
//dirLister()->setMimeFilter(m_mimeTypes);
#endif
m_previewTimer = new QTimer(this);
m_previewTimer->setSingleShot(true);
connect(m_previewTimer, &QTimer::timeout,
this, &DirModel::delayedPreview);
//using the same cache of the engine, they index both by url
m_imageCache = new KImageCache(QStringLiteral("org.kde.dirmodel-qml"), 10485760);
connect(this, &QAbstractItemModel::rowsInserted,
this, &DirModel::countChanged);
connect(this, &QAbstractItemModel::rowsRemoved,
this, &DirModel::countChanged);
connect(this, &QAbstractItemModel::modelReset,
this, &DirModel::countChanged);
}
示例2: populate
void MimetypeModel::populate()
{
typedef QList<QMimeType>::Iterator Iterator;
QMimeDatabase mimeDatabase;
QList<QMimeType> allTypes = mimeDatabase.allMimeTypes();
// Move top level types to rear end of list, sort this partition,
// create top level items and truncate the list.
Iterator end = allTypes.end();
const Iterator topLevelStart =
std::stable_partition(allTypes.begin(), end,
[](const QMimeType &t) { return !t.parentMimeTypes().isEmpty(); });
std::stable_sort(topLevelStart, end);
for (Iterator it = topLevelStart; it != end; ++it) {
const StandardItemList row = createRow(*it);
appendRow(row);
m_nameIndexHash.insert(it->name(), indexFromItem(row.constFirst()));
}
allTypes.erase(topLevelStart, end);
while (!allTypes.isEmpty()) {
// Find a type inheriting one that is already in the model.
end = allTypes.end();
auto nameIndexIt = m_nameIndexHash.constEnd();
for (Iterator it = allTypes.begin(); it != end; ++it) {
nameIndexIt = m_nameIndexHash.constFind(it->parentMimeTypes().constFirst());
if (nameIndexIt != m_nameIndexHash.constEnd())
break;
}
if (nameIndexIt == m_nameIndexHash.constEnd()) {
qWarning() << "Orphaned mime types:" << allTypes;
break;
}
// Move types inheriting the parent type to rear end of list, sort this partition,
// append the items to parent and truncate the list.
const QString &parentName = nameIndexIt.key();
const Iterator start =
std::stable_partition(allTypes.begin(), end, [parentName](const QMimeType &t)
{ return !t.parentMimeTypes().contains(parentName); });
std::stable_sort(start, end);
QStandardItem *parentItem = itemFromIndex(nameIndexIt.value());
for (Iterator it = start; it != end; ++it) {
const StandardItemList row = createRow(*it);
parentItem->appendRow(row);
m_nameIndexHash.insert(it->name(), indexFromItem(row.constFirst()));
}
allTypes.erase(start, end);
}
}
示例3: loadAllMimeTypes
void MimetypeViewer::loadAllMimeTypes()
{
mediaTypes.clear();
mGroupItems.clear();
mItemList.clear();
QStringList selectedMimeTypes;
QMimeDatabase db;
QList<QMimeType> mimetypes = db.allMimeTypes();
qSort(mimetypes.begin(), mimetypes.end(), mimeTypeLessThan);
for (const QMimeType &mt : qAsConst(mimetypes)) {
const QString mimetype = mt.name();
const int i = mimetype.indexOf(QLatin1Char('/'));
const QString mediaType = mimetype.left(i);
const QString subType = mimetype.mid(i + 1);
MimeTypeData* data = new MimeTypeData(mt);
if (!mediaTypes.contains(mediaType)) { // A new type of media
mediaTypes.append(mediaType);
QTreeWidgetItem *item = new QTreeWidgetItem(widget.mimetypeTreeWidget, GroupType);
item->setText(0, mediaType);
widget.mimetypeTreeWidget->insertTopLevelItem(0, item);
mGroupItems.insert(mediaType, item);
}
QTreeWidgetItem *item = new QTreeWidgetItem(mGroupItems.value(mediaType), EntrieType);
QVariant v;
v.setValue(*data);
item->setData(0, Qt::UserRole, v);
item->setText(0, subType);
mItemList.append(item);
}
widget.mimetypeTreeWidget->resizeColumnToContents(1);
widget.mimetypeTreeWidget->show();
}