save file as

master
Denes Matetelki 14 years ago
parent 89afb2dd3a
commit 822eea5a5b

@ -4,6 +4,7 @@
#include <QStatusBar>
#include <QMessageBox>
#include <QFileDialog>
#include <QtXml>
#include "node.h"
#include "edge.h"
@ -162,7 +163,7 @@ void GraphWidget::closeFile()
this,
tr("Save File"),
QDir::homePath(),
tr("Images (*.png *.xpm *.jpg)"));
tr("QtMindMap (*.qmm)"));
qDebug() << fileName;
@ -197,7 +198,36 @@ void GraphWidget::saveFile()
void GraphWidget::saveFileAs()
{
QString fileName = QFileDialog::getSaveFileName(
this,
tr("Save File"),
QDir::homePath(),
tr("QtMindMap (*.qmm)"));
QDomDocument doc("QtMindMap");
QDomElement root = doc.createElement("qtmindmap");
doc.appendChild( root );
foreach(Node *node, m_nodeList)
root.appendChild(node->createXMLNode(doc));
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly))
{
dynamic_cast<MainWindow *>(m_parent)->getStatusBar()->showMessage(
tr("Couldn't open file to write."),
3000); // millisec
return;
}
QTextStream ts( &file );
ts << doc.toString();
file.close();
dynamic_cast<MainWindow *>(m_parent)->getStatusBar()->showMessage(
tr("Saved."),
3000); // millisec
}
void GraphWidget::openFile()
@ -551,6 +581,11 @@ void GraphWidget::nodeSelected(Node *node)
}
}
int GraphWidget::nodeId(Node *node)
{
return m_nodeList.indexOf(node);
}
void GraphWidget::addEdge(Node *source, Node *destination)
{
if (source->isConnected(destination))

@ -23,6 +23,7 @@ public:
void insertNode();
void setActiveNodeEditable();
void nodeSelected(Node *node);
int nodeId(Node *node);
public slots:

@ -37,16 +37,23 @@ MainWindow::MainWindow(QWidget *parent) :
m_graphicsView = new GraphWidget(this);
m_ui->setupUi(this);
connect(m_ui->actionNew, SIGNAL(activated()), m_graphicsView, SLOT(newFile()));
connect(m_ui->actionOpen, SIGNAL(activated()), this, SLOT(klakk()));
connect(m_ui->actionSave, SIGNAL(activated()), this, SLOT(klakk()));
connect(m_ui->actionClose, SIGNAL(activated()), m_graphicsView, SLOT(closeFile()));
connect(m_ui->actionExport, SIGNAL(activated()), this, SLOT(exportScene()));
connect(m_ui->actionQuit, SIGNAL(activated()), QApplication::instance(),
SLOT(quit()));
connect(m_ui->actionAbout_QtMindMap, SIGNAL(activated()), this,
SLOT(about()));
connect(m_ui->actionNew, SIGNAL(activated()),
m_graphicsView, SLOT(newFile()));
connect(m_ui->actionOpen, SIGNAL(activated()),
m_graphicsView, SLOT(openFile()));
connect(m_ui->actionSave, SIGNAL(activated()),
m_graphicsView, SLOT(saveFile()));
connect(m_ui->actionSaveAs, SIGNAL(activated()),
m_graphicsView, SLOT(saveFileAs()));
connect(m_ui->actionClose, SIGNAL(activated()),
m_graphicsView, SLOT(closeFile()));
connect(m_ui->actionExport, SIGNAL(activated()),
this, SLOT(exportScene()));
connect(m_ui->actionQuit, SIGNAL(activated()),
QApplication::instance(), SLOT(quit()));
connect(m_ui->actionAbout_QtMindMap, SIGNAL(activated()),
this, SLOT(about()));
setCentralWidget(m_graphicsView);
m_graphicsView->hide();
@ -57,11 +64,6 @@ MainWindow::~MainWindow()
delete m_ui;
}
void MainWindow::klakk()
{
qDebug() << __PRETTY_FUNCTION__;
}
void MainWindow::exportScene()
{
QFileDialog dialog(this,

@ -22,7 +22,7 @@ public:
void setFileName(QString fileName) { m_fileName = fileName; }
public slots:
void klakk();
void exportScene();
void about();

@ -30,6 +30,7 @@
<addaction name="actionNew"/>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionSaveAs"/>
<addaction name="actionClose"/>
<addaction name="separator"/>
<addaction name="actionExport"/>
@ -67,7 +68,7 @@
</action>
<action name="actionOpen">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Open</string>
@ -78,7 +79,7 @@
</action>
<action name="actionSave">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Save</string>
@ -122,6 +123,14 @@
<string notr="true">Ctrl+X</string>
</property>
</action>
<action name="actionSaveAs">
<property name="text">
<string>Save&amp;As</string>
</property>
<property name="shortcut">
<string>Ctrl+A</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>

@ -319,3 +319,30 @@ bool Node::isConnected(const Node *node) const
return false;
}
QDomElement Node::createXMLNode( QDomDocument &d )
{
QDomElement cn = d.createElement("node");
cn.setAttribute( "id", QString::number(m_graph->nodeId(this)));
cn.setAttribute( "pos_x", QString::number(pos().x()));
cn.setAttribute( "pos_y", QString::number(pos().y()));
cn.setAttribute( "content", toHtml());
foreach(EdgeElement element, m_edgeList)
{
QDomElement edge = d.createElement("edge");
if (element.startsFromThisNode)
{
edge.setAttribute("to",
QString::number(m_graph->nodeId(element.edge->destNode())));
} else
{
edge.setAttribute("from",
QString::number(m_graph->nodeId(element.edge->sourceNode())));
}
cn.appendChild(edge);
}
return cn;
}

@ -3,6 +3,7 @@
#include <QGraphicsTextItem>
#include <QTextCursor>
#include <QDomElement>
#include "edge.h"
#include "graphwidget.h"
@ -29,6 +30,7 @@ public:
// changing visibility from prot to pub
void keyPressEvent(QKeyEvent *event);
bool isConnected(const Node *node) const;
QDomElement createXMLNode( QDomDocument &d );
protected:

@ -4,7 +4,7 @@
#
#-------------------------------------------------
QT += core gui svg
QT += core gui svg xml
TARGET = qtmindmap
TEMPLATE = app

Loading…
Cancel
Save