const ExprStrSpec* ExprStrSpec::match(const ExprNode* node) { if (const ExprStrNode* strnode = isString(node)) { std::string comment = findComment(*node); char* name = new char[comment.length() + 1]; char* type = new char[comment.length() + 1]; int numMatched = sscanf(comment.c_str(), "#%s %s\n", type, name); Type newType; if (numMatched == 2) { bool valid = true; if (!strcmp(type, "string")) newType = STRING; else if (!strcmp(type, "file")) newType = FILE; else if (!strcmp(type, "directory")) newType = DIRECTORY; else valid = false; if (valid) return new ExprStrSpec(*strnode, name, newType); } delete[] name; delete[] type; } return 0; }
void CommentsModel::deleteComment(int id) { int index = findComment(id); if (index == -1) return; beginRemoveRows(QModelIndex(), index, index); m_comments.removeAt(index); endRemoveRows(); }
ExprScalarAssignSpec::ExprScalarAssignSpec(const ExprAssignNode& node) : ControlSpec(node), _min(0), _max(1), _val(static_cast<const ExprNumNode*>(node.child(0))->value()) { _name = node.name(); std::string comment = findComment(node); // TODO: handle integer case int numParsed = sscanf(comment.c_str(), "#%lf,%lf\n", &_min, &_max); if (numParsed != 2) { _min = 0; _max = 1; } }
ExprVectorAssignSpec::ExprVectorAssignSpec(const ExprAssignNode& node) : ControlSpec(node), _min(0), _max(1), _val(Vec3d(static_cast<const ExprNumNode*>(node.child(0)->child(0))->value(), static_cast<const ExprNumNode*>(node.child(0)->child(1))->value(), static_cast<const ExprNumNode*>(node.child(0)->child(2))->value())) { _name = node.name(); std::string comment = findComment(node); int numParsed = sscanf(comment.c_str(), "#%lf,%lf\n", &_min, &_max); if (numParsed != 2) { _min = 0; _max = 1; } }
void CommentsModel::addComment(const QVariantMap &data) { int cid = data.value("cid").toInt(); if (findComment(cid) != -1) return; auto it = qLowerBound(m_comments.begin(), m_comments.end(), data , commentLessThan); auto last = it - m_comments.begin(); beginInsertRows(QModelIndex(), last, last); m_comments.insert(it, data); endInsertRows(); qApp->processEvents(QEventLoop::ExcludeUserInputEvents); }