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)  

future_Folder.cpp
Go to the documentation of this file.
1 
12 
30 #include "core/Project.h"
31 #include "core/future_Folder.h"
32 #include "lib/XmlStreamReader.h"
33 #include "core/column/Column.h"
34 
35 #include <QIcon>
36 #include <QApplication>
37 #include <QStyle>
38 #include <QXmlStreamWriter>
39 #include <QPluginLoader>
40 #include <QtDebug>
41 
42 namespace future{
43 Folder::Folder(const QString &name)
45 {
46 }
47 
49 {
50 }
51 
52 QIcon Folder::icon() const
53 {
54  QIcon result;
55  result.addFile(":/folder_closed.xpm", QSize(), QIcon::Normal, QIcon::Off);
56  result.addFile(":/folder_open.xpm", QSize(), QIcon::Normal, QIcon::On);
57  return result;
58 }
59 
61 {
62  if (project())
63  return project()->createFolderContextMenu(this);
64  return 0;
65 }
66 
67 void Folder::save(QXmlStreamWriter * writer) const
68 {
69  writer->writeStartElement("folder");
70  writeBasicAttributes(writer);
71  writeCommentElement(writer);
72 
73  int child_count = childCount();
74  for (int i=0; i<child_count; i++)
75  {
76  writer->writeStartElement("child_aspect");
77  child(i)->save(writer);
78  writer->writeEndElement(); // "child_aspect"
79  }
80  writer->writeEndElement(); // "folder"
81 }
82 
84 {
85  if(reader->isStartElement() && reader->name() == "folder")
86  {
87  setComment("");
89 
90  if (!readBasicAttributes(reader)) return false;
91 
92  // read child elements
93  while (!reader->atEnd())
94  {
95  reader->readNext();
96 
97  if (reader->isEndElement()) break;
98 
99  if (reader->isStartElement())
100  {
101  if (reader->name() == "comment")
102  {
103  if (!readCommentElement(reader))
104  return false;
105  }
106  else if(reader->name() == "child_aspect")
107  {
108  if (!readChildAspectElement(reader))
109  return false;
110  }
111  else // unknown element
112  {
113  reader->raiseWarning(tr("unknown element '%1'").arg(reader->name().toString()));
114  if (!reader->skipToEndElement()) return false;
115  }
116  }
117  }
118  }
119  else // no folder element
120  reader->raiseError(tr("no folder element found"));
121 
122  return !reader->hasError();
123 }
124 
126 {
127  bool loaded = false;
128  Q_ASSERT(reader->isStartElement() && reader->name() == "child_aspect");
129 
130  if (!reader->skipToNextTag()) return false;
131  if (reader->isEndElement() && reader->name() == "child_aspect") return true; // empty element tag
132  QString element_name = reader->name().toString();
133  if (element_name == "folder")
134  {
135  Folder * folder = new Folder(tr("Folder %1").arg(1));
136  if (!folder->load(reader))
137  {
138  delete folder;
139  return false;
140  }
141  addChild(folder);
142  loaded = true;
143  }
144  else if (element_name == "column")
145  {
146  Column * column = new Column(tr("Column %1").arg(1), SciDAVis::Text);
147  if (!column->load(reader))
148  {
149  delete column;
150  return false;
151  }
152  addChild(column);
153  loaded = true;
154  }
155  else
156  {
157  foreach(QObject * plugin, QPluginLoader::staticInstances())
158  {
159  XmlElementAspectMaker * maker = qobject_cast<XmlElementAspectMaker *>(plugin);
160  if (maker && maker->canCreate(element_name))
161  {
162  AbstractAspect * aspect = maker->createAspectFromXml(reader);
163  if (aspect)
164  {
165  addChild(aspect);
166  loaded = true;
167  break;
168  }
169  else
170  {
171  reader->raiseError(tr("creation of aspect from element '%1' failed").arg(element_name));
172  return false;
173  }
174  }
175  }
176  }
177  if (!loaded)
178  {
179  reader->raiseWarning(tr("no plugin to load element '%1' found").arg(element_name));
180  if (!reader->skipToEndElement()) return false;
181  }
182  if (!reader->skipToNextTag()) return false;
183  Q_ASSERT(reader->isEndElement() && reader->name() == "child_aspect");
184  return !reader->hasError();
185 }
186 
187 } // namespace
future
Definition: AbstractAspect.h:43
AbstractAspect::writeCommentElement
void writeCommentElement(QXmlStreamWriter *writer) const
Save the comment to XML.
Definition: AbstractAspect.cpp:52
future_Folder.h
XmlStreamReader::skipToNextTag
bool skipToNextTag()
Go to the next start or end element tag.
Definition: XmlStreamReader.cpp:92
Column.h
Project.h
XmlStreamReader::raiseError
void raiseError(const QString &message=QString())
Definition: XmlStreamReader.cpp:80
XmlStreamReader
XML stream parser that supports errors as well as warnings.
Definition: XmlStreamReader.h:42
AbstractAspect::setComment
void setComment(const QString &value)
Definition: AbstractAspect.cpp:265
AbstractAspect::removeAllChildAspects
virtual void removeAllChildAspects()
Remove all child aspects.
Definition: AbstractAspect.cpp:352
Column
Aspect that manages a column.
Definition: Column.h:59
XmlElementAspectMaker::canCreate
virtual bool canCreate(const QString &element_name)=0
Determine whether the loader can handle the given element.
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
future::Folder::Folder
Folder(const QString &name)
Definition: future_Folder.cpp:43
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
XmlElementAspectMaker
Factory that creates an aspect out of an XML element.
Definition: interfaces.h:118
XmlElementAspectMaker::createAspectFromXml
virtual AbstractAspect * createAspectFromXml(XmlStreamReader *reader)=0
The factory method.
future::Folder::icon
virtual QIcon icon() const
Return an icon to be used for decorating my views.
Definition: future_Folder.cpp:52
AbstractAspect::childCount
int childCount() const
Return the number of child Aspects.
Definition: AbstractAspect.cpp:186
Column::load
bool load(XmlStreamReader *reader) override
Load the column from XML.
Definition: Column.cpp:364
AbstractAspect::readBasicAttributes
bool readBasicAttributes(XmlStreamReader *reader)
Load name, creation time and caption spec from XML.
Definition: AbstractAspect.cpp:77
AbstractAspect::child
AbstractAspect * child(int index) const
Get a child by its position in my list of children.
Definition: AbstractAspect.cpp:180
XmlStreamReader.h
SciDAVis::Text
@ Text
column contains strings
Definition: globals.h:68
AbstractAspect::writeBasicAttributes
void writeBasicAttributes(QXmlStreamWriter *writer) const
Save name, creation time and caption spec to XML.
Definition: AbstractAspect.cpp:70
AbstractAspect::folder
future::Folder * folder()
Return the folder the Aspect is contained in or 0 if not.
Definition: AbstractAspect.cpp:316
AbstractAspect::project
virtual const Project * project() const
Return the Project this Aspect belongs to, or 0 if it is currently not part of one.
Definition: AbstractAspect.h:150
future::Folder::createContextMenu
virtual QMenu * createContextMenu() const
Return a new context menu.
Definition: future_Folder.cpp:60
name
char * name()
Definition: exp_saturation.c:45
future::Folder::~Folder
virtual ~Folder()
Definition: future_Folder.cpp:48
AbstractAspect::addChild
void addChild(AbstractAspect *child)
Add the given Aspect to my list of children.
Definition: AbstractAspect.cpp:114
future::Folder::load
virtual bool load(XmlStreamReader *)
Load from XML.
Definition: future_Folder.cpp:83
future::Folder::readChildAspectElement
bool readChildAspectElement(XmlStreamReader *reader)
Read child aspect from XML.
Definition: future_Folder.cpp:125
XmlStreamReader::raiseWarning
void raiseWarning(const QString &message=QString())
Definition: XmlStreamReader.cpp:86
AbstractAspect::save
virtual void save(QXmlStreamWriter *) const
Save as XML.
Definition: AbstractAspect.h:201
AbstractAspect::readCommentElement
bool readCommentElement(XmlStreamReader *reader)
Load comment from an XML element.
Definition: AbstractAspect.cpp:61
AbstractAspect
Base class of all persistent objects in a Project.
Definition: AbstractAspect.h:86