[kgraphviewer-devel] [KGraphViewer/libkgraphviz] f530ef4: Remove most of the code that got merged to GraphIO
Kevin Funk
krf at electrostorm.net
Tue Dec 14 18:13:30 CET 2010
commit f530ef40304abbb74ed6c2b13fdecda286366d01
branch libkgraphviz
Author: Kevin Funk <krf at electrostorm.net>
Date: Tue Dec 14 16:47:13 2010 +0100
Remove most of the code that got merged to GraphIO
diff --git a/src/kgraphviz/dotgraph.cpp b/src/kgraphviz/dotgraph.cpp
index eac87e9..ce35504 100644
--- a/src/kgraphviz/dotgraph.cpp
+++ b/src/kgraphviz/dotgraph.cpp
@@ -53,13 +53,27 @@ using namespace boost::spirit::classic;
extern KGraphViz::DotGraphParsingHelper* phelper;
-namespace KGraphViz
-{
+using namespace KGraphViz;
const distinct_parser<> keyword_p("0-9a-zA-Z_");
+DotGraphPrivate::DotGraphPrivate()
+{
+}
+
+DotGraphPrivate::~DotGraphPrivate()
+{
+}
+
+void DotGraphPrivate::init()
+{
+ Q_Q(DotGraph);
+ q->connect(&m_graphIO, SIGNAL(finished()), q, SIGNAL(readyToDisplay()));
+}
+
DotGraph::DotGraph() :
GraphElement(),
+ d_ptr(new DotGraphPrivate),
m_dotFileName(""),m_width(0.0), m_height(0.0),m_scale(1.0),
m_directed(true),m_strict(false),
m_layoutCommand(""),
@@ -75,6 +89,7 @@ DotGraph::DotGraph() :
DotGraph::DotGraph(const QString& command, const QString& fileName) :
GraphElement(),
+ d_ptr(new DotGraphPrivate),
m_dotFileName(fileName),m_width(0.0), m_height(0.0),m_scale(1.0),
m_directed(true),m_strict(false),
m_layoutCommand(command),
@@ -103,73 +118,18 @@ DotGraph::~DotGraph()
{
delete (*ite);
}
-}
-QString DotGraph::chooseLayoutProgramForFile(const QString& str)
-{
- QFile iFILE(str);
-
- if (!iFILE.open(QIODevice::ReadOnly))
- {
- kError() << "Can't test dot file. Will try to use the dot command on the file: '" << str << "'" << endl;
- return "dot";// -Txdot";
- }
-
- QByteArray fileContent = iFILE.readAll();
- if (fileContent.isEmpty()) return "";
- std::string s = fileContent.data();
- std::string cmd = "dot";
- parse(s.c_str(),
- (
- !(keyword_p("strict")) >> (keyword_p("graph")[assign_a(cmd,"neato")])
- ), (space_p|comment_p("/*", "*/")) );
-
- return QString::fromStdString(cmd);// + " -Txdot" ;
+ delete d_ptr;
}
-bool DotGraph::parseDot(const QString& str)
+bool DotGraph::parseDot(const QString& fileName)
{
- kDebug() << str;
- m_useLibrary = false;
- if (m_layoutCommand.isEmpty())
- {
- m_layoutCommand = chooseLayoutProgramForFile(str);
- if (m_layoutCommand.isEmpty())
- {
- m_layoutCommand = chooseLayoutProgramForFile(str);
- return false;
- }
- }
+ kDebug() << fileName;
+
+ Q_D(DotGraph);
+ d->m_graphIO.loadFromDotFile(fileName);
- kDebug() << "Running " << m_layoutCommand << str;
- QStringList options;
- /// @TODO handle the non-dot commands that could don't know the -T option
-// if (m_readWrite && m_phase == Initial)
-// {
-// options << "-Tdot";
-// }
-// else
-// {
- options << "-Txdot";
-// }
- options << str;
-
- kDebug() << "m_dot is " << m_dot << ". Acquiring mutex";
- QMutexLocker locker(&m_dotProcessMutex);
- kDebug() << "mutex acquired ";
- if (m_dot != 0)
- {
- disconnect(m_dot,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotDotRunningDone(int,QProcess::ExitStatus)));
- disconnect(m_dot,SIGNAL(error(QProcess::ProcessError)),this,SLOT(slotDotRunningError(QProcess::ProcessError)));
- m_dot->kill();
- delete m_dot;
- }
- m_dot = new QProcess();
- connect(m_dot,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotDotRunningDone(int,QProcess::ExitStatus)));
- connect(m_dot,SIGNAL(error(QProcess::ProcessError)),this,SLOT(slotDotRunningError(QProcess::ProcessError)));
- m_dot->start(m_layoutCommand, options);
- kDebug() << "process started";
- return true;
+ return true;
}
bool DotGraph::update()
@@ -199,107 +159,6 @@ bool DotGraph::update()
}
}
-QByteArray DotGraph::getDotResult(int , QProcess::ExitStatus )
-{
- kDebug();
-
- QMutexLocker locker(&m_dotProcessMutex);
- if (m_dot == 0)
- {
- return QByteArray();
- }
- QByteArray result = m_dot->readAll();
- delete m_dot;
- m_dot = 0;
- return result;
-}
-
-void DotGraph::slotDotRunningDone(int exitCode, QProcess::ExitStatus exitStatus)
-{
- kDebug();
-
- QByteArray result = getDotResult(exitCode, exitStatus);
- result.replace("\\\n","");
-
- kDebug() << "string content is:" << endl << result << endl << "=====================" << result.size();
- std::string s = result.data();
- // std::cerr << "stdstring content is:" << std::endl << s << std::endl << "===================== " << s.size() << std::endl;
- if (phelper != 0)
- {
- phelper->graph = 0;
- delete phelper;
- }
-// if (parsingResult)
-// {
-// if (m_readWrite)
-// {
-// storeOriginalAttributes();
-// update();
-// }
-// computeCells();
-// }
-
- DotGraph newGraph(m_layoutCommand, m_dotFileName);
- phelper = new DotGraphParsingHelper;
- phelper->graph = &newGraph;
- phelper->z = 1;
- phelper->maxZ = 1;
- phelper->uniq = 0;
-
- kDebug() << "parsing new dot";
- bool parsingResult = parse(s);
- delete phelper;
- phelper = 0;
- kDebug() << "phelper deleted";
-
- if (parsingResult)
- {
- kDebug() << "calling updateWithGraph";
- updateWithGraph(newGraph);
- }
- else
- {
- kDebug() << "parsing failed";
- kError() << "parsing failed";
- }
-// return parsingResult;
-// if (m_readWrite && m_phase == Initial)
-// {
-// m_phase = Final;
-// update();
-// }
-// else
-// {
- kDebug() << "emiting readyToDisplay";
- emit(readyToDisplay());
-// }
-}
-
-void DotGraph::slotDotRunningError(QProcess::ProcessError error)
-{
- kError() << "DotGraph::slotDotRunningError" << error;
- switch (error)
- {
- case QProcess::FailedToStart:
- KMessageBox::error(0, i18n("Unable to start %1.", m_layoutCommand),i18n("Layout process failed"),KMessageBox::Notify);
- break;
- case QProcess::Crashed:
- KMessageBox::error(0, i18n("%1 crashed.", m_layoutCommand),i18n("Layout process failed"),KMessageBox::Notify);
- break;
- case QProcess::Timedout:
- KMessageBox::error(0, i18n("%1 timed out.", m_layoutCommand),i18n("Layout process failed"),KMessageBox::Notify);
- break;
- case QProcess::WriteError:
- KMessageBox::error(0, i18n("Was not able to write data to the %1 process.", m_layoutCommand),i18n("Layout process failed"),KMessageBox::Notify);
- break;
- case QProcess::ReadError:
- KMessageBox::error(0, i18n("Was not able to read data from the %1 process.", m_layoutCommand),i18n("Layout process failed"),KMessageBox::Notify);
- break;
- default:
- KMessageBox::error(0, i18n("Unknown error running %1.", m_layoutCommand),i18n("Layout process failed"),KMessageBox::Notify);
- }
-}
-
unsigned int DotGraph::cellNumber(int x, int y)
{
/* kDebug() << "x= " << x << ", y= " << y << ", m_width= " << m_width << ", m_height= " << m_height << ", m_horizCellFactor= " << m_horizCellFactor << ", m_vertCellFactor= " << m_vertCellFactor << ", m_wdhcf= " << m_wdhcf << ", m_hdvcf= " << m_hdvcf;*/
@@ -1013,7 +872,4 @@ QString DotGraph::backColor() const
}
}
-
-}
-
#include "dotgraph.moc"
diff --git a/src/kgraphviz/dotgraph.h b/src/kgraphviz/dotgraph.h
index 533e13c..8fbe481 100644
--- a/src/kgraphviz/dotgraph.h
+++ b/src/kgraphviz/dotgraph.h
@@ -57,8 +57,7 @@ public:
virtual ~DotGraph();
- QString chooseLayoutProgramForFile(const QString& str);
- bool parseDot(const QString& str);
+ bool parseDot(const QString& fileName);
/** Constant accessor to the nodes of this graph */
inline const GraphNodeMap& nodes() const {return m_nodesMap;}
@@ -133,10 +132,6 @@ public:
Q_SIGNALS:
void readyToDisplay();
-private Q_SLOTS:
- void slotDotRunningDone(int,QProcess::ExitStatus);
- void slotDotRunningError(QProcess::ProcessError);
-
private:
Q_DECLARE_PRIVATE(DotGraph);
DotGraphPrivate* d_ptr;
diff --git a/src/kgraphviz/dotgraph_p.h b/src/kgraphviz/dotgraph_p.h
index 1369afb..70a1c3f 100644
--- a/src/kgraphviz/dotgraph_p.h
+++ b/src/kgraphviz/dotgraph_p.h
@@ -20,11 +20,26 @@
#ifndef DOTGRAPH_P_H
#define DOTGRAPH_P_H
+#include "graphio.h"
+
namespace KGraphViz
{
+class DotGraph;
+
class DotGraphPrivate
{
+public:
+ explicit DotGraphPrivate();
+ virtual ~DotGraphPrivate();
+
+ void init();
+
+ GraphIO m_graphIO;
+
+private:
+ Q_DECLARE_PUBLIC(DotGraph);
+ DotGraph* q_ptr;
};
}
diff --git a/src/kgraphviz/dotgraphview.cpp b/src/kgraphviz/dotgraphview.cpp
index 7d50f03..4ad248b 100644
--- a/src/kgraphviz/dotgraphview.cpp
+++ b/src/kgraphviz/dotgraphview.cpp
@@ -29,6 +29,7 @@
#include "dotgraph.h"
#include "graphelement.h"
+#include "graphio.h"
#include "canvassubgraph.h"
#include "canvasedge.h"
#include "graphnode.h"
@@ -1917,12 +1918,8 @@ void DotGraphView::slotAGraphReadFinished()
{
Q_D(DotGraphView);
QString layoutCommand = (d->m_graph!=0?d->m_graph->layoutCommand():"");
- if (layoutCommand.isEmpty())
- {
- if (!d->m_loadThread.dotFileName().isEmpty())
- layoutCommand = d->m_graph->chooseLayoutProgramForFile(d->m_loadThread.dotFileName());
- else
- layoutCommand = "dot";
+ if (layoutCommand.isEmpty()) {
+ layoutCommand = GraphIO::internalLayoutCommandForFile(d->m_loadThread.dotFileName());
}
d->m_layoutThread.layoutGraph(d->m_loadThread.g(), layoutCommand);
}
More information about the kgraphviewer-devel
mailing list