1 // interface.h
2 // Copyright (C)  2002  Dominique Devriese <devriese@kde.org>
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301  USA
18 
19 #ifndef KGRAPHVIEWER_INTERFACE_H
20 #define KGRAPHVIEWER_INTERFACE_H
21 
22 #include <QObject>
23 #include <QMap>
24 
25 namespace KParts
26 {
27   class Part;
28 }
29 class QCursor;
30 
31 extern "C" {
32     typedef struct Agraph_s graph_t;
33 }
34 
35 
36 namespace KGraphViewer
37 {
38 /**
39  * KGraphViewerInterface is an interface implemented by KGraphViewer to
40  * allow developers access to the KGraphViewerPart in ways that are not
41  * possible through the normal KPart interface.
42  *
43  * Note that besides the functions below here, KGraphViewer also has
44  * some signals you can connect to.  They aren't in this class cause
45  * we can't have signals without having a QObject, which
46  * KGraphViewerInterface is not. To see a list of signals, take a look at kgraphviewer_part.h
47  *
48  * See the example code below for how to connect to these..
49  *
50  * Use it like this:
51  * \code
52  *  // fetch the Part..
53  *  KPluginFactory *factory = KPluginLoader("kgraphviewerpart").factory();
54  *  if (factory) {
55  *      KParts::ReadOnlyPart* part = factory->create<KParts::ReadOnlyPart>(this);
56  *
57  *      // cast the part to the KGraphViewerInterface...
58  *      KGraphViewerInterface* graph = qobject_cast<KGraphViewerInterface*>( part );
59  *      if( ! graph )
60  *      {
61  *        // This should not happen
62  *        return;
63  *      }
64  *      // now use the interface in all sorts of ways...
65  *  }
66  * \endcode
67  *
68  * @author Milian Wolff <mail@milianw.de>
69  *
70  *
71  * WARNING: This is highly experimental and no kind of BC guarantees are given!
72  * TODO: documentation
73  */
74 class KGraphViewerInterface
75 {
76 public:
77   enum LayoutMethod
78   {
79     ExternalProgram,
80     InternalLibrary
81   };
82 
83   virtual void setLayoutMethod(LayoutMethod method) = 0;
84   virtual void zoomIn() = 0;
85   virtual void zoomOut() = 0;
86   virtual void zoomBy(double factor) = 0;
87   virtual void setZoomFactor(double factor) = 0;
88 
89   enum PannerPosition { TopLeft, TopRight, BottomLeft, BottomRight, Auto };
90   virtual void setPannerPosition(PannerPosition position) = 0;
91   virtual void setPannerEnabled(bool enabled) = 0;
92 
93   virtual void setLayoutCommand(const QString& command) = 0;
94 
95   virtual void selectNode(const QString& nodeId) = 0;
96   virtual void centerOnNode(const QString& nodeId) = 0;
97 
98   // Slots
99   virtual void slotHide(KParts::Part* part) = 0;
100   virtual void slotUpdate() = 0;
101   virtual void prepareAddNewElement(const QMap<QString,QString>& attribs) = 0;
102   virtual void prepareAddNewEdge(const QMap<QString,QString>& attribs) = 0;
103   virtual void setReadOnly() = 0;
104   virtual void setReadWrite() = 0;
105   virtual void saveTo(const QString& fileName) = 0;
106   virtual void slotRemoveNode(const QString&) = 0;
107   virtual void slotRemoveNodeFromSubgraph(const QString& nodeName, const QString& subgraphName) = 0;
108   virtual void slotRemoveSubgraph(const QString&) = 0;
109   virtual void slotAddAttribute(const QString&) = 0;
110   virtual void slotSetAttribute(const QString& elementId, const QString& attributeName, const QString& attributeValue) = 0;
111   virtual void slotRemoveAttribute(const QString&,const QString&) = 0;
112   virtual void slotSetGraphAttributes(const QMap<QString,QString>& attribs) = 0;
113   virtual void slotAddNewNode(const QMap<QString,QString>& attribs) = 0;
114   virtual void slotAddNewNodeToSubgraph(const QMap<QString,QString>& attribs, const QString& subgraph) = 0;
115   virtual void slotAddExistingNodeToSubgraph(const QMap<QString,QString>& attribs, const QString& subgraph) = 0;
116   virtual void slotMoveExistingNodeToMainGraph(const QMap<QString,QString>& attribs) = 0;
117   virtual void slotAddNewSubgraph(const QMap<QString,QString>& attribs) = 0;
118   virtual void slotAddNewEdge(const QString& src, const QString& tgt, const QMap<QString,QString>& attribs) = 0;
119   virtual void slotRemoveEdge(const QString& id) = 0;
120   virtual void slotRemoveElement(const QString& id) = 0;
121   virtual void slotSelectNode(const QString&) = 0;
122   virtual void slotSetHighlighting(bool highlightingValue) = 0;
123   virtual void slotPrepareToSelect() = 0;
124   virtual void slotSetCursor(const QCursor& cursor) = 0;
125   virtual void slotUnsetCursor() = 0;
126   virtual void slotSetLayoutMethod(LayoutMethod method) = 0;
127   virtual void slotRenameNode(const QString& oldName, const QString& newName) = 0;
128   virtual bool slotLoadLibrary(graph_t* graph) = 0;
129   virtual void setBackgroundColor(const QColor& color) = 0;
130 
131 
132 protected:
KGraphViewerInterface()133   KGraphViewerInterface() {}
~KGraphViewerInterface()134   virtual ~KGraphViewerInterface() {}
135 };
136 
137 }
138 
139 Q_DECLARE_INTERFACE(KGraphViewer::KGraphViewerInterface, "org.kde.KGraphViewerInterface")
140 
141 #endif // KGRAPHVIEWER_INTERFACE_H
142