summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2009-07-20 10:33:14 +0200
committerLukáš Lalinský <lalinsky@gmail.com>2009-07-20 10:33:14 +0200
commitee4e0002025099edd716bbd5b5c4f21b467ac7ab (patch)
tree3babf8ecd41dc93eac4aeae04c522114e908e1ca /src
parent043cf094f6494039cc5b8ba6c0a95406702c2ed4 (diff)
downloaddbmodel-ee4e0002025099edd716bbd5b5c4f21b467ac7ab.tar.xz
Open file passed on the command line
Diffstat (limited to 'src')
-rw-r--r--src/diagramdocument.cpp10
-rw-r--r--src/diagramdocument.h2
-rw-r--r--src/main.cpp8
-rw-r--r--src/mainwindow.cpp20
-rw-r--r--src/mainwindow.h2
5 files changed, 32 insertions, 10 deletions
diff --git a/src/diagramdocument.cpp b/src/diagramdocument.cpp
index a697bc7..a541d7a 100644
--- a/src/diagramdocument.cpp
+++ b/src/diagramdocument.cpp
@@ -432,15 +432,20 @@ DiagramDocument::save(const QString &fileName)
#include "diagramitemfactory.h"
-void
+bool
DiagramDocument::load(const QString &fileName)
{
QDomDocument doc;
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
- doc.setContent(&file);
+ if (!doc.setContent(&file)) {
+ return false;
+ }
file.close();
}
+ else {
+ return false;
+ }
setFileName(fileName);
QDomElement root = doc.firstChildElement("diagram");
@@ -460,6 +465,7 @@ DiagramDocument::load(const QString &fileName)
}
itemElement = itemElement.nextSiblingElement("item");
}
+ return true;
}
DiagramItem *
diff --git a/src/diagramdocument.h b/src/diagramdocument.h
index fa061b1..4a3fd34 100644
--- a/src/diagramdocument.h
+++ b/src/diagramdocument.h
@@ -72,7 +72,7 @@ public:
QList<DiagramItem *> selectedItems();
void save(const QString &fileName);
- void load(const QString &fileName);
+ bool load(const QString &fileName);
QString fileName() { return m_fileName; }
void setFileName(const QString &fileName) { m_fileName = fileName; }
diff --git a/src/main.cpp b/src/main.cpp
index 628856c..a76a90c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -37,7 +37,13 @@ main(int argc, char **argv)
translator.load("dbmodel_" + QLocale::system().name(), ":/translations/");
app.installTranslator(&translator);
- MainWindow window;
+ QString fileName;
+ QStringList args = app.arguments();
+ if (args.size() > 1) {
+ fileName = args.at(1);
+ }
+
+ MainWindow window(fileName);
window.show();
return app.exec();
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index eac5f02..7d26984 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -68,14 +68,19 @@ public:
ExporterList exporters;
};
-MainWindow::MainWindow()
+MainWindow::MainWindow(const QString &fileName)
: QMainWindow(), d(new MainWindowPrivate), m_model(NULL)
{
setupUi();
setupActions();
setupToolBar();
setupMenuBar();
- newModel();
+ if (fileName.isEmpty()) {
+ newModel();
+ }
+ else {
+ loadFile(fileName);
+ }
QIcon icon;
icon.addFile(":/icons/16x16/item-table.png", QSize(32, 32));
@@ -448,9 +453,14 @@ void
MainWindow::loadFile(const QString &fileName)
{
DiagramDocument *model = new DiagramDocument(this);
- model->load(fileName);
- newModel(model);
- addRecentFile(fileName);
+ if (model->load(fileName)) {
+ newModel(model);
+ addRecentFile(fileName);
+ }
+ else {
+ QMessageBox::critical(this, tr("Error"), tr("Unknown format."));
+ newModel();
+ }
}
void
diff --git a/src/mainwindow.h b/src/mainwindow.h
index a1b7723..923f6cd 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -33,7 +33,7 @@ class MainWindow: public QMainWindow
Q_OBJECT
public:
- MainWindow();
+ MainWindow(const QString &fileName = QString());
~MainWindow();
QIcon loadIcon(const QString &name);