Example #1
0
QVariant MetricDomModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (role != Qt::DisplayRole)
        return QVariant();

    DomItem *item = static_cast<DomItem*>(index.internalPointer());

    QDomNode node = item->node();

    QStringList attributes;
    QDomNamedNodeMap attributeMap = node.attributes();

    switch (index.column()) {
        case 0:
            return node.nodeName();
        case 1:
        	if( !attributeMap.contains("Type") ) {
        		return QVariant();
        	}
        	return attributeMap.namedItem("Type").nodeValue();
        case 2:
        	if( !attributeMap.contains("Format") ) {
        		return QVariant();
        	}
        	return attributeMap.namedItem("Format").nodeValue();
        default:
            return QVariant();
    }
}
Example #2
0
bool Configurator::loadSectionItem( QDomNode sectionItem, QListWidget& listWidget )
{
	if( false == sectionItem.hasChildNodes() )
		return false;

	if( sectionItem.nodeName() != c_sectionItemNodeName )
		return false;

	QDomNamedNodeMap sectionItemAttributes = sectionItem.attributes();
	if( false == sectionItemAttributes.contains(c_attributeName) )
		return false;

	if( false == sectionItemAttributes.contains(c_attributeText) )
		return false;

	// add the item to the section
	QString sectionItemName = sectionItemAttributes.namedItem(c_attributeName).nodeValue();
	QString sectionItemText = sectionItemAttributes.namedItem(c_attributeText).nodeValue();
	
	QListWidgetItem*	listWidgetItem = new QListWidgetItem();
					    listWidgetItem->setText( sectionItemText );
					    listWidgetItem->setData( Qt::UserRole, sectionItemName );

    listWidget.addItem( listWidgetItem );

	return true;
}
Example #3
0
void ComponentItem::initPins()
{
    QDomNode pinsNode;
    QDomNodeList list = m_svgDocument.elementsByTagName("g");
    for (int i=0;i<list.count();i++){
        QDomNamedNodeMap attrs = list.item(i).attributes();
        if (attrs.contains("id") &&
            attrs.namedItem("id").toAttr().value() == QString("pins")){
            pinsNode = list.item(i);
            break;
        }
    }
    if (pinsNode.isNull() || !pinsNode.hasChildNodes()){
        kWarning() << "No pins definition found for this component";
        return;
    }
    QDomElement pin = pinsNode.firstChildElement();
    while (!pin.isNull()) {
        QRectF pinRect;
        double r = pin.attribute("r").toDouble();
        pinRect.setLeft(pin.attribute("cx").toDouble());
        pinRect.setTop(pin.attribute("cy").toDouble());
        pinRect.setWidth(r*2);
        pinRect.setHeight(r*2);
        PinItem* p = new PinItem(pinRect, this, qobject_cast< IDocumentScene* >(scene()));
        p->setId(pin.attribute("id"));
        pin = pin.nextSiblingElement();
    }
}
bool QDomNamedNodeMapProto:: contains(const QString& name) const
{
  QDomNamedNodeMap *item = qscriptvalue_cast<QDomNamedNodeMap*>(thisObject());
  if (item)
    return item->contains(name);
  return false;
}
bool RedisConnectionConfig::getValueFromXml(const QDomNamedNodeMap & attr, const QString& name, QString & value)
{
    if (!attr.contains(name))
        return false;

    value = attr.namedItem(name).nodeValue();

    return true;
}
Example #6
0
bool Configurator::loadSection( QDomNode section )
{
	// make some checks
	if( false == section.hasChildNodes() )
		return false;

	if( section.nodeName() != c_sectionNodeName )
		return false;

	QDomNamedNodeMap sectionAttributes = section.attributes();
	if( false == sectionAttributes.contains(c_attributeName) )
		return false;

	if( false == sectionAttributes.contains(c_attributeText) )
		return false;

	// we have all the attribbutes for this section, now build it usign GUI controls
	QString sectionName = sectionAttributes.namedItem(c_attributeName).nodeValue();
	QString sectionText = sectionAttributes.namedItem(c_attributeText).nodeValue();
	
	// build the UI
	QListWidget*	listWidget = new QListWidget();
				    listWidget->setObjectName( sectionName );
				    listWidget->setSelectionBehavior( QAbstractItemView::SelectRows );

	connect( listWidget,    SIGNAL	(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
			 this,		    SLOT	(currentItemChanged(QListWidgetItem*,QListWidgetItem*))	);

	_sections->addItem( listWidget, sectionText );
			
	// adding items for this section
	QDomNode sectionItem = section.firstChild();
	while( false == sectionItem.isNull() )
	{
	    if( QDomNode::CommentNode != section.nodeType() )
		if( false == loadSectionItem(sectionItem,*listWidget) )
			return false;
	
		sectionItem = sectionItem.nextSibling();				
	}

	return true;
}
Example #7
0
/******************************************************************************
    PopulateComponent
******************************************************************************/
void
CUpdateInfoGetter::PopulateComponent(
    const QDomNode &appNode,
    CComponentInfo& info)
{

    //TODO: sanity check xml

    //if (vecStrings.size() != 5)
    //{
    //    Q_ASSERT(false);
    //    throw ConnectionException(QT_TR_NOOP("Downloaded update info for "
    //        "component didn't contain the correct number of entries."));
    //}

    info.Clear();

    QDomNamedNodeMap appAttributes = appNode.attributes();

    info.SetName(appAttributes.namedItem( "name" ).nodeValue());

    #ifdef WIN32
        string sPF = UnicornUtils::programFilesPath();
        if (sPF == "")
        {
            // Do our best at faking it. Will at least work some of the time.
            LOG(1, "Couldn't get PF path so trying to fake it.");
            sPF = "C:\\Program Files\\";
        }
        info.SetPath(QString::fromStdString(sPF) +
                     appNode.firstChildElement("Path").text());
    #else // not WIN32
        info.SetPath(appNode.firstChildElement("Path").text());
    #endif // WIN32

    if ( !appNode.firstChildElement("Size").isNull() )
        info.SetSize( appNode.firstChildElement("Size").text().toInt() );
    else
        info.SetSize( 0 );

    info.SetDownloadURL ( appNode.firstChildElement("Url").text() );
    info.SetVersion     ( appAttributes.namedItem( "version" ).nodeValue() );
    info.SetInstallArgs ( appNode.firstChildElement("Args").text()  );

    if( appAttributes.contains( "majorUpgrade" )) {
        info.SetMajorUpgrade( appAttributes.namedItem( "majorUpgrade" ).nodeValue()
                              == "true" );
    }

    if( !appNode.firstChildElement("Description").isNull())
        info.SetDescription( appNode.firstChildElement("Description").text());

    if( !appNode.firstChildElement("Image").isNull())
        info.SetImage( QUrl( appNode.firstChildElement("Image").text()));
}
Example #8
0
/** Sets the layout attributes for the given report section */
void MReportEngine::setSectionAttributes(MReportSection *section, QDomNode *report)
{
  // Get the attributes for the section
  QDomNamedNodeMap attributes = report->attributes();

  // Get the section attributes
  section->setHeight(attributes.namedItem("Height").nodeValue().toInt());
  section->setPrintFrequency(attributes.namedItem("PrintFrequency").nodeValue().toInt());
  if (attributes.contains("SectionId"))
    section->setIdSec(attributes.namedItem("SectionId").nodeValue().toUInt());

  // Process the sections labels
  QDomNodeList children = report->childNodes();
  int childCount = children.length();

  // For each label, extract the attr list and add the new label
  // to the sections's label collection

  for (int j = 0; j < childCount; j++) {
    QDomNode child = children.item(j);

    if (child.nodeType() == QDomNode::ElementNode) {
      if (child.nodeName() == "Line") {
        QDomNamedNodeMap attributes = child.attributes();
        MLineObject *line = new MLineObject();

        setLineAttributes(line, &attributes);
        section->addLine(line);
      } else if (child.nodeName() == "Label") {
        QDomNamedNodeMap attributes = child.attributes();
        MLabelObject *label = new MLabelObject();

        setLabelAttributes(label, &attributes);
        section->addLabel(label);
      } else if (child.nodeName() == "Special") {
        QDomNamedNodeMap attributes = child.attributes();
        MSpecialObject *field = new MSpecialObject();

        setSpecialAttributes(field, &attributes);
        section->addSpecialField(field);
      } else if (child.nodeName() == "CalculatedField") {
        QDomNamedNodeMap attributes = child.attributes();
        MCalcObject *field = new MCalcObject();

        setCalculatedFieldAttributes(field, &attributes);
        section->addCalculatedField(field);
      }
    }
  }
}
Example #9
0
File: ssu.cpp Project: lbt/ssu
bool Ssu::setCredentials(QDomDocument *response){
  SsuCoreConfig *settings = SsuCoreConfig::instance();
  // generate list with all scopes for generic section, add sections
  QDomNodeList credentialsList = response->elementsByTagName("credentials");
  QStringList credentialScopes;
  for (int i=0;i<credentialsList.size();i++){
    QDomNode node = credentialsList.at(i);
    QString scope;

    QDomNamedNodeMap attributes = node.attributes();
    if (attributes.contains("scope")){
      scope = attributes.namedItem("scope").toAttr().value();
    } else {
      setError(tr("Credentials element does not have scope"));
      return false;
    }

    if (node.hasChildNodes()){
      QDomElement username = node.firstChildElement("username");
      QDomElement password = node.firstChildElement("password");
      if (username.isNull() || password.isNull()){
        setError(tr("Username and/or password not set"));
        return false;
      } else {
        settings->beginGroup("credentials-" + scope);
        settings->setValue("username", username.text());
        settings->setValue("password", password.text());
        settings->endGroup();
        settings->sync();
        credentialScopes.append(scope);
      }
    } else {
      setError("");
      return false;
    }
  }
  settings->setValue("credentialScopes", credentialScopes);
  settings->setValue("lastCredentialsUpdate", QDateTime::currentDateTime());
  settings->sync();
  emit credentialsChanged();

  return true;
}
Example #10
0
/** Sets the layout attributes for the detail headers and footers */
void MReportEngine::setDetMiscAttributes(MReportSection *section, QDomNode *report)
{
  // Get the attributes for the section
  QDomNamedNodeMap attributes = report->attributes();

  // Get the section attributes
  section->setDrawIf(attributes.namedItem("DrawIf").nodeValue());

  if (attributes.contains("SectionId"))
    section->setIdSec(attributes.namedItem("SectionId").nodeValue().toUInt());

  QDomNode levelNode = attributes.namedItem("Level");

  if (!levelNode.isNull())
    section->setLevel(attributes.namedItem("Level").nodeValue().toInt());
  else
    section->setLevel(-1);

  QDomNode n = attributes.namedItem("NewPage");

  if (!n.isNull())
    section->setNewPage(n.nodeValue().upper() == "TRUE");
  else
    section->setNewPage(false);

  n = attributes.namedItem("PlaceAtBottom");

  if (!n.isNull())
    section->setPlaceAtBottom(n.nodeValue().upper() == "TRUE");
  else
    section->setPlaceAtBottom(false);

  n = attributes.namedItem("DrawAllPages");

  if (!n.isNull())
    section->setDrawAllPages(n.nodeValue().upper() == "TRUE");
  else
    section->setDrawAllPages(false);
}
Example #11
0
void GLSLUberShaderFactory::load(ResourceData *resource)
{
	GLSLUberShader* program = static_cast<GLSLUberShader*>(resource);

	QFile file(program->m_path);

	if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		logWarn("GLSLUberShader : Can't open file" << program->m_path);
		return;
	}

	QDomDocument doc;
	if(!doc.setContent(&file))
	{
		logWarn("GLSLUberShader : Can't parse file" << program->m_path);
		return;
	}

	QDomNodeList programs = doc.elementsByTagName("ubershader");

	if(programs.length() < 1)
	{
		logWarn("GLSLUberShader : No program tag in file" << program->m_path);
		return;
	}

	QDomNodeList nodes = programs.at(0).childNodes();

	for(int i=0 ; i < (int)nodes.length() ; i++)
	{
		QString tag = nodes.at(i).nodeName();

		if(tag == "shader")
		{
			QDomNamedNodeMap attributes = nodes.at(i).attributes();
			if(attributes.contains("source"))
			{
				QString shader_name = attributes.namedItem("source").nodeValue();
				Shader shader = SHADER_MANAGER.get(shader_name);
				if(shader.isValid())
				{
					QGLShader* qgl_shader = shader->shader();
					if(qgl_shader->shaderType() == QGLShader::Fragment) {
						program->m_fragment_shader = qgl_shader->sourceCode();
						program->m_fragment_shader_file = shader_name;
					} else {
						program->m_vertex_shader = qgl_shader->sourceCode();
						program->m_vertex_shader_file = shader_name;
					}
				}
				else
				{
					logError("shader" << shader_name << "not available" << nodes.at(i).lineNumber());
				}
			}
		}
		else if(tag == "uniform")
		{
			GLSLUberShader::UniformBase* uniform;
			QDomNamedNodeMap attributes = nodes.at(i).attributes();
			QString uniform_type;
			QString name;
			QString value;
			if(attributes.contains("name"))
			{
				name = attributes.namedItem("name").nodeValue();
			}
			if(attributes.contains("value"))
			{
				value = attributes.namedItem("value").nodeValue();
			}
			if(attributes.contains("type"))
			{
				uniform_type = attributes.namedItem("type").nodeValue();
			}
			else
			{
				uniform_type = "float";
			}
			QStringList vallist = value.split(" ",QString::SkipEmptyParts);
			if(uniform_type == "int")
			{
				GLint* data = new GLint[vallist.length()]();
				uniform = new GLSLUberShader::Uniform<GLint>(name,data,vallist.length(),1);
				for(int i=0 ; i<vallist.length() ; i++)
				{
					bool ok;
					GLint val = vallist.at(i).toInt(&ok);
					if(ok)
						data[i] = val;
					else
						logWarn("non int while reading" << value << "in file" << program->m_path);
				}
			}
			else
			{
				GLfloat* data = new GLfloat[vallist.length()]();
				uniform = new GLSLUberShader::Uniform<GLfloat>(name,data,vallist.length(),1);
				for(int i=0 ; i<vallist.length() ; i++)
				{
					bool ok;
					GLfloat val = vallist.at(i).toFloat(&ok);
					if(ok)
						data[i] = val;
					else
						logWarn("non float while reading" << value << "in file" << program->m_path);
				}
			}
			program->m_uniforms.push_back(uniform);
		}
		else
		{
			logWarn("In file" << program->m_name << "Unknown tag" << tag);
		}
	}

	program->m_state = GLSLUberShader::STATE_LOADED;
	logInfo("GLSLUberShader loaded" << program->name());

	debugGL("while loading shader program" << program->m_path);
}
Example #12
0
/** Sets the layout attributes for the detail section */
void MReportEngine::setDetailAttributes(MReportSection *section, QDomNode *report)
{
  // Get the attributes for the detail section
  QDomNamedNodeMap attributes = report->attributes();

  section->setHeight(attributes.namedItem("Height").nodeValue().toInt());

  if (attributes.contains("SectionId"))
    section->setIdSec(attributes.namedItem("SectionId").nodeValue().toUInt());

  QDomNode levelNode = attributes.namedItem("Level");
  if (!levelNode.isNull())
    section->setLevel(attributes.namedItem("Level").nodeValue().toInt());
  else
    section->setLevel(-1);

  section->setDrawIf(attributes.namedItem("DrawIf").nodeValue());

  QString cols = attributes.namedItem("Cols").nodeValue();

  if (!cols)
    cols = "1";

  int width = ceil((pageWidth - rightMargin - leftMargin) / cols.toFloat());
  section->setWidth(width);

  // Process the report detail labels
  QDomNodeList children = report->childNodes();

  int childCount = children.length();

  for (int j = 0; j < childCount; j++) {
    QDomNode child = children.item(j);

    if (child.nodeType() == QDomNode::ElementNode) {
      if (child.nodeName() == "Line") {
        QDomNamedNodeMap attributes = child.attributes();
        MLineObject *line = new MLineObject();

        setLineAttributes(line, &attributes);
        section->addLine(line);
      } else if (child.nodeName() == "Label") {
        QDomNamedNodeMap attributes = child.attributes();
        MLabelObject *label = new MLabelObject();

        setLabelAttributes(label, &attributes);
        section->addLabel(label);
      } else if (child.nodeName() == "Special") {
        QDomNamedNodeMap attributes = child.attributes();
        MSpecialObject *field = new MSpecialObject();

        setSpecialAttributes(field, &attributes);
        section->addSpecialField(field);
      } else if (child.nodeName() == "CalculatedField") {
        QDomNamedNodeMap attributes = child.attributes();
        MCalcObject *field = new MCalcObject();

        setCalculatedFieldAttributes(field, &attributes);
        section->addCalculatedField(field);
      } else if (child.nodeName() == "Field") {
        QDomNamedNodeMap attributes = child.attributes();
        MFieldObject *field = new MFieldObject();

        setFieldAttributes(field, &attributes);
        section->addField(field);
      }
    }
  }
}