File indexing completed on 2024-05-12 05:39:49

0001 /***************************************************************************
0002  *  Copyright (C) 2009 by Renaud Guezennec                             *
0003  *   https://rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   Rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #ifndef RESSOURCESNODE_H
0021 #define RESSOURCESNODE_H
0022 
0023 #include "network_global.h"
0024 #include <QIcon>
0025 #include <QString>
0026 #include <QVariant>
0027 /**
0028  * @brief RessourceNode is part of the composite design pattern, it's the abstract class
0029  * @brief providing the basic API for ressources, Shortname and has children.
0030  */
0031 
0032 class NETWORK_EXPORT ResourcesNode : public QObject
0033 {
0034     Q_OBJECT
0035     Q_PROPERTY(QString uuid READ uuid WRITE setUuid NOTIFY uuidChanged)
0036     Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
0037     Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged)
0038     Q_PROPERTY(bool hasChildren READ hasChildren NOTIFY hasChildrenChanged)
0039     Q_PROPERTY(int childrenCount READ childrenCount NOTIFY childrenCountChanged)
0040     Q_PROPERTY(TypeResource resourcesType READ type CONSTANT)
0041     Q_PROPERTY(QIcon icon READ icon CONSTANT)
0042     Q_PROPERTY(ResourcesNode* parentNode READ parentNode WRITE setParentNode NOTIFY parentNodeChanged)
0043 public:
0044     enum DataValue
0045     {
0046         NAME,
0047         MODE,
0048         DISPLAYED,
0049         URI
0050     };
0051     Q_ENUM(DataValue)
0052 
0053     enum TypeResource
0054     {
0055         Cleveruri,
0056         Person,
0057         Chapter
0058     };
0059     Q_ENUM(TypeResource)
0060 
0061     ResourcesNode(TypeResource type, const QString& uuid= QString());
0062     virtual ~ResourcesNode();
0063 
0064     QString uuid() const;
0065     virtual void setUuid(const QString& uuid);
0066 
0067     QString name() const;
0068     virtual void setName(const QString& name);
0069 
0070     ResourcesNode* parentNode() const;
0071 
0072     virtual QString value() const;
0073     virtual void setValue(QString);
0074 
0075     virtual bool hasChildren() const;
0076     virtual bool isLeaf() const;
0077     virtual int childrenCount() const;
0078     virtual QIcon icon() const;
0079     virtual ResourcesNode::TypeResource type() const;
0080     virtual QVariant getData(ResourcesNode::DataValue) const= 0;
0081 
0082     virtual ResourcesNode* getChildAt(int) const;
0083     virtual bool contains(const QString& id);
0084     virtual int indexOf(ResourcesNode*) const;
0085     virtual bool removeChild(ResourcesNode*);
0086     virtual void insertChildAt(int row, ResourcesNode*);
0087     int rowInParent();
0088 
0089     virtual ResourcesNode* findNode(const QString& id);
0090 
0091 public slots:
0092     void setParentNode(ResourcesNode* parent);
0093 
0094 signals:
0095     void uuidChanged(QString id);
0096     void nameChanged();
0097     void valueChanged();
0098     void hasChildrenChanged();
0099     void childrenCountChanged();
0100     void parentNodeChanged();
0101 
0102 protected:
0103     QString m_uuid;
0104     QString m_name;
0105     QString m_value;
0106     ResourcesNode* m_parent= nullptr;
0107     TypeResource m_type;
0108 };
0109 
0110 #endif // RESSOURCESNODE_H