CoreBufferViewManager::CoreBufferViewManager(SignalProxy *proxy, CoreSession *parent)
    : BufferViewManager(proxy, parent),
    _coreSession(parent)
{
    QVariantMap views = Core::getUserSetting(_coreSession->user(), "BufferViews").toMap();
    QVariantMap::iterator iter = views.begin();
    QVariantMap::iterator iterEnd = views.end();
    CoreBufferViewConfig *config = 0;
    while (iter != iterEnd) {
        config = new CoreBufferViewConfig(iter.key().toInt(), iter.value().toMap(), this);
        addBufferViewConfig(config);
        ++iter;
    }
}
void CdoSampleAppWindow::onMediaDevicesListChanged(int devType,
                                                   QVariantMap devs)
{
    QComboBox * targetCombo;
    switch (devType)
    {
    case AUDIO_IN:
        targetCombo = ui->micCombo;
        break;
    case AUDIO_OUT:
        targetCombo = ui->spkCombo;
        break;
    case VIDEO_IN:
        targetCombo = ui->camCombo;
        break;
    case SCREEN:
        targetCombo = ui->screenCombo;
        break;
    }

    targetCombo->clear();

    QVariantMap::iterator i;
    for (i = devs.begin(); i != devs.end(); ++i)
    {
        qDebug() << "Adding device: " << i.key();
        targetCombo->addItem(QIcon(), i.value().toString(), i.key());
    }
}
Exemple #3
0
static void setupCompilerPathByLanguage(Profile &profile, const QStringList &toolchainTypes,
        const QString &toolchainInstallPath, const QString &toolchainPrefix)
{
    QVariantMap m;
    if (toolchainTypes.contains(QLatin1String("clang"))) {
        m[QLatin1String("c")] = m[QLatin1String("objc")] = QLatin1String("clang");
        m[QLatin1String("cpp")] = m[QLatin1String("objcpp")] = QLatin1String("clang++");
    } else if (toolchainTypes.contains(QLatin1String("gcc"))) {
        m[QLatin1String("c")] = m[QLatin1String("objc")] = QLatin1String("gcc");
        m[QLatin1String("cpp")] = m[QLatin1String("objcpp")] = QLatin1String("g++");
    } else {
        qDebug("WARNING: unexpected toolchain %s", qPrintable(toJSLiteral(toolchainTypes)));
        return;
    }

    const QString toolchainPathPrefix = toolchainInstallPath + QLatin1Char('/') + toolchainPrefix;
    for (QVariantMap::iterator it = m.begin(); it != m.end();) {
        const QString filePath = HostOsInfo::appendExecutableSuffix(toolchainPathPrefix
                                                                    + it.value().toString());
        if (QFile::exists(filePath)) {
            it.value() = filePath;
            ++it;
            continue;
        }
        qDebug("WARNING: Compiler %s for file tag %s not found.",
               qPrintable(QDir::toNativeSeparators(filePath)), qPrintable(it.key()));
        it = m.erase(it);
    }
    if (!m.isEmpty())
        profile.setValue(QLatin1String("cpp.compilerPathByLanguage"), m);
}
Exemple #4
0
/* This only parses uniform variables between the following lines:

// BEGIN UNIFORM
uniform float x;    // default
uniform vec4 color; // red green blue alpha
// END UNIFORM

uniform can be replaced by 'in' and if no default is given the floats default
to 0.0 and the color to white.  Comments between the BEGIN and END lines are
ignored.
*/
QVariantMap ShaderLibrary::parseUniformVariables(QString const& vertexShaderPath)
{
   QVariantMap map;

   QFile file(vertexShaderPath);
   if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
      Parser2::TextStream textStream(&file);

      int n;
      bool tf;
      double value;
      QString line;
      QString name;
      QColor  color;
      QStringList tokens;
      textStream.seek("BEGIN UNIFORM");

      while (!textStream.atEnd()) {
         line = textStream.nextLine();      
         if (line.contains("END UNIFORM")) break;

         if (!line.startsWith("//")) {
            line = line.replace(";"," ");
            line = line.replace(","," ");
            line = line.replace("//"," ");

            tokens = Parser2::TextStream::tokenize(line);
            n = tokens.size();

            if (n >= 3 && (tokens[0] == "uniform" || tokens[0] == "in"))  {
               name = tokens[2];

               if (tokens[1] == "float") {
                  value = (n >= 4) ? tokens[3].toDouble() : 0.0;
                  map.insert(name, value);
               }else if (tokens[1] == "bool") {
                  tf = (n >= 4) ? tokens[3].toInt() : false;
                  map.insert(name, tf);
               }else if (tokens[1] == "vec4") {
                  color = Qt::white;
                  if (n >= 7) {
                     color.setRgbF(tokens[3].toDouble(), tokens[4].toDouble(), 
                        tokens[5].toDouble(), tokens[6].toDouble());
                  }
                  map.insert(name, color);
               }else {
                  qDebug() << "Unknown uniform variable in shader" << tokens[1];
               }
            }
         }
      }

      file.close();
   }   
   qDebug() << "Parsed the following uniform variables:";
   for (QVariantMap::iterator iter = map.begin(); iter != map.end(); ++iter) {
        qDebug() << iter.key() << iter.value();
   }
   return map;
}
Exemple #5
0
mongo::BSONObj toBson(QVariantMap obj) {
    mongo::BSONObjBuilder b;

    QVariantMap::iterator it = obj.begin();
    while(it != obj.end()) {
        QByteArray byteName = it.key().toStdString().c_str();
        const char* name = byteName.constData();
        QVariant v = it.value();
        int type = v.type();

//        qDebug() << "toBson converting type" << v.typeName();
        if (v.canConvert<QObject*>()) {
            QMongoType* mongo = qobject_cast<QMongoType*>( v.value<QObject*>() );
            Q_ASSERT(mongo->o.nFields() == 1);
            b.appendAs(mongo->o.firstElement(), name);
            ++it;
            continue;
        }

        bool ok = true;
        switch(type) {
        case QVariant::Int:
            b.append(name, v.toInt(&ok));
            break;
        case QVariant::String:
            b.append(name, v.toString().toStdString());
            break;
        case QVariant::LongLong:
            b.append(name, v.toLongLong(&ok));
            break;
        case QVariant::UInt:
            b.append(name, v.toUInt(&ok));
            break;
        case QVariant::Map:
            b.append(name, toBson(v.toMap()));
            break;
        case QVariant::Double:
            b.append(name, v.toDouble(&ok));
            break;
        case QVariant::Bool:
            b.appendBool(name, v.toBool());
            break;            
        case QVariant::Time:
            b.appendTimeT(name, v.toDateTime().toTime_t());
            break;
        case QVariant::Invalid:
            b.appendUndefined(name);
            break;
        default:
            qCritical() << "toBson() failed to convert" << obj << "for" << name << "with type" << v.typeName();
            ok = false;
        }
        Q_ASSERT(ok);
        ++it;
    }
    return b.obj();
}
void ComponentWidget::insertComponent()
{
    QStringList options;
    QVariantMap::iterator iterator;

    for (iterator = m_options.begin(); iterator != m_options.end(); ++iterator) {
        options.append(QString("'%1': %2").arg(iterator.key()).arg(iterator.value().toString()));
    }

    emit insertComponent(Clock::getComponentString(m_component), (options.isEmpty() ? QString() : options.join(QString(", "))));
}
  QMap<QString, QString>  BIGHOME_NetWork_logIn::setJson(QByteArray jsonDoc)
{
  QJson::Parser parser;
  bool OK;
  QVariantMap jsonMap = parser.parse(jsonDoc, &OK).toMap();
  QMap<QString, QString> jsonDocMap;
  if (!jsonDocMap.isEmpty())
  {
    jsonDocMap.clear();
  }
  if (OK)
  {
    QVariantList tempVariant = jsonMap["userinfo"].toList();
    QVariantMap tempMap = tempVariant[0].toMap();
    for (QVariantMap::iterator i = tempMap.begin(); i != tempMap.end(); i++)
    {
      jsonDocMap[i.key()] = i.value().toString();
    }
    emit signalsLogin(OK, jsonDocMap);
    return jsonDocMap;
  }
  emit signalsLogin(OK, jsonDocMap);
  return jsonDocMap;
}
Exemple #8
0
Map::Map(const QString &filename) :
    d(new MapPrivate)
{
    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly))
    {
        setError(1, QString("Could not open %1 for reading: %2")
                       .arg(filename)
                       .arg(file.errorString())
        );
        return;
    }

    QByteArray rawJson = file.readAll();
    QJsonParseError error;
    QJsonDocument doc = QJsonDocument::fromJson(rawJson, &error);
    if (error.error != QJsonParseError::NoError) {
        setError(1, QString("Failed to load imagemap %1, error %2 on offset %3")
                    .arg(filename)
                    .arg(error.errorString())
                    .arg(error.offset));
        return;
    }

    QVariantMap result = doc.toVariant().toMap();
    if (result.isEmpty())
    {
        setError(1, QString("Empty Map %1").arg(filename));
        return;
    }

    QString basepath = QFileInfo(filename).absolutePath();

    QVariantMap imagemaps = result["images"].toMap();
    for (QVariantMap::iterator files = imagemaps.begin();
         files != imagemaps.end(); ++files)
    {
        QString filename = basepath + "/" + files.key() ;
        QVariantMap fileOpts = files.value().toMap();

        // Load the image container.
        Container* container;
        if (filename.endsWith(".svg"))
        {
            container = ContainerSVG::create(this, filename);
        }
        else
        {
            container = ContainerImage::create(this, filename);
        }

        if (errorCode() != 0)
        {
            setError(1, QString("Failed to load image %1: %2")
                            .arg(filename)
                            .arg(errorString()));
            return;
        }

        // Create the list of images.
        if (fileOpts.contains("full"))
        {
            QVariantMap value = fileOpts["full"].toMap();
            if (value.isEmpty())
            {
                wzLog(LOG_IM) << "Image" << filename << "is empty!";
            }
            else
            {
                Image myImage;

                // Add the first found image.
                myImage.type = FixedType;
                myImage.xPosition = 0;
                myImage.yPosition = 0;
                myImage.size = QSize(value.begin().value().toList()[0].toInt(),
                                     value.begin().value().toList()[1].toInt());
                myImage.container = container;

                d->m_images.insert(value.begin().key(), myImage);
            }
        }

        if (fileOpts.contains("fixed"))
        {
            QVariantMap value = fileOpts["fixed"].toMap();
            for (QVariantMap::iterator images = value.begin();
                 images != value.end(); ++images)
            {
                QVariantList imgdefList = images.value().toList();

                Image myImage;
                myImage.type = FixedType;
                myImage.xPosition = imgdefList[0].toInt();
                myImage.yPosition = imgdefList[1].toInt();
                myImage.size = QSize(imgdefList[2].toInt(),
                                     imgdefList[3].toInt());
                myImage.container = container;

                d->m_images.insert(images.key(), myImage);
            }
        }

        if (filename.endsWith(".svg") && fileOpts.contains("named"))
        {
            QVariantMap value = fileOpts["named"].toMap();
            for (QVariantMap::iterator images = value.begin();
                 images != value.end(); ++images)
            {
                Image myImage;
                myImage.type = NamedType;
                myImage.name = images.value().toString();
                myImage.container = container;

                d->m_images.insert(images.key(), myImage);
            }
        }

        if (fileOpts.contains("cache"))
        {
            container->setCache(fileOpts["cache"].toBool());
        }
    } // for files
}
bool FEMemoryMetaData::parseMetaData(QString json)
{
	QJson::Parser parser;
	QVariant top = parser.parse(json.toStdString().c_str());
	if (!top.isValid())
	{
		QString errormsg = QString("Error parsing JSON from config file on line number: ") + QString::number(parser.errorLine()) + " error text: " + parser.errorString();
		qDebug() << "Error parsing JSON";
		qDebug() << "Line number:" << parser.errorLine() << "error text:" << parser.errorString();
		qDebug() << "Start Json";
		qDebug() << "Json:" << json;
		qDebug() << "End Json";
		return false;
	}
	QVariantMap topmap = top.toMap();
	QVariantMap errormap = topmap["errormap"].toMap();
	QVariantMap::iterator i = errormap.begin();
	while (i != errormap.end())
	{
		bool ok = false;
		m_errorMap[i.value().toString().mid(2).toInt(&ok,16)] = i.key();
		i++;
	}

	QVariantMap ramvars = topmap["ramvars"].toMap();
	i = ramvars.begin();
	while (i != ramvars.end())
	{
		bool ok = false;
		unsigned short locid = i.key().mid(2).toInt(&ok,16);
		m_readOnlyMetaDataMap[locid] = ReadOnlyRamBlock();
		QVariantMap locidlist = i.value().toMap();
		QString title = locidlist["title"].toString();
		m_readOnlyMetaDataMap[locid].title = title;
		QVariantList locidmap = locidlist["vars"].toList();
		int offset = 0;
		for (int j=0;j<locidmap.size();j++)
		{
			QVariantMap newlocidmap = locidmap[j].toMap();
			ReadOnlyRamData rdata;
			rdata.dataTitle = newlocidmap["name"].toString();
			rdata.dataDescription = newlocidmap["title"].toString();
			rdata.locationId = locid;
			rdata.offset = offset;
			rdata.size = newlocidmap["size"].toInt();
			offset += rdata.size;
			m_readOnlyMetaDataMap[locid].m_ramData.append(rdata);
			m_readOnlyMetaData.append(rdata);
		}
		i++;
	}

	QVariantMap lookups = topmap["lookuptables"].toMap();
	i = lookups.begin();
	while (i != lookups.end())
	{
		QVariantMap lookupmap = i.value().toMap();
		QString keystr = i.key();
		bool ok = false;
		unsigned short keyint = keystr.mid(2).toInt(&ok,16);
		LookupMetaData meta;
		meta.locationid = keyint;
		meta.title = lookupmap["title"].toString();
		if (lookupmap["editable"].toString().toLower() == "true")
		{
			meta.editable = true;
		}
		else
		{
			meta.editable = false;
		}
		m_lookupMetaData[keyint] = meta;
		i++;
	}
	qDebug() << m_readOnlyMetaData.size() << "Ram entries found";
	QVariantMap tables = topmap["tables"].toMap();
	i = tables.begin();
	while (i != tables.end())
	{
		QVariantMap tabledata = i.value().toMap();
		if (tabledata["type"] == "3D")
		{
			Table3DMetaData meta;
			QString id = tabledata["locationid"].toString();
			QString xtitle = tabledata["xtitle"].toString();
			QVariantList xcalc = tabledata["xcalc"].toList();
			QString xdp = tabledata["xdp"].toString();
			unsigned int size = tabledata["size"].toInt();

			QString ytitle = tabledata["ytitle"].toString();
			QVariantList ycalc = tabledata["ycalc"].toList();
			QString ydp = tabledata["ydp"].toString();

			QString ztitle = tabledata["ztitle"].toString();
			QVariantList zcalc = tabledata["zcalc"].toList();
			QString zdp = tabledata["zdp"].toString();

			QString xhighlight = tabledata["xhighlight"].toString();
			QString yhighlight = tabledata["yhighlight"].toString();

			QList<QPair<QString,double> > xcalclist;
			QList<QPair<QString,double> > ycalclist;
			QList<QPair<QString,double> > zcalclist;
			for (int j=0;j<xcalc.size();j++)
			{
				qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble();
				xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble()));
			}
			for (int j=0;j<ycalc.size();j++)
			{
				ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble()));
			}
			for (int j=0;j<zcalc.size();j++)
			{
				zcalclist.append(QPair<QString,double>(zcalc[j].toMap()["type"].toString(),zcalc[j].toMap()["value"].toDouble()));
			}

			bool ok = false;
			meta.locationId = id.mid(2).toInt(&ok,16);
			meta.tableTitle = i.key();
			meta.xAxisCalc = xcalclist;
			meta.xAxisTitle = xtitle;
			meta.xDp = xdp.toInt();
			meta.yAxisCalc = ycalclist;
			meta.yAxisTitle = ytitle;
			meta.yDp = ydp.toInt();
			meta.zAxisCalc = zcalclist;
			meta.zAxisTitle = ztitle;
			meta.zDp = zdp.toInt();
			meta.size = size;
			meta.valid = true;
			meta.xHighlight = xhighlight;
			meta.yHighlight = yhighlight;
            for (int i=0;i<m_table3DMetaData.size();i++)
            {
                if (m_table3DMetaData[i].locationId == meta.locationId)
                {
                    //Error, already exists;
                    qDebug() << "Error: Location ID 0x" + QString::number(meta.locationId,16).toUpper() + " is defined twice in the metadata file";
                    return false;
                }
            }
			m_table3DMetaData.append(meta);
		}
		else if (tabledata["type"] == "2D")
		{
			Table2DMetaData meta;
			QString id = tabledata["locationid"].toString();
			QString xtitle = tabledata["xtitle"].toString();
			QVariantList xcalc = tabledata["xcalc"].toList();
			QString xdp = tabledata["xdp"].toString();
			QString ytitle = tabledata["ytitle"].toString();
			QVariantList ycalc = tabledata["ycalc"].toList();
			QString ydp = tabledata["ydp"].toString();
			unsigned int size = tabledata["size"].toInt();
			QString xhighlight = tabledata["xhighlight"].toString();

			QList<QPair<QString,double> > xcalclist;
			QList<QPair<QString,double> > ycalclist;

			for (int j=0;j<xcalc.size();j++)
			{
				qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble();
				xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble()));
			}
			for (int j=0;j<ycalc.size();j++)
			{
				ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble()));
			}
			bool ok = false;
			meta.locationId = id.mid(2).toInt(&ok,16);
			meta.tableTitle = i.key();
			meta.xAxisCalc = xcalclist;
			meta.xAxisTitle = xtitle;
			meta.xDp = xdp.toInt();
			meta.yAxisCalc = ycalclist;
			meta.yAxisTitle = ytitle;
			meta.yDp = ydp.toInt();
			meta.size = size;
			meta.valid = true;
			meta.xHighlight = xhighlight;
            for (int i=0;i<m_table2DMetaData.size();i++)
            {
                if (m_table2DMetaData[i].locationId == meta.locationId)
                {
                    //Error, already exists;
                    qDebug() << "Error: Location ID 0x" + QString::number(meta.locationId,16).toUpper() + " is defined twice in the metadata file";
                    return false;
                }
            }
			m_table2DMetaData.append(meta);
		}
		i++;
	}
	return true;
}
Exemple #10
0
QString QJson::encodeData(const QVariant &data, EncodeOptions options, QString *errorMessage,
	int indentation, QString currentLinePrefix)
{
	QString indentedLinePrefix = options.testFlag(Compact) ?
		QString::fromLatin1("") :
		(currentLinePrefix + QString::fromLatin1(" ").repeated(indentation));

	QString optionalNewLine = options.testFlag(Compact) ?
		QString::fromLatin1("") :
		(QString::fromLatin1("\n") + currentLinePrefix);

	QString optionalIndentedNewLine = options.testFlag(Compact) ?
		QString::fromLatin1("") :
		(QString::fromLatin1("\n") + indentedLinePrefix);

	QString encoded;

	switch (data.type())
	{
	case(QVariant::Bool) :
		encoded += QString::fromLatin1(data.toBool() ? "true" : "false");
		break;

	case(QVariant::Int) :
	case(QVariant::UInt) :
	case(QVariant::LongLong) :
	case(QVariant::ULongLong) :
							  Q_ASSERT(data.canConvert(QVariant::String));
		encoded = data.toString();
		break;

	case(QVariant::Double) :
		encoded = QString::number(data.toDouble(), 'g', 16);
		if (!encoded.contains(QString::fromLatin1(".")) && !encoded.contains(QString::fromLatin1("e")))
			encoded += ".0";
		break;

	case(QVariant::String) :
		encoded = encodeString(data.toString());
		break;

	case(QVariant::ByteArray) :
		encoded = encodeByteArray(data.toByteArray());
		break;

	case(QVariant::List) :
	{
		encoded = QString::fromLatin1("[") + optionalIndentedNewLine;
		QVariantList list = data.toList();
		for (int i = 0; i < list.count(); ++i)
		{
			if (i) encoded += QString::fromLatin1(",") + optionalIndentedNewLine;
			encoded += encodeData(list.at(i), options, errorMessage, indentation, indentedLinePrefix);
			if (errorMessage && !errorMessage->isNull())
				return QString();
		}
		encoded += optionalNewLine + QString::fromLatin1("]");
	}
						 break;

	case(QVariant::StringList) :
	{
		encoded = QString::fromLatin1("[") + optionalIndentedNewLine;
		QStringList list = data.toStringList();
		for (int i = 0; i < list.count(); ++i)
		{
			if (i) encoded += QString::fromLatin1(",") + optionalIndentedNewLine;
			encoded += encodeData(list.at(i), options, errorMessage, indentation, indentedLinePrefix);
			if (errorMessage && !errorMessage->isNull())
				return QString();
		}
		encoded += optionalNewLine + QString::fromLatin1("]");
	}
							   break;

	case(QVariant::Map) :
	{
		encoded = QString::fromLatin1("{") + optionalIndentedNewLine;
		QVariantMap map = data.toMap();
		QVariantMap::iterator i;
		bool first = true;
		for (i = map.begin(); i != map.end(); ++i)
		{
			if (!first)
				encoded += QString::fromLatin1(",") + optionalIndentedNewLine;
			first = false;
			encoded += encodeString(i.key());
			encoded += options.testFlag(Compact) ? QString::fromLatin1(":") : QString::fromLatin1(" : ");
			encoded += encodeData(i.value(), options, errorMessage, indentation, indentedLinePrefix);
			if (errorMessage && !errorMessage->isNull())
				return QString();
		}
		encoded += optionalNewLine + QString::fromLatin1("}");
	}
						break;

	case(QVariant::Hash) :
	{
		encoded = QString::fromLatin1("{") + optionalIndentedNewLine;
		QVariantHash hash = data.toHash();
		QVariantHash::iterator i;
		bool first = true;
		for (i = hash.begin(); i != hash.end(); ++i)
		{
			if (!first)
				encoded += QString::fromLatin1(",") + optionalIndentedNewLine;
			first = false;
			encoded += encodeString(i.key());
			encoded += options.testFlag(Compact) ? QString::fromLatin1(":") : QString::fromLatin1(" : ");
			encoded += encodeData(i.value(), options, errorMessage, indentation, indentedLinePrefix);
			if (errorMessage && !errorMessage->isNull())
				return QString();
		}
		encoded += optionalNewLine + QString::fromLatin1("}");
	}
						 break;

	case(QVariant::Invalid) :
		encoded = QString::fromLatin1("null");
		break;

	default:
		if (!options.testFlag(EncodeUnknownTypesAsNull))
		{
			if (errorMessage)
				*errorMessage = QString::fromLatin1("Can't encode this type of data to JSON: %1")
				.arg(data.typeName());
			return QString();
		}
		encoded = QString::fromLatin1("null");
		break;
	}

	return encoded;
}
Exemple #11
0
bool Settings::save(const QString &path)
{
	if (path.isEmpty() && m_path.isEmpty())
	{
		m_hasError = true;

		return false;
	}

	QFile file(path.isEmpty() ? m_path : path);

	if (!file.open(QIODevice::WriteOnly))
	{
		m_hasError = true;

		return false;
	}

	m_hasError = false;

	bool canAddNewLine(false);
	QTextStream stream(&file);
	stream.setCodec("UTF-8");

	if (!m_comment.isEmpty())
	{
		QStringList comment(m_comment.split(QLatin1Char('\n')));

		for (int i = 0; i < comment.count(); ++i)
		{
			stream << QLatin1String("; ") << comment.at(i) << QLatin1Char('\n');
		}

		canAddNewLine = true;
	}

	QMap<QString, QVariantMap>::iterator groupsIterator;

	for (groupsIterator = m_data.begin(); groupsIterator != m_data.end(); ++groupsIterator)
	{
		if (groupsIterator.value().isEmpty())
		{
			continue;
		}

		if (canAddNewLine)
		{
			stream << QLatin1Char('\n');
		}
		else
		{
			canAddNewLine = true;
		}

		stream << QLatin1Char('[') << groupsIterator.key() << QLatin1String("]\n");

		QVariantMap::iterator keysIterator;

		for (keysIterator = groupsIterator.value().begin(); keysIterator != groupsIterator.value().end(); ++keysIterator)
		{
			stream << keysIterator.key() << QLatin1Char('=') << keysIterator.value().toString() << QLatin1Char('\n');
		}
	}

	file.close();

	return true;
}
Exemple #12
0
bool FEMemoryMetaData::parseMetaData(QString json)
{
	QJson::Parser parser;
	QVariant top = parser.parse(json.toStdString().c_str());
	if (!top.isValid())
	{
		QString errormsg = QString("Error parsing JSON from config file on line number: ") + QString::number(parser.errorLine()) + " error text: " + parser.errorString();
		//QMessageBox::information(0,"Error",errormsg);
		qDebug() << "Error parsing JSON";
		qDebug() << "Line number:" << parser.errorLine() << "error text:" << parser.errorString();
		qDebug() << "Start Json";
		qDebug() << "Json:" << json;
		qDebug() << "End Json";
		return false;
	}
	QVariantMap topmap = top.toMap();
	QVariantMap errormap = topmap["errormap"].toMap();
	QVariantMap::iterator i = errormap.begin();
	while (i != errormap.end())
	{
		bool ok = false;
		m_errorMap[i.value().toString().mid(2).toInt(&ok,16)] = i.key();
		i++;
	}

	QVariantMap ramvars = topmap["ramvars"].toMap();
	i = ramvars.begin();
	while (i != ramvars.end())
	{
		bool ok = false;
		unsigned short locid = i.key().mid(2).toInt(&ok,16);
		m_readOnlyMetaDataMap[locid] = ReadOnlyRamBlock();
		QVariantMap locidlist = i.value().toMap();
		QString title = locidlist["title"].toString();
		m_readOnlyMetaDataMap[locid].title = title;
		QVariantList locidmap = locidlist["vars"].toList();
		int offset = 0;
		for (int j=0;j<locidmap.size();j++)
		{
			QVariantMap newlocidmap = locidmap[j].toMap();
			ReadOnlyRamData rdata;
			rdata.dataTitle = newlocidmap["name"].toString();
			rdata.dataDescription = newlocidmap["title"].toString();
			rdata.locationId = locid;
			rdata.offset = offset;
			rdata.size = newlocidmap["size"].toInt();
			offset += rdata.size;
			m_readOnlyMetaDataMap[locid].m_ramData.append(rdata);
			m_readOnlyMetaData.append(rdata);
			//m_readOnlyMetaDataMap[locid].append(rdata);

		}
		/*QVariantMap::iterator j = locidmap.begin();
		while (j != locidmap.end())
		{
			if (j.key() == "title")
			{
				QString title = j.value().toString();
				qDebug() << "Location title:" << title;
			}
			else
			{
				qDebug() << j.key();
				QVariantMap valuemap = j.value().toMap();
				if (valuemap.contains("type"))
				{
					ConfigData cdata;
					cdata.configDescription = valuemap["title"].toString();
					cdata.configTitle = j.key();
					cdata.elementSize = valuemap["size"].toInt();
					cdata.locationId = locid;
					cdata.offset = valuemap["offset"].toInt();
					cdata.type = valuemap["type"].toString();
					QVariantMap calcmap = valuemap["calc"].toMap();
					QList<QPair<QString,double> > calclist;
					QVariantMap::iterator k = calcmap.begin();
					while (k != calcmap.end())
					{
						calclist.append(QPair<QString,double>(k.key(),k.value().toDouble()));
						k++;
					}
					cdata.elementCalc = calclist;
					if (valuemap["type"] == "value")
					{

					}
					else if (valuemap["type"] == "array")
					{
						cdata.arraySize = valuemap["arraysize"].toInt();
					}
					m_configMetaData.append(cdata);
				}

			}
			j++;
		}*/
		i++;
	}
	/*"lookuptables" : {
 "0x8000" : {
  "title": "IAT Transfer Table",
  "size" : "1024",
  "editable" : "false"
 },
 "0x8001" : {
  "title" : "CHT Transfer Table",
  "size" : "1024",
  "editable" : "false"
 }
}*/
	QVariantMap lookups = topmap["lookuptables"].toMap();
	i = lookups.begin();
	while (i != lookups.end())
	{
		QVariantMap lookupmap = i.value().toMap();
		QString keystr = i.key();
		bool ok = false;
		unsigned short keyint = keystr.mid(2).toInt(&ok,16);
		LookupMetaData meta;
		meta.locationid = keyint;
		meta.title = lookupmap["title"].toString();
		if (lookupmap["editable"].toString().toLower() == "true")
		{
			meta.editable = true;
		}
		else
		{
			meta.editable = false;
		}
		m_lookupMetaData[keyint] = meta;
		i++;
	}
	qDebug() << m_readOnlyMetaData.size() << "Ram entries found";
	QVariantMap tables = topmap["tables"].toMap();
	i = tables.begin();
	while (i != tables.end())
	{
		QVariantMap tabledata = i.value().toMap();
		if (tabledata["type"] == "3D")
		{
			Table3DMetaData meta;
			QString id = tabledata["locationid"].toString();
			QString xtitle = tabledata["xtitle"].toString();
			QVariantList xcalc = tabledata["xcalc"].toList();
			QString xdp = tabledata["xdp"].toString();
			unsigned int size = tabledata["size"].toInt();

			QString ytitle = tabledata["ytitle"].toString();
			QVariantList ycalc = tabledata["ycalc"].toList();
			QString ydp = tabledata["ydp"].toString();

			QString ztitle = tabledata["ztitle"].toString();
			QVariantList zcalc = tabledata["zcalc"].toList();
			QString zdp = tabledata["zdp"].toString();

			QString xhighlight = tabledata["xhighlight"].toString();
			QString yhighlight = tabledata["yhighlight"].toString();

			//QVariantMap::iterator calci = xcalc.begin();
			QList<QPair<QString,double> > xcalclist;
			QList<QPair<QString,double> > ycalclist;
			QList<QPair<QString,double> > zcalclist;
			for (int j=0;j<xcalc.size();j++)
			{
				qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble();
				xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble()));
			}
			for (int j=0;j<ycalc.size();j++)
			{
				ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble()));
			}
			for (int j=0;j<zcalc.size();j++)
			{
				zcalclist.append(QPair<QString,double>(zcalc[j].toMap()["type"].toString(),zcalc[j].toMap()["value"].toDouble()));
			}

			bool ok = false;
			meta.locationId = id.mid(2).toInt(&ok,16);
			meta.tableTitle = i.key();
			meta.xAxisCalc = xcalclist;
			meta.xAxisTitle = xtitle;
			meta.xDp = xdp.toInt();
			meta.yAxisCalc = ycalclist;
			meta.yAxisTitle = ytitle;
			meta.yDp = ydp.toInt();
			meta.zAxisCalc = zcalclist;
			meta.zAxisTitle = ztitle;
			meta.zDp = zdp.toInt();
			meta.size = size;
			meta.valid = true;
			meta.xHighlight = xhighlight;
			meta.yHighlight = yhighlight;
			m_table3DMetaData.append(meta);
		}
		else if (tabledata["type"] == "2D")
		{
			Table2DMetaData meta;
			QString id = tabledata["locationid"].toString();
			QString xtitle = tabledata["xtitle"].toString();
			QVariantList xcalc = tabledata["xcalc"].toList();
			QString xdp = tabledata["xdp"].toString();
			QString ytitle = tabledata["ytitle"].toString();
			QVariantList ycalc = tabledata["ycalc"].toList();
			QString ydp = tabledata["ydp"].toString();
			unsigned int size = tabledata["size"].toInt();
			QString xhighlight = tabledata["xhighlight"].toString();

			QList<QPair<QString,double> > xcalclist;
			QList<QPair<QString,double> > ycalclist;

			for (int j=0;j<xcalc.size();j++)
			{
				qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble();
				xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble()));
			}
			for (int j=0;j<ycalc.size();j++)
			{
				ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble()));
			}
			bool ok = false;
			meta.locationId = id.mid(2).toInt(&ok,16);
			meta.tableTitle = i.key();
			meta.xAxisCalc = xcalclist;
			meta.xAxisTitle = xtitle;
			meta.xDp = xdp.toInt();
			meta.yAxisCalc = ycalclist;
			meta.yAxisTitle = ytitle;
			meta.yDp = ydp.toInt();
			meta.size = size;
			meta.valid = true;
			meta.xHighlight = xhighlight;
			m_table2DMetaData.append(meta);
		}
		i++;
	}
	return true;
}
Exemple #13
0
void CFilesModel::IncrSync(const QVariantList& Files)
{
	QMap<QString, QList<SFileNode*> > New;
	QMap<uint64, SFileNode*> Old;

	foreach (const QVariant vFile, Files)
	{
		QVariantMap File = vFile.toMap();
		uint64 ID = File["ID"].toULongLong();

		bool bUpdate = true;
		
		SFileNode* pNode = m_Map.value(ID);
		if(File.value("FileState") == "Deprecated")
		{
			if(pNode)
				Old.insert(ID, pNode);
			continue;
		}

		SFileNode* pOldNode = NULL;
		if(pNode && ((File.contains("FileDir") && pNode->Path != File["FileDir"].toString()) || (File.contains("FileName") && pNode->Name  != File["FileName"].toString()))) 
		{
			pOldNode = pNode;

			Old.insert(ID, pNode);	
			pNode = NULL;
		}

		if(!pNode)
		{
			pNode = new SFileNode(ID);

			if(pOldNode)
			{
				pNode->File = pOldNode->File;
				pNode->Name = pOldNode->Name;
				pNode->Path = pOldNode->Path;
			}

			if(File.contains("FileDir"))
				pNode->Path = File["FileDir"].toString();
			if(File.contains("FileName"))
				pNode->Name = File["FileName"].toString();

			New[pNode->Path].append(pNode);
			bUpdate = false;
		}

		for(QVariantMap::iterator I = File.begin(); I != File.end(); I++)
			pNode->File[I.key()] = I.value();

		if(!bUpdate)
			continue;

		//
		QModelIndex Index;
		//emit dataChanged(createIndex(Index.row(), 0, pNode), createIndex(Index.row(), columnCount()-1, pNode));
		int Col = 0;
		bool State = false;
		for(int i = 0; i < columnCount(); i++)
		{
			bool Changed = false;
			switch(i)
			{
				case eFileName:		Changed = File.contains("FileName") || File.contains("FileState") || File.contains("KnownStatus"); break;
				case eSize:			Changed = File.contains("FileSize"); break;
				case eType:			Changed = File.contains("FileType"); break;
				case eStatus:		Changed = File.contains("FileState") || File.contains("FileStatus") || File.contains("FileJobs") || File.contains("HosterStatus"); break;
				case eProgress:		Changed = File.contains("Progress"); break;
				case eAvailability:	Changed = File.contains("Availability") || File.contains("AuxAvailability"); break;
				case eSources:		Changed = File.contains("ConnectedTransfers") || File.contains("CheckedTransfers") || File.contains("SeedTransfers") || File.contains("Transfers"); break;
				case eUpRate:		Changed = File.contains("Upload") || File.contains("UpRate"); break;
				case eDownRate:		Changed = File.contains("Download") || File.contains("DownRate"); break;
				case eUploaded:		Changed = File.contains("Uploaded") || File.contains("Downloaded") || File.contains("ShareRatio"); break;
				case eDownloaded:	Changed = File.contains("Downloaded"); break;
				case eQueuePos:		Changed = File.contains("QueuePos") || File.contains("Priority") || File.contains("Force") || File.contains("Upload") || File.contains("Download"); break;
			}

			if(State != Changed)
			{
				if(State)
				{
					if(!Index.isValid())
						Index = Find(m_Root, pNode);
					emit dataChanged(createIndex(Index.row(), Col, pNode), createIndex(Index.row(), i-1, pNode));
				}
				State = Changed;
				Col = i;
			}
		}
		if(State)
		{
			if(!Index.isValid())
				Index = Find(m_Root, pNode);
			emit dataChanged(createIndex(Index.row(), Col, pNode), createIndex(Index.row(), columnCount()-1, pNode));
		}
		//
	}
Exemple #14
0
void CTransfersModel::IncrSync(const QVariantList& Transfers, UINT Mode)
{
	QList<STransferNode*> New;
	QMap<uint64, STransferNode*> Old;

	foreach (const QVariant vTransfer, Transfers)
	{
		QVariantMap Transfer = vTransfer.toMap();
		uint64 SubID = Transfer["ID"].toULongLong();

		bool bUpdate = true;
		STransferNode* pNode = m_Map.value(SubID);
		if(Transfer.value("TransferStatus") == "Deprecated")
		{
			if(pNode)
				Old.insert(SubID, pNode);
			continue;
		}

		if(!pNode)
		{
			pNode = new STransferNode();
			pNode->SubID = SubID;
			pNode->ID = Transfer["FileID"].toULongLong();
			New.append(pNode);
			bUpdate = false;
		}

		for(QVariantMap::iterator I = Transfer.begin(); I != Transfer.end(); I++)
			pNode->Transfer[I.key()] = I.value();

		if(!bUpdate)
			continue;

		//
		int Row = m_List.indexOf(pNode);
		ASSERT(Row != -1);
		//emit dataChanged(createIndex(Row, 0), createIndex(Row, columnCount()-1));
		int Col = 0;
		bool State = false;
		for(int i = 0; i < columnCount(); i++)
		{
			bool Changed = false;
			switch(i)
			{
				case eUrl:			Changed = (Transfer.contains("Url")); break;
				case eFileName:		Changed = (Transfer.contains("FileName") || Transfer.contains("FileSize")); break;
				case eType:			Changed = (Transfer.contains("Type") || Transfer.contains("Found")); break;
				case eSoftware:		Changed = (Transfer.contains("Software")); break;
				case eStatus:		Changed = (Transfer.contains("TransferStatus") || Transfer.contains("UploadState") || Transfer.contains("DownloadState") || Transfer.contains("TransferInfo"));  break;
				case eProgress:		Changed = (Transfer.contains("Progress")); break;
				case eUpRate:		Changed = (Transfer.contains("Upload") || Transfer.contains("UpRate")); break;
				case eDownRate:		Changed = (Transfer.contains("Download") || Transfer.contains("DownRate")); break;
				case eUploaded:		Changed = (Transfer.contains("Uploaded")); break;
				case eDownloaded:	Changed = (Transfer.contains("Downloaded")); break;
			}

			if(State != Changed)
			{
				if(State)
					emit dataChanged(createIndex(Row, Col), createIndex(Row, i-1));
				State = Changed;
				Col = i;
			}
		}
		if(State)
			emit dataChanged(createIndex(Row, Col), createIndex(Row, columnCount()-1));
		//
	}
Exemple #15
0
void MemoryMetaData::loadMetaDataFromFile(QString filestr)
{


	qDebug() << "Loading config file from:" << filestr;
	QFile file(filestr);
	file.open(QIODevice::ReadOnly);
	QByteArray filebytes = file.readAll();
	file.close();

	QJson::Parser parser;
	QVariant top = parser.parse(filebytes);
	if (!top.isValid())
	{
		QString errormsg = QString("Error parsing JSON from config file on line number: ") + QString::number(parser.errorLine()) + " error text: " + parser.errorString();
		//QMessageBox::information(0,"Error",errormsg);
		qDebug() << "Error parsing JSON";
		qDebug() << "Line number:" << parser.errorLine() << "error text:" << parser.errorString();
		return;
	}
	QVariantMap topmap = top.toMap();
	QVariantMap errormap = topmap["errormap"].toMap();
	QVariantMap::iterator i = errormap.begin();
	while (i != errormap.end())
	{
		bool ok = false;
		m_errorMap[i.value().toString().mid(2).toInt(&ok,16)] = i.key();
		i++;
	}

	QVariantMap ramvars = topmap["ramvars"].toMap();
	i = ramvars.begin();
	while (i != ramvars.end())
	{
		bool ok = false;
		unsigned short locid = i.key().mid(2).toInt(&ok,16);
		m_readOnlyMetaDataMap[locid] = ReadOnlyRamBlock();
		QVariantMap locidlist = i.value().toMap();
		QString title = locidlist["title"].toString();
		m_readOnlyMetaDataMap[locid].title = title;
		QVariantList locidmap = locidlist["vars"].toList();
		int offset = 0;
		for (int j=0;j<locidmap.size();j++)
		{
			QVariantMap newlocidmap = locidmap[j].toMap();
			ReadOnlyRamData rdata;
			rdata.dataTitle = newlocidmap["name"].toString();
			rdata.dataDescription = newlocidmap["title"].toString();
			rdata.locationId = locid;
			rdata.offset = offset;
			rdata.size = newlocidmap["size"].toInt();
			offset += rdata.size;
			m_readOnlyMetaDataMap[locid].m_ramData.append(rdata);
			m_readOnlyMetaData.append(rdata);
			//m_readOnlyMetaDataMap[locid].append(rdata);

		}
		/*QVariantMap::iterator j = locidmap.begin();
		while (j != locidmap.end())
		{
			if (j.key() == "title")
			{
				QString title = j.value().toString();
				qDebug() << "Location title:" << title;
			}
			else
			{
				qDebug() << j.key();
				QVariantMap valuemap = j.value().toMap();
				if (valuemap.contains("type"))
				{
					ConfigData cdata;
					cdata.configDescription = valuemap["title"].toString();
					cdata.configTitle = j.key();
					cdata.elementSize = valuemap["size"].toInt();
					cdata.locationId = locid;
					cdata.offset = valuemap["offset"].toInt();
					cdata.type = valuemap["type"].toString();
					QVariantMap calcmap = valuemap["calc"].toMap();
					QList<QPair<QString,double> > calclist;
					QVariantMap::iterator k = calcmap.begin();
					while (k != calcmap.end())
					{
						calclist.append(QPair<QString,double>(k.key(),k.value().toDouble()));
						k++;
					}
					cdata.elementCalc = calclist;
					if (valuemap["type"] == "value")
					{

					}
					else if (valuemap["type"] == "array")
					{
						cdata.arraySize = valuemap["arraysize"].toInt();
					}
					m_configMetaData.append(cdata);
				}

			}
			j++;
		}*/
		i++;
	}
	qDebug() << m_readOnlyMetaData.size() << "Ram entries found";
	QVariantMap tables = topmap["tables"].toMap();
	i = tables.begin();
	while (i != tables.end())
	{
		QVariantMap tabledata = i.value().toMap();
		if (tabledata["type"] == "3D")
		{
			Table3DMetaData meta;
			QString id = tabledata["locationid"].toString();
			QString xtitle = tabledata["xtitle"].toString();
			QVariantList xcalc = tabledata["xcalc"].toList();
			QString xdp = tabledata["xdp"].toString();
			unsigned int size = tabledata["size"].toInt();

			QString ytitle = tabledata["ytitle"].toString();
			QVariantList ycalc = tabledata["ycalc"].toList();
			QString ydp = tabledata["ydp"].toString();

			QString ztitle = tabledata["ztitle"].toString();
			QVariantList zcalc = tabledata["zcalc"].toList();
			QString zdp = tabledata["zdp"].toString();

			//QVariantMap::iterator calci = xcalc.begin();
			QList<QPair<QString,double> > xcalclist;
			QList<QPair<QString,double> > ycalclist;
			QList<QPair<QString,double> > zcalclist;
			for (int j=0;j<xcalc.size();j++)
			{
				qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble();
				xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble()));
			}
			for (int j=0;j<ycalc.size();j++)
			{
				ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble()));
			}
			for (int j=0;j<zcalc.size();j++)
			{
				zcalclist.append(QPair<QString,double>(zcalc[j].toMap()["type"].toString(),zcalc[j].toMap()["value"].toDouble()));
			}

			bool ok = false;
			meta.locationId = id.mid(2).toInt(&ok,16);
			meta.tableTitle = i.key();
			meta.xAxisCalc = xcalclist;
			meta.xAxisTitle = xtitle;
			meta.xDp = xdp.toInt();
			meta.yAxisCalc = ycalclist;
			meta.yAxisTitle = ytitle;
			meta.yDp = ydp.toInt();
			meta.zAxisCalc = zcalclist;
			meta.zAxisTitle = ztitle;
			meta.zDp = zdp.toInt();
			meta.size = size;
			meta.valid = true;
			m_table3DMetaData.append(meta);
		}
		else if (tabledata["type"] == "2D")
		{
			Table2DMetaData meta;
			QString id = tabledata["locationid"].toString();
			QString xtitle = tabledata["xtitle"].toString();
			QVariantList xcalc = tabledata["xcalc"].toList();
			QString xdp = tabledata["xdp"].toString();
			QString ytitle = tabledata["ytitle"].toString();
			QVariantList ycalc = tabledata["ycalc"].toList();
			QString ydp = tabledata["ydp"].toString();
			unsigned int size = tabledata["size"].toInt();

			QList<QPair<QString,double> > xcalclist;
			QList<QPair<QString,double> > ycalclist;

			for (int j=0;j<xcalc.size();j++)
			{
				qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble();
				xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble()));
			}
			for (int j=0;j<ycalc.size();j++)
			{
				ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble()));
			}
			bool ok = false;
			meta.locationId = id.mid(2).toInt(&ok,16);
			meta.tableTitle = i.key();
			meta.xAxisCalc = xcalclist;
			meta.xAxisTitle = xtitle;
			meta.xDp = xdp.toInt();
			meta.yAxisCalc = ycalclist;
			meta.yAxisTitle = ytitle;
			meta.yDp = ydp.toInt();
			meta.size = size;
			meta.valid = true;
			m_table2DMetaData.append(meta);
		}
		i++;
	}
}