File indexing completed on 2024-05-19 15:27:49

0001 /* This file is part of KGraphViewer.
0002    Copyright (C) 2005-2007 Gael de Chalendar <kleag@free.fr>
0003 
0004    KGraphViewer is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation, version 2.
0007 
0008    This program is distributed in the hope that it will be useful,
0009    but WITHOUT ANY WARRANTY; without even the implied warranty of
0010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011    General Public License for more details.
0012 
0013    You should have received a copy of the GNU General Public License
0014    along with this program; if not, write to the Free Software
0015    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0016    02110-1301, USA
0017 */
0018 
0019 /*
0020  * Subgraph model
0021  */
0022 
0023 #ifndef GRAPH_SUBGRAPH_H
0024 #define GRAPH_SUBGRAPH_H
0025 
0026 #include <QMap>
0027 #include <QTextStream>
0028 
0029 #include "dotgrammar.h"
0030 #include "dotrenderop.h"
0031 #include "graphelement.h"
0032 
0033 #include <graphviz/gvc.h>
0034 
0035 namespace KGraphViewer
0036 {
0037 class CanvasSubgraph;
0038 class GraphSubgraph;
0039 
0040 typedef QMap<QString, GraphSubgraph *> GraphSubgraphMap;
0041 
0042 /**
0043  * Colors and styles are DOT names
0044  */
0045 class GraphSubgraph : public GraphElement
0046 {
0047     Q_OBJECT
0048 public:
0049     GraphSubgraph();
0050     explicit GraphSubgraph(graph_t *sg);
0051 
0052     ~GraphSubgraph() override
0053     {
0054     }
0055 
0056     inline const GraphSubgraphMap &subgraphs() const
0057     {
0058         return m_subgraphsMap;
0059     }
0060     inline GraphSubgraphMap &subgraphs()
0061     {
0062         return m_subgraphsMap;
0063     }
0064 
0065     void updateWithSubgraph(const GraphSubgraph &subgraph);
0066     void updateWithSubgraph(graph_t *subgraph);
0067 
0068     CanvasSubgraph *canvasSubgraph()
0069     {
0070         return (CanvasSubgraph *)canvasElement();
0071     }
0072     void setCanvasSubgraph(CanvasSubgraph *cs)
0073     {
0074         setCanvasElement((CanvasElement *)cs);
0075     }
0076 
0077     QString backColor() const override;
0078 
0079     inline const QList<GraphElement *> &content() const
0080     {
0081         return m_content;
0082     }
0083     inline QList<GraphElement *> &content()
0084     {
0085         return m_content;
0086     }
0087     inline void setContent(QList<GraphElement *> &c)
0088     {
0089         m_content = c;
0090     }
0091 
0092     void removeElement(GraphElement *element);
0093 
0094     /// Recursively walk through this subgraph and its subsubgraphs to find an element named id
0095     /// @return the node found or 0 if there is no such node
0096     GraphElement *elementNamed(const QString &id);
0097 
0098     /// Recursively walk through this subgraph and its subsubgraphs to make
0099     /// the given element selected or not depending on the selectValue parameter
0100     /// and unselect other elements depending on the  unselect others parameter
0101     /// @return true if the given node was found
0102     virtual bool setElementSelected(GraphElement *element, bool selectValue, bool unselectOthers);
0103 
0104     void retrieveSelectedElementsIds(QList<QString> selection);
0105 
0106 private:
0107     QList<GraphElement *> m_content;
0108     GraphSubgraphMap m_subgraphsMap;
0109 };
0110 
0111 QTextStream &operator<<(QTextStream &stream, const GraphSubgraph &s);
0112 
0113 }
0114 
0115 #endif