示例#1
0
QVariant QQmlStringConverters::variantFromString(const QString &s, int preferredType, bool *ok)
{
    switch (preferredType) {
    case QMetaType::Int:
        return QVariant(int(qRound(s.toDouble(ok))));
    case QMetaType::UInt:
        return QVariant(uint(qRound(s.toDouble(ok))));
#ifndef QT_NO_DATESTRING
    case QMetaType::QDate:
        return QVariant::fromValue(dateFromString(s, ok));
    case QMetaType::QTime:
        return QVariant::fromValue(timeFromString(s, ok));
    case QMetaType::QDateTime:
        return QVariant::fromValue(dateTimeFromString(s, ok));
#endif // QT_NO_DATESTRING
    case QMetaType::QPointF:
        return QVariant::fromValue(pointFFromString(s, ok));
    case QMetaType::QPoint:
        return QVariant::fromValue(pointFFromString(s, ok).toPoint());
    case QMetaType::QSizeF:
        return QVariant::fromValue(sizeFFromString(s, ok));
    case QMetaType::QSize:
        return QVariant::fromValue(sizeFFromString(s, ok).toSize());
    case QMetaType::QRectF:
        return QVariant::fromValue(rectFFromString(s, ok));
    case QMetaType::QRect:
        return QVariant::fromValue(rectFFromString(s, ok).toRect());
    default:
        return QQml_valueTypeProvider()->createVariantFromString(preferredType, s, ok);
    }
}
示例#2
0
void DOHLCVparser(const char* buff, int nbLine, char tokenID, Descriptor * d)
{
	DOHLCV* data = (DOHLCV*)d->dataPtr;
	switch (tokenID)
	{
		case 0:
			data[nbLine].date = dateFromString(buff);
			break;
		case 1:
			data[nbLine].open = (float)atof(buff);
			break;
		case 2:
			data[nbLine].high = (float)atof(buff);
			break;
		case 3:
			data[nbLine].low = (float)atof(buff);
			break;
		case 4:
			data[nbLine].close = (float)atof(buff);
			break;
		case 5:
			data[nbLine].volume = atoi(buff);
			break;
		default:
			throw "Wrong tokenID";
	} // switch (token)
} // void DOHLCVparser(char* buff, int nbLine, char token, Descriptor * d)
void AddTulpaWidget::loadTulpa(QString name)
{
    tulpa.loadByName(name.toStdString());

    this->lineEdits.at(LINE_EDIT_NAME)->setText(QString(tulpa.getName().c_str()));
    this->dateEdit->setDate(dateFromString(tulpa.getBirthTime()));
    this->lineEdits.at(LINE_EDIT_FIRST_WORD)->setText(QString(tulpa.getFirstWordTime().c_str()));

    for(unsigned int i=0;i<tulpa.getPersonalityTraits().size();i++)
    {
        personalityTraits << QString(tulpa.getPersonalityTrait(i).c_str());
    }

    loadPersonality(personalityTraits);
}
示例#4
0
Choqok::Post *TwitterSearch::readStatusesFromJsonMap(const QVariantMap &var)
{
    Choqok::Post *post = new Choqok::Post;

    post->content = var[QLatin1String("text")].toString();
    //%*s %s %d %d:%d:%d %d %d
    post->creationDateTime = dateFromString(var[QLatin1String("created_at")].toString());
    post->postId = var[QLatin1String("id")].toString();
    post->source = var[QLatin1String("source")].toString();
    QVariantMap userMap = var[QLatin1String("user")].toMap();
    post->author.realName = userMap[QLatin1String("name")].toString();
    post->author.userName = userMap[QLatin1String("screen_name")].toString();
    post->author.profileImageUrl = userMap[QLatin1String("profile_image_url")].toString();
    post->isPrivate = false;
    post->isFavorited = false;
    post->replyToPostId = var[QLatin1String("in_reply_to_status_id_str")].toString();
    post->replyToUserName = var[QLatin1String("in_reply_to_screen_name")].toString();

    post->link = QStringLiteral("https://twitter.com/%1/status/%2").arg(post->author.userName).arg(post->postId);

    return post;
}
QVariant QDeclarativeStringConverters::variantFromString(const QString &s, int preferredType, bool *ok)
{
    switch (preferredType) {
    case QMetaType::Int:
        return QVariant(int(qRound(s.toDouble(ok))));
    case QMetaType::UInt:
        return QVariant(uint(qRound(s.toDouble(ok))));
    case QMetaType::QColor:
        return QVariant::fromValue(colorFromString(s, ok));
#ifndef QT_NO_DATESTRING
    case QMetaType::QDate:
        return QVariant::fromValue(dateFromString(s, ok));
    case QMetaType::QTime:
        return QVariant::fromValue(timeFromString(s, ok));
    case QMetaType::QDateTime:
        return QVariant::fromValue(dateTimeFromString(s, ok));
#endif // QT_NO_DATESTRING
    case QMetaType::QPointF:
        return QVariant::fromValue(pointFFromString(s, ok));
    case QMetaType::QPoint:
        return QVariant::fromValue(pointFFromString(s, ok).toPoint());
    case QMetaType::QSizeF:
        return QVariant::fromValue(sizeFFromString(s, ok));
    case QMetaType::QSize:
        return QVariant::fromValue(sizeFFromString(s, ok).toSize());
    case QMetaType::QRectF:
        return QVariant::fromValue(rectFFromString(s, ok));
    case QMetaType::QRect:
        return QVariant::fromValue(rectFFromString(s, ok).toRect());
    case QMetaType::QVector3D:
        return QVariant::fromValue(vector3DFromString(s, ok));
    default:
        if (ok) *ok = false;
        return QVariant();
    }
}
示例#6
0
bool QQmlStringConverters::createFromString(int type, const QString &s, void *data, size_t n)
{
    Q_ASSERT(data);

    bool ok = false;

    switch (type) {
    case QMetaType::Int:
        {
        Q_ASSERT(n >= sizeof(int));
        int *p = reinterpret_cast<int *>(data);
        *p = int(qRound(s.toDouble(&ok)));
        return ok;
        }
    case QMetaType::UInt:
        {
        Q_ASSERT(n >= sizeof(uint));
        uint *p = reinterpret_cast<uint *>(data);
        *p = uint(qRound(s.toDouble(&ok)));
        return ok;
        }
#ifndef QT_NO_DATESTRING
    case QMetaType::QDate:
        {
        Q_ASSERT(n >= sizeof(QDate));
        QDate *p = reinterpret_cast<QDate *>(data);
        *p = dateFromString(s, &ok);
        return ok;
        }
    case QMetaType::QTime:
        {
        Q_ASSERT(n >= sizeof(QTime));
        QTime *p = reinterpret_cast<QTime *>(data);
        *p = timeFromString(s, &ok);
        return ok;
        }
    case QMetaType::QDateTime:
        {
        Q_ASSERT(n >= sizeof(QDateTime));
        QDateTime *p = reinterpret_cast<QDateTime *>(data);
        *p = dateTimeFromString(s, &ok);
        return ok;
        }
#endif // QT_NO_DATESTRING
    case QMetaType::QPointF:
        {
        Q_ASSERT(n >= sizeof(QPointF));
        QPointF *p = reinterpret_cast<QPointF *>(data);
        *p = pointFFromString(s, &ok);
        return ok;
        }
    case QMetaType::QPoint:
        {
        Q_ASSERT(n >= sizeof(QPoint));
        QPoint *p = reinterpret_cast<QPoint *>(data);
        *p = pointFFromString(s, &ok).toPoint();
        return ok;
        }
    case QMetaType::QSizeF:
        {
        Q_ASSERT(n >= sizeof(QSizeF));
        QSizeF *p = reinterpret_cast<QSizeF *>(data);
        *p = sizeFFromString(s, &ok);
        return ok;
        }
    case QMetaType::QSize:
        {
        Q_ASSERT(n >= sizeof(QSize));
        QSize *p = reinterpret_cast<QSize *>(data);
        *p = sizeFFromString(s, &ok).toSize();
        return ok;
        }
    case QMetaType::QRectF:
        {
        Q_ASSERT(n >= sizeof(QRectF));
        QRectF *p = reinterpret_cast<QRectF *>(data);
        *p = rectFFromString(s, &ok);
        return ok;
        }
    case QMetaType::QRect:
        {
        Q_ASSERT(n >= sizeof(QRect));
        QRect *p = reinterpret_cast<QRect *>(data);
        *p = rectFFromString(s, &ok).toRect();
        return ok;
        }
    default:
        return QQml_valueTypeProvider()->createValueFromString(type, s, data, n);
    }
}