1
/***************************************************************************
4
Description : Represents a SciDAVis project.
5
--------------------------------------------------------------------
6
Copyright : (C) 2007 Tilman Benkert (thzs*gmx.net)
7
Copyright : (C) 2007 Knut Franke (knut.franke*gmx.de)
8
(replace * with @ in the email addresses)
10
***************************************************************************/
12
/***************************************************************************
14
* This program is free software; you can redistribute it and/or modify *
15
* it under the terms of the GNU General Public License as published by *
16
* the Free Software Foundation; either version 2 of the License, or *
17
* (at your option) any later version. *
19
* This program is distributed in the hope that it will be useful, *
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22
* GNU General Public License for more details. *
24
* You should have received a copy of the GNU General Public License *
25
* along with this program; if not, write to the Free Software *
26
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
27
* Boston, MA 02110-1301 USA *
29
***************************************************************************/
30
#include "core/Project.h"
31
#ifndef LEGACY_CODE_0_2_x
32
#include "core/ProjectWindow.h"
33
#include "core/ScriptingEngineManager.h"
35
#include "core/interfaces.h"
36
#include "core/globals.h"
37
#include "lib/XmlStreamReader.h"
38
#include "core/ProjectConfigPage.h"
41
#include <QKeySequence>
44
#include <QPluginLoader>
47
#include <QXmlStreamWriter>
50
#define NOT_IMPL (QMessageBox::information(0, "info", "not yet implemented"))
52
class Project::Private
56
mdi_window_visibility(static_cast<MdiWindowVisibility>(Project::global("default_mdi_window_visibility").toInt())),
58
scripting_engine(0) {}
60
#ifndef LEGACY_CODE_0_2_x
64
QUndoStack undo_stack;
65
MdiWindowVisibility mdi_window_visibility;
66
#ifndef LEGACY_CODE_0_2_x
67
ProjectWindow * primary_view;
71
AbstractScriptingEngine * scripting_engine;
76
: future::Folder(tr("Unnamed")), d(new Private())
78
#ifndef LEGACY_CODE_0_2_x
79
// TODO: intelligent engine choosing
80
Q_ASSERT(ScriptingEngineManager::instance()->engineNames().size() > 0);
81
QString engine_name = ScriptingEngineManager::instance()->engineNames()[0];
82
d->scripting_engine = ScriptingEngineManager::instance()->engine(engine_name);
91
QUndoStack *Project::undoStack() const
93
return &d->undo_stack;
96
#ifndef LEGACY_CODE_0_2_x
97
ProjectWindow *Project::view()
100
d->primary_view = new ProjectWindow(this);
101
return d->primary_view;
103
void *Project::view()
109
QMenu *Project::createContextMenu() const
111
#ifndef LEGACY_CODE_0_2_x
112
return const_cast<Project *>(this)->view()->createContextMenu();
118
QMenu *Project::createFolderContextMenu(const future::Folder * folder) const
120
#ifndef LEGACY_CODE_0_2_x
121
return const_cast<Project *>(this)->view()->createFolderContextMenu(folder);
128
void Project::setMdiWindowVisibility(MdiWindowVisibility visibility)
130
d->mdi_window_visibility = visibility;
131
#ifndef LEGACY_CODE_0_2_x
132
view()->updateMdiWindowVisibility();
136
Project::MdiWindowVisibility Project::mdiWindowVisibility() const
138
return d->mdi_window_visibility;
141
AbstractScriptingEngine * Project::scriptingEngine() const
143
return d->scripting_engine;
146
/* ================== static methods ======================= */
147
ConfigPageWidget * Project::makeConfigPage()
149
return new ProjectConfigPage();
152
QString Project::configPageLabel()
154
return QObject::tr("General");
157
void Project::setFileName(const QString & file_name)
159
d->file_name = file_name;
162
QString Project::fileName() const
167
void Project::save(QXmlStreamWriter * writer) const
169
writer->writeStartDocument();
170
writer->writeStartElement("scidavis_project");
171
writer->writeAttribute("version", QString::number(SciDAVis::version()));
172
// TODO: write project attributes
173
writer->writeStartElement("project_root");
174
future::Folder::save(writer);
175
writer->writeEndElement(); // "project_root"
176
writer->writeEndElement(); // "scidavis_project"
177
writer->writeEndDocument();
180
bool Project::load(XmlStreamReader * reader)
182
while (!(reader->isStartDocument() || reader->atEnd()))
184
if(!(reader->atEnd()))
186
if (!reader->skipToNextTag()) return false;
188
if (reader->name() == "scidavis_project")
191
int version = reader->readAttributeInt("version", &ok);
194
reader->raiseError(tr("invalid or missing project version"));
198
// version dependent staff goes here
200
while (!reader->atEnd())
204
if (reader->isEndElement()) break;
206
if (reader->isStartElement())
208
if (reader->name() == "project_root")
210
if (!reader->skipToNextTag()) return false;
211
if (!future::Folder::load(reader)) return false;
212
if (!reader->skipToNextTag()) return false;
213
Q_ASSERT(reader->isEndElement() && reader->name() == "project_root");
215
else // unknown element
217
reader->raiseWarning(tr("unknown element '%1'").arg(reader->name().toString()));
218
if (!reader->skipToEndElement()) return false;
223
else // no project element
224
reader->raiseError(tr("no scidavis_project element found"));
226
else // no start document
227
reader->raiseError(tr("no valid XML document found"));
229
return !reader->hasError();