File indexing completed on 2024-05-12 15:58:29

0001 /*
0002  *  SPDX-FileCopyrightText: 2009 Cyrille Berger <cberger@cberger.net>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef _KIS_NODE_QUERY_PATH_H_
0008 #define _KIS_NODE_QUERY_PATH_H_
0009 
0010 #include <kis_types.h>
0011 #include <kritaimage_export.h>
0012 
0013 /**
0014  * This class represent a path to access a node starting from an other node.
0015  */
0016 class KRITAIMAGE_EXPORT KisNodeQueryPath
0017 {
0018     KisNodeQueryPath();
0019 public:
0020     ~KisNodeQueryPath();
0021     KisNodeQueryPath(const KisNodeQueryPath&);
0022     KisNodeQueryPath& operator=(const KisNodeQueryPath&);
0023     QList<KisNodeSP> queryNodes(KisImageWSP image, KisNodeSP currentNode) const;
0024     KisNodeSP queryUniqueNode(KisImageWSP image, KisNodeSP currentNode = 0) const;
0025     bool isRelative() const;
0026     // Use "///" style because of the needed "/*"
0027     /// This function return a string representing this path. Which is a list separated by '\' of:
0028     /// - '*': represents all layers
0029     /// - '..': represents the parent layer
0030     /// - number: index of the layer
0031     /// - '.': represents the current layer
0032     ///
0033     /// For instance: "1/*" return all children of the first layer, "../3" return the third layer of the parent
0034     /// of the current layer
0035     /// If the string starts with "/" then it's an absolute path, otherwise it's a relative path.
0036     QString toString() const;
0037     /**
0038      * @param path
0039      * @param err if non null, it will be filled with an error message
0040      * @see toString for an explanation of the string format
0041      */
0042     static KisNodeQueryPath fromString(const QString& path);
0043     static KisNodeQueryPath absolutePath(KisNodeSP node);
0044 private:
0045     struct Private;
0046     Private* const d;
0047 };
0048 
0049 #endif