|
From: <dhu...@us...> - 2006-12-21 11:58:45
|
Revision: 77
http://svn.sourceforge.net/qcell/?rev=77&view=rev
Author: dhubleizh
Date: 2006-12-21 03:58:43 -0800 (Thu, 21 Dec 2006)
Log Message:
-----------
- menu actions call parsers
Modified Paths:
--------------
trunk/qcell/visgui/MainWindow.cpp
trunk/qcell/visgui/MainWindow.h
Modified: trunk/qcell/visgui/MainWindow.cpp
===================================================================
--- trunk/qcell/visgui/MainWindow.cpp 2006-12-21 11:55:24 UTC (rev 76)
+++ trunk/qcell/visgui/MainWindow.cpp 2006-12-21 11:58:43 UTC (rev 77)
@@ -10,7 +10,7 @@
MainWindow::MainWindow(QWidget* parent)
{
- // GUI setup
+ // GUI setup - earlies possible to show the user, that we're in buisness
setupUi(this);
// Plugin parsing
@@ -25,7 +25,7 @@
// according to supported types and file extensions
foreach(QObject* plugin, QPluginLoader::staticInstances())
{
- iParser = qobject_cast<ParserInterface *>(plugin);
+ iParser = qobject_cast<ParserInterface*>(plugin);
// If this is a parser plugin
if(iParser)
{
@@ -42,6 +42,7 @@
{
neighbourhood_parsers[extension] = iParser;
}
+
}
if(type == "Function")
{
@@ -97,7 +98,8 @@
QFileDialog fd(
/*parent*/ this,
- /*cation*/ tr("Open Neighbourhood")
+ /*cation*/ tr("Open Neighbourhood"),
+ /*dir*/ "."
);
fd.setFileMode(QFileDialog::ExistingFile);
@@ -116,6 +118,7 @@
fd.exec();
+ callParser(fd.selectedFiles().first(), "Neighbourhood");
}
void MainWindow::on_action_Function_activated()
@@ -134,7 +137,8 @@
QFileDialog fd(
/*parent*/ this,
- /*cation*/ tr("Open Function")
+ /*cation*/ tr("Open Function"),
+ /*dir*/ "."
);
fd.setFileMode(QFileDialog::ExistingFile);
@@ -171,7 +175,8 @@
QFileDialog fd(
/*parent*/ this,
- /*cation*/ tr("Open World")
+ /*cation*/ tr("Open World"),
+ /*dir*/ "."
);
fd.setFileMode(QFileDialog::ExistingFile);
@@ -192,3 +197,65 @@
}
+void MainWindow::callParser(QString filename, QString type)
+{
+ QFile file(filename);
+ QByteArray file_content;
+ QString subtype = filename.section('.', -1);
+
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ {
+ qDebug(tr("Error opening file %1.")
+ .arg(filename)
+ .toAscii()
+ );
+ }
+
+ if (type == "Neighbourhood")
+ {
+ if (!neighbourhood_parsers.contains(subtype))
+ {
+ qDebug(tr("The file extensions %1 isn't supported.")
+ .arg(subtype)
+ .toAscii()
+ );
+ return;
+ }
+
+ neighbourhood_parsers[subtype]->parse(file_content, type, subtype);
+
+ }
+ else if (type == "LocalFunction")
+ {
+ if (!function_parsers.contains(subtype))
+ {
+ qDebug(tr("The file extensions %1 isn't supported.")
+ .arg(subtype)
+ .toAscii()
+ );
+ return;
+ }
+
+ function_parsers[subtype]->parse(file_content, type, subtype);
+ }
+ else if (type == "World")
+ {
+ if (!world_parsers.contains(subtype))
+ {
+ qDebug(tr("The file extensions %1 isn't supported.")
+ .arg(subtype)
+ .toAscii()
+ );
+ return;
+ }
+
+ world_parsers[subtype]->parse(file_content, type, subtype);
+ }
+ else
+ {
+ qDebug(tr("Unsupported file type to parse.").toAscii());
+ return;
+ }
+
+}
+
Modified: trunk/qcell/visgui/MainWindow.h
===================================================================
--- trunk/qcell/visgui/MainWindow.h 2006-12-21 11:55:24 UTC (rev 76)
+++ trunk/qcell/visgui/MainWindow.h 2006-12-21 11:58:43 UTC (rev 77)
@@ -36,10 +36,12 @@
void on_action_World_activated();
private:
- QMap<QString, ParserInterface*> neighbourhood_parsers;
- QMap<QString, ParserInterface*> function_parsers;
- QMap<QString, ParserInterface*> world_parsers;
+ QMap<QString, ParserInterface*> neighbourhood_parsers;
+ QMap<QString, ParserInterface*> function_parsers;
+ QMap<QString, ParserInterface*> world_parsers;
+ void callParser(QString filename, QString type);
+
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|