[kgraphviewer-devel] [KGraphViewer/libkgraphviz] 3b5cf3c: Add DotGraphScene for debugging purposes
Kevin Funk
krf at electrostorm.net
Thu Jan 13 17:29:45 CET 2011
A src/kgraphviz/dotgraphscene.h [License: UNKNOWN]
A src/kgraphviz/dotgraphscene.cpp [License: UNKNOWN]
commit 3b5cf3c1436c76c62477a44d253b0fa5dda04589
Author: Kevin Funk <krf at electrostorm.net>
Date: Thu Jan 13 10:42:03 2011 +0100
Add DotGraphScene for debugging purposes
Adds all bounding rects of items, scene, and items' bounding rect to
scene in debugging mode.
diff --git a/src/kgraphviz/CMakeLists.txt b/src/kgraphviz/CMakeLists.txt
index 490dd31..b052d8a 100644
--- a/src/kgraphviz/CMakeLists.txt
+++ b/src/kgraphviz/CMakeLists.txt
@@ -18,7 +18,7 @@ link_directories(
${LIB_INSTALL_DIR}
)
-set(kgraphvz_LIB_SRCS
+set(kgraphviz_LIB_SRCS
canvasedge.cpp
canvaselement.cpp
canvasnode.cpp
@@ -32,6 +32,7 @@ set(kgraphvz_LIB_SRCS
graphsubgraph.cpp
dotgraph.cpp
+ dotgraphscene.cpp
dotgraphview.cpp
pannerview.cpp
@@ -43,7 +44,7 @@ set(kgraphvz_LIB_SRCS
support/fontscache.cpp
)
-kde4_add_library(kgraphviz SHARED ${kgraphvz_LIB_SRCS})
+kde4_add_library(kgraphviz SHARED ${kgraphviz_LIB_SRCS})
add_definitions(-DQT_STL)
target_link_libraries(kgraphviz ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDEUI_LIBRARY} ${KDE4_KFILE_LIBRARY} ${KDE4_KDECORE_LIBRARY} ${graphviz_LIBRARIES})
diff --git a/src/kgraphviz/canvaselement.cpp b/src/kgraphviz/canvaselement.cpp
index a398889..ced23fb 100644
--- a/src/kgraphviz/canvaselement.cpp
+++ b/src/kgraphviz/canvaselement.cpp
@@ -574,13 +574,6 @@ void CanvasElement::paint(QPainter* p,
p->drawRect(QRectF(d->m_boundingRect.bottomRight()-QPointF(6,6),QSizeF(6,6)));
p->restore();
}
-
-#ifdef KGRAPHVIZ_GRAPHICSVIEW_DEBUG
- p->save();
- p->setPen(Qt::red);
- p->drawRect(boundingRect());
- p->restore();
-#endif
}
void CanvasElement::mousePressEvent(QGraphicsSceneMouseEvent* event)
diff --git a/src/kgraphviz/dotgraphscene.cpp b/src/kgraphviz/dotgraphscene.cpp
new file mode 100644
index 0000000..7d8b47f
--- /dev/null
+++ b/src/kgraphviz/dotgraphscene.cpp
@@ -0,0 +1,70 @@
+/*
+ Copyright (C) 2010 Kevin Funk <krf at electrostorm.net>
+
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include "dotgraphscene.h"
+
+#include "canvasedge.h"
+#include "canvasnode.h"
+
+#include <KDebug>
+
+#include <QPainter>
+#include <QGraphicsItem>
+
+using namespace KGraphViz;
+
+DotGraphScene::DotGraphScene(QObject* parent)
+ : QGraphicsScene(parent)
+{
+ kDebug();
+}
+
+DotGraphScene::~DotGraphScene()
+{
+ kDebug();
+}
+
+
+void DotGraphScene::drawForeground(QPainter* painter, const QRectF& rect)
+{
+#ifdef KGRAPHVIZ_GRAPHICSVIEW_DEBUG
+ painter->save();
+
+ foreach(const QGraphicsItem* item, items()) {
+ if (dynamic_cast<const CanvasNode*>(item))
+ painter->setPen(Qt::red);
+ else if (dynamic_cast<const CanvasEdge*>(item))
+ painter->setPen(Qt::green);
+ else
+ painter->setPen(Qt::yellow);
+
+ painter->drawRect(item->boundingRect());
+ }
+
+ painter->setPen(QPen(Qt::magenta, 1, Qt::DashLine));
+ painter->drawRect(itemsBoundingRect());
+
+ painter->setPen(QPen(Qt::blue, 1, Qt::DashLine));
+ painter->drawRect(sceneRect());
+
+ painter->restore();
+#endif
+
+ QGraphicsScene::drawForeground(painter, rect);
+}
\ No newline at end of file
diff --git a/src/kgraphviz/dotgraphscene.h b/src/kgraphviz/dotgraphscene.h
new file mode 100644
index 0000000..95e0a2d
--- /dev/null
+++ b/src/kgraphviz/dotgraphscene.h
@@ -0,0 +1,39 @@
+/*
+ Copyright (C) 2010 Kevin Funk <krf at electrostorm.net>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef DOTGRAPHSCENE_H
+#define DOTGRAPHSCENE_H
+
+#include <QGraphicsScene>
+
+namespace KGraphViz
+{
+
+class DotGraphScene : public QGraphicsScene
+{
+public:
+ explicit DotGraphScene(QObject* parent = 0);
+ virtual ~DotGraphScene();
+
+protected:
+ virtual void drawForeground(QPainter* painter, const QRectF& rect);
+};
+
+}
+
+#endif // DOTGRAPHSCENE_H
diff --git a/src/kgraphviz/dotgraphview.cpp b/src/kgraphviz/dotgraphview.cpp
index fc6bfd7..4412dfc 100644
--- a/src/kgraphviz/dotgraphview.cpp
+++ b/src/kgraphviz/dotgraphview.cpp
@@ -28,6 +28,7 @@
#include "dotgraphview_p.h"
#include "dotgraph.h"
+#include "dotgraphscene.h"
#include "graphelement.h"
#include "graphio.h"
#include "canvassubgraph.h"
@@ -617,7 +618,7 @@ void DotGraphViewPrivate::setupCanvas()
m_xMargin = 50;
m_yMargin = 50;
- QGraphicsScene* newCanvas = new QGraphicsScene(q);
+ QGraphicsScene* newCanvas = new DotGraphScene(q);
// add text item
m_textItem = newCanvas->addSimpleText(i18n("No graph loaded."));
More information about the kgraphviewer-devel
mailing list