File indexing completed on 2024-06-02 05:46:51
0001 /*************************************************************************** 0002 * Copyright (C) 2019 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * This software 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 BOXMODEL_H 0021 #define BOXMODEL_H 0022 0023 #include <QAbstractListModel> 0024 0025 #include "mindmap/mindmap_global.h" 0026 namespace mindmap 0027 { 0028 class MindNode; 0029 class LinkModel; 0030 class Link; 0031 class MINDMAP_EXPORT BoxModel : public QAbstractItemModel 0032 { 0033 Q_OBJECT 0034 Q_PROPERTY(QAbstractItemModel* linkModel READ linkModel WRITE setLinkModel NOTIFY linkModelChanged) 0035 Q_PROPERTY(int defaultStyleIndex READ defaultStyleIndex WRITE setDefaultStyleIndex NOTIFY defaultStyleIndexChanged) 0036 Q_PROPERTY(qreal nodeWidth READ nodeWidth NOTIFY nodeWidthChanged) 0037 Q_PROPERTY(qreal nodeHeight READ nodeHeight NOTIFY nodeHeightChanged) 0038 public: 0039 enum Roles : int 0040 { 0041 // Curves 0042 Label= Qt::UserRole + 1, 0043 Color, 0044 ContentWidth, 0045 ContentHeight, 0046 Position, 0047 Node, 0048 Posx, 0049 Posy, 0050 ImageUri 0051 }; 0052 explicit BoxModel(QObject* parent= nullptr); 0053 ~BoxModel() override; 0054 0055 // Basic functionality: 0056 int rowCount(const QModelIndex& parent= QModelIndex()) const override; 0057 int columnCount(const QModelIndex& parent= QModelIndex()) const override; 0058 QModelIndex parent(const QModelIndex&) const override; 0059 QVariant data(const QModelIndex& index, int role= Qt::DisplayRole) const override; 0060 0061 // Editable: 0062 bool setData(const QModelIndex& index, const QVariant& value, int role= Qt::EditRole) override; 0063 QModelIndex index(int row, int column, const QModelIndex& parent) const override; 0064 0065 QHash<int, QByteArray> roleNames() const override; 0066 QAbstractItemModel* linkModel() const; 0067 void setLinkModel(QAbstractItemModel* linkModel); 0068 Qt::ItemFlags flags(const QModelIndex& index) const override; 0069 0070 std::vector<MindNode*>& nodes(); 0071 0072 void clear(); 0073 void appendNode(const QList<MindNode*>& nodes, bool network= false); 0074 MindNode* nodeFromId(const QString& id) const; 0075 int defaultStyleIndex() const; 0076 0077 qreal nodeWidth() const; 0078 qreal nodeHeight() const; 0079 0080 signals: 0081 void linkModelChanged(); 0082 void defaultStyleIndexChanged(); 0083 void nodeHeightChanged(); 0084 void nodeWidthChanged(); 0085 // void nodeAdded(QList<MindNode*> nodes); 0086 // void nodeRemoved(const QStringList& id); 0087 0088 public slots: 0089 // Add data: 0090 std::pair<MindNode*, Link*> addBox(const QString& idparent); 0091 void setImageUriToNode(const QString& id, const QString& url); 0092 0093 // Remove data: 0094 bool removeBox(const QStringList& id, bool network= false); 0095 void openNode(const QString& id, bool status); 0096 void setDefaultStyleIndex(int indx); 0097 0098 private: 0099 void setNodeWidth(qreal w); 0100 void setNodeHeight(qreal h); 0101 void computeContentSize(const MindNode* newNode); 0102 void preventSamePositionForParentAndChild(); 0103 0104 private: 0105 std::vector<MindNode*> m_data; 0106 LinkModel* m_linkModel= nullptr; 0107 int m_defaultStyleIndex= 0; 0108 qreal m_nodeWidth= 0.; 0109 qreal m_nodeHeight= 0.; 0110 }; 0111 } // namespace mindmap 0112 #endif // BOXMODEL_H