File indexing completed on 2024-05-19 15:27:50
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 #ifndef _KGRAPHVIEWERPART_H_ 0020 #define _KGRAPHVIEWERPART_H_ 0021 0022 #include <KParts/ReadOnlyPart> 0023 #include <KPluginFactory> 0024 #include <kparts/part.h> 0025 #include <kparts_version.h> 0026 0027 #include "kgraphviewer_interface.h" 0028 0029 class QWidget; 0030 0031 namespace KGraphViewer 0032 { 0033 class DotGraph; 0034 0035 class KGraphViewerPartPrivate; 0036 0037 /** 0038 * This is a "Part". It that does all the real work in a KPart 0039 * application. 0040 * 0041 * @short Main Part 0042 * @author Gael de Chalendar <kleag@free.fr> 0043 */ 0044 class KGraphViewerPart : public KParts::ReadOnlyPart, public KGraphViewerInterface 0045 { 0046 Q_OBJECT 0047 Q_INTERFACES(KGraphViewer::KGraphViewerInterface) 0048 0049 // BEGIN: KGraphViewerInterface 0050 public: 0051 void setLayoutMethod(LayoutMethod method) override; 0052 void centerOnNode(const QString &nodeId) override; 0053 void selectNode(const QString &nodeId) override; 0054 void setLayoutCommand(const QString &command) override; 0055 void setPannerPosition(PannerPosition position) override; 0056 void setPannerEnabled(bool enabled) override; 0057 void zoomBy(double factor) override; 0058 void setZoomFactor(double factor) override; 0059 void zoomIn() override; 0060 void zoomOut() override; 0061 void setBackgroundColor(const QColor &color) override; 0062 0063 public: 0064 /** 0065 * Default constructor 0066 */ 0067 KGraphViewerPart(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &); 0068 0069 /** 0070 * Destructor 0071 */ 0072 ~KGraphViewerPart() override; 0073 0074 Q_SIGNALS: 0075 void graphLoaded(); 0076 void newNodeAdded(const QString &); 0077 void newEdgeAdded(const QString &, const QString &); 0078 /** signals that the user has activated a remove edge command */ 0079 void removeEdge(const QString &); 0080 /** signals that the user has activated a remove element command */ 0081 void removeElement(const QString &); 0082 void selectionIs(const QList<QString>, const QPoint &); 0083 void contextMenuEvent(const QString &, const QPoint &); 0084 /** let the application tweak the created edge if necessary */ 0085 void newEdgeFinished(const QString &, const QString &, const QMap<QString, QString> &); 0086 /// emitted when the mouse enters a node, a subgraph or an edge. The parameter is the hovered element id 0087 void hoverEnter(const QString &); 0088 /// emitted when the mouse leaves a node, a subgraph or an edge. The parameter is the hovered element id 0089 void hoverLeave(const QString &); 0090 0091 public Q_SLOTS: 0092 void slotHide(KParts::Part *part) override; 0093 void slotUpdate() override; 0094 void prepareAddNewElement(const QMap<QString, QString> &attribs) override; 0095 void prepareAddNewEdge(const QMap<QString, QString> &attribs) override; 0096 void setReadOnly() override; 0097 void setReadWrite() override; 0098 void saveTo(const QString &fileName) override; 0099 void slotRemoveNode(const QString &) override; 0100 void slotRemoveNodeFromSubgraph(const QString &nodeName, const QString &subgraphName) override; 0101 void slotRemoveSubgraph(const QString &) override; 0102 void slotAddAttribute(const QString &) override; 0103 void slotSetAttribute(const QString &elementId, const QString &attributeName, const QString &attributeValue) override; 0104 void slotRemoveAttribute(const QString &, const QString &) override; 0105 void slotSetGraphAttributes(const QMap<QString, QString> &attribs) override; 0106 void slotAddNewNode(const QMap<QString, QString> &attribs) override; 0107 void slotAddNewNodeToSubgraph(const QMap<QString, QString> &attribs, const QString &subgraph) override; 0108 void slotAddExistingNodeToSubgraph(const QMap<QString, QString> &attribs, const QString &subgraph) override; 0109 void slotMoveExistingNodeToMainGraph(const QMap<QString, QString> &attribs) override; 0110 void slotAddNewSubgraph(const QMap<QString, QString> &attribs) override; 0111 void slotAddNewEdge(const QString &src, const QString &tgt, const QMap<QString, QString> &attribs) override; 0112 void slotRemoveEdge(const QString &id) override; 0113 void slotRemoveElement(const QString &id) override; 0114 void slotSelectNode(const QString &) override; 0115 void slotSetHighlighting(bool highlightingValue) override; 0116 void slotPrepareToSelect() override; 0117 void slotSetCursor(const QCursor &cursor) override; 0118 void slotUnsetCursor() override; 0119 bool closeUrl() override; 0120 bool slotLoadLibrary(graph_t *graph) override; 0121 void slotSetLayoutMethod(LayoutMethod method) override; 0122 void slotRenameNode(const QString &oldNodeName, const QString &newNodeName) override; 0123 0124 /* inline DotGraph* graph() {return m_widget->graph();} 0125 inline const DotGraph* graph() const {return m_widget->graph();}*/ 0126 0127 public: 0128 /** 0129 * Return custom compnentName for KXMLGUIClient, as by history not the plugin id is used 0130 */ 0131 QString componentName() const override; 0132 0133 protected: 0134 /** 0135 * This must be implemented by each part. Use openUrl to open a file 0136 */ 0137 bool openFile() override; 0138 0139 private: 0140 KGraphViewerPartPrivate *const d; 0141 }; 0142 0143 } 0144 #endif // _KGRAPHVIEWERPART_H_