tools/designer/src/lib/shared/qtresourcemodel_p.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Designer of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 //
       
    43 //  W A R N I N G
       
    44 //  -------------
       
    45 //
       
    46 // This file is not part of the Qt API.  It exists for the convenience
       
    47 // of Qt Designer.  This header
       
    48 // file may change from version to version without notice, or even be removed.
       
    49 //
       
    50 // We mean it.
       
    51 //
       
    52 
       
    53 #ifndef QTRESOURCEMODEL_H
       
    54 #define QTRESOURCEMODEL_H
       
    55 
       
    56 #include "shared_global_p.h"
       
    57 #include <QtCore/QMap>
       
    58 #include <QtCore/QObject>
       
    59 #include <QtCore/QScopedPointer>
       
    60 
       
    61 QT_BEGIN_NAMESPACE
       
    62 
       
    63 class QtResourceModel;
       
    64 
       
    65 class QDESIGNER_SHARED_EXPORT QtResourceSet // one instance per one form
       
    66 {
       
    67 public:
       
    68     QStringList activeQrcPaths() const;
       
    69 
       
    70     // activateQrcPaths(): if this QtResourceSet is active it emits resourceSetActivated();
       
    71     // otherwise only in case if active QtResource set contains one of
       
    72     // paths which was marked as modified by this resource set, the signal
       
    73     // is emitted (with reload = true);
       
    74     // If new path appears on the list it is automatically added to
       
    75     // loaded list of QtResourceModel. In addition it is marked as modified in case
       
    76     // QtResourceModel didn't contain the path.
       
    77     // If some path is removed from that list (and is not used in any other
       
    78     // resource set) it is automatically unloaded. The removed file can also be
       
    79     // marked as modified (later when another resource set which contains
       
    80     // removed path is activated will be reloaded)
       
    81     void activateQrcPaths(const QStringList &paths, int *errorCount = 0, QString *errorMessages = 0);
       
    82 
       
    83     bool isModified(const QString &path) const; // for all paths in resource model (redundant here, maybe it should be removed from here)
       
    84     void setModified(const QString &path);      // for all paths in resource model (redundant here, maybe it should be removed from here)
       
    85 private:
       
    86     QtResourceSet();
       
    87     QtResourceSet(QtResourceModel *model);
       
    88     ~QtResourceSet();
       
    89     friend class QtResourceModel;
       
    90 
       
    91     QScopedPointer<class QtResourceSetPrivate> d_ptr;
       
    92     Q_DECLARE_PRIVATE(QtResourceSet)
       
    93     Q_DISABLE_COPY(QtResourceSet)
       
    94 };
       
    95 
       
    96 class QDESIGNER_SHARED_EXPORT QtResourceModel : public QObject // one instance per whole designer
       
    97 {
       
    98     Q_OBJECT
       
    99 public:
       
   100     QtResourceModel(QObject *parent = 0);
       
   101     ~QtResourceModel();
       
   102 
       
   103     QStringList loadedQrcFiles() const;
       
   104     bool isModified(const QString &path) const; // only for paths which are on loadedQrcFiles() list
       
   105     void setModified(const QString &path);      // only for paths which are on loadedQrcPaths() list
       
   106 
       
   107     QList<QtResourceSet *> resourceSets() const;
       
   108 
       
   109     QtResourceSet *currentResourceSet() const;
       
   110     void setCurrentResourceSet(QtResourceSet *resourceSet, int *errorCount = 0, QString *errorMessages = 0);
       
   111 
       
   112     QtResourceSet *addResourceSet(const QStringList &paths);
       
   113     void removeResourceSet(QtResourceSet *resourceSet);
       
   114 
       
   115     void reload(const QString &path, int *errorCount = 0, QString *errorMessages = 0);
       
   116     void reload(int *errorCount = 0, QString *errorMessages = 0);
       
   117 
       
   118     // Contents of the current resource set (content file to qrc path)
       
   119     QMap<QString, QString> contents() const;
       
   120     // Find the qrc file belonging to the contained file (from current resource set)
       
   121     QString qrcPath(const QString &file) const;
       
   122 
       
   123     void setWatcherEnabled(bool enable);
       
   124     bool isWatcherEnabled() const;
       
   125 
       
   126     void setWatcherEnabled(const QString &path, bool enable);
       
   127     bool isWatcherEnabled(const QString &path);
       
   128 
       
   129 signals:
       
   130     void resourceSetActivated(QtResourceSet *resourceSet, bool resourceSetChanged); // resourceSetChanged since last time it was activated!
       
   131     void qrcFileModifiedExternally(const QString &path);
       
   132 
       
   133 private:
       
   134     friend class QtResourceSet;
       
   135 
       
   136     QScopedPointer<class QtResourceModelPrivate> d_ptr;
       
   137     Q_DECLARE_PRIVATE(QtResourceModel)
       
   138     Q_DISABLE_COPY(QtResourceModel)
       
   139 
       
   140     Q_PRIVATE_SLOT(d_func(), void slotFileChanged(const QString &))
       
   141 };
       
   142 
       
   143 QT_END_NAMESPACE
       
   144 
       
   145 #endif