Permalink
Browse files

Started adding support for run configurations

Also added export targets for SVG and LaTeX
  • Loading branch information...
aelliott committed Apr 26, 2013
1 parent 4ec0f82 commit aa6c5b214c87a66b45bb543393afda77621a660c
View
@@ -52,6 +52,7 @@ ENDIF()
SET(QT_USE_QTMAIN true)
SET(QT_USE_QTXML true)
SET(QT_USE_QTSVG true)
INCLUDE(${QT_USE_FILE})
@@ -4,7 +4,7 @@
#
#-------------------------------------------------
QT += core gui xml widgets
QT += core gui xml widgets svg
TARGET = GPDeveloper
TEMPLATE = app
@@ -72,7 +72,8 @@ HEADERS += \
openprojectprogressdialog.hpp \
list.hpp \
firstrundialog.hpp \
listvalidator.hpp
listvalidator.hpp \
runconfig.hpp
FORMS += \
welcome.ui \
@@ -171,7 +172,8 @@ SOURCES += \
openprojectprogressdialog.cpp \
list.cpp \
firstrundialog.cpp \
listvalidator.cpp
listvalidator.cpp \
runconfig.cpp
OTHER_FILES += \
templates/newproject.gpp \
View
@@ -55,7 +55,9 @@ enum GraphTypes
//! GXL (Graph eXchange Language) format
GxlGraph,
//! The "alternative" graph format documented in the GP2 design documents
AlternativeGraph
AlternativeGraph,
//! A LaTeX output format
LaTeXGraph
};
/*!
@@ -126,6 +128,7 @@ enum LayoutDirections
#define GP_GRAPH_ALTERNATIVE_EXTENSION ".gpg"
#define GP_GRAPH_DOT_EXTENSION ".gv"
#define GP_GRAPH_GXL_EXTENSION ".gxl"
#define GP_GRAPH_LATEX_EXTENSION ".tex"
//! The number of recent projects to track
#define MAX_RECENT_PROJECTS 5
View
@@ -137,16 +137,20 @@ bool Graph::saveAs(const QString &filePath)
bool Graph::exportTo(const QString &filePath, GraphTypes outputType)
{
QMessageBox::StandardButton ret = QMessageBox::question(
0,
tr("Retain Layout Information?"),
tr("Do you wish to retain layout information in the exported "
"file?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes
);
bool keepLayout = true;
if(outputType != LaTeXGraph)
{
QMessageBox::StandardButton ret = QMessageBox::question(
0,
tr("Retain Layout Information?"),
tr("Do you wish to retain layout information in the exported "
"file?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes
);
bool keepLayout = (ret == QMessageBox::Yes);
keepLayout = (ret == QMessageBox::Yes);
}
QString thePath = filePath;
if(filePath.isEmpty())
@@ -161,6 +165,9 @@ bool Graph::exportTo(const QString &filePath, GraphTypes outputType)
QString filter;
switch(outputType)
{
case LaTeXGraph:
filter = tr("LaTeX File (*.tex)");
break;
case AlternativeGraph:
filter = tr("GP Graph Format (*.gpg)");
break;
@@ -469,6 +476,9 @@ QString Graph::toString(int outputType, bool keepLayout) const
switch(outputType)
{
case LaTeXGraph:
return toLaTeX();
break;
case GxlGraph:
return toGxl(keepLayout);
break;
@@ -679,6 +689,70 @@ QString Graph::toAlternative() const
return result;
}
QString Graph::toLaTeX() const
{
QString result = "\\begin{tikzpicture}[every path/.style={>=latex}]\n";
QRect rect = canvas();
result += QString(" %\\path [use as bounding box] (0,0) rectangle (")
+ QVariant(rect.width()).toString() + "pt,"
+ QVariant(rect.height()).toString() + "pt);\n\n";
QList<int> xPositions;
QList<int> yPositions;
for(nodeConstIter iter = _nodes.begin(); iter != _nodes.end(); ++iter)
{
Node *n = *iter;
QPoint pos = n->pos().toPoint();
if(!xPositions.contains(pos.x()))
xPositions << pos.x();
if(!yPositions.contains(pos.y()))
yPositions << pos.y();
}
qSort(xPositions);
qSort(yPositions);
for(nodeConstIter iter = _nodes.begin(); iter != _nodes.end(); ++iter)
{
Node *n = *iter;
QPoint nPos = n->pos().toPoint();
QPoint pos(0,0);
pos.setX(xPositions.indexOf(nPos.x()));
pos.setY(yPositions.size() - yPositions.indexOf(nPos.y()));
result += QString(" \\node [style={draw=blue!75,circle,thick,fill=blue!20}] (") + n->id() + ") at ("
+ QVariant(pos.x()).toString() + ","
+ QVariant(pos.y()).toString() + ") { "
+ n->label().toString() + " };\n";
}
result += "\n";
for(edgeConstIter iter = _edges.begin(); iter != _edges.end(); ++iter)
{
Edge *e = *iter;
result += QString(" \\draw[->] (") + e->from()->id() + ") edge ";
if(e->from()->id() == e->to()->id())
result += "[loop above] ";
/*if(!e->label().isEmpty())
{
QString labelStr = e->label().toString();
labelStr.replace("_", "\\_");
result += QString("node [above] { ") + labelStr + "} ";
}*/
result += QString("(") + e->to()->id() + ");\n";
}
result += "\\end{tikzpicture}\n";
return result;
}
void Graph::setCanvas(const QRect &rect)
{
_canvas = rect;
View
@@ -51,6 +51,7 @@ class Graph : public GPFile
QString toGxl(bool keepLayout = true) const;
QString toDot(bool keepLayout = true) const;
QString toAlternative() const;
QString toLaTeX() const;
signals:
@@ -34,6 +34,7 @@
#include <QCloseEvent>
#include <QMessageBox>
#include <QUndoStack>
#include <QtSvg/QSvgGenerator>
namespace Developer {
@@ -234,6 +235,7 @@ void MainWindow::setProject(Project *project)
_ui->title->setText(QString("GP Developer - ") + project->name());
_ui->quickRunWidget->setProject(project);
_edit->setProject(project);
_run->setProject(project);
}
void MainWindow::setProjectActive(bool state)
@@ -900,6 +902,56 @@ void MainWindow::exportGraphToPng()
image.save(savePath);
}
void MainWindow::exportGraphToSvg()
{
if(_currentGraph == 0)
{
qDebug() << "Export graph requested with no active graph";
return;
}
reinterpret_cast<GraphScene *>(_currentGraph->scene())->resizeToContents();
QRect rect = _currentGraph->scene()->sceneRect().toRect();
QSvgGenerator generator;
QString savePath = QFileDialog::getSaveFileName(
this,
tr("Save Graph as Image"),
QDir::homePath(),
tr("SVG Files (*.svg)"));
if(savePath.isEmpty())
return;
generator.setFileName(savePath);
generator.setSize(QSize(rect.width(), rect.height()));
generator.setViewBox(QRect(0, 0, rect.width(), rect.height()));
generator.setTitle("Graph Export - GP Developer");
generator.setDescription(tr("Export from GP Developer's graph view"));
QPainter painter;
painter.begin(&generator);
if(!painter.isActive())
{
QMessageBox::information(
this,
tr("Failed to Export Graph"),
tr("GP Developer could not export this graph as an image. "
"It may be too large for Qt's QPainter to handle. The "
"graph file is %1x%2 pixels in size.").arg(
QVariant(rect.width()).toString(),
QVariant(rect.height()).toString()
));
return;
}
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setBrush(QColor(Qt::white));
painter.drawRect(rect);
_currentGraph->scene()->render(&painter);
painter.end();
}
void MainWindow::exportGraphToDot()
{
if(_currentGraph == 0)
@@ -926,6 +978,19 @@ void MainWindow::exportGraphToGxl()
)->graph()->exportTo(QString(), GxlGraph);
}
void MainWindow::exportGraphToLaTeX()
{
if(_currentGraph == 0)
{
qDebug() << "Export graph requested with no active graph";
return;
}
reinterpret_cast<GraphScene *>(
_currentGraph->scene()
)->graph()->exportTo(QString(), LaTeXGraph);
}
void MainWindow::showPreferences()
{
PreferencesDialog *dialog = new PreferencesDialog(this);
@@ -213,8 +213,10 @@ public slots:
void layoutGEM();
void exportGraphToPng();
void exportGraphToSvg();
void exportGraphToDot();
void exportGraphToGxl();
void exportGraphToLaTeX();
/*!
* \brief Handle a QWidget close event
Oops, something went wrong.

0 comments on commit aa6c5b2

Please sign in to comment.