1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Designer of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 //
30 //  W A R N I N G
31 //  -------------
32 //
33 // This file is not part of the Qt API.  It exists for the convenience
34 // of Qt Designer.  This header
35 // file may change from version to version without notice, or even be removed.
36 //
37 // We mean it.
38 //
39 
40 #ifndef QTRESOURCEMODEL_H
41 #define QTRESOURCEMODEL_H
42 
43 #include "shared_global_p.h"
44 #include <QtCore/qmap.h>
45 #include <QtCore/qobject.h>
46 #include <QtCore/qscopedpointer.h>
47 
48 QT_BEGIN_NAMESPACE
49 
50 class QtResourceModel;
51 
52 class QDESIGNER_SHARED_EXPORT QtResourceSet // one instance per one form
53 {
54 public:
55     QStringList activeResourceFilePaths() const;
56 
57     // activateQrcPaths(): if this QtResourceSet is active it emits resourceSetActivated();
58     // otherwise only in case if active QtResource set contains one of
59     // paths which was marked as modified by this resource set, the signal
60     // is emitted (with reload = true);
61     // If new path appears on the list it is automatically added to
62     // loaded list of QtResourceModel. In addition it is marked as modified in case
63     // QtResourceModel didn't contain the path.
64     // If some path is removed from that list (and is not used in any other
65     // resource set) it is automatically unloaded. The removed file can also be
66     // marked as modified (later when another resource set which contains
67     // removed path is activated will be reloaded)
68     void activateResourceFilePaths(const QStringList &paths, int *errorCount = nullptr, QString *errorMessages = nullptr);
69 
70     bool isModified(const QString &path) const; // for all paths in resource model (redundant here, maybe it should be removed from here)
71     void setModified(const QString &path);      // for all paths in resource model (redundant here, maybe it should be removed from here)
72 private:
73     QtResourceSet();
74     QtResourceSet(QtResourceModel *model);
75     ~QtResourceSet();
76     friend class QtResourceModel;
77 
78     QScopedPointer<class QtResourceSetPrivate> d_ptr;
79     Q_DECLARE_PRIVATE(QtResourceSet)
80     Q_DISABLE_COPY_MOVE(QtResourceSet)
81 };
82 
83 class QDESIGNER_SHARED_EXPORT QtResourceModel : public QObject // one instance per whole designer
84 {
85     Q_OBJECT
86 public:
87     QtResourceModel(QObject *parent = nullptr);
88     ~QtResourceModel();
89 
90     QStringList loadedQrcFiles() const;
91     bool isModified(const QString &path) const; // only for paths which are on loadedQrcFiles() list
92     void setModified(const QString &path);      // only for paths which are on loadedQrcPaths() list
93 
94     QList<QtResourceSet *> resourceSets() const;
95 
96     QtResourceSet *currentResourceSet() const;
97     void setCurrentResourceSet(QtResourceSet *resourceSet, int *errorCount = nullptr, QString *errorMessages = nullptr);
98 
99     QtResourceSet *addResourceSet(const QStringList &paths);
100     void removeResourceSet(QtResourceSet *resourceSet);
101 
102     void reload(const QString &path, int *errorCount = nullptr, QString *errorMessages = nullptr);
103     void reload(int *errorCount = nullptr, QString *errorMessages = nullptr);
104 
105     // Contents of the current resource set (content file to qrc path)
106     QMap<QString, QString> contents() const;
107     // Find the qrc file belonging to the contained file (from current resource set)
108     QString qrcPath(const QString &file) const;
109 
110     void setWatcherEnabled(bool enable);
111     bool isWatcherEnabled() const;
112 
113     void setWatcherEnabled(const QString &path, bool enable);
114     bool isWatcherEnabled(const QString &path);
115 
116 signals:
117     void resourceSetActivated(QtResourceSet *resourceSet, bool resourceSetChanged); // resourceSetChanged since last time it was activated!
118     void qrcFileModifiedExternally(const QString &path);
119 
120 private:
121     friend class QtResourceSet;
122 
123     QScopedPointer<class QtResourceModelPrivate> d_ptr;
124     Q_DECLARE_PRIVATE(QtResourceModel)
125     Q_DISABLE_COPY_MOVE(QtResourceModel)
126 
127     Q_PRIVATE_SLOT(d_func(), void slotFileChanged(const QString &))
128 };
129 
130 QT_END_NAMESPACE
131 
132 #endif
133