pqIconListModel.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-License-Identifier: BSD-3-Clause
3 
4 #ifndef pqIconListModel_h
5 #define pqIconListModel_h
6 
7 #include "pqCoreModule.h"
8 
9 #include <QAbstractListModel>
10 
11 #include <memory>
12 
13 class QFileInfo;
14 using QFileInfoList = QList<QFileInfo>;
15 
22 class PQCORE_EXPORT pqIconListModel : public QAbstractListModel
23 {
24  Q_OBJECT;
25  typedef QAbstractListModel Superclass;
26 
27 public:
28  pqIconListModel(QObject* parent);
29  ~pqIconListModel() override;
30 
31  enum IconRoles
32  {
33  PathRole = Qt::UserRole + 1, // icon absolute path
34  OriginRole, // icon file location, like application resources or user dir
35  };
36 
40  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
41 
45  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
46 
50  bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
51 
55  void addIcons(const QFileInfoList& iconInfoList);
56 
60  void addIcon(const QFileInfo& iconInfo);
61 
65  void clearAll();
66 
71  static QStringList getSupportedIconFormats()
72  {
73  return QStringList() << ".svg"
74  << ".png";
75  }
76 
80  static QMap<QString, QString> getAvailableOrigins()
81  {
82  QMap<QString, QString> origins;
83  origins["Resources"] = tr("Application resources");
84  origins["UserDefined"] = tr("User icons");
85  return origins;
86  }
87 
91  static bool isUserDefined(const QModelIndex& index);
92 
93 private:
94  struct pqInternal;
95  std::unique_ptr<pqInternal> Internal;
96 };
97 
98 #endif
data
QList< QFileInfo > QFileInfoList
#define PQCORE_EXPORT
Definition: pqCoreModule.h:15
static QMap< QString, QString > getAvailableOrigins()
Returns available extensions as a map of {name: display name}.
pqIconListModel is a model for list of icons.
index
static QStringList getSupportedIconFormats()
Returns the list of file extensions that can be used for icons.