summaryrefslogtreecommitdiffstats
path: root/examples/corelib/mimetypes/mimetypebrowser/mimetypemodel.h
blob: 061ede3c47a1db63490554943fcf78fd37844b73 (plain)
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
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef MIMETYPEMODEL_H
#define MIMETYPEMODEL_H

#include <QCoreApplication>
#include <QHash>
#include <QMimeType>
#include <QStandardItemModel>

class MimetypeModel : public QStandardItemModel
{
    Q_DECLARE_TR_FUNCTIONS(MimetypeModel)
public:
    enum Columns { NameColumn, ColumnCount };

    explicit MimetypeModel(QObject *parent = nullptr);

    QVariant data(const QModelIndex &index, int role) const override;

    QMimeType mimeType(const QModelIndex &) const;

    QModelIndex indexForMimeType(const QString &name) const
    { return m_nameIndexHash.value(name); }

    static QString formatMimeTypeInfo(const QMimeType &);

private:
    typedef QHash<QString, QModelIndex> NameIndexHash;

    void populate();

    NameIndexHash m_nameIndexHash;
};

#endif // MIMETYPEMODEL_H