예제 #1
0
QString ReportItemPara::paraText()
{
	qfLogFuncFrame();
	QString ret;
	if(m_getTextJsFn.isCallable()) {
		QJSValue jsv = m_getTextJsFn.call();
		if(jsv.isDate()) {
			QDateTime dt = jsv.toDateTime();
			ret = dt.toString(Qt::ISODate);//.date().toString(Qt::ISODate);
		}
		else
			ret = jsv.toString();
	}
	else if(m_getTextCppFn) {
		ret = m_getTextCppFn();
	}
	else {
		ret = text();
	}
	{
		static QString new_line;
		if(new_line.isEmpty())
			new_line += QChar::LineSeparator;
		ret.replace("\\n", new_line);
		ret.replace("\n", new_line);

		/// jinak nedokazu zadat mezeru mezi dvema <data> elementy nez <data>\s<data>
		ret.replace("\\s", " ");
		/// non breaking space
		ret.replace("\\S", QString(QChar::Nbsp));
	}
	return ret;
}
예제 #2
0
/**
 * @internal
 * @brief QBsonConverter::mapValue converts alls simple values and redirects to
 * mapObject and mapArray methods. If a value can not converted an
 * empty bsonvalue is returned.
 *
 * @param jsValue jsValue to convert
 *
 * @return QBsonValue
 */
QBsonValue QBsonConverter::mapValue(const QJSValue &jsValue)
{
    if (jsValue.isBool()) {
        return QBsonValue(jsValue.toBool());
    }
    if (jsValue.isDate()) {
        return QBsonValue(jsValue.toDateTime());
    }
    if (jsValue.isString()) {
        return QBsonValue(jsValue.toString());
    }
    if (jsValue.isNumber()) {
        int vType = jsValue.toVariant().type();
        switch (vType) {
            case QVariant::Double:
                return QBsonValue(jsValue.toVariant().toDouble());
                break;
            case QVariant::Int:
                return QBsonValue(jsValue.toVariant().toInt());
                break;
        }
    }
    if (jsValue.isArray()) {
        return mapArray(jsValue);
    }
    if (jsValue.isObject()) {
        return mapObject(jsValue);
    }

    return QBsonValue();
}
static QString qjsValueToString(const QJSValue &v)
{
  if (v.isArray()) {
    return QStringLiteral("<array>");
  } else if (v.isBool()) {
    return v.toBool() ? QStringLiteral("true") : QStringLiteral("false");
  } else if (v.isCallable()) {
    return QStringLiteral("<callable>");
  } else if (v.isDate()) {
    return v.toDateTime().toString();
  } else if (v.isError()) {
    return QStringLiteral("<error>");
  } else if (v.isNull()) {
    return QStringLiteral("<null>");
  } else if (v.isNumber()) {
    return QString::number(v.toNumber());
  } else if (v.isObject()) {
    return QStringLiteral("<object>");
  } else if (v.isQObject()) {
    return Util::displayString(v.toQObject());
  } else if (v.isRegExp()) {
    return QStringLiteral("<regexp>");
  } else if (v.isString()) {
    return v.toString();
  } else if (v.isUndefined()) {
    return QStringLiteral("<undefined>");
  } else if (v.isVariant()) {
    return VariantHandler::displayString(v.toVariant());
  }
  return QStringLiteral("<unknown QJSValue>");
}