scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Project.cpp
Go to the documentation of this file.
1 
12 
30 #include "core/Project.h"
31 #ifndef LEGACY_CODE_0_2_x
32 #include "core/ProjectWindow.h"
33 #include "core/ScriptingEngineManager.h"
34 #endif
35 #include "core/interfaces.h"
36 #include "globals.h"
37 #include "lib/XmlStreamReader.h"
38 #include "core/ProjectConfigPage.h"
39 #include <QUndoStack>
40 #include <QString>
41 #include <QKeySequence>
42 #include <QMenu>
43 #include <QSettings>
44 #include <QPluginLoader>
45 #include <QComboBox>
46 #include <QFile>
47 #include <QXmlStreamWriter>
48 #include <QtDebug>
49 
50 #define NOT_IMPL (QMessageBox::information(0, "info", "not yet implemented"))
51 
53 {
54  public:
55  Private() :
56  mdi_window_visibility(static_cast<MdiWindowVisibility>(Project::global("default_mdi_window_visibility").toInt())),
57  primary_view(0),
58  scripting_engine(0) {}
60 #ifndef LEGACY_CODE_0_2_x
61  delete primary_view;
62 #endif
63  }
64  QUndoStack undo_stack;
66 #ifndef LEGACY_CODE_0_2_x
67  ProjectWindow * primary_view;
68 #else
69  void * primary_view;
70 #endif
71  AbstractScriptingEngine * scripting_engine;
72  QString file_name;
73 };
74 
76  : future::Folder(tr("Unnamed")), d(new Private())
77 {
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);
83 #endif
84 }
85 
87 {
88  delete d;
89 }
90 
91 QUndoStack *Project::undoStack() const
92 {
93  return &d->undo_stack;
94 }
95 
96 #ifndef LEGACY_CODE_0_2_x
97 ProjectWindow *Project::view()
98 {
99  if (!d->primary_view)
100  d->primary_view = new ProjectWindow(this);
101  return d->primary_view;
102 #else
103 void *Project::view()
104 {
105  return NULL;
106 #endif
107 }
108 
110 {
111 #ifndef LEGACY_CODE_0_2_x
112  return const_cast<Project *>(this)->view()->createContextMenu();
113 #else
114  return NULL;
115 #endif
116 }
117 
119 {
120 #ifndef LEGACY_CODE_0_2_x
121  return const_cast<Project *>(this)->view()->createFolderContextMenu(folder);
122 #else
123  Q_UNUSED(folder)
124  return NULL;
125 #endif
126 }
127 
129 {
130  d->mdi_window_visibility = visibility;
131 #ifndef LEGACY_CODE_0_2_x
132  view()->updateMdiWindowVisibility();
133 #endif
134 }
135 
137 {
138  return d->mdi_window_visibility;
139 }
140 
141 AbstractScriptingEngine * Project::scriptingEngine() const
142 {
143  return d->scripting_engine;
144 }
145 
146 /* ================== static methods ======================= */
148 {
149  return new ProjectConfigPage();
150 }
151 
153 {
154  return QObject::tr("General");
155 }
156 
157 void Project::setFileName(const QString & file_name)
158 {
159  d->file_name = file_name;
160 }
161 
162 QString Project::fileName() const
163 {
164  return d->file_name;
165 }
166 
167 void Project::save(QXmlStreamWriter * writer) const
168 {
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();
178 }
179 
181 {
182  while (!(reader->isStartDocument() || reader->atEnd()))
183  reader->readNext();
184  if(!(reader->atEnd()))
185  {
186  if (!reader->skipToNextTag()) return false;
187 
188  if (reader->name() == "scidavis_project")
189  {
190  bool ok;
191  reader->readAttributeInt("version", &ok);
192  if(!ok)
193  {
194  reader->raiseError(tr("invalid or missing project version"));
195  return false;
196  }
197 
198  // version dependent staff goes here
199 
200  while (!reader->atEnd())
201  {
202  reader->readNext();
203 
204  if (reader->isEndElement()) break;
205 
206  if (reader->isStartElement())
207  {
208  if (reader->name() == "project_root")
209  {
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");
214  }
215  else // unknown element
216  {
217  reader->raiseWarning(tr("unknown element '%1'").arg(reader->name().toString()));
218  if (!reader->skipToEndElement()) return false;
219  }
220  }
221  }
222  }
223  else // no project element
224  reader->raiseError(tr("no scidavis_project element found"));
225  }
226  else // no start document
227  reader->raiseError(tr("no valid XML document found"));
228 
229  return !reader->hasError();
230 }
231 
Project::undoStack
virtual QUndoStack * undoStack() const
Return the undo stack of the Project, or 0 if this Aspect is not part of a Project.
Definition: Project.cpp:91
future
Definition: AbstractAspect.h:43
Project::scriptingEngine
AbstractScriptingEngine * scriptingEngine() const
Definition: Project.cpp:141
Project::fileName
QString fileName() const
Definition: Project.cpp:162
Project::view
virtual ProjectWindow * view()
Definition: Project.cpp:97
SciDAVis::version
static int version()
Return the SciDAVis version number.
Definition: globals.cpp:110
Project::setFileName
void setFileName(const QString &file_name)
Definition: Project.cpp:157
XmlStreamReader::skipToNextTag
bool skipToNextTag()
Go to the next start or end element tag.
Definition: XmlStreamReader.cpp:92
Project::ProjectConfigPage
friend class ProjectConfigPage
Definition: Project.h:100
Project::Private::Private
Private()
Definition: Project.cpp:55
Project.h
XmlStreamReader::raiseError
void raiseError(const QString &message=QString())
Definition: XmlStreamReader.cpp:80
AbstractAspect::global
static QVariant global(const QString &key)
Retrieve a global setting.
Definition: AbstractAspect.cpp:360
interfaces.h
Project::MdiWindowVisibility
MdiWindowVisibility
MDI subwindow visibility setting.
Definition: Project.h:53
ConfigPageWidget
Widget for configuration pages that has an apply slot.
Definition: ConfigPageWidget.h:37
XmlStreamReader::readAttributeInt
int readAttributeInt(const QString &name, bool *ok)
Read an XML attribute and convert it to int.
Definition: XmlStreamReader.cpp:110
XmlStreamReader
XML stream parser that supports errors as well as warnings.
Definition: XmlStreamReader.h:42
Project::Private::~Private
~Private()
Definition: Project.cpp:59
Project::Private::mdi_window_visibility
MdiWindowVisibility mdi_window_visibility
Definition: Project.cpp:65
Project::Private
Definition: Project.cpp:53
Project
Represents a SciDAVis project.
Definition: Project.h:47
Project::setMdiWindowVisibility
void setMdiWindowVisibility(MdiWindowVisibility visibility)
Definition: Project.cpp:128
future::Folder
Folder in a project.
Definition: future_Folder.h:38
future::Folder::save
virtual void save(QXmlStreamWriter *) const
Save as XML.
Definition: future_Folder.cpp:67
Project::save
virtual void save(QXmlStreamWriter *) const
Save as XML.
Definition: Project.cpp:167
Project::Private::undo_stack
QUndoStack undo_stack
Definition: Project.cpp:64
XmlStreamReader::skipToEndElement
bool skipToEndElement()
Go to the end element tag of the current element.
Definition: XmlStreamReader.cpp:121
Project::createFolderContextMenu
virtual QMenu * createFolderContextMenu(const ::future::Folder *folder) const
Definition: Project.cpp:118
globals.h
Project::Project
Project()
Definition: Project.cpp:75
Project::configPageLabel
static QString configPageLabel()
Definition: Project.cpp:152
Folder
Folder for the project explorer.
Definition: Folder.h:62
XmlStreamReader.h
Project::~Project
~Project()
Definition: Project.cpp:86
Project::Private::file_name
QString file_name
Definition: Project.cpp:72
Project::Private::scripting_engine
AbstractScriptingEngine * scripting_engine
Definition: Project.cpp:71
ProjectConfigPage.h
AbstractAspect::folder
future::Folder * folder()
Return the folder the Aspect is contained in or 0 if not.
Definition: AbstractAspect.cpp:316
Project::load
virtual bool load(XmlStreamReader *)
Load from XML.
Definition: Project.cpp:180
Project::createContextMenu
virtual QMenu * createContextMenu() const
Return a new context menu.
Definition: Project.cpp:109
Project::makeConfigPage
static ConfigPageWidget * makeConfigPage()
Definition: Project.cpp:147
future::Folder::load
virtual bool load(XmlStreamReader *)
Load from XML.
Definition: future_Folder.cpp:83
XmlStreamReader::raiseWarning
void raiseWarning(const QString &message=QString())
Definition: XmlStreamReader.cpp:86
Project::mdiWindowVisibility
MdiWindowVisibility mdiWindowVisibility() const
Definition: Project.cpp:136
Project::Private::primary_view
ProjectWindow * primary_view
Definition: Project.cpp:67
Project::d
Private * d
Definition: Project.h:97