File indexing completed on 2024-04-28 16:30:34

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 #ifndef SKGTREEMAP_H
0007 #define SKGTREEMAP_H
0008 /** @file
0009  * This file defines classes SKGTreeMap.
0010  *
0011  * @author Stephane MANKOWSKI
0012  */
0013 #include <qlist.h>
0014 #include <qmap.h>
0015 #include <qstring.h>
0016 
0017 #include "skgbasemodeler_export.h"
0018 
0019 /**
0020 * This class allows to compute a tree map
0021 */
0022 class SKGBASEMODELER_EXPORT SKGTreeMap
0023 {
0024 public:
0025     /**
0026     * Constructor
0027     * @param iID The ID of this tile
0028     * @param iValue The value (this attribute is only needed for leaves)
0029     * @param iX The x of the tile
0030     * @param iY The y of the tile
0031     * @param iW The width of the tile
0032     * @param iH The height of the tile
0033     */
0034     explicit SKGTreeMap(QString  iID = QLatin1String(""),
0035                         double iValue = 0.0,
0036                         double iX = 0.0,
0037                         double iY = 0.0,
0038                         double iW = 100.0,
0039                         double iH = 100.0);
0040 
0041     /**
0042     * Destructor
0043     */
0044     ~SKGTreeMap();
0045 
0046     /**
0047     * Add a child tile
0048     * @param iChildren The child tile
0049     */
0050     void addChild(const SKGTreeMap& iChildren);
0051 
0052     /**
0053     * Compute the tiles layout
0054     */
0055     void compute();
0056 
0057     /**
0058     * Get children tile
0059     * @return children tile
0060     */
0061     QList<SKGTreeMap> getChildren() const;
0062 
0063     /**
0064     * Get the ID of the tile
0065     * @return the ID of the tile
0066     */
0067     QString getID() const;
0068 
0069     /**
0070     * Get the value of the tile
0071     * @return value x of the tile
0072     */
0073     double getValue() const;
0074 
0075     /**
0076     * Set the x of the tile
0077     * @param iX The x of the tile
0078     */
0079     void setX(double iX);
0080 
0081     /**
0082     * Get the x of the tile
0083     * @return the x of the tile
0084     */
0085     double getX() const;
0086 
0087     /**
0088     * Set the y of the tile
0089     * @param iY The y of the tile
0090     */
0091     void setY(double iY);
0092 
0093     /**
0094     * Get the y of the tile
0095     * @return the y of the tile
0096     */
0097     double getY() const;
0098 
0099     /**
0100     * Set the width of the tile
0101     * @param iW The width of the tile
0102     */
0103     void setW(double iW);
0104 
0105     /**
0106     * Get the width of the tile
0107     * @return the width of the tile
0108     */
0109     double getW() const;
0110 
0111     /**
0112     * Set the height of the tile
0113     * @param iH The height of the tile
0114     */
0115     void setH(double iH);
0116 
0117     /**
0118     * Get the height of the tile
0119     * @return the height of the tile
0120     */
0121     double getH() const;
0122 
0123     /**
0124     * Get all tiles by ID
0125     * @return all tiles
0126     */
0127     QMap<QString, SKGTreeMap> getAllTilesById() const;
0128 
0129 private:
0130     QString m_id;
0131     double m_value;
0132     double m_x;
0133     double m_y;
0134     double m_w;
0135     double m_h;
0136 
0137     QList<SKGTreeMap> m_children;
0138 
0139     void computeValuesAndSort();
0140 };
0141 #endif  // SKGTREEMAP_H