[kgraphviewer-devel] [KGraphViewer/libkgraphviz] e88826e: Minimalize DotGraph interface, fixes view
Kevin Funk
krf at electrostorm.net
Tue Jan 11 17:45:55 CET 2011
commit e88826e484c1662fa4e0e8d3d4ae69e52ec6d677
branch libkgraphviz
Author: Kevin Funk <krf at electrostorm.net>
Date: Tue Jan 11 16:19:13 2011 +0100
Minimalize DotGraph interface, fixes view
* Drop method: setReadWrite() is redundant, use setReadOnly(bool) for this
* Fix view: Make items only movable if graph allows it
diff --git a/src/kgrapheditor.cpp b/src/kgrapheditor.cpp
index 32bde47..79ea0f1 100644
--- a/src/kgrapheditor.cpp
+++ b/src/kgrapheditor.cpp
@@ -169,7 +169,7 @@ DotGraphView* KGraphEditor::slotNewGraph()
kDebug();
DotGraphView* view = new DotGraphView(actionCollection(), m_widget);
view->initEmpty();
- view->setReadWrite();
+ view->setReadOnly(false);
m_widget-> insertTab(view, QIcon( DesktopIcon("kgraphviewer") ), "");
m_widget->setCurrentPage(m_widget->indexOf(view));
diff --git a/src/kgraphviz/canvaselement.cpp b/src/kgraphviz/canvaselement.cpp
index 610fcde..2f94482 100644
--- a/src/kgraphviz/canvaselement.cpp
+++ b/src/kgraphviz/canvaselement.cpp
@@ -204,7 +204,6 @@ void CanvasElement::initialize(qreal scaleX, qreal scaleY,
{
Q_D(CanvasElement);
kDebug();
- setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
d->m_scaleX = scaleX; d->m_scaleY = scaleY;
@@ -316,7 +315,7 @@ QWidget *widget)
}
// kDebug() << msg;
- if (element()->renderOperations().isEmpty() && d->m_view->isReadWrite())
+ if (element()->renderOperations().isEmpty() && !d->m_view->isReadOnly())
{
kError() << element()->id() << ": no render operation. This should not happen.";
return;
diff --git a/src/kgraphviz/dotgraph.cpp b/src/kgraphviz/dotgraph.cpp
index 9e8d352..64d05d2 100644
--- a/src/kgraphviz/dotgraph.cpp
+++ b/src/kgraphviz/dotgraph.cpp
@@ -283,18 +283,6 @@ void DotGraph::setUseLibrary(bool value)
d->m_useLibrary = value;
}
-void DotGraph::setReadWrite()
-{
- Q_D(DotGraph);
- d->m_readWrite = true;
-}
-
-void DotGraph::setReadOnly()
-{
- Q_D(DotGraph);
- d->m_readWrite = false;
-}
-
bool DotGraph::parseDot(const QString& fileName)
{
kDebug() << fileName;
diff --git a/src/kgraphviz/dotgraph.h b/src/kgraphviz/dotgraph.h
index 990f846..1183b45 100644
--- a/src/kgraphviz/dotgraph.h
+++ b/src/kgraphviz/dotgraph.h
@@ -90,9 +90,6 @@ public:
bool update();
- void setReadWrite();
- void setReadOnly();
-
virtual void storeOriginalAttributes();
void saveTo(const QString& fileName);
diff --git a/src/kgraphviz/dotgraphview.cpp b/src/kgraphviz/dotgraphview.cpp
index c16fab3..63e5233 100644
--- a/src/kgraphviz/dotgraphview.cpp
+++ b/src/kgraphviz/dotgraphview.cpp
@@ -100,7 +100,7 @@ DotGraphViewPrivate::DotGraphViewPrivate(KActionCollection* actions, DotGraphVie
m_editingMode(DotGraphView::None),
m_newEdgeSource(0),
m_newEdgeDraft(0),
- m_readWrite(false),
+ m_readOnly(true),
m_leavedTimer(std::numeric_limits<int>::max()),
m_highlighting(false),
m_loadThread(),
@@ -275,6 +275,7 @@ int DotGraphViewPrivate::displaySubgraph(GraphSubgraph* gsubgraph, int zValue, C
csubgraph->initialize(
scaleX, scaleY, m_xMargin, m_yMargin, gh,
m_graph->wdhcf(), m_graph->hdvcf());
+ csubgraph->setFlag(QGraphicsItem::ItemIsMovable, !q->isReadOnly());
gsubgraph->setCanvasElement(csubgraph);
// csubgraph->setZValue(gsubgraph->z());
csubgraph->setZValue(zValue+=2);
@@ -293,6 +294,7 @@ int DotGraphViewPrivate::displaySubgraph(GraphSubgraph* gsubgraph, int zValue, C
cnode->initialize(
scaleX, scaleY, m_xMargin, m_yMargin, gh,
m_graph->wdhcf(), m_graph->hdvcf());
+ cnode->setFlag(QGraphicsItem::ItemIsMovable, !q->isReadOnly());
gnode->setCanvasElement(cnode);
m_canvas->addItem(cnode);
// cnode->setZValue(gnode->z());
@@ -559,8 +561,21 @@ QPixmap DotGraphView::defaultNewElementPixmap() const {Q_D(const DotGraphView);
void DotGraphView::setDefaultNewElement(GraphElement* elem) {Q_D(DotGraphView); d->m_defaultNewElement = elem;}
void DotGraphView::setDefaultNewElementPixmap(const QPixmap& pm) {Q_D(DotGraphView); d->m_defaultNewElementPixmap = pm;}
-bool DotGraphView::isReadWrite() const {Q_D(const DotGraphView); return d->m_readWrite;}
-bool DotGraphView::isReadOnly() const {Q_D(const DotGraphView); return !d->m_readWrite;}
+bool DotGraphView::isReadOnly() const
+{
+ Q_D(const DotGraphView);
+ return d->m_readOnly;
+}
+void DotGraphView::setReadOnly(bool readOnly)
+{
+ Q_D(DotGraphView);
+ kDebug() << readOnly;
+ d->m_readOnly = readOnly;
+
+ foreach(QGraphicsItem* item, items()) {
+ item->setFlag(QGraphicsItem::ItemIsMovable, !readOnly);
+ }
+}
bool DotGraphView::highlighting() const {Q_D(const DotGraphView); return d->m_highlighting;}
void DotGraphView::setHighlighting(bool highlightingValue) {Q_D(DotGraphView); d->m_highlighting = highlightingValue;}
@@ -590,10 +605,6 @@ void DotGraphViewPrivate::setupCanvas()
delete m_graph;
m_graph = new DotGraph();
q->connect(m_graph,SIGNAL(readyToDisplay()),q,SLOT(displayGraph()));
-
- if (m_readWrite) {
- m_graph->setReadWrite();
- }
// kDebug() << "Parsing " << m_graph->dotFileName() << " with " << m_graph->layoutCommand();
m_xMargin = 50;
@@ -724,6 +735,7 @@ bool DotGraphView::displayGraph()
cnode->initialize(
scaleX, scaleY, d->m_xMargin, d->m_yMargin, gh,
d->m_graph->wdhcf(), d->m_graph->hdvcf());
+ cnode->setFlag(QGraphicsItem::ItemIsMovable, !isReadOnly());
gnode->setCanvasElement(cnode);
d->m_canvas->addItem(cnode);
// cnode->setZValue(gnode->z());
@@ -752,7 +764,7 @@ bool DotGraphView::displayGraph()
cedge->initialize(scaleX, scaleY,
d->m_xMargin, d->m_yMargin, gh,
d->m_graph->wdhcf(), d->m_graph->hdvcf());
-
+ cedge->setFlag(QGraphicsItem::ItemIsMovable, !isReadOnly());
gedge->setCanvasElement(cedge);
// std::cerr << "setting z = " << gedge->z() << std::endl;
// cedge->setZValue(gedge->z());
@@ -1541,28 +1553,6 @@ void DotGraphView::finishNewEdgeTo(CanvasElement* node)
// emit newEdgeAdded(gedge->fromNode()->id(),gedge->toNode()->id());
// }
-void DotGraphView::setReadOnly()
-{
- Q_D(DotGraphView);
- kDebug() ;
- d-> m_readWrite = false;
- if (d->m_graph != 0)
- {
- d->m_graph->setReadOnly();
- }
-}
-
-void DotGraphView::setReadWrite()
-{
- Q_D(DotGraphView);
- kDebug() ;
- d->m_readWrite = true;
- if (d->m_graph != 0)
- {
- d->m_graph->setReadWrite();
- }
-}
-
void DotGraphView::slotElementSelected(CanvasElement* element, Qt::KeyboardModifiers modifiers)
{
Q_D(DotGraphView);
diff --git a/src/kgraphviz/dotgraphview.h b/src/kgraphviz/dotgraphview.h
index b85dc04..24bfb71 100644
--- a/src/kgraphviz/dotgraphview.h
+++ b/src/kgraphviz/dotgraphview.h
@@ -101,9 +101,7 @@ public:
EditingMode editingMode() const;
- void setReadOnly();
- void setReadWrite();
- bool isReadWrite() const;
+ void setReadOnly(bool readOnly = true);
bool isReadOnly() const;
void removeSelectedNodes();
diff --git a/src/kgraphviz/dotgraphview_p.h b/src/kgraphviz/dotgraphview_p.h
index 5f53f70..4874cf5 100644
--- a/src/kgraphviz/dotgraphview_p.h
+++ b/src/kgraphviz/dotgraphview_p.h
@@ -93,7 +93,7 @@ public:
CanvasElement* m_newEdgeSource;
QGraphicsLineItem* m_newEdgeDraft;
- bool m_readWrite;
+ bool m_readOnly;
QMap<QString, QString> m_newElementAttributes;
diff --git a/src/part/kgraphviewer_part.cpp b/src/part/kgraphviewer_part.cpp
index bcaf732..190e016 100644
--- a/src/part/kgraphviewer_part.cpp
+++ b/src/part/kgraphviewer_part.cpp
@@ -278,12 +278,12 @@ void KGraphViewerPart::prepareAddNewEdge(QMap<QString,QString> attribs)
void KGraphViewerPart::setReadOnly()
{
- d->m_widget->setReadOnly();
+ d->m_widget->setReadOnly(true);
}
void KGraphViewerPart::setReadWrite()
{
- d->m_widget->setReadWrite();
+ d->m_widget->setReadOnly(false);
}
void KGraphViewerPart::saveTo(const QString& fileName)
More information about the kgraphviewer-devel
mailing list