29 #include <QMessageBox>
36 #include <QRegExpValidator>
42 inline std::string
_toLower(std::string input) {
44 input.begin(), input.end(), input.begin(),
45 (int(*)(int)) tolower);
53 if (metaFile.isEmpty()) {
54 qFatal(
"No metaFile in GraphModel given! Pleas specify one!");
57 qFatal(
"MetaInfo not usable!");
63 Qt::QueuedConnection);
89 QSet<QString> wClasses;
90 const QStringList& nds =
nodes();
91 foreach (
const QString& cur, nds) {
97 const QStringList& knownClasses =
getClasses();
98 foreach(
const QString& s, wClasses) {
99 if (!knownClasses.contains(s,Qt::CaseInsensitive)) {
104 if (!uClasses.isEmpty()) {
105 QMessageBox::warning(
106 0,tr(
"missing modules"),
107 tr(
"The following classes are used in the workflow "
108 "but are unknown to Tuchulcha:")
109 +QString(
"<ul><li>%1</li></ul>").arg(uClasses.join(
"</li><li>"))
110 +tr(
"Please check your plugin path settings, "
111 "then update plugin informations "
112 "and look if these plugins are found at all "
113 "or error messages related with tese plugins occur."
129 QString source, QString target)
const {
132 qSwap(source,target);
135 throw std::runtime_error(
136 tr(
"At least one of (%1,%2) has to be an input slot!")
137 .arg(source).arg(target).toStdString());
142 throw std::runtime_error(
143 tr(
"%1 has to be an output slot!").arg(target).toStdString());
147 QString inSlotType =
getType(target);
148 QString outSlotType =
getType(source);
149 if ((inSlotType.toLower() != outSlotType.toLower())&&!(inSlotType.toLower()==
"virtual"||outSlotType.toLower()==
"virtual"))
150 throw std::runtime_error(
151 tr(
"Type of \"%1\" (%2) does not match type of \"%3\" (%4)")
152 .arg(target).arg(inSlotType).arg(source).arg(outSlotType)
156 getValue(source).contains(QRegExp(target,Qt::CaseInsensitive));
160 !(
getValue(target).contains(QRegExp(source,Qt::CaseInsensitive)))) {
161 throw std::runtime_error(
162 tr(
"Node %1 missing in List %2!")
163 .arg(source).arg(target).toStdString());
171 qFatal(
"Tried to set emtpy metaFile in GraphModel!");
184 qSwap(source,target);
196 Q_ASSERT(content.indexOf(target,Qt::CaseInsensitive) < 0);
197 QStringList targetList = content.split(
";", QString::SkipEmptyParts);
199 targetList << target;
200 setValue(source, targetList.join(
";"));
208 if (content.indexOf(source,Qt::CaseInsensitive) < 0) {
209 QStringList sourceList = content.split(
";", QString::SkipEmptyParts);
211 sourceList << source;
212 setValue(target, sourceList.join(
";"));
219 tr(
"connect slot %1 with %2").arg(source).arg(target));
223 QString content =
getValue(source).toLower();
224 QStringList targets = content.split(
";", QString::SkipEmptyParts);
225 if (target.isEmpty()) {
226 foreach (
const QString& tar, targets) {
232 int pos = targets.indexOf(target.toLower(),0);
234 targets.removeAt(pos);
235 setValue(source, targets.join(
";"));
245 tr(
"disconnected slot %1 from all targets").arg(source) :
246 tr(
"disconnected slot %1 from %2").arg(source).arg(target));
250 node = node.section(
".",0,0).toLower();
251 foreach (
const QString& slot,
getInputs(node)) {
252 disconnectSlot(QString(
"%1.%2").arg(node).arg(slot),QString(),
false);
254 foreach (
const QString& slot,
getOutputs(node)) {
255 disconnectSlot(QString(
"%1.%2").arg(node).arg(slot),QString(),
false);
261 emit
statusMessage(tr(
"disconnected all slots of node %1").arg(node));
265 nodename = nodename.section(
".",0,0).toLower();
269 0, tr(
"rename node"),
270 tr(
"Enter new name for node \"%1\":").arg(nodename),
271 QLineEdit::Normal, nodename, &ok,0,Qt::ImhNone,
273 newName = newName.toLower() ;
275 if (newName.compare(nodename,Qt::CaseInsensitive)==0) {
280 QMessageBox::warning(
281 0, tr(
"node exists"),
282 tr(
"A node named <i>%1</i> does already exist.<br/>"
283 "Please choose another name.").arg(newName));
286 if (
rename(nodename,newName)) {
291 tr(
"renamed node %1 to %2").arg(nodename).arg(newName));
295 tr(
"renaming failed! (%1 to %2)").arg(nodename).arg(newName)
296 .toLocal8Bit().constData());
302 if(
nodeValid(nodename) && QMessageBox::question(
303 0, tr(
"confirm delete"),
304 tr(
"Do you really want to delete node \"%1\"?").arg(nodename),
305 QMessageBox::No | QMessageBox::Yes, QMessageBox::No)
306 == QMessageBox::Yes) {
311 if (QString::compare(nodename,
prefix(),Qt::CaseInsensitive) == 0) {
314 if (QString::compare(nodename,
prefix(),Qt::CaseInsensitive) == 0) {
328 foreach (
const QString& cur, toDelete) {
344 QSet<QString> nodeSet;
348 foreach (
const QString& ckey, keys) {
349 nodeSet << ckey.section(
".",0,0);
353 foreach(
const QString& node, nodeSet) {
363 const QStringList& curNodes =
nodes();
366 if (!curNodes.size())
372 pos = curNodes.indexOf(
prefix());
375 pos = (pos - 1 + curNodes.size()) % curNodes.size();
378 pos = (pos + 1) % curNodes.size();
386 QString info, newName, baseName = className.toLower();
389 QRegExp cNameCheck(
"([\\w]+)[\\s\\.]+.*");
390 if (cNameCheck.exactMatch(baseName)) {
391 baseName = cNameCheck.cap(1).toLower();
392 Q_ASSERT(!baseName.isEmpty());
403 newName = QString(
"%1%2").arg(baseName).arg(++nameNr);
408 0, tr(
"add new node"),
409 info + tr(
"Enter a name for the new node:"),
410 QLineEdit::Normal, newName,
411 0,0,Qt::ImhNone,&validator).trimmed();
413 if (newName.isEmpty()) {
418 newName = newName.toLower() ;
423 info = tr(
"This name is already in use.") +
"\n"
424 + tr(
"Please use another name.") +
"\n";
426 if( cNameCheck.exactMatch(newName) ) {
428 info = tr(
"Whitespace and dots in names are not allowed.") +
"\n"
429 + tr(
"Please use a valid name.") +
"\n";
430 baseName = cNameCheck.cap(1).toLower();
434 setValue(newName+
".type", className);
437 tr(
"add node %1 of class %2").arg(newName).arg(className));
445 const QModelIndex& ind,
const QVariant& value,
int role) {
446 QString param =
data(index(ind.row(),0)).toString();
447 if (!
prefix().isEmpty()) {
449 param =
prefix() +
"." + param;
451 QRegExp ttype(
"(.*\\.)?templatetype",Qt::CaseInsensitive);
453 (role == Qt::DisplayRole || role == Qt::EditRole) &&
455 value !=
data(ind) &&
456 ttype.exactMatch(param)) {
459 QString node = param.section(
".",0,0).toLower();
460 QStringList allSlots;
462 foreach (
const QString& slot, allSlots) {
463 QString slotName = QString(
"%1.%2").arg(node).arg(slot);
464 QString slotTypeR =
getType(slotName,
true);
465 QString slotTypeT =
getType(slotName,
false);
466 if (slotTypeR != slotTypeT) {
477 const QModelIndex& parentInd) {
478 QRegExp ttype(
"(.*\\.)?templatetype",Qt::CaseInsensitive);
483 for (
int i = row; i < row+count; i++) {
484 QString cur =
data(index(row,0)).toString();
485 if (!
prefix().isEmpty()) {
486 cur =
prefix() +
"." + cur;
488 if (ttype.exactMatch(cur)) {
void setOnlyParams(bool value)
Set property _onlyparams.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Set item content.
void statusMessage(const QString &msg)
send status message
void erase(QString parName)
Delete a parameter from the the underlying parameter file.
QStringList nodes() const
Get nodes in current graph.
virtual QString setPrefix(const QString &prefix)
Change prefix.
bool rename(QString oldPrefix, QString newPrefix)
rename prefix
void disconnectAllSlots(QString node, bool draw=true)
disconnect all slots of given node
void dynamicUpdate()
inform about dynamic plugin update
QStringList getClasses() const
get classes contained in metadata file
QString getValue(QString parName) const
Get a parameter from the underlying parameter file.
GraphModel(QString fileName="", QObject *parent=0, QString metaFile="")
Constructor initializing the model with the given file.
void graphChanged()
Initiate graph rebuild and Display refresh.
Declaration of class GraphModel.
const QParameterFile & parameterFile() const
Get const pointer of ParameterFile.
QString getDefault(QString parName) const
pass to metaInfo, use dynamic metadata if needed
QStringList getInputs(QString objName) const
Get input slots of object.
Declaration of class QParameterFile.
QString prefix() const
Get property _prefix.
void reDraw()
emit graph changed signal to update displays
QStringList getOutputs(QString objName) const
Get output slots of object.
virtual void loadMetaInfo(const QString &fileName)
load metaFile
QString getClass(QString objName, bool fixCase=false) const
get class of some given object
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Return number of table rows.
void selectNext(bool back=false)
select next item
bool isMultiSlot(QString name) const
Check if some slot is a multi slot.
This model serves to provide a model frontend to access a ParameterFile instance. ...
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Access to item content.
QString addNode(QString className, bool draw=true)
add new node of given kind
bool prefixValid() const
Check prefix.
void disconnectSlot(QString source, QString target=QString(), bool draw=true)
disconnect slots
bool connected(QString source, QString target) const
Check if given connection is valid and established.
bool deleteNode(QString nodename, bool draw=true)
delete node
bool isOutputSlot(QString name) const
Check if some parameter/slot is an output slot.
void setValue(QString parName, QString value)
Set a parameter in the underlying parameter file.
bool useMetaInfo() const
Get property _useMetadata;.
QStringList getKeyList(QString beginsWith="") const
Look for parameters beginning with a given string.
void connectSlot(QString source, QString target, bool draw=true)
connect slots
void renameNode(QString nodename, bool draw=true)
rename node
virtual bool _load()
Load data without showing OpenFile Dialog.
bool nodeValid(const QString &name) const
Checks if the given node is a valid object in the ParameterFile.
virtual void clear()
Clear ParameterFile content.
virtual void clear()
Clear ParameterFile content with redraw.
QString getType(QString parName, bool applyTmplType=true) const
Get type of some parameter or slot.
virtual bool _load()
Load data without showing OpenFile Dialog.
Declaration of class QTextInputDialog.
static QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode=QLineEdit::Normal, const QString &text=QString(), bool *ok=0, Qt::WindowFlags flags=0, Qt::InputMethodHints iHints=Qt::ImhNone, QValidator *val=0)
get text
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Remove data from the model.
std::string _toLower(std::string input)
transform std::string into lowercase
bool isInputSlot(QString name) const
Check if some parameter/slot is an input slot.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Set item content.
virtual void loadMetaFile(QString fileName)
load metaFile
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Remove data from the model.
static const QRegExp prefixCheck
instance name or prefix check regex