tuchulcha  0.10.1
Graphical Workflow Configuration Editor
MetaData.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2009 Jens-Malte Gottfried
2 
3  This file is part of Tuchulcha.
4 
5  Tuchulcha is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Tuchulcha is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with Tuchulcha. If not, see <http://www.gnu.org/licenses/>.
17 */
23 #include "MetaData.h"
24 #include "QParameterFile.h"
25 #include <QSet>
26 #include <QVariant>
27 
28 MetaData::MetaData(QString fileName) :
29  _data(new QParameterFile(fileName)) {
30  Q_ASSERT(!fileName.isEmpty());
31  QStringList keyList = _data->getKeyList();
32  // contains all keys in _metadata
33  QSet<QString> keys = QSet<QString>::fromList(keyList);
34  QSet<QString> classes; // contains all classes in _metadata
35  QSet<QString>::const_iterator keyIter;
36 
37  // each key needs a separator (classes cannot have a default value)
38  for(keyIter = keys.begin(); keyIter != keys.end(); keyIter++) {
39  int pos = keyIter->indexOf(".");
40  if (pos < 0)
41  qFatal("Invalid key (separator missing): %s",
42  keyIter->toLocal8Bit().constData());
43  classes.insert(keyIter->left(pos));
44  }
45 
46  // create/update class vector
47  _classes = classes.toList();
48 }
49 
50 MetaData::~MetaData() {
51  if(_data)
52  delete _data;
53 }
54 
55 QStringList MetaData::getClasses() const {
56  return _classes;
57 }
58 
59 QStringList MetaData::getOutputs (QString className) const {
60  return _data->get(className + ".outputs")
61  .split(";",QString::SkipEmptyParts);
62 
63 }
64 
65 QStringList MetaData::getInputs(QString className) const {
66 
67  return _data->get(className + ".inputs")
68  .split(";",QString::SkipEmptyParts);
69 
70 }
71 
72 QStringList MetaData::getParameters(QString className) const {
73  return _data->get(className + ".parameters")
74  .split(";",QString::SkipEmptyParts);
75 }
76 
77 QString MetaData::getType(QString parName, QString className) const {
78  parName = parName.section(".",-1,-1).toLower();
79  QString par = className + "." + parName + ".type";
80  QString result = _data->get(par);
81  if(result.isEmpty())
82  result = "string";
83  return result;
84 }
85 
86 QString MetaData::getDefault(QString parName, QString className) const {
87  parName = parName.section(".",-1,-1).toLower();
88  QString par = className + "." + parName;
89  QString result = _data->get(par);
90  return result;
91 }
92 
93 QString MetaData::getDocString(QString parName, QString className) const {
94  parName = parName.section(".",-1,-1).toLower();
95  QString par = parName.isEmpty() ?
96  className + ".doc" :
97  className + "." + parName + ".doc";
98  QString result = _data->get(par);
99  return result;
100 }
101 
102 QString MetaData::getDocFile(QString parName, QString className) const {
103  parName = parName.section(".",-1,-1).toLower();
104  QString par = parName.isEmpty() ?
105  className + ".docfile" :
106  className + "." + parName + ".docfile";
107  QString result = _data->get(par);
108  return result;
109 }
110 
111 bool MetaData::isInputSlot(QString name, QString className) const {
112  name = name.section(".",-1,-1).toLower();
113  QStringList list = getInputs(className);
114  return (list.indexOf(QRegExp(name,Qt::CaseInsensitive)) >= 0);
115 }
116 
117 bool MetaData::isOptionalSlot(QString slotName, QString className) const {
118  slotName = slotName.section(".",-1,-1).toLower();
119  bool slotIsIn = isInputSlot(slotName, className);
120  QString optName = className + "." + slotName + ".optional";
121  return _data->isSet(optName) ?
122  QVariant(_data->get(optName)).toBool() : !slotIsIn;
123 }
124 
125 bool MetaData::isMultiSlot(QString slotName, QString className) const {
126  slotName = slotName.section(".",-1,-1).toLower();
127  bool slotIsIn = isInputSlot(slotName, className);
128  QString optName = className + "." + slotName + ".multi";
129  return _data->isSet(optName) ?
130  QVariant(_data->get(optName)).toBool() : !slotIsIn;
131 }
132 
133 bool MetaData::isDynamic(QString className) const {
134  return QVariant(_data->get(className + ".isDynamicModule")).toBool();
135 }
136 
137 QStringList MetaData::getTags(QString className) const {
138  QString result = _data->get(className + ".tags") ;
139  return result.split(";", QString::SkipEmptyParts);
140 }
141 
142 QStringList MetaData::getInputDisplayNames(QString className) const
143 {
144  QStringList inputs= _data->get(className + ".inputs")
145  .split(";",QString::SkipEmptyParts);
146  QStringList res;
147  foreach(const QString& inp , inputs)
148  {
149  QString disp=_data->get(className +"."+inp+".displayname");
150 
151  if(disp!=QString::null)
152  res.push_back(disp);
153  else
154  res.push_back(inp);
155  }
156  return res;
157 }
158 
159 QStringList MetaData::getOutputDisplayNames(QString className) const
160 {
161  QStringList outputs= _data->get(className + ".outputs")
162  .split(";",QString::SkipEmptyParts);
163  QStringList res;
164  foreach(const QString& outp , outputs)
165  {
166  QString disp=_data->get(className +"."+outp+".displayname");
167 
168  if(disp!=QString::null)
169  res.push_back(disp);
170  else
171  res.push_back(outp);
172  }
173  return res;
174 }
QString get(QString parameter) const
get parameter value
bool isMultiSlot(QString slotName, QString className) const
Check if some slot is a multi slot.
Definition: MetaData.cpp:125
MetaData(QString fileName)
Load metadata from given file.
Definition: MetaData.cpp:28
QString getType(QString parName, QString className) const
Get type of some parameter or slot.
Definition: MetaData.cpp:77
Implementation of class ParameterFileModel.
bool isSet(QString parameter) const
check if a given parameter has been set
QStringList getParameters(QString className) const
get parameters of some given object
Definition: MetaData.cpp:72
QString getDefault(QString parName, QString className) const
get default value for some editable parameter
Definition: MetaData.cpp:86
bool isOptionalSlot(QString slotName, QString className) const
Check if some slot is optional.
Definition: MetaData.cpp:117
const QParameterFile * _data
used ParameterFile (read only)
Definition: MetaData.h:154
Declaration of class QParameterFile.
QString getDocString(QString parName, QString className) const
get docstring for some parameter or some class.
Definition: MetaData.cpp:93
Qt implementation for ParameterFile class.
QStringList getInputs(QString className) const
get output slots of some given object
Definition: MetaData.cpp:65
QString getDocFile(QString parName, QString className) const
get filename for some parameter or class documentation.
Definition: MetaData.cpp:102
bool isDynamic(QString className) const
Check if module is dynamic.
Definition: MetaData.cpp:133
QStringList getTags(QString className) const
Get the tags of a given object.
Definition: MetaData.cpp:137
QStringList getKeyList(QString beginsWith="") const
Look for parameters beginning with a given string.
QStringList getOutputDisplayNames(QString className) const
get input slots of some given object
Definition: MetaData.cpp:159
QStringList getInputDisplayNames(QString className) const
get output slots of some given object
Definition: MetaData.cpp:142
QStringList getClasses() const
get classes contained in this metadata file
Definition: MetaData.cpp:55
QStringList getOutputs(QString className) const
get input slots of some given object
Definition: MetaData.cpp:59
QStringList _classes
contained classes
Definition: MetaData.h:151
bool isInputSlot(QString name, QString className) const
Check if some parameter/slot is an input slot.
Definition: MetaData.cpp:111